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

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

	town2 = Image.load("backgrounds/town2.png")
	
-----------**Walls**---------
         	 
	wall1 = Image.createEmpty(1,35)   -----left hand roof, top
	wall2 = Image.createEmpty(1,35)   -----right hand roof, top
	wall3 = Image.createEmpty(1,1)    -----left hand house wall vertical part1
	wall4 = Image.createEmpty(1,20)   -----left  hand house wall vertical part2
	wall5 = Image.createEmpty(1,4)    -----right hand house wall vertical part1
	wall6 = Image.createEmpty(1,10)   -----right hand house wall vertical part2
	wall7 = Image.createEmpty(40,1)   -----Left hand (before door) house wall horizontal part1
	wall8 = Image.createEmpty(38,1)   -----Left hand (after door) house wall horizontal part2
	wall9 = Image.createEmpty(20,1)   -----door wall Left
	wall10 = Image.createEmpty(40,1)  -----Right hand (before door) house wall horizontal part1
	wall11 = Image.createEmpty(38,1)  -----Right hand (after door) house wall horizontal part2
   	wall13 = Image.createEmpty(89,1)  -----roof bottom Left
	wall14 = Image.createEmpty(89,1)  -----roof bottom Right
	wall15 = Image.createEmpty(1,1)   -----Roof Vertical, small edge of roof Right side
	wall16 = Image.createEmpty(1,10)  -----Right Roof Edge....1
	wall17 = Image.createEmpty(1,1)   -----Right Roof Edge....2
   	wall18 = Image.createEmpty(1,1)   -----Right Roof Edge....3
	wall19 = Image.createEmpty(1,1)   -----Right Roof Edge....4
	wall20 = Image.createEmpty(1,1)   -----Roof Vertical Right Side
	wall21 = Image.createEmpty(1,1)   -----Roof Vertical, small edge of roof Left side  
	wall22 = Image.createEmpty(1,10)  -----Left Roof Edge.....1
	wall23 = Image.createEmpty(1,1)   -----Left Roof Edge.....2
	wall24 = Image.createEmpty(1,1)   -----Left Roof Edge.....3
	wall25 = Image.createEmpty(1,1)   -----Left Roof Edge.....4
	wall26 = Image.createEmpty(1,3)   -----Roof Vertical Left Side
	wall27 = Image.createEmpty(44,40) -----Fountain Base
	wall28 = Image.createEmpty(67,8)  -----Fountain upper1
	wall29 = Image.createEmpty(60,3)  -----Fountain upper2
	wall30 = Image.createEmpty(12,8)  -----Fountain upper3
	wall31 = Image.createEmpty(70,1)  -----pond wall top
	wall32 = Image.createEmpty(1,30)  -----pond wall block1 left
	wall33 = Image.createEmpty(2,7)   -----pond wall block2 left
	wall34 = Image.createEmpty(18,9)  -----pond wall block1 right
		
------------Walls------
	   
   	wall1 = {x = 148, y = 0, height = wall1:height(), width = wall1:width() }
   	wall2 = {x = 338, y = 0, height = wall2:height(), width = wall2:width() } 
   	wall3 = {x = 138, y = 45, height = wall3:height(), width = wall3:width() }
   	wall4 = {x = 126, y = 60, height = wall4:height(), width = wall4:width() }
   	wall5 = {x = 350, y = 50, height = wall5:height(), width = wall5:width() }
   	wall6 = {x = 362, y = 72, height = wall6:height(), width = wall6:width() }
   	wall7 = {x = 82, y = 80, height = wall7:height(), width = wall7:width() } 
   	wall8 = {x = 0, y = 80, height = wall8:height(), width = wall8:width() }
   	wall9 = {x = 38, y = 60, height = wall9:height(), width = wall9:width() }
   	wall10 = {x = 364, y = 80, height = wall10:height(), width = wall10:width() }
   	wall11 = {x = 448, y = 80, height = wall11:height(), width = wall11:width() }
   	wall13 = {x = 0, y = 228, height = wall13:height(), width = wall13:width() }
   	wall14 = {x = 389, y = 228, height = wall14:height(), width = wall14:width() }
   	wall15 = {x = 377, y = 210, height = wall15:height(), width = wall15:width() }
   	wall16 = {x = 363, y = 222, height = wall16:height(), width = wall16:width() } 
   	wall17 = {x = 355, y = 245, height = wall17:height(), width = wall17:width() }
   	wall18 = {x = 346, y = 238, height = wall18:height(), width = wall18:width() }
   	wall19 = {x = 336, y = 250, height = wall19:height(), width = wall19:width() }
   	wall20 = {x = 337, y = 259, height = wall20:height(), width = wall20:width() }
   	wall21 = {x = 107, y = 215, height = wall21:height(), width = wall21:width() }
   	wall22 = {x = 120, y = 225, height = wall22:height(), width = wall22:width() }
   	wall23 = {x = 128, y = 245, height = wall23:height(), width = wall23:width() }
   	wall24 = {x = 134, y = 238, height = wall24:height(), width = wall24:width() }
   	wall25 = {x = 143, y = 250, height = wall25:height(), width = wall25:width() }   
   	wall26 = {x = 153, y = 259, height = wall26:height(), width = wall26:width() }
   	wall27 = {x = 220, y = 170, height = wall27:height(), width = wall27:width() }
   	wall28 = {x = 210, y = 127, height = wall28:height(), width = wall28:width() }
   	wall29 = {x = 214, y = 147, height = wall29:height(), width = wall29:width() }
   	wall30 = {x = 238, y = 162, height = wall30:height(), width = wall30:width() }
   	wall31 = {x = 222, y = 95, height = wall31:height(), width = wall31:width() }
   	wall32 = {x = 199, y = 96, height = wall32:height(), width = wall32:width() }
   	wall33 = {x = 182, y = 118, height = wall33:height(), width = wall33:width() }
   	wall34 = {x = 283, y = 114, height = wall34:height(), width = wall34: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 >=36 and player.x <=79 and
	player.y >=72 and player.y <=76 then
	player.x = 234
	player.y = 250
	player.img = player7
	dofile("shop2.lua")
	end
	   	
	if player.x >=402 and player.x <=442 and
	player.y >=72 and player.y <=76 then
	player.x = 234                
	player.y = 250
	player.img = player7
	dofile("shop1.lua")
	end 
	
	
	if player.x >=470 and player.x <=480 and
	player.y >=80 and player.y <=223 then
	player.x = 6
	player.y = 144
	player.img = player1
	dofile("map5.lua")
	end
      
    if player.x >=155 and player.x <=323 and
    player.y >=270 and player.y <=272 then
	player.y = 10
	player.img = player10
	dofile("map3.lua")
	end

	if player.x >=146 and player.x <=335 and
	player.y >=5 and player.y <=8 then
	player.x = 240
	player.y = 266
	player.img = player7
	dofile("map.lua")
	end

	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("map4.lua")
	end
end 
    
----------player text---------

	function playertext()
       
-------------talking---------

	if player.x >=190 and player.x <=213 and    
	player.y >=152 and player.y <=169 and
	pad:cross() then
	select:play()
    screen:blit(180,50, box1)
 	screen:print(198,80, "The Shops", black)
 	screen:print(198, 100, "have a", black)
 	screen:print(198, 120, "lot of", black)
 	screen:print(198, 140, "cool stuff", black)
 	screen:print(198, 160, "for sale", black)
    screen.flip()
   	screen.waitVblankStart(130)
 	end
 	
--------talking 2--------

	if player.x >=264 and player.x <=274 and 
	player.y >=146 and player.y <=162 and
	pad:cross() then
	select:play()
	screen:blit(165,50, box1)
 	screen:print(183,80, "My Dad", black)
 	screen:print(183, 100, "Works in", black)
 	screen:print(183, 120, "the shop", black)
 	screen:print(183, 140, "over there", 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**-----
    
	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(wall13)
	collisionCheck(wall14)
	collisionCheck(wall15)
	collisionCheck(wall16)
	collisionCheck(wall17)
	collisionCheck(wall18)
	collisionCheck(wall19)
	collisionCheck(wall20)
	collisionCheck(wall21)
	collisionCheck(wall22)
	collisionCheck(wall23)
	collisionCheck(wall24)
	collisionCheck(wall25)
	collisionCheck(wall26)
	collisionCheck(wall27)
	collisionCheck(wall28)
	collisionCheck(wall29)
	collisionCheck(wall30)
	collisionCheck(wall31)
	collisionCheck(wall32)
	collisionCheck(wall33)
	collisionCheck(wall34)
end
	
-------------**Blit To Screen**----

	screen:blit(0, 0, town2)
	screen:blit(player.x, player.y, player.img)
	screen:blit(210, 167, child2)
	screen:blit(251, 160, child1)
	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

  