status = "game"

---------**backgrounds and title screens**-----

    background = Image.load("backgrounds/background.png")
         

-----------**Walls**---------
         	 
	wall1 = Image.createEmpty(14,135) -----Top Left Hand Wall
	wall2 = Image.createEmpty(14,100) -----Bottom Left Hand Wall
	wall3 = Image.createEmpty(452,27) -----Top Wall
	wall4 = Image.createEmpty(40,66)  -----Middle Wall - Vertical
	wall5 = Image.createEmpty(30,38)  -----Middle Wall - Stone Block
	wall6 = Image.createEmpty(128,50) -----Middle Wall - Horizontal
	wall7 = Image.createEmpty(3,1)    -----Middle Wall - Right Pillar
	wall8 = Image.createEmpty(47,1)   -----Middle Door/Wall - Near bed
	wall9 = Image.createEmpty(14,120) -----Right Wall - Bottom
	wall10 = Image.createEmpty(74,19) -----Bottom Wall - Right Side
	wall11 = Image.createEmpty(283,19) ----Bottom Wall - Left Side
		
----------**Object Collision**---

	wall12 = Image.createEmpty(38,40) ------Table
	wall13 = Image.createEmpty(10,20) ------Chairs  
	wall14 = Image.createEmpty(30,1)  ------Stone Brick - Top Left
	wall15 = Image.createEmpty(30,2)  ------Fireplace? Top Middle
	wall16 = Image.createEmpty(8,2)   ------Box - Top Middle
	wall17 = Image.createEmpty(2,2)   ------Statue - Top Right
	wall18 = Image.createEmpty(43,1)  ------Table - Bottom Left
	wall19 = Image.createEmpty(43,1)  ------Table - Bottom Right
	wall20 = Image.createEmpty(10,1)  ------Chair - Bottom Left
	wall21 = Image.createEmpty(10,1)  ------Chair - Bottom Right
	wall22 = Image.createEmpty(17,16) ------Well? - Middle Next To Pillar
	wall23 = Image.createEmpty(19,14) ------zelda
	  
------------House Walls------
	   
   	wall1 = {x = 2, y = 6, height = wall1:height(), width = wall1:width() }
   	wall2 = {x = 2, y = 172, height = wall2:height(), width = wall2:width() } 
   	wall3 = {x = 3, y = 6, height = wall3:height(), width = wall3:width() }
   	wall4 = {x = 230, y = 29, height = wall4:height(), width = wall4:width() }
   	wall5 = {x = 225, y = 116, height = wall5:height(), width = wall5:width() }
   	wall6 = {x = 270, y = 98, height = wall6:height(), width = wall6:width() }
   	wall7 = {x = 394, y = 155, height = wall7:height(), width = wall7:width() } 
   	wall8 = {x = 399, y = 130, height = wall8:height(), width = wall8:width() }
   	wall9 = {x = 464, y = 130, height = wall9:height(), width = wall9:width() }
   	wall10 = {x = 366, y = 249, height = wall10:height(), width = wall10:width() }
   	wall11 = {x = 2, y = 249, height = wall11:height(), width = wall11:width() }
   	
----------Object walls-------   	
      
	wall12 = {x = 107, y = 79, height = wall12:height(), width = wall12:width() }
   	wall13 = {x = 150, y = 90, height = wall13:height(), width = wall13:width() }
   	wall14 = {x = 50, y = 41, height = wall14:height(), width = wall14:width() }
   	wall15 = {x = 104, y = 40, height = wall15:height(), width = wall15:width() }
   	wall16 = {x = 161, y = 41, height = wall16:height(), width = wall16:width() } 
   	wall17 = {x = 196, y = 40, height = wall17:height(), width = wall17:width() }
   	wall18 = {x = 86, y = 238, height = wall18:height(), width = wall18:width() }
   	wall19 = {x = 170, y = 238, height = wall19:height(), width = wall19:width() }
   	wall20 = {x = 106, y = 230, height = wall20:height(), width = wall20:width() }
   	wall21 = {x = 181, y = 230, height = wall21:height(), width = wall21:width() }
   	wall22 = {x = 281, y = 167, height = wall22:height(), width = wall22:width() }
   	wall23 = {x = 1, y = 152, height = wall23:height(), width = wall23:width() }
   	
---------------**collision**---------

function collisionCheck(test)
	
	if (player.x + playerWidth > test.x) and (player.x < test.x + test.width) and
	(player.y + playerHeight > test.y) and (player.y < test.y + test.height) then
	
	player.x = oldx
	player.y = oldy
	end
end


----------**music level 1**------

	Music.playFile("music/ingmusic1.it", true)  ----First House Music

------------------**functions**------------

----------player text---------

	function playertext()
       
---------character conversation-----

	if player.x >=20 and player.x <=25 and
	player.y >=110 and player.y <=150 and
	pad:cross() then
	select:play()
 	screen:blit(240, 80, box1)
	screen:print(258, 120, "What are", black)
	screen:print(254, 140, "you doing,.", black)
	screen:print(254, 160, "back here?.", black)
	screen.flip()
	screen.waitVblankStart(100)
 	screen:blit(240, 80, box1)
 	screen:print(254, 120, "Your quest.", black)
	screen:print(254, 140, "awaits....", black)
  	screen.flip()
	screen.waitVblankStart(100)
   	end

-------------chest empty---------

	if player.x >=140 and player.x <=165 and    
	player.y >=41 and player.y <=46 and
	pad:cross() then
	chest:play()
    screen:blit(180,50, box1)
 	screen:print(198,90, "The box", black)
 	screen:print(198, 110, "is empty", black)
    screen.flip()
   	screen.waitVblankStart(100)
 	end
 	
--------other--------

	if player.x >=82 and player.x <=166 and 
	player.y >=57 and player.y <=125 and
	pad:cross() then
	select:play()
	screen:blit(165,50, box1)
	screen:print(183,90, "A Table", black)
	screen:print(183,110, "& Chairs", black)
	screen.flip()
	screen.waitVblankStart(100)
	end
end
   
   
--------------**map loading**------

function maps()   ------Map 1 (Outside House)
 
	if player.x >=270 and player.x <=359 and
	player.y >=263 and player.y <=272 then
	player.img = player10
	player.x = 306
	player.y = 86
	dofile("map.lua")
	end 
end 

	while true do
	
	maps()
	
-------**store players position at beginning of each loop**----

	oldx = player.x
	oldy = player.y
	screen:clear()


-------init controls---------
	
	pad = Controls.read()
	
	---------init functions-----
	
	if pad:right() then    -----Right Movement
	moveRight()
	player.x = player.x + 2
 	end

	if pad:left() then    -----Left Movement
	moveLeft()
	player.x = player.x - 2
  	end

	if pad:up() then      -----Up Movement
	moveUp()
 	player.y = player.y - 2
	end

	if pad:down() then   -----Down Movement
	moveDown()
 	player.y = player.y + 2
	end

------**check collision for wall**-----
    
	if status == "game" then
	
	collisionCheck(wall1)
	collisionCheck(wall2)
	collisionCheck(wall3)
	collisionCheck(wall4)
	collisionCheck(wall5)
	collisionCheck(wall6)
	collisionCheck(wall7)
	collisionCheck(wall8)
	collisionCheck(wall9)
	collisionCheck(wall10)
	collisionCheck(wall11)
	collisionCheck(wall12)
	collisionCheck(wall13)
	collisionCheck(wall14)
	collisionCheck(wall15)
	collisionCheck(wall16)
	collisionCheck(wall17)
	collisionCheck(wall18)
	collisionCheck(wall19)
	collisionCheck(wall20)
	collisionCheck(wall21)
	collisionCheck(wall22)
	collisionCheck(wall23)
	end
	


-------**blit the background & player**------

	screen:blit(0, 0, background)
 	screen:blit(player.x, player.y, player.img)
 	screen:blit(3, 132, zelda)
   	screen:blit(400, 10, container)
 	screen:blit(417, 13, triangle)
 	screen:blit(432, 30, circle)
   	screen:blit(403, 30, square)
   	screen:blit(417, 45, cross)
 	screen:blit(404, 32, sword)
 	screen:blit(420, 15, bomb)
 	screen:blit(420, 49, maja)
 	screen:blit(2, 0, hearts)
 	screen:blit(240, 0, rupee)
   	screen.flip()
   	
------**init text**-----

   playertext()
   	
   	screen.waitVblankStart() 
end



	
    
    