Advertisement
CasterHorst

Untitled

Jan 26th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.32 KB | None | 0 0
  1. Debug.Log ("Good Luck")
  2.  
  3. Level.Load ("Game.tmx")
  4.  
  5. player = {
  6.   object = nil,
  7.   music = nil,  
  8.   health = 40,
  9.   score = 0,
  10.   beenBitten = false,
  11.   beenHit = false,
  12.   canFire = true,
  13.   obstacle1 = nil,
  14.   obstacle2 = nil,
  15.   obstacle3 = nil,
  16.   obstacle4 = nil,
  17.   keys = 0,
  18.   gate = nil,
  19.   pause = false,
  20.   items = 0,
  21.   exit = nil,
  22. }
  23.  
  24. enemies= {
  25.   objects = nil,
  26.   health = 2
  27. }
  28.  
  29. sounds = {
  30.   horror = Sound.Load ( "Horror.wav", true, true ),
  31.   humming = Sound.Load ( "Humming.wav", true, true ),
  32.   heartbeat = Sound.Load ( "HeartBeat.wav", true, true ),
  33.   shoot = Sound.Load ( "Gunshot1.wav", false, false ),
  34.   reload = Sound.Load ( "Reload.wav", false, false ),
  35.   dying = Sound.Load ( "Scream.wav", false, false),
  36.   stabing
  37. }
  38.  
  39. function Start ()
  40.   Sound.Play ( sounds.horror )
  41.   Sound.Play ( sounds.humming )
  42.   Sound.Play ( sounds.heartbeat )
  43.   player.object = Level.GetObject ( "Player" )                                                          
  44.   player.keys = Level.GetObject ( "Key1" )
  45.   player.keys = Level.GetObject ( "Key2" )
  46.   player.keys = Level.GetObject ( "Key3" )
  47.   player.keys = Level.GetObject ( "Key4" )
  48.   player.keys = Level.GetObject ( "Key5" )
  49.   player.keys = Level.GetObject ( "Key6" )
  50.   obstacles1 = Level.GetObjects ( "Obstacle1" )
  51.   obstacles2 = Level.GetObjects ( "Obstacle2" )
  52.   obstacles3 = Level.GetObjects ( "Obstacle3" )
  53.   obstacles4 = Level.GetObjects ( "Obstacle4" )
  54.   gates = Level.GetObjects ( "Gate" )
  55.   exit = Level.GetObjects ( "Exit" )
  56.   Hud.Message ( "Run!!\n\nYou're Being Hunted!", 4 )
  57.   Timer.Start ( "SpawnEnemy",5 , false )  
  58. end
  59.  
  60. function Update ()
  61.   if not player.pause then
  62.     DoPlayer ()
  63.     DoEnemy ()
  64.     DoHud ()
  65.     DoCamera ()
  66.     DoFiring ()
  67.     DoGate ()
  68.     --DoExit ()
  69.   end
  70. end
  71.  
  72. function DoPlayer ()
  73.   move = Controller.Wasd (player.object, 3)    
  74.   if not move then
  75.     if not Sound.IsPlaying ( playingBump ) then
  76.       playingBump = Sound.Play ( sounds.bump )      
  77.     end    
  78.   end
  79. end  
  80.  
  81. function DoEnemy ()
  82.   enemies.objects = Level.GetObjects ( "Enemy" )  
  83.   for i = 1, #enemies.objects do
  84.     enemy = enemies.objects [ i ]
  85.     move = Controller.Chase ( enemy, player.object, 1 )
  86.   end  
  87. end
  88.  
  89. function DoHud ()
  90.   Hud.Score ( "Dollars: "..player.score )
  91.   Hud.Health ( "Health: "..player.health )
  92. end
  93.  
  94. function DoCamera ()
  95.   Camera.Follow ( player.object )
  96. end
  97.  
  98. function DoFiring ()
  99.   if Input.GetKey ( 32 ) and player.canFire then
  100.     Level.Fire ( player.object, "Bullet", 50, "Hit" )
  101.     playingShoot = Sound.Play ( sounds.shoot )
  102.     player.canFire = false
  103.     Timer.Start ("canFireAgain" , 2, false)
  104.     if player.canFire == false then
  105.       playingReload = Sound.Play ( sounds.reload )
  106.     end
  107.   end      
  108.   bullets = Level.GetObjects ( "Bullet" )
  109.   for i = 1, #bullets do                                    
  110.     bullet = bullets [ i ]
  111.     moved = Object.Forward ( bullet, 8 )
  112.     if not moved then
  113.       Level.RemoveObject ( bullet )
  114.     end
  115.   end
  116. end
  117.  
  118. function DoGate ()
  119.   if player.items == 6 then
  120.     for i = 1, #gates do                                            -- Do not completely understand this part.
  121.       gate = gates [ i ]
  122.       Level.RemoveObject ( gate )
  123.     end
  124.   end  
  125. end
  126.  
  127. --function DoExit ()
  128.   --if Level.InRange ( player.observer, player.exit, 2 ) then
  129.     --GameOver ()
  130.   --end  
  131. --end
  132.  
  133. --Triggers
  134. function Hit ( target, source )
  135.   name = Object.GetName ( target )
  136.   if name == "Enemy" then
  137.   --if target == enemy and player.beenHit == false then
  138.     Debug.Log ("HIT")  
  139.     enemies.health = enemies.health - 1
  140.     Timer.Start ( "HitAgain", 0.1, false )
  141.     player.beenHit = true
  142.   end      
  143.     if enemies.health == 0 then      
  144.       Hud.Message ( "You Killed Jason.\n\nBut Watch Out!\n He May Yet Return...", 3 )
  145.       KillEnemy ()
  146.     end
  147. end  
  148.  
  149. function CollectKey1 ( target, source )                
  150.   if target == player.object then  
  151.     player.items = player.items + 1
  152.     Level.RemoveObject ( source )    
  153.     Hud.Message ( "You've collected the First Key...\nMake sure you collect all six!", 2 )    
  154.   end
  155. end
  156.  
  157. function CollectKey2 ( target, source )                    
  158.   if target == player.object then  
  159.     player.items = player.items + 1
  160.     Level.RemoveObject ( source )      
  161.     Hud.Message ( "You've collected the Second Key...\nMake sure you collect all six!", 3 )
  162.     for i = 1, #obstacles1 do                              
  163.     obstacle1 = obstacles1 [ i ]
  164.     Level.RemoveObject ( obstacle1 )
  165.     end  
  166.   end
  167. end
  168.  
  169. function CollectKey3 ( target, source )                                
  170.   if target == player.object then    
  171.     player.items = player.items + 1
  172.     Level.RemoveObject ( source )
  173.     Hud.Message ( "You've collected the Third Key...\nMake sure you collect all six!", 3 )
  174.     for i = 1, #obstacles2 do                                            
  175.     obstacle2 = obstacles2 [ i ]
  176.     Level.RemoveObject ( obstacle2 )
  177.     end
  178.   end
  179. end
  180.  
  181. function CollectKey4 ( target, source )
  182.   if target == player.object then  
  183.     player.items = player.items + 1
  184.     Level.RemoveObject ( source )
  185.     Hud.Message ( "You've collected the Fourth Key...\nMake sure you collect all six!", 3 )
  186.     for i = 1, #obstacles3 do                                            
  187.     obstacle3 = obstacles3 [ i ]
  188.     Level.RemoveObject ( obstacle3 )
  189.     end
  190.   end
  191. end
  192.  
  193. function CollectKey5 ( target, source )                                
  194.   if target == player.object then  
  195.     player.items = player.items + 1
  196.     Level.RemoveObject ( source )
  197.     Hud.Message ( "You've collected the Fifth Key...\nMake sure you collect all six!", 3 )
  198.     for i = 1, #obstacles5 do                                            -- Do not completely understand this part.
  199.     obstacle5 = obstacles5 [ i ]
  200.     Level.RemoveObject ( obstacle5 )
  201.     end
  202.   end
  203. end
  204.  
  205. function CollectKey6 ( target, source )                
  206.   if target == player.object then  
  207.     player.items = player.items + 1
  208.     Level.RemoveObject ( source )
  209.     Hud.Message ( "You've collected the Sixth Key...\nMake sure you collect all six!", 3 )    
  210.     for i = 1, #obstacles6 do                                            -- Do not completely understand this part.
  211.     obstacle6 = obstacles6 [ i ]
  212.     Level.RemoveObject ( obstacle6 )
  213.     end
  214.   end
  215. end
  216.  
  217. function CollectCoin ( target, source )      
  218.   if target == player.object then
  219.     player.score = player.score + 1
  220.     coins = Level.GetObjects ( "D" )
  221.     Level.RemoveObject ( source )
  222.     Hud.Message ( "You Found A Dollar!", 1.5)
  223.   end  
  224.     if player.score == 1 then
  225.       Hud.Message ( "Every Dollar Has Been Found!", 3 )
  226.     end  
  227. end
  228.  
  229. function BushBite ( target, source )      
  230.   if target == player.object then
  231.     if player.beenBitten == false then
  232.       player.health = player.health - 20
  233.       Level.RemoveObject ( enemy )
  234.       Timer.Start ( "BiteAgain", 1, true)
  235.       Timer.Start ( "RegainHealth", 20, true )
  236.       Timer.Start ( "SpawnEnemy",1 , false )
  237.     end
  238.   end  
  239.         if player.health == 0 then
  240.           Level.RemoveObject ( player.object )
  241.           Sound.Play ( sounds.dying )
  242.           Timer.Stop ( Timer.Start( "SpawnEnemy", 1.0, true ))
  243.           Hud.Message ( "GAME OVER\n\n You Have Died",5 )
  244.           player.pause = true
  245.           --Timer.Start ( "GameOver", 1, true )
  246.           GameOver ()  
  247.         end      
  248. end
  249.  
  250. -- TimeOuts
  251. function RegainHealth ()
  252.   player.health = player.health + 1
  253.   if player.health == 40 then
  254.     Timer.Stop ( Timer.Start ( "RegainHealth", 20, true ) )
  255.   end  
  256. end
  257.  
  258. function BiteAgain ()
  259.   player.beenBitten = false
  260. end
  261.  
  262. function HitAgain ()
  263.   player.beenHit = false
  264. end
  265.  
  266. function GameOver ()
  267.   if player.pause == true then
  268.     Hud.Message ( "Exit and restart game to retry.\n\n\nNo use staring at the screen...\nNothing is gonna happen.", 100 )
  269.   end  
  270. end
  271.  
  272. function canFireAgain ()
  273.   player.canFire = true  
  274. end
  275.  
  276. function SpawnEnemy()  
  277.   if not player.pause then
  278.     if not walkable then  
  279.       spawning = Level.Spawn ( "Enemy", 64, math.random ( 700, 800 ),math.random ( 700, 800 ), "BushBite" )
  280.       if enemies.health == 0 then
  281.         enemies.health = enemies.health + 2
  282.       end
  283.     end
  284.   Timer.Start ( "KillEnemy", 5, true )
  285.   end  
  286. end
  287.  
  288. function KillEnemy ()
  289.   Level.RemoveObject ( enemy )
  290.   Timer.Start ( "SpawnEnemy",3 , false )
  291. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement