Advertisement
CasterHorst

adasd

Jan 28th, 2015
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.92 KB | None | 0 0
  1. Debug.Log ("Good Luck")                                                                 -- Check if game runs
  2.  
  3. Level.Load ("Game.tmx")                                                                 -- Loads the Tiled Game map
  4.  
  5. player = {                                                                              -- Archive of player related objects and functions
  6.   object = nil,                                                                         -- nil means the object = non existent
  7.   health = 1,                                                                           -- true means that a certain function in already running
  8.   score = 0,                                                                            -- false is oposite of true, so certain function does not run
  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= {                                                                            -- Archive of enemy related objects and functions
  25.   objects = nil,
  26.   health = math.random ( 3, 5 )                                                       -- math.random ( x,y ) means a random number between x and y
  27. }
  28.  
  29. sounds = {                                                                            -- All the sounds from the assets folder are loaded into game here
  30.   bump2 = Sound.Load ( "Bump2.wav", false, false ),                                   -- String Name is the name of the sound in the assets folder              
  31.   walking = Sound.Load ( "Walking.wav", false, false ),                               -- Bool looping meaning if sound should keep repeating itself
  32.   running = Sound.Load ( "Running.wav", false, false ),                               -- Bool Streaming is for sounds that are not frequently used,
  33.   horror = Sound.Load ( "Horror.wav", true, true ),                                      -- sound gets cut off otherwise and will sound weird.
  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.   sparkle = Sound.Load ( "Sparkle.wav", false, false),
  45.   dollarPick = Sound.Load ( "MoneySound.wav", false, false),
  46.   keyPick = Sound.Load ( "KeySound.mp3", false, false ),
  47. }
  48.  
  49. function Start ()                                                                         -- Every thing in here wil be done ONCE at the start of the game.
  50.   Sound.Play ( sounds.horror )                                                            -- Plays the sound mentiond between the  ( )
  51.   Sound.Play ( sounds.humming )
  52.   Sound.Play ( sounds.heartbeat )
  53.   player.object = Level.GetObject ( "Player" )                                            -- Loads the object between the () at start of the game
  54.   player.keys = Level.GetObject ( "Key1" )                                                -- An object is something you can remove fot example
  55.   player.keys = Level.GetObject ( "Key2" )
  56.   player.keys = Level.GetObject ( "Key3" )
  57.   player.keys = Level.GetObject ( "Key4" )
  58.   player.keys = Level.GetObject ( "Key5" )
  59.   player.keys = Level.GetObject ( "Key6" )
  60.   obstacles1 = Level.GetObjects ( "Obstacle1" )
  61.   obstacles2 = Level.GetObjects ( "Obstacle2" )
  62.   obstacles3 = Level.GetObjects ( "Obstacle3" )
  63.   obstacles4 = Level.GetObjects ( "Obstacle4" )
  64.   obstacles5 = Level.GetObjects ( "Obstacle5" )
  65.   gates = Level.GetObjects ( "Gate" )
  66.   exit = Level.GetObjects ( "Exit" )
  67.   if player.pause == true then                                                            -- if game is paused do these functions                                
  68.     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 )
  69.                                                                                           -- A message will be shown on screen for a set duration.
  70.     Camera.Follow ( player.object )                                                       -- Camera will follow the object in the (), keeps that object centered
  71.     Timer.Start ( "Begin", 1, false )
  72.     Timer.Start ( "SpawnEnemy",1 , false )                                                -- A Timer allows a function to happen after a set amount of time.
  73.   end                                                                                      -- Bool Repeat means it wil repeat proces every given nummber of times
  74. end
  75.  
  76. function Update ()                                                                        -- Every thing in here wil be repeated every frame of the game.
  77.   if not player.pause then                                                                -- if game isn't paused do the functions.
  78.     DoPlayer ()                                                                           -- Organized the functions.
  79.     DoEnemy ()
  80.     DoHud ()
  81.     DoCamera ()
  82.     DoFiring ()
  83.     DoGate ()    
  84.   end
  85. end
  86.  
  87. function DoPlayer ()                                                                      -- Function conserning the Player
  88.   move = Controller.Wasd (player.object, 5)                                               -- Using Wasd the player can move himself  
  89.   if not move then                                                                        -- But if bumping into something it will play a sound to indicate
  90.     if not Sound.IsPlaying ( playingBump2 ) then                                          -- he hit something where he can't walk through
  91.       playingBump2 = Sound.Play ( sounds.bump2 )      
  92.     end    
  93.   end
  94. end
  95.  
  96. function DoEnemy ()                                                                       -- Function conserning the Enemy
  97.   enemies.objects = Level.GetObjects ( "Enemy" )                                          -- When Enemy spawns the game wil reconginze the enemy
  98.   for i = 1, #enemies.objects do                                                          -- Function wil do run if there are multiple or just 1 Enemy in-game
  99.     enemy = enemies.objects [ i ]
  100.     --moved = Controller.Patrol ( enemy , 1 )
  101.     if moved then                                                                         -- if enemy is patrol is plays a walking sound
  102.       if Sound.IsPlaying (playingWalking ) == false then
  103.         playingWalking = Sound.Play ( sounds.walking )
  104.       end
  105.     end
  106.     if Level.InRange ( player.object,enemy, 224 ) then                                    -- if Enemy is in range of player then enemy start chasing.
  107.       --moving = Controller.Chase ( enemy, player.object, 4.3 )
  108.       if Sound.IsPlaying (playingRunning ) == false then                                  -- if enemy is chasing play running sound
  109.         playingRunning = Sound.Play ( sounds.running )
  110.       end      
  111.     end        
  112.   end
  113. end
  114.  
  115. function DoHud ()
  116.   Hud.Score ( "Dollars: "..player.score )                                                 -- Display score and health
  117.   Hud.Health ( "Bullets: "..player.ammo )
  118. end
  119.  
  120. function DoCamera ()
  121.   Camera.Follow ( player.object )                                                         -- Camera follows the object in ()
  122. end
  123.  
  124. function DoFiring ()
  125.   if Input.GetKey ( 32 ) and player.canFire then                                          -- if spacebar is pressed and palyer is allowed to fire then do function
  126.     Level.Fire ( player.object, "Bullet", 50, "Hit" )                                     -- Spawns an object into the game
  127.     playingShoot = Sound.Play ( sounds.shoot )                                            -- plays shooting sound
  128.     player.ammo = player.ammo - 1                                                         -- for every bullet fired ammo is -1
  129.     player.canFire = false                                                                -- player cannot fire for a moment
  130.     Timer.Start ("canFireAgain" , 0.5, false )                                            -- start timer so that player is allowed to fire again
  131.     if player.ammo == 0 then                                                              -- if no more bullets then do function
  132.       player.canFire = false                                                              -- player cannot shoot anymore
  133.       Timer.Start ("canFireAgain" , 2, false)                                             -- start timer so that player can fire again
  134.       if not Sound.IsPlaying ( reloading ) then                                           -- play reloading sound if sound isnt already playing
  135.         reloading = Sound.Play ( sounds.reload )
  136.       end
  137.     end
  138.   end  
  139.   bullets = Level.GetObjects ( "Bullet" )                                                 -- Game reconginzes that bullet is fired and gives is value    
  140.   for i = 1, #bullets do                                                                  -- if there are multiple bullets in the game they will all act the same
  141.     bullet = bullets [ i ]
  142.     moved = Object.Forward ( bullet, 8 )                                                  -- bullet moves in forward direction
  143.     if not moved then                                                                     -- if not moving anymore then it will remove the bullet
  144.       Level.RemoveObject ( bullet )  
  145.     end
  146.   end
  147. end
  148.  
  149. function DoGate ()                                                                        
  150.   if player.items == 6 then                                                               -- if 6 items have been picked up do function ( items are keys )
  151.     for i = 1, #gates do                                                                  -- if there are multiple gates in-game they will all act the same way
  152.       gate = gates [ i ]
  153.       Level.RemoveObject ( gate )                                                         -- removes object after 6th key is picked up
  154.       Hud.Message ( "You Unlocked the Main Door!\n\nFind the Exit!",3)                    -- displays message
  155.     end  
  156.   end
  157. end
  158.  
  159. --Triggers
  160. function Hit ( target, source )                                                          
  161.   if player.beenHit == false then
  162.     name = Object.GetName ( target )                                                         -- if bullet is hitting the enemy do this function
  163.     if name == "Enemy" then  
  164.       enemies.health = enemies.health - 1                                                    -- health of enemy deceases with 1
  165.       Timer.Start ( "HitAgain", 0.1, false )                                                 -- Starts timer when enemy van be hit again
  166.       player.beenHit = true                                                                  -- enemy cannot be hit again until timer expires
  167.     end      
  168.   end      
  169.     if enemies.health == 0 then                                                              -- if enemy health = 0    
  170.       Sound.Play ( sounds.jasonDie )                                                         -- play dying sound
  171.       Sound.Play ( sounds.teleportOut )                                                      -- play teleportOut sound
  172.       Level.RemoveObject ( enemy )                                                           -- removes the player form the game
  173.       KillEnemy ()                                                                           -- does this function ( making sure enemy respawns )
  174.     end
  175. end  
  176.  
  177. function CollectKey1 ( target, source )                                                       -- if player hits a key do function                
  178.   if target == player.object then  
  179.     player.items = player.items + 1                                                           -- increase amount of items with 1
  180.     Level.RemoveObject ( source )                                                             -- removes key from game
  181.     Sound.Play ( sounds.keyPick )                                                             -- plays sound when picking up key
  182.     Hud.Message ( "You collected the 1ste Key!", 2 )                                          -- displays a message
  183.   end
  184. end
  185.  
  186. function CollectKey2 ( target, source )                                                       -- see function CollectKey 1 for first part                    
  187.   if target == player.object then  
  188.     player.items = player.items + 1
  189.     Level.RemoveObject ( source )      
  190.     Sound.Play ( sounds.keyPick )
  191.     Hud.Message ( "You collected the 2nd Key!", 3 )
  192.     for i = 1, #obstacles1 do                                                                 -- for every object named obstacle1 do the same thing            
  193.     obstacle1 = obstacles1 [ i ]
  194.     Level.RemoveObject ( obstacle1 )                                                          -- removes all obstacles with the same name
  195.     end  
  196.   end
  197. end
  198.  
  199. function CollectKey3 ( target, source )                                                       -- CollectKey 3 to 6 all work the same way as 1 and 2              
  200.   if target == player.object then    
  201.     player.items = player.items + 1
  202.     Level.RemoveObject ( source )
  203.     Sound.Play ( sounds.keyPick )
  204.     Hud.Message ( "You collected the 3rd Key!", 3 )
  205.     for i = 1, #obstacles2 do                                            
  206.     obstacle2 = obstacles2 [ i ]
  207.     Level.RemoveObject ( obstacle2 )
  208.     end
  209.   end
  210. end
  211.  
  212. function CollectKey4 ( target, source )
  213.   if target == player.object then  
  214.     player.items = player.items + 1
  215.     Level.RemoveObject ( source )
  216.     Sound.Play ( sounds.keyPick )
  217.     Hud.Message ( "You collected the 4th Key!", 3 )
  218.     for i = 1, #obstacles3 do                                            
  219.     obstacle3 = obstacles3 [ i ]
  220.     Level.RemoveObject ( obstacle3 )
  221.     end
  222.   end
  223. end
  224.  
  225. function CollectKey5 ( target, source )                                
  226.   if target == player.object then  
  227.     player.items = player.items + 1
  228.     Level.RemoveObject ( source )
  229.     Sound.Play ( sounds.keyPick )
  230.     Hud.Message ( "You collected the 5th Key!", 3 )
  231.     for i = 1, #obstacles5 do                                          
  232.     obstacle5 = obstacles5 [ i ]
  233.     Level.RemoveObject ( obstacle5 )
  234.     end
  235.   end
  236. end
  237.  
  238. function CollectKey6 ( target, source )                
  239.   if target == player.object then  
  240.     player.items = player.items + 1
  241.     Level.RemoveObject ( source )
  242.     Sound.Play ( sounds.keyPick )
  243.     Hud.Message ( "You collected the 6th Key!", 3 )    
  244.     for i = 1, #obstacles4 do                                            
  245.     obstacle4 = obstacles4 [ i ]
  246.     Level.RemoveObject ( obstacle4 )
  247.     end
  248.   end
  249. end
  250.  
  251. function CollectDollar ( target, source )      
  252.   if target == player.object then                                                               -- only player is allowed to do this function
  253.     player.score = player.score + 1                                                             -- increase the score with 1
  254.     Dollars = Level.GetObjects ( "Dollar" )                                                     -- puts the objects in game and checks every frame if still there
  255.     Level.RemoveObject ( source )                                                               -- removes the objet from the game
  256.     Sound.Play ( sounds.dollarPick )
  257.     if player.score == 1 then                                                                   -- if picked up then display a message
  258.       Hud.Message ( "You Found a Dollar!\n\n There are More Left", 1.5)
  259.     end
  260.   end  
  261.     if player.score == 50 then                                                                  -- if every object has been found displays message
  262.       Hud.Message ( "Every Dollar Has Been Found!", 3 )
  263.     end  
  264. end
  265.  
  266. function BushBite ( target, source )                                                            -- enemy doing damage to player
  267.   if target == player.object and player.beenBitten == false then                                -- if player is the one getting hit and it has been before
  268.     player.health = player.health - 1                                                           -- player's health decreases by 1
  269.     Sound.Play ( sounds.stab )                                                                  -- play stabbing sound
  270.     --Timer.Start ( "BiteAgain", 1, true)                                                       -- ( these are option I had before but didn't fit in the game)
  271.     --Timer.Start ( "RegainHealth", 20, true )                                                  -- ( they all work of course )        
  272.   end  
  273.     if player.health <= 0 then                                                                  -- if players health os 0 do this function
  274.       PlayerDied ()
  275.     end      
  276. end
  277.  
  278. function LeaveMaze ( target, source )
  279.   if target == player.object then                                                               -- if player hits object then
  280.     Level.RemoveObject ( player.object )                                                        -- remove the player
  281.     Sound.Play ( sounds.sparkle )                                                               -- plays sound
  282.     player.pause = true                                                                         -- pause the game
  283.     Hud.Message ( "You Made It Out!",5 )                                                        -- dispay message for 5 second
  284.     Timer.Start ( "GameOver" ,5,false )                                                         -- do this function after 5 second
  285.   end
  286. end
  287.  
  288. -- TimeOuts
  289. function Begin ()            
  290.   player.pause = false                                                                          -- unpauses the game so that player can move  
  291.   Hud.Message ("Run!!!", 1 )                                                                    -- displays message
  292. end
  293. function HitAgain ()
  294.   player.beenHit = false                                                                        -- Enemy can be damaged again
  295. end
  296.  
  297.  
  298. function canFireAgain ()
  299.   if player.ammo > 0 then                                                                       -- if player has more then 1 bullet, he's able to fire again
  300.     player.canFire = true
  301.   end
  302.   if player.ammo == 0 then                                                                      -- if alle bullets are gone reload weapon and firing is allowed
  303.     player.ammo = player.ammo + 9
  304.     player.canFire = true
  305.   end
  306. end
  307. function SpawnEnemy()  
  308.   if not player.pause then                                                                      -- if not paused do this function
  309.       spawning = Level.Spawn ( "Enemy", (64), math.random ( 32, 1568  ),math.random ( 32, 1568 ), "BushBite" )
  310.     if spawning then                                                                            -- spawns enemy rendomly between these coordinates
  311.       Sound.Play ( sounds.teleportIn )                                                          -- if enemy spawns play a sound
  312.     end
  313.   end
  314.   Timer.Start ( "KillEnemy", 7, false )                                                         -- start a timer for enemy to disapear after 7 seconds
  315. end
  316. function KillEnemy ()
  317.   if not player.pause then
  318.     if Level.RemoveObject ( enemy ) then                                                        -- removes enemy from the game
  319.       teleportout = Sound.Play ( sounds.teleportOut )                                           -- plays sound
  320.     end
  321.     if enemies.health ==0 then                                                                  -- after enemy died gives it it's health back before respawn
  322.       enemies.health = enemies.health + 2
  323.     end
  324.     Timer.Start ( "SpawnEnemy",10 , false )                                                     -- timer when enemy is allowed to spawn again
  325.   end
  326. end
  327. function PlayerDied ()
  328.   Level.RemoveObject ( player.object )                                                          -- if player is dead removes the player form game
  329.   Level.RemoveObject ( bullet )
  330.   Sound.Play ( sounds.dying )                                                                   -- plays dying sound
  331.   Sound.Stop ( Sound.Play ( sounds.heartbeat ) )                                                -- stops heartbeat sound
  332.   Timer.Stop ( Timer.Start( "SpawnEnemy", 1.0, true ))                                          -- stops spawning
  333.   Hud.Message ( "GAME OVER\n\n You Have Died",5 )                                               -- displays message
  334.   player.pause = true                                                                           -- pauses the game
  335.   Timer.Start ( "GameOver", 5, false )                                                          -- start time for gameover function
  336. end
  337. function GameOver ()
  338.   if player.pause == true then                                                                  -- if game is paused do this function
  339.     Hud.Message ( "Exit And Restart Game To Try Again.", 100 )                                  -- displays message
  340.   end  
  341. end
  342.  
  343. --function RegainHealth ()            
  344.   --player.health = player.health + 1                                                            player regains health after set amount of time
  345.   --if player.health == 40 then                                                                  if back to full health stop regaining health
  346.     --Timer.Stop ( Timer.Start ( "RegainHealth", 20, true ) )
  347.   --end  
  348. --end
  349. --function BiteAgain ()                                                                           enemy can bite again
  350.   --player.beenBitten = false
  351. --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement