
--------stop wall collision from first level-----

	wall = nil

	status = "game"

--------load map-------

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

-----------**Walls**---------

	wall1 = Image.createEmpty(1,23)   -----left vertical wall - enterance
	wall2 = Image.createEmpty(1,23)   -----right vertical wall - enterance
	wall3 = Image.createEmpty(23,1)   -----left horizontal wall 1
	wall4 = Image.createEmpty(1,250)  -----left vertical wall
	wall5 = Image.createEmpty(232,1)  -----horizontal wall - middle 
	wall6 = Image.createEmpty(1,135)  -----vertical wall - middle
	wall7 = Image.createEmpty(97,1)   -----horzontal wall - top
	wall8 = Image.createEmpty(1,480)  -----vertical wall - right
	wall9 = Image.createEmpty(370,1)  -----horizontal wall - bottom
	wall10 = Image.createEmpty(25,30) -----table left - bottom
   	wall11 = Image.createEmpty(4,2)   -----chair with left table
	wall12 = Image.createEmpty(5,2)   -----box....near chair - left
	wall13 = Image.createEmpty(44,2)  -----table - bottom
	wall14 = Image.createEmpty(60,2)  -----boxes - top left --sorta
	wall15 = Image.createEmpty(55,5)  -----table - top left
	wall16 = Image.createEmpty(6,3)   -----chair top left
	wall17 = Image.createEmpty(120,1) -----wall, tp right
	wall18 = Image.createEmpty(1,1)   -----statue top right
	wall19 = Image.createEmpty(5,2)   -----box top
	wall20 = Image.createEmpty(5,2)   -----box underneath
	
------------Walls------

   	wall1 = {x = 55, y = 247, height = wall1:height(), width = wall1:width() }
   	wall2 = {x = 124, y = 247, height = wall2:height(), width = wall2:width() }
   	wall3 = {x = 15, y = 247, height = wall3:height(), width = wall3:width() }
   	wall4 = {x = 16, y = 101, height = wall4:height(), width = wall4:width() }
   	wall5 = {x = 17, y = 136, height = wall5:height(), width = wall5:width() }
   	wall6 = {x = 248, y = 4, height = wall6:height(), width = wall6:width() }
   	wall7 = {x = 249, y = 36, height = wall7:height(), width = wall7:width() }
   	wall8 = {x = 469, y = 0, height = wall8:height(), width = wall8:width() }
   	wall9 = {x = 133, y = 248, height = wall9:height(), width = wall9:width() }
   	wall10 = {x = 129, y = 191, height = wall10:height(), width = wall10:width() }
   	wall11 = {x = 156, y = 210, height = wall11:height(), width = wall11:width() }
	wall12 = {x = 180, y = 231, height = wall12:height(), width = wall12:width() }
   	wall13 = {x = 314, y = 239, height = wall13:height(), width = wall13:width() }
   	wall14 = {x = 260, y = 103, height = wall14:height(), width = wall14:width() }
   	wall15 = {x = 260, y = 72, height = wall15:height(), width = wall15:width() }
   	wall16 = {x = 298, y = 60, height = wall16:height(), width = wall16:width() } 
   	wall17 = {x = 392, y = 36, height = wall17:height(), width = wall17:width() }
   	wall18 = {x = 414, y = 47, height = wall18:height(), width = wall18:width() }
   	wall19 = {x = 450, y = 61, height = wall19:height(), width = wall19:width() }
   	wall20 = {x = 450, y = 84, height = wall20:height(), width = wall20:width() }
   	  
-----------------**Collision Check**---------

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

--------------**map loading**------

function maps()   ------House

	if player.x >=346 and player.x <=378 and
	player.y >=35 and player.y <=40 then
	screen:blit(0,0,soon)
	screen.flip()
	screen.waitVblankStart(9999)
	end
     
	if player.x >=57 and player.x <=113 and
	player.y >=267 and player.y <=271 then
	player.x = 412                
	player.y = 145
	player.img = player10
	dofile("map3.lua")
	end
end


----------start main loop--------

	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**-----

	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)         

-------------**Blit To Screen**----

	screen:blit(0, 0, dungeon)
	screen:blit(player.x, player.y, player.img)
	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()

  screen.waitVblankStart()
  end

