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

	wall = nil

	status = "game"

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

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

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

	wall1 = Image.createEmpty(203,1)  -----house left
	wall2 = Image.createEmpty(120,1)  -----top wall
	wall3 = Image.createEmpty(1,1)    -----right house roof/wall 
	wall4 = Image.createEmpty(1,2)    -----right vertical house wall
	wall5 = Image.createEmpty(80,1)   -----right house wall horizontal
	wall6 = Image.createEmpty(1,57)   -----vertical wall 1 right side
	wall7 = Image.createEmpty(1,40)   -----vertical wall 2 right side
	wall8 = Image.createEmpty(300,1)  -----bottom horizontal wall 
	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(200,1) -----Bottom Roof Wall 
	wall14 = Image.createEmpty(1,40) -----Bottom Roof Wall
	
------------Walls------

   	wall1 = {x = 0, y = 85, height = wall1:height(), width = wall1:width() }
   	wall2 = {x = 207, y = 72, height = wall2:height(), width = wall2:width() }
   	wall3 = {x = 348, y = 87, height = wall3:height(), width = wall3:width() }
   	wall4 = {x = 356, y = 95, height = wall4:height(), width = wall4:width() }
   	wall5 = {x = 354, y = 94, height = wall5:height(), width = wall5:width() }
   	wall6 = {x = 450, y = 95, height = wall6:height(), width = wall6:width() }
   	wall7 = {x = 454, y = 215, height = wall7:height(), width = wall7:width() }
   	wall8 = {x = 230, y = 256, height = wall8:height(), width = wall8:width() }
   	wall9 = {x = 188, y = 216, height = wall9:height(), width = wall9:width() }
   	wall10 = {x = 200, y = 251, height = wall10:height(), width = wall10:width() }
   	wall11 = {x = 193, y = 233, height = wall11:height(), width = wall11:width() }
	wall12 = {x = 207, y = 240, height = wall12:height(), width = wall12:width() }
   	wall13 = {x = 0, y = 230, height = wall13:height(), width = wall13:width() }
   	wall14 = {x = 450, y = 168, height = wall14:height(), width = wall14: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>=1 and player.x <=5 and
	player.y >=80 and player.y <=223 then
	player.x = 467
	player.y = 165
	player.img = player4
	dofile("map2.lua")
	end
end

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

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

	if player.x >=390 and player.x <=439 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)
	collisionCheck(wall14)
	
-------------**Blit To Screen**----

	screen:blit(0, 0, town5)
	screen:blit(player.x, player.y, player.img)
	screen:blit(444, 146, hylian1)
	screen:blit(444, 179, 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


