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

	wall = nil  
	
	status = "game"   		
	
--------load map-------

	town1 = Image.load("backgrounds/town1.png")
	     	
-----------**Walls**---------
         	 
	wall1 = Image.createEmpty(195,25) -----House Wall - Left Side
	wall2 = Image.createEmpty(42,25)  -----House Wall - Right Side
	wall3 = Image.createEmpty(48,2)   -----House Wall - Far Right
	wall4 = Image.createEmpty(2,75)   -----Right Hand Vertical Wall
	wall5 = Image.createEmpty(48,2)   -----House Wall - Far Left
	wall6 = Image.createEmpty(2,95)   -----Left Hand Vertical Wall
	wall7 = Image.createEmpty(48,2)   -----Roof Horisontal, Left Side, Next to Wall
	wall8 = Image.createEmpty(48,2)   -----Roof Horisontal, Right Side, Next to Wall
	wall9 = Image.createEmpty(1,10)   -----Roof Vertical, small edge of roof Right side
	wall10 = Image.createEmpty(1,10)  -----Right Roof Edge....1
	wall11 = Image.createEmpty(1,1)   -----Right Roof Edge....2
   	wall12 = Image.createEmpty(1,1)   -----Right Roof Edge....3
	wall13 = Image.createEmpty(1,1)   -----Right Roof Edge....4
	wall14 = Image.createEmpty(1,90)  -----Roof Vertical Right Side
	wall15 = Image.createEmpty(1,10)  -----Roof Vertical, small edge of roof Left side  
	wall16 = Image.createEmpty(1,1)   -----Left Roof Edge.....1
	wall17 = Image.createEmpty(1,1)   -----Left Roof Edge.....2
	wall18 = Image.createEmpty(1,1)   -----Left Roof Edge.....3
	wall19 = Image.createEmpty(1,1)   -----Left Roof Edge.....4
	wall20 = Image.createEmpty(1,90)  -----Roof Vertical Right Side
	wall21 = Image.createEmpty(6,25)  -----child
	wall22 = Image.createEmpty(6,25)  -----guard left
	wall23 = Image.createEmpty(6,25)  -----guard right	
	
------------Walls------
	   
   	wall1 = {x = 100, y = 58, height = wall1:height(), width = wall1:width() }
   	wall2 = {x = 338, y = 58, height = wall2:height(), width = wall2:width() } 
   	wall3 = {x = 396, y = 70, height = wall3:height(), width = wall3:width() }
   	wall4 = {x = 454, y = 71, height = wall4:height(), width = wall4:width() }
   	wall5 = {x = 40, y = 64, height = wall5:height(), width = wall5:width() }
   	wall6 = {x = 25, y = 80, height = wall6:height(), width = wall6:width() }
   	wall7 = {x = 42, y = 190, height = wall7:height(), width = wall7:width() } 
   	wall8 = {x = 386, y = 151, height = wall8:height(), width = wall8:width() }
   	wall9 = {x = 375, y = 140, height = wall9:height(), width = wall9:width() }
   	wall10 = {x = 355, y = 165, height = wall10:height(), width = wall10:width() }
   	wall11 = {x = 360, y = 156, height = wall11:height(), width = wall11:width() }
	wall12 = {x = 364, y = 155, height = wall12:height(), width = wall12:width() }
   	wall13 = {x = 340, y = 172, height = wall13:height(), width = wall13:width() }
   	wall14 = {x = 334, y = 181, height = wall14:height(), width = wall14:width() }
   	wall15 = {x = 110, y = 180, height = wall15:height(), width = wall15:width() }
   	wall16 = {x = 115, y = 206, height = wall16:height(), width = wall16:width() } 
   	wall17 = {x = 123, y = 190, height = wall17:height(), width = wall17:width() }
   	wall18 = {x = 136, y = 205, height = wall18:height(), width = wall18:width() }
   	wall19 = {x = 146, y = 215, height = wall19:height(), width = wall19:width() }
   	wall20 = {x = 151, y = 220, height = wall20:height(), width = wall20:width() }
   	wall21 = {x = 165, y = 100, height = wall21:height(), width = wall21:width() }
   	wall22 = {x = 275, y = 82, height = wall22:height(), width = wall22:width() }
   	wall23 = {x = 361, y = 82, height = wall23:height(), width = wall23: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 >=290 and player.x <=359 and
	player.y >=70 and player.y <=80 then
 	player.y = 260
	player.img = player7
	dofile("house.lua")
	end 
    
    if player.x >=100 and player.x <=323 and
    player.y >=270 and player.y <=272 then
	player.y = 10
	player.img = player10
	dofile("map2.lua")
	end
end 

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

	function playertext()

--------**character interaction**--------

    if player.x >=262 and player.x <=280 and 
	player.y >=100 and player.y <=110 and
	pad:cross() then
	select:play()
	screen:blit(165,50, box1)
	screen:print(183,80, "Hello there.", black)
	screen:print(183,100, "Don't worry.", black)
	screen:print(183,120, "Zelda is,", black)
	screen:print(183,140, "safe with", black)
	screen:print(183,160, "us.", black)
	screen.flip()
	screen.waitVblankStart(130)
	end

    if player.x >=338 and player.x <=363 and 
	player.y >=100 and player.y <=110 and
	pad:cross() then
	select:play()                       
	screen:blit(165,50, box1)
	screen:print(183,80, "Your eyes", black)
	screen:print(183,100, "seem to", black)
	screen:print(183,120, "be filled,", black)
	screen:print(183,140, "with a", black)
	screen:print(178,160, "burning rage", black)
	screen.flip()
	screen.waitVblankStart(130)
	end
    
	if player.x >=143 and player.x <=163 and 
	player.y >=124 and player.y <=130 and
	pad:cross() then
	select:play()
	screen:blit(165,50, box1)
	screen:print(183,80, "Hello, you", black)
	screen:print(183,100, "look angry!", black)
	screen:print(183,120, "Are you,", black)
	screen:print(183,140, "seeking", black)
	screen:print(183,160, "revenge?", black)
	screen.flip()
	screen.waitVblankStart(130)
	end
end
   
----------**music level 1**------

	Music.playFile("music/ingmusic2.it", true)

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

	screen:blit(0, 0, town1)
	screen:blit(player.x, player.y, player.img)
	screen:blit(154, 100, child1)
	screen:blit(269, 70, hylian1)
	screen:blit(351, 70, hylian1) 
	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

  