Advertisement
CasterHorst

My game Done (Except spawning bug )

Jan 28th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.29 KB | None | 0 0
  1. Debug.Log ("Good Luck")
  2.  
  3. Level.Load ("Game.tmx")
  4.  
  5. player = {
  6.   object = nil,  
  7.   health = 1,
  8.   score = 0,
  9.   beenBitten = false,
  10.   beenHit = false,
  11.   canFire = true,
  12.   obstacle1 = nil,
  13.   obstacle2 = nil,
  14.   obstacle3 = nil,
  15.   obstacle4 = nil,
  16.   obstacle5 = nil,
  17.   gate = nil,
  18.   pause = true,
  19.   items = 0,
  20.   exit = nil,
  21.   ammo = 9,
  22. }
  23.  
  24. enemies= {
  25.   objects = nil,
  26.   health = math.random ( 3, 5 )
  27. }
  28.  
  29. sounds = {
  30.   bump2 = Sound.Load ( "Bump2.wav", false, false ),
  31.   walking = Sound.Load ( "Walking.wav", false, false ),
  32.   running = Sound.Load ( "Running.wav", false, false ),
  33.   horror = Sound.Load ( "Horror.wav", true, true ),
  34.   humming = Sound.Load ( "Humming.wav", true, true ),
  35.   heartbeat = Sound.Load ( "HeartBeat.wav", true, true ),
  36.   shoot = Sound.Load ( "Gunshot1.wav", false, false ),
  37.   impact = Sound.Load ( "Impact.mp3", false, false ),
  38.   reload = Sound.Load ( "Reload.wav", false, false ),
  39.   dying = Sound.Load ( "Scream.wav", false, false ),
  40.   stab = Sound.Load ( "Stab.wav", false, false ),
  41.   jasonDie = Sound.Load ( "JasonDie.wav", false, false ),
  42.   teleportIn = Sound.Load ( "Teleport2.wav", false, false ),
  43.   teleportOut = Sound.Load ( "Teleport.wav", false, false )
  44. }
  45.  
  46. function Start ()
  47.   Sound.Play ( sounds.horror )
  48.   Sound.Play ( sounds.humming )
  49.   Sound.Play ( sounds.heartbeat )
  50.   player.object = Level.GetObject ( "Player" )                                                          
  51.   player.keys = Level.GetObject ( "Key1" )
  52.   player.keys = Level.GetObject ( "Key2" )
  53.   player.keys = Level.GetObject ( "Key3" )
  54.   player.keys = Level.GetObject ( "Key4" )
  55.   player.keys = Level.GetObject ( "Key5" )
  56.   player.keys = Level.GetObject ( "Key6" )
  57.   obstacles1 = Level.GetObjects ( "Obstacle1" )
  58.   obstacles2 = Level.GetObjects ( "Obstacle2" )
  59.   obstacles3 = Level.GetObjects ( "Obstacle3" )
  60.   obstacles4 = Level.GetObjects ( "Obstacle4" )
  61.   obstacles5 = Level.GetObjects ( "Obstacle5" )
  62.   gates = Level.GetObjects ( "Gate" )
  63.   exit = Level.GetObjects ( "Exit" )
  64.   --Timer.Start ( "SpawnEnemy",1 , false )
  65.   if player.pause == true then
  66.     Hud.Message ( "You're trapped and being hunted!\n_______________________________Objectives:\nFind 6 Keys.\nFind as much money as you can.\nExit the Maze unscathed\n_______________________________\nTip:   Use Wasd to move and spacebar to shoot.\n_______________________________", 10 )
  67.     Camera.Follow ( player.object )
  68.     Timer.Start ( "Begin", 1, false )
  69.     Timer.Start ( "SpawnEnemy",1 , false )
  70.   end    
  71. end
  72.  
  73. function Update ()
  74.   if not player.pause then
  75.     DoPlayer ()
  76.     DoEnemy ()
  77.     DoHud ()
  78.     DoCamera ()
  79.     DoFiring ()
  80.     DoGate ()    
  81.   end
  82. end
  83.  
  84. function DoPlayer ()
  85.   move = Controller.Wasd (player.object, 3)  
  86.   if not move then
  87.     if not Sound.IsPlaying ( playingBump2 ) then
  88.       playingBump2 = Sound.Play ( sounds.bump2 )      
  89.     end    
  90.   end
  91. end
  92.  
  93. function DoEnemy ()
  94.   enemies.objects = Level.GetObjects ( "Enemy" )  
  95.   for i = 1, #enemies.objects do
  96.     enemy = enemies.objects [ i ]
  97.     moved = Controller.Patrol ( enemy , 1 )
  98.     if moved then
  99.       if Sound.IsPlaying (playingWalking ) == false then
  100.         playingWalking = Sound.Play ( sounds.walking )
  101.       end
  102.     end
  103.     if Level.InRange ( player.object,enemy, 224 ) then
  104.       moved = false
  105.       moving = Controller.Chase ( enemy, player.object, 2.3 )
  106.       if Sound.IsPlaying (playingRunning ) == false then
  107.         playingRunning = Sound.Play ( sounds.running )
  108.       end      
  109.     end        
  110.   end
  111. end
  112.  
  113. function DoHud ()
  114.   Hud.Score ( "Dollars: "..player.score )
  115.   Hud.Health ( "Bullets: "..player.ammo )
  116. end
  117.  
  118. function DoCamera ()
  119.   Camera.Follow ( player.object )
  120. end
  121.  
  122. function DoFiring ()
  123.   if Input.GetKey ( 32 ) and player.canFire then
  124.     Level.Fire ( player.object, "Bullet", 50, "Hit" )
  125.     playingShoot = Sound.Play ( sounds.shoot )
  126.     player.ammo = player.ammo - 1
  127.     player.canFire = false
  128.     Timer.Start ("canFireAgain" , 0.5, false )      
  129.     if player.ammo == 0 then
  130.       Debug.Log ( "reload" )
  131.       player.canFire = false
  132.       Timer.Start ("canFireAgain" , 2, false)
  133.       if not Sound.IsPlaying ( reloading ) then
  134.         reloading = Sound.Play ( sounds.reload )
  135.       end
  136.     end
  137.   end  
  138.   bullets = Level.GetObjects ( "Bullet" )
  139.   for i = 1, #bullets do                                    
  140.     bullet = bullets [ i ]
  141.     moved = Object.Forward ( bullet, 8 )
  142.     if not moved then
  143.       Level.RemoveObject ( bullet )  
  144.     end
  145.   end
  146. end
  147.  
  148. function DoGate ()
  149.   if player.items == 6 then
  150.     for i = 1, #gates do                                            
  151.       gate = gates [ i ]
  152.       Level.RemoveObject ( gate )
  153.       Hud.Message ( "You Unlocked the Main Door!\n\nFind the Exit!",3)
  154.   end  
  155. end
  156. end
  157.  
  158. --Triggers
  159. function Hit ( target, source )
  160.   name = Object.GetName ( target )
  161.   if name == "Enemy" then  
  162.     enemies.health = enemies.health - 1
  163.     Timer.Start ( "HitAgain", 0.1, false )
  164.     player.beenHit = true
  165.     if enemies.health == enemies.health - 1 then
  166.       if not Sound.IsPlaying ( hitting) then
  167.         hitting = Sound.Play ( sounds.impact )
  168.       end
  169.     end      
  170.   end      
  171.     if enemies.health == 0 then      
  172.       Sound.Play ( sounds.jasonDie )
  173.       Sound.Play ( sounds.teleportOut )
  174.       Level.RemoveObject ( enemy )
  175.       KillEnemy ()            
  176.     end
  177. end  
  178.  
  179. function CollectKey1 ( target, source )                
  180.   if target == player.object then  
  181.     player.items = player.items + 1
  182.     Level.RemoveObject ( source )    
  183.     Hud.Message ( "You collected the 1ste Key!", 2 )    
  184.   end
  185. end
  186.  
  187. function CollectKey2 ( target, source )                    
  188.   if target == player.object then  
  189.     player.items = player.items + 1
  190.     Level.RemoveObject ( source )      
  191.     Hud.Message ( "You collected the 2nd Key!", 3 )
  192.     for i = 1, #obstacles1 do                              
  193.     obstacle1 = obstacles1 [ i ]
  194.     Level.RemoveObject ( obstacle1 )
  195.     end  
  196.   end
  197. end
  198.  
  199. function CollectKey3 ( target, source )              
  200.   if target == player.object then    
  201.     player.items = player.items + 1
  202.     Level.RemoveObject ( source )
  203.     Hud.Message ( "You collected the 3rd Key!", 3 )
  204.     for i = 1, #obstacles2 do                                            
  205.     obstacle2 = obstacles2 [ i ]
  206.     Level.RemoveObject ( obstacle2 )
  207.     end
  208.   end
  209. end
  210.  
  211. function CollectKey4 ( target, source )
  212.   if target == player.object then  
  213.     player.items = player.items + 1
  214.     Level.RemoveObject ( source )
  215.     Hud.Message ( "You collected the 4th Key!", 3 )
  216.     for i = 1, #obstacles3 do                                            
  217.     obstacle3 = obstacles3 [ i ]
  218.     Level.RemoveObject ( obstacle3 )
  219.     end
  220.   end
  221. end
  222.  
  223. function CollectKey5 ( target, source )                                
  224.   if target == player.object then  
  225.     player.items = player.items + 1
  226.     Level.RemoveObject ( source )
  227.     Hud.Message ( "You collected the 5th Key!", 3 )
  228.     for i = 1, #obstacles5 do                                          
  229.     obstacle5 = obstacles5 [ i ]
  230.     Level.RemoveObject ( obstacle5 )
  231.     end
  232.   end
  233. end
  234.  
  235. function CollectKey6 ( target, source )                
  236.   if target == player.object then  
  237.     player.items = player.items + 1
  238.     Level.RemoveObject ( source )
  239.     Hud.Message ( "You collected the 6th Key!", 3 )    
  240.     for i = 1, #obstacles4 do                                            
  241.     obstacle4 = obstacles4 [ i ]
  242.     Level.RemoveObject ( obstacle4 )
  243.     end
  244.   end
  245. end
  246.  
  247. function CollectDollar ( target, source )      
  248.   if target == player.object then
  249.     player.score = player.score + 1
  250.     Dollars = Level.GetObjects ( "Dollar" )
  251.     Level.RemoveObject ( source )
  252.     if player.score == 1 then
  253.       Hud.Message ( "You Found a Dollar!\n\n There are More Left", 1.5)
  254.     end
  255.   end  
  256.     if player.score == 50 then
  257.       Hud.Message ( "Every Dollar Has Been Found!", 3 )
  258.     end  
  259. end
  260.  
  261. function BushBite ( target, source )      
  262.   if target == player.object and player.beenBitten == false then
  263.     player.health = player.health - 1
  264.     Sound.Play ( sounds.stab )
  265.     --Level.RemoveObject ( enemy )
  266.     --Timer.Start ( "BiteAgain", 1, true)
  267.     --Timer.Start ( "RegainHealth", 20, true )
  268.     --Timer.Start ( "SpawnEnemy",5, false )    
  269.   end  
  270.     if player.health <= 0 then
  271.       PlayerDied ()
  272.     end      
  273. end
  274.  
  275. function LeaveMaze ( target, source )
  276.   if target == player.object then
  277.     Level.RemoveObject ( player.object )
  278.     player.pause = true
  279.     Hud.Message ( "You Made It Out!",5 )
  280.     Timer.Start ( "GameOver" ,5,false )
  281.   end
  282. end
  283.  
  284. -- TimeOuts
  285. function Begin ()
  286.   player.pause = false
  287.   Hud.Message ("Run!!!", 1 )
  288. end
  289. function HitAgain ()
  290.   player.beenHit = false
  291. end
  292. function GameOver ()
  293.   if player.pause == true then
  294.     Hud.Message ( "Exit And Restart Game To Try Again.", 100 )
  295.    
  296.   end  
  297. end
  298.  
  299. function canFireAgain ()
  300.   if player.ammo > 0 then
  301.     player.canFire = true
  302.   end
  303.   if player.ammo == 0 then
  304.     player.ammo = player.ammo + 9
  305.     player.canFire = true
  306.   end
  307. end
  308. function SpawnEnemy()  
  309.   if not player.pause then
  310.     if move == false then
  311.       spawning = false
  312.  
  313.    
  314.       spawning = Level.Spawn ( "Enemy", (64), math.random ( 32*20, 32*25 ),math.random ( 32*23, 32*28 ), "BushBite" )
  315.     if spawning then
  316.       Sound.Play ( sounds.teleportIn )
  317.     end
  318.     end
  319.   end
  320.   Timer.Start ( "KillEnemy", 7, false )
  321. end
  322. function KillEnemy ()
  323.   if not player.pause then
  324.     if Level.RemoveObject ( enemy ) then
  325.       teleportout = Sound.Play ( sounds.teleportOut )
  326.     end
  327.     if enemies.health ==0 then
  328.       enemies.health = enemies.health + 2
  329.     end
  330.     Timer.Start ( "SpawnEnemy",10 , false )
  331.   end
  332. end
  333. function PlayerDied ()
  334.   Level.RemoveObject ( player.object )
  335.   --Level.RemoveObject ( enemy )
  336.   Level.RemoveObject ( bullet )
  337.   Sound.Play ( sounds.dying )
  338.   Sound.Stop ( Sound.Play ( sounds.heartbeat ) )
  339.   Timer.Stop ( Timer.Start( "SpawnEnemy", 1.0, true ))
  340.   Hud.Message ( "GAME OVER\n\n You Have Died",5 )
  341.   player.pause = true
  342.   Timer.Start ( "GameOver", 5, false )
  343. end
  344.  
  345. --function RegainHealth ()
  346.   --player.health = player.health + 1
  347.   --if player.health == 40 then
  348.     --Timer.Stop ( Timer.Start ( "RegainHealth", 20, true ) )
  349.   --end  
  350. --end
  351. --function BiteAgain ()
  352.   --player.beenBitten = false
  353. --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement