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

	wall = nil

	status = "game"

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

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

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

	wall1 = Image.createEmpty(200,1)  -----Right Hand house horizontal 
	wall2 = Image.createEmpty(1,1)    -----Right hand house vetical
	wall3 = Image.createEmpty(98,1)   -----Middle Wall top
	wall4 = Image.createEmpty(1,2)    -----left house roof/wall vertical
	wall5 = Image.createEmpty(1,2)    -----left house wall vertical
	wall6 = Image.createEmpty(60,1)   -----left house wall, horizontal
	wall7 = Image.createEmpty(1,300)  -----Left Wall - vertical
	wall8 = Image.createEmpty(250,1)  -----Bottom Wall - Horizontal
	wall9 = Image.createEmpty(1,10)   -----Roof bottom Side Pilar
	wall10 = Image.createEmpty(20,1)  -----Roof bottom block1
	wall11 = Image.createEmpty(1,1)   -----Roof bottom block2
   	wall12 = Image.createEmpty(1,1)   -----Roof bottom block3
	wall13 = Image.createEmpty(250,1) -----Roof Wall bottom
             
------------Walls------

   	wall1 = {x = 285, y = 84, height = wall1:height(), width = wall1:width() }
   	wall2 = {x = 284, y = 82, height = wall2:height(), width = wall2:width() }
   	wall3 = {x = 163, y = 70, height = wall3:height(), width = wall3:width() }
   	wall4 = {x = 140, y = 76, height = wall4:height(), width = wall4:width() }
   	wall5 = {x = 127, y = 96, height = wall5:height(), width = wall5:width() }
   	wall6 = {x = 42, y = 96, height = wall6:height(), width = wall6:width() }
   	wall7 = {x = 39, y = 97, height = wall7:height(), width = wall7:width() }
   	wall8 = {x = 45, y = 254, height = wall8:height(), width = wall8:width() }
   	wall9 = {x = 292, y = 216, height = wall9:height(), width = wall9:width() }
   	wall10 = {x = 268, y = 247, height = wall10:height(), width = wall10:width() }
   	wall11 = {x = 281, y = 233, height = wall11:height(), width = wall11:width() }
	wall12 = {x = 257, y = 257, height = wall12:height(), width = wall12:width() }
   	wall13 = {x = 299, y = 229, height = wall13:height(), width = wall13: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 >=470 and player.x <=480 and
	player.y >=80 and player.y <=240 then
	player.x = 6
	player.y = 144
	player.img = player1
	dofile("map2.lua")
	end
end
     
----------player text---------

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

	if player.x >=36 and player.x <=47 and
	player.y >=145 and player.y <=203 and
	pad:cross() then
	select:play()
 	screen:blit(240, 80, box1)
	screen:print(254, 120, "Sorry", black)
	screen:print(254, 140, "you may", black)
	screen:print(254, 160, "not pass", black)
	screen.flip()
	screen.waitVblankStart(130)
   	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)

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

	screen:blit(0, 0, town4)
	screen:blit(player.x, player.y, player.img)
	screen:blit(25, 146, hylian1)
	screen:blit(25, 177, hylian2)
	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()
   	
   	playertext()

  screen.waitVblankStart()
  end


