Advertisement
CasterHorst

Jason 2

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