	status = "game"

------------**init some colors**-----

	blue = Color.new(0 , 153, 255)
	black = Color.new(0, 0, 0)
	orange = Color.new(255, 102, 0)

---------**backgrounds and title screens**-----

    background = Image.load("backgrounds/background.png")
    title = Image.load("backgrounds/title.png")
    shopmenu = Image.load("backgrounds/shopmenu.png")
    soon = Image.load("backgrounds/soon.png")

--------Right sprites---------

	player1 = Image.load("sprites/right1.png")
	player2 = Image.load("sprites/right2.png")
	player3 = Image.load("sprites/right3.png")

---------left sprites--------

	player4 = Image.load("sprites/left1.png")
	player5 = Image.load("sprites/left2.png")
	player6 = Image.load("sprites/left3.png")

-------Up sprites-------------

	player7 = Image.load("sprites/up1.png")
	player8 = Image.load("sprites/up2.png")
	player9 = Image.load("sprites/up3.png")
       	
-------Down sprites------------

	player10 = Image.load("sprites/down1.png")
	player11 = Image.load("sprites/down2.png")
	player12 = Image.load("sprites/down3.png")

-------**Townspeople**----

	zelda = Image.load("townspeople/zelda.png")
	child1 = Image.load("townspeople/child1.png")
	child2 = Image.load("townspeople/child2.png")
	hylian1 = Image.load("townspeople/hylian1.png")
	hylian2 = Image.load("townspeople/hylian2.png")
	postman = Image.load("townspeople/postman.png")
	shopkeeper1 = Image.load("townspeople/shopkeeper1.png")
	shopkeeper2 = Image.load("townspeople/shopkeeper2.png")
	shopkeeper3 = Image.load("townspeople/shopkeeper3.png")
	   
-------**objects**-----

	box1 = Image.load("objects/box1.png")
	rupee = Image.load("objects/rupee.png")
 	triangle = Image.load("objects/triangle.png")
	circle = Image.load("objects/circle.png")
	square = Image.load("objects/square.png")
	cross = Image.load("objects/cross.png")
	bomb =  Image.load("objects/bomb.png")
	sword = Image.load("objects/sword.png")
	explode = Image.load("objects/explode.png")
	hearts = Image.load("objects/hearts.png")
	container = Image.load("objects/container.png")
	maja = Image.load("objects/maja.png")
		
----------**Sound Loading**----

	att = Sound.load("music/att.wav", false)
	chest = Sound.load("music/chest.wav", false)
	select = Sound.load("music/select.wav", false)
	
-----------**Walls**---------
         	 
	wall1 = Image.createEmpty(14,135) -----Top Left Hand Wall
	wall2 = Image.createEmpty(14,100) -----Bottom Left Hand Wall
	wall3 = Image.createEmpty(452,27) -----Top Wall
	wall4 = Image.createEmpty(40,70)  -----Middle Wall - Vertical
	wall5 = Image.createEmpty(30,38)  -----Middle Wall - Stone Block
	wall6 = Image.createEmpty(128,50) -----Middle Wall - Horizontal
	wall7 = Image.createEmpty(3,1)    -----Middle Wall - Right Pillar
	wall8 = Image.createEmpty(47,1)   -----Middle Door/Wall - Near bed
	wall9 = Image.createEmpty(14,120) -----Right Wall - Bottom
	wall10 = Image.createEmpty(74,19) -----Bottom Wall - Right Side
	wall11 = Image.createEmpty(283,19) ----Bottom Wall - Left Side
		
----------**Object Collision**---

	wall12 = Image.createEmpty(38,40) ------Table
	wall13 = Image.createEmpty(10,20) ------Chairs  
	wall14 = Image.createEmpty(30,1)  ------Stone Brick - Top Left
	wall15 = Image.createEmpty(30,2)  ------Fireplace? Top Middle
	wall16 = Image.createEmpty(8,2)   ------Box - Top Middle
	wall17 = Image.createEmpty(2,2)   ------Statue - Top Right
	wall18 = Image.createEmpty(43,1)  ------Table - Bottom Left
	wall19 = Image.createEmpty(43,1)  ------Table - Bottom Right
	wall20 = Image.createEmpty(10,1)  ------Chair - Bottom Left
	wall21 = Image.createEmpty(10,1)  ------Chair - Bottom Right
	wall22 = Image.createEmpty(17,16) ------Well? - Middle Next To Pillar
	wall23 = Image.createEmpty(19,14) ------zelda
	  
------------House Walls------
	   
   	wall1 = {x = 2, y = 6, height = wall1:height(), width = wall1:width() }
   	wall2 = {x = 2, y = 172, height = wall2:height(), width = wall2:width() } 
   	wall3 = {x = 3, y = 6, height = wall3:height(), width = wall3:width() }
   	wall4 = {x = 230, y = 29, height = wall4:height(), width = wall4:width() }
   	wall5 = {x = 225, y = 116, height = wall5:height(), width = wall5:width() }
   	wall6 = {x = 270, y = 98, height = wall6:height(), width = wall6:width() }
   	wall7 = {x = 394, y = 155, height = wall7:height(), width = wall7:width() } 
   	wall8 = {x = 399, y = 130, height = wall8:height(), width = wall8:width() }
   	wall9 = {x = 464, y = 130, height = wall9:height(), width = wall9:width() }
   	wall10 = {x = 366, y = 249, height = wall10:height(), width = wall10:width() }
   	wall11 = {x = 2, y = 249, height = wall11:height(), width = wall11:width() }
   	
----------Object walls-------   	
      
	wall12 = {x = 107, y = 79, height = wall12:height(), width = wall12:width() }
   	wall13 = {x = 150, y = 90, height = wall13:height(), width = wall13:width() }
   	wall14 = {x = 50, y = 41, height = wall14:height(), width = wall14:width() }
   	wall15 = {x = 104, y = 40, height = wall15:height(), width = wall15:width() }
   	wall16 = {x = 161, y = 41, height = wall16:height(), width = wall16:width() } 
   	wall17 = {x = 196, y = 40, height = wall17:height(), width = wall17:width() }
   	wall18 = {x = 86, y = 238, height = wall18:height(), width = wall18:width() }
   	wall19 = {x = 170, y = 238, height = wall19:height(), width = wall19:width() }
   	wall20 = {x = 106, y = 230, height = wall20:height(), width = wall20:width() }
   	wall21 = {x = 181, y = 230, height = wall21:height(), width = wall21:width() }
   	wall22 = {x = 281, y = 167, height = wall22:height(), width = wall22:width() }
   	wall23 = {x = 1, y = 152, height = wall23:height(), width = wall23:width() }
   	                             

--------**player values**---------

	player = {}
	player.x = 420
	player.y = 140
	playerHeight = 20
	playerWidth = 25

	player.img = player10

---------------**character values**----

-----------**Timer init**--------

	counter = Timer.new()
	counter:start()
    oldTime = counter:time()
    
---------**timer values**--------
    
    Timer = 0

-------------**player sprite loading & Timer values**--------
   
function moveRight()   ------Right Animation
Timer = Timer + 1
  
   
 	if Timer>= 20 or Timer<=0  then
    Timer = 0
  	end         
			                 
        if Timer==5 then
        player.img = player1
        end
        
        if Timer==10 then
        player.img = player2
        end
        
		if Timer==15 then
		player.img = player3
		counter:reset()
		end
 end

function  moveLeft()   ------Left Animation
  Timer = Timer + 1

	if Timer>= 20 or Timer<=0 then
	    Timer = 0
	    end
	           	            			    
		if Timer==5 then
		player.img = player4
		end
		
		if Timer==10 then
		player.img = player5
		end
		
		if Timer==15 then
		player.img = player6
		counter:reset()
		end
 end

function moveUp()    ------Up Animation
   Timer  = Timer + 1
   
        if Timer>= 20 or Timer <= 0 then
        Timer = 0
		end
		
		if Timer==5 then
		player.img = player7
		end
		
		if Timer==10 then
		player.img  = player8
		end
		
		if Timer==15 then
		player.img = player9
		counter:reset()
		end
end


function moveDown()  ------Down Animation
   Timer = Timer + 1
   
        if Timer>= 20 or Timer<=0 then
        Timer = 0
        end
        
        if Timer==5 then
        player.img = player10
        end
        
        if Timer==10 then
        player.img = player11
        end
        
        if Timer==15 then
		player.img = player12
		counter:reset()
		end
 end

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

function maps()   ------Map 1 (Outside House)
 
	if player.x >=270 and player.x <=359 and
	player.y >=263 and player.y <=272 then
    player.x = 306
	player.y = 86
	player.img = player10
   	dofile("map.lua")
	end 
end 

---------------**collision**---------

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

----------**music level 1**------

	Music.playFile("music/ingmusic1.it", true)  ----First House Music

------------------**functions**------------

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

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

	if player.x >=20 and player.x <=25 and
	player.y >=110 and player.y <=150 and
	pad:cross() then
	select:play()
 	screen:blit(240, 80, box1)
	screen:print(254, 120, "Linken, You", black)
	screen:print(254, 140, "have awoken.", black)
	screen:print(254, 160, "Go outside.", black)
	screen.flip()
	screen.waitVblankStart(130)
 	screen:blit(240, 80, box1)
 	screen:print(254, 120, "And begin.", black)
	screen:print(254, 140, "your quest.", black)
  	screen.flip()
	screen.waitVblankStart(130)
   	end

-------------chest empty---------

	if player.x >=140 and player.x <=165 and    
	player.y >=41 and player.y <=46 and
	pad:cross() then
	chest:play()
    screen:blit(180,50, box1)
 	screen:print(198,90, "The box", black)
 	screen:print(198, 110, "is empty", black)
    screen.flip()
   	screen.waitVblankStart(130)
 	end
 	
--------other--------

	if player.x >=82 and player.x <=166 and 
	player.y >=57 and player.y <=125 and
	pad:cross() then
	select:play()
	screen:blit(165,50, box1)
	screen:print(183,90, "A Table", black)
	screen:print(183,110, "& Chairs", black)
	screen.flip()
	screen.waitVblankStart(130)
	end
end
   
--------**Start Main Game Loop**-----

     while true do
     
-------**load Map**---------

    maps()
      
-------**store players position at beginning of each loop**----

	oldx = player.x
	oldy = player.y
	screen:clear()

---------**init gamepad**-------

	pad = Controls.read()

---------**player movement**---

	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

------------**Other**--------

 	if pad:select() then screen:save("screenshot.png") end  ----Take Screenshot 
	
------**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 the background & player**------

	screen:blit(0, 0, background)
 	screen:blit(player.x, player.y, player.img)
  	screen:blit(3, 132, zelda)
   	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()
   
-------**end loop**-----
               
	screen.waitVblankStart()                                          
end
