Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Debug.Log ("Good Luck") -- Check if game runs
- Level.Load ("Game.tmx") -- Loads the Tiled Game map
- player = { -- Archive of player related objects and functions
- object = nil, -- nil means the object = non existent
- health = 1, -- true means that a certain function in already running
- score = 0, -- false is oposite of true, so certain function does not run
- beenBitten = false,
- beenHit = false,
- canFire = true,
- obstacle1 = nil,
- obstacle2 = nil,
- obstacle3 = nil,
- obstacle4 = nil,
- obstacle5 = nil,
- gate = nil,
- pause = true,
- items = 0,
- exit = nil,
- ammo = 9,
- }
- enemies= { -- Archive of enemy related objects and functions
- objects = nil,
- health = math.random ( 3, 5 ) -- math.random ( x,y ) means a random number between x and y
- }
- sounds = { -- All the sounds from the assets folder are loaded into game here
- bump2 = Sound.Load ( "Bump2.wav", false, false ), -- String Name is the name of the sound in the assets folder
- walking = Sound.Load ( "Walking.wav", false, false ), -- Bool looping meaning if sound should keep repeating itself
- running = Sound.Load ( "Running.wav", false, false ), -- Bool Streaming is for sounds that are not frequently used,
- horror = Sound.Load ( "Horror.wav", true, true ), -- sound gets cut off otherwise and will sound weird.
- humming = Sound.Load ( "Humming.wav", true, true ),
- heartbeat = Sound.Load ( "HeartBeat.wav", true, true ),
- shoot = Sound.Load ( "Gunshot1.wav", false, false ),
- impact = Sound.Load ( "Impact.mp3", false, false ),
- reload = Sound.Load ( "Reload.wav", false, false ),
- dying = Sound.Load ( "Scream.wav", false, false ),
- stab = Sound.Load ( "Stab.wav", false, false ),
- jasonDie = Sound.Load ( "JasonDie.wav", false, false ),
- teleportIn = Sound.Load ( "Teleport2.wav", false, false ),
- teleportOut = Sound.Load ( "Teleport.wav", false, false ),
- sparkle = Sound.Load ( "Sparkle.wav", false, false),
- dollarPick = Sound.Load ( "MoneySound.wav", false, false),
- keyPick = Sound.Load ( "KeySound.mp3", false, false ),
- }
- function Start () -- Every thing in here wil be done ONCE at the start of the game.
- Sound.Play ( sounds.horror ) -- Plays the sound mentiond between the ( )
- Sound.Play ( sounds.humming )
- Sound.Play ( sounds.heartbeat )
- player.object = Level.GetObject ( "Player" ) -- Loads the object between the () at start of the game
- player.keys = Level.GetObject ( "Key1" ) -- An object is something you can remove fot example
- player.keys = Level.GetObject ( "Key2" )
- player.keys = Level.GetObject ( "Key3" )
- player.keys = Level.GetObject ( "Key4" )
- player.keys = Level.GetObject ( "Key5" )
- player.keys = Level.GetObject ( "Key6" )
- obstacles1 = Level.GetObjects ( "Obstacle1" )
- obstacles2 = Level.GetObjects ( "Obstacle2" )
- obstacles3 = Level.GetObjects ( "Obstacle3" )
- obstacles4 = Level.GetObjects ( "Obstacle4" )
- obstacles5 = Level.GetObjects ( "Obstacle5" )
- gates = Level.GetObjects ( "Gate" )
- exit = Level.GetObjects ( "Exit" )
- if player.pause == true then -- if game is paused do these functions
- 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 )
- -- A message will be shown on screen for a set duration.
- Camera.Follow ( player.object ) -- Camera will follow the object in the (), keeps that object centered
- Timer.Start ( "Begin", 1, false )
- Timer.Start ( "SpawnEnemy",1 , false ) -- A Timer allows a function to happen after a set amount of time.
- end -- Bool Repeat means it wil repeat proces every given nummber of times
- end
- function Update () -- Every thing in here wil be repeated every frame of the game.
- if not player.pause then -- if game isn't paused do the functions.
- DoPlayer () -- Organized the functions.
- DoEnemy ()
- DoHud ()
- DoCamera ()
- DoFiring ()
- DoGate ()
- end
- end
- function DoPlayer () -- Function conserning the Player
- move = Controller.Wasd (player.object, 5) -- Using Wasd the player can move himself
- if not move then -- But if bumping into something it will play a sound to indicate
- if not Sound.IsPlaying ( playingBump2 ) then -- he hit something where he can't walk through
- playingBump2 = Sound.Play ( sounds.bump2 )
- end
- end
- end
- function DoEnemy () -- Function conserning the Enemy
- enemies.objects = Level.GetObjects ( "Enemy" ) -- When Enemy spawns the game wil reconginze the enemy
- for i = 1, #enemies.objects do -- Function wil do run if there are multiple or just 1 Enemy in-game
- enemy = enemies.objects [ i ]
- --moved = Controller.Patrol ( enemy , 1 )
- if moved then -- if enemy is patrol is plays a walking sound
- if Sound.IsPlaying (playingWalking ) == false then
- playingWalking = Sound.Play ( sounds.walking )
- end
- end
- if Level.InRange ( player.object,enemy, 224 ) then -- if Enemy is in range of player then enemy start chasing.
- --moving = Controller.Chase ( enemy, player.object, 4.3 )
- if Sound.IsPlaying (playingRunning ) == false then -- if enemy is chasing play running sound
- playingRunning = Sound.Play ( sounds.running )
- end
- end
- end
- end
- function DoHud ()
- Hud.Score ( "Dollars: "..player.score ) -- Display score and health
- Hud.Health ( "Bullets: "..player.ammo )
- end
- function DoCamera ()
- Camera.Follow ( player.object ) -- Camera follows the object in ()
- end
- function DoFiring ()
- if Input.GetKey ( 32 ) and player.canFire then -- if spacebar is pressed and palyer is allowed to fire then do function
- Level.Fire ( player.object, "Bullet", 50, "Hit" ) -- Spawns an object into the game
- playingShoot = Sound.Play ( sounds.shoot ) -- plays shooting sound
- player.ammo = player.ammo - 1 -- for every bullet fired ammo is -1
- player.canFire = false -- player cannot fire for a moment
- Timer.Start ("canFireAgain" , 0.5, false ) -- start timer so that player is allowed to fire again
- if player.ammo == 0 then -- if no more bullets then do function
- player.canFire = false -- player cannot shoot anymore
- Timer.Start ("canFireAgain" , 2, false) -- start timer so that player can fire again
- if not Sound.IsPlaying ( reloading ) then -- play reloading sound if sound isnt already playing
- reloading = Sound.Play ( sounds.reload )
- end
- end
- end
- bullets = Level.GetObjects ( "Bullet" ) -- Game reconginzes that bullet is fired and gives is value
- for i = 1, #bullets do -- if there are multiple bullets in the game they will all act the same
- bullet = bullets [ i ]
- moved = Object.Forward ( bullet, 8 ) -- bullet moves in forward direction
- if not moved then -- if not moving anymore then it will remove the bullet
- Level.RemoveObject ( bullet )
- end
- end
- end
- function DoGate ()
- if player.items == 6 then -- if 6 items have been picked up do function ( items are keys )
- for i = 1, #gates do -- if there are multiple gates in-game they will all act the same way
- gate = gates [ i ]
- Level.RemoveObject ( gate ) -- removes object after 6th key is picked up
- Hud.Message ( "You Unlocked the Main Door!\n\nFind the Exit!",3) -- displays message
- end
- end
- end
- --Triggers
- function Hit ( target, source )
- if player.beenHit == false then
- name = Object.GetName ( target ) -- if bullet is hitting the enemy do this function
- if name == "Enemy" then
- enemies.health = enemies.health - 1 -- health of enemy deceases with 1
- Timer.Start ( "HitAgain", 0.1, false ) -- Starts timer when enemy van be hit again
- player.beenHit = true -- enemy cannot be hit again until timer expires
- end
- end
- if enemies.health == 0 then -- if enemy health = 0
- Sound.Play ( sounds.jasonDie ) -- play dying sound
- Sound.Play ( sounds.teleportOut ) -- play teleportOut sound
- Level.RemoveObject ( enemy ) -- removes the player form the game
- KillEnemy () -- does this function ( making sure enemy respawns )
- end
- end
- function CollectKey1 ( target, source ) -- if player hits a key do function
- if target == player.object then
- player.items = player.items + 1 -- increase amount of items with 1
- Level.RemoveObject ( source ) -- removes key from game
- Sound.Play ( sounds.keyPick ) -- plays sound when picking up key
- Hud.Message ( "You collected the 1ste Key!", 2 ) -- displays a message
- end
- end
- function CollectKey2 ( target, source ) -- see function CollectKey 1 for first part
- if target == player.object then
- player.items = player.items + 1
- Level.RemoveObject ( source )
- Sound.Play ( sounds.keyPick )
- Hud.Message ( "You collected the 2nd Key!", 3 )
- for i = 1, #obstacles1 do -- for every object named obstacle1 do the same thing
- obstacle1 = obstacles1 [ i ]
- Level.RemoveObject ( obstacle1 ) -- removes all obstacles with the same name
- end
- end
- end
- function CollectKey3 ( target, source ) -- CollectKey 3 to 6 all work the same way as 1 and 2
- if target == player.object then
- player.items = player.items + 1
- Level.RemoveObject ( source )
- Sound.Play ( sounds.keyPick )
- Hud.Message ( "You collected the 3rd Key!", 3 )
- for i = 1, #obstacles2 do
- obstacle2 = obstacles2 [ i ]
- Level.RemoveObject ( obstacle2 )
- end
- end
- end
- function CollectKey4 ( target, source )
- if target == player.object then
- player.items = player.items + 1
- Level.RemoveObject ( source )
- Sound.Play ( sounds.keyPick )
- Hud.Message ( "You collected the 4th Key!", 3 )
- for i = 1, #obstacles3 do
- obstacle3 = obstacles3 [ i ]
- Level.RemoveObject ( obstacle3 )
- end
- end
- end
- function CollectKey5 ( target, source )
- if target == player.object then
- player.items = player.items + 1
- Level.RemoveObject ( source )
- Sound.Play ( sounds.keyPick )
- Hud.Message ( "You collected the 5th Key!", 3 )
- for i = 1, #obstacles5 do
- obstacle5 = obstacles5 [ i ]
- Level.RemoveObject ( obstacle5 )
- end
- end
- end
- function CollectKey6 ( target, source )
- if target == player.object then
- player.items = player.items + 1
- Level.RemoveObject ( source )
- Sound.Play ( sounds.keyPick )
- Hud.Message ( "You collected the 6th Key!", 3 )
- for i = 1, #obstacles4 do
- obstacle4 = obstacles4 [ i ]
- Level.RemoveObject ( obstacle4 )
- end
- end
- end
- function CollectDollar ( target, source )
- if target == player.object then -- only player is allowed to do this function
- player.score = player.score + 1 -- increase the score with 1
- Dollars = Level.GetObjects ( "Dollar" ) -- puts the objects in game and checks every frame if still there
- Level.RemoveObject ( source ) -- removes the objet from the game
- Sound.Play ( sounds.dollarPick )
- if player.score == 1 then -- if picked up then display a message
- Hud.Message ( "You Found a Dollar!\n\n There are More Left", 1.5)
- end
- end
- if player.score == 50 then -- if every object has been found displays message
- Hud.Message ( "Every Dollar Has Been Found!", 3 )
- end
- end
- function BushBite ( target, source ) -- enemy doing damage to player
- if target == player.object and player.beenBitten == false then -- if player is the one getting hit and it has been before
- player.health = player.health - 1 -- player's health decreases by 1
- Sound.Play ( sounds.stab ) -- play stabbing sound
- --Timer.Start ( "BiteAgain", 1, true) -- ( these are option I had before but didn't fit in the game)
- --Timer.Start ( "RegainHealth", 20, true ) -- ( they all work of course )
- end
- if player.health <= 0 then -- if players health os 0 do this function
- PlayerDied ()
- end
- end
- function LeaveMaze ( target, source )
- if target == player.object then -- if player hits object then
- Level.RemoveObject ( player.object ) -- remove the player
- Sound.Play ( sounds.sparkle ) -- plays sound
- player.pause = true -- pause the game
- Hud.Message ( "You Made It Out!",5 ) -- dispay message for 5 second
- Timer.Start ( "GameOver" ,5,false ) -- do this function after 5 second
- end
- end
- -- TimeOuts
- function Begin ()
- player.pause = false -- unpauses the game so that player can move
- Hud.Message ("Run!!!", 1 ) -- displays message
- end
- function HitAgain ()
- player.beenHit = false -- Enemy can be damaged again
- end
- function canFireAgain ()
- if player.ammo > 0 then -- if player has more then 1 bullet, he's able to fire again
- player.canFire = true
- end
- if player.ammo == 0 then -- if alle bullets are gone reload weapon and firing is allowed
- player.ammo = player.ammo + 9
- player.canFire = true
- end
- end
- function SpawnEnemy()
- if not player.pause then -- if not paused do this function
- spawning = Level.Spawn ( "Enemy", (64), math.random ( 32, 1568 ),math.random ( 32, 1568 ), "BushBite" )
- if spawning then -- spawns enemy rendomly between these coordinates
- Sound.Play ( sounds.teleportIn ) -- if enemy spawns play a sound
- end
- end
- Timer.Start ( "KillEnemy", 7, false ) -- start a timer for enemy to disapear after 7 seconds
- end
- function KillEnemy ()
- if not player.pause then
- if Level.RemoveObject ( enemy ) then -- removes enemy from the game
- teleportout = Sound.Play ( sounds.teleportOut ) -- plays sound
- end
- if enemies.health ==0 then -- after enemy died gives it it's health back before respawn
- enemies.health = enemies.health + 2
- end
- Timer.Start ( "SpawnEnemy",10 , false ) -- timer when enemy is allowed to spawn again
- end
- end
- function PlayerDied ()
- Level.RemoveObject ( player.object ) -- if player is dead removes the player form game
- Level.RemoveObject ( bullet )
- Sound.Play ( sounds.dying ) -- plays dying sound
- Sound.Stop ( Sound.Play ( sounds.heartbeat ) ) -- stops heartbeat sound
- Timer.Stop ( Timer.Start( "SpawnEnemy", 1.0, true )) -- stops spawning
- Hud.Message ( "GAME OVER\n\n You Have Died",5 ) -- displays message
- player.pause = true -- pauses the game
- Timer.Start ( "GameOver", 5, false ) -- start time for gameover function
- end
- function GameOver ()
- if player.pause == true then -- if game is paused do this function
- Hud.Message ( "Exit And Restart Game To Try Again.", 100 ) -- displays message
- end
- end
- --function RegainHealth ()
- --player.health = player.health + 1 player regains health after set amount of time
- --if player.health == 40 then if back to full health stop regaining health
- --Timer.Stop ( Timer.Start ( "RegainHealth", 20, true ) )
- --end
- --end
- --function BiteAgain () enemy can bite again
- --player.beenBitten = false
- --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement