Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Debug.Log ("Good Luck")
- Level.Load ("Game.tmx")
- player = {
- object = nil,
- health = 1,
- score = 0,
- 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= {
- objects = nil,
- health = math.random ( 3, 5 )
- }
- sounds = {
- bump2 = Sound.Load ( "Bump2.wav", false, false ),
- walking = Sound.Load ( "Walking.wav", false, false ),
- running = Sound.Load ( "Running.wav", false, false ),
- horror = Sound.Load ( "Horror.wav", true, true ),
- 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 )
- }
- function Start ()
- Sound.Play ( sounds.horror )
- Sound.Play ( sounds.humming )
- Sound.Play ( sounds.heartbeat )
- player.object = Level.GetObject ( "Player" )
- player.keys = Level.GetObject ( "Key1" )
- 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" )
- --Timer.Start ( "SpawnEnemy",1 , false )
- if player.pause == true then
- 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 )
- Camera.Follow ( player.object )
- Timer.Start ( "Begin", 1, false )
- Timer.Start ( "SpawnEnemy",1 , false )
- end
- end
- function Update ()
- if not player.pause then
- DoPlayer ()
- DoEnemy ()
- DoHud ()
- DoCamera ()
- DoFiring ()
- DoGate ()
- end
- end
- function DoPlayer ()
- move = Controller.Wasd (player.object, 3)
- if not move then
- if not Sound.IsPlaying ( playingBump2 ) then
- playingBump2 = Sound.Play ( sounds.bump2 )
- end
- end
- end
- function DoEnemy ()
- enemies.objects = Level.GetObjects ( "Enemy" )
- for i = 1, #enemies.objects do
- enemy = enemies.objects [ i ]
- moved = Controller.Patrol ( enemy , 1 )
- if moved then
- if Sound.IsPlaying (playingWalking ) == false then
- playingWalking = Sound.Play ( sounds.walking )
- end
- end
- if Level.InRange ( player.object,enemy, 224 ) then
- moved = false
- moving = Controller.Chase ( enemy, player.object, 2.3 )
- if Sound.IsPlaying (playingRunning ) == false then
- playingRunning = Sound.Play ( sounds.running )
- end
- end
- end
- end
- function DoHud ()
- Hud.Score ( "Dollars: "..player.score )
- Hud.Health ( "Bullets: "..player.ammo )
- end
- function DoCamera ()
- Camera.Follow ( player.object )
- end
- function DoFiring ()
- if Input.GetKey ( 32 ) and player.canFire then
- Level.Fire ( player.object, "Bullet", 50, "Hit" )
- playingShoot = Sound.Play ( sounds.shoot )
- player.ammo = player.ammo - 1
- player.canFire = false
- Timer.Start ("canFireAgain" , 0.5, false )
- if player.ammo == 0 then
- Debug.Log ( "reload" )
- player.canFire = false
- Timer.Start ("canFireAgain" , 2, false)
- if not Sound.IsPlaying ( reloading ) then
- reloading = Sound.Play ( sounds.reload )
- end
- end
- end
- bullets = Level.GetObjects ( "Bullet" )
- for i = 1, #bullets do
- bullet = bullets [ i ]
- moved = Object.Forward ( bullet, 8 )
- if not moved then
- Level.RemoveObject ( bullet )
- end
- end
- end
- function DoGate ()
- if player.items == 6 then
- for i = 1, #gates do
- gate = gates [ i ]
- Level.RemoveObject ( gate )
- Hud.Message ( "You Unlocked the Main Door!\n\nFind the Exit!",3)
- end
- end
- end
- --Triggers
- function Hit ( target, source )
- name = Object.GetName ( target )
- if name == "Enemy" then
- enemies.health = enemies.health - 1
- Timer.Start ( "HitAgain", 0.1, false )
- player.beenHit = true
- if enemies.health == enemies.health - 1 then
- if not Sound.IsPlaying ( hitting) then
- hitting = Sound.Play ( sounds.impact )
- end
- end
- end
- if enemies.health == 0 then
- Sound.Play ( sounds.jasonDie )
- Sound.Play ( sounds.teleportOut )
- Level.RemoveObject ( enemy )
- KillEnemy ()
- end
- end
- function CollectKey1 ( target, source )
- if target == player.object then
- player.items = player.items + 1
- Level.RemoveObject ( source )
- Hud.Message ( "You collected the 1ste Key!", 2 )
- end
- end
- function CollectKey2 ( target, source )
- if target == player.object then
- player.items = player.items + 1
- Level.RemoveObject ( source )
- Hud.Message ( "You collected the 2nd Key!", 3 )
- for i = 1, #obstacles1 do
- obstacle1 = obstacles1 [ i ]
- Level.RemoveObject ( obstacle1 )
- end
- end
- end
- function CollectKey3 ( target, source )
- if target == player.object then
- player.items = player.items + 1
- Level.RemoveObject ( source )
- 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 )
- 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 )
- 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 )
- 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
- player.score = player.score + 1
- Dollars = Level.GetObjects ( "Dollar" )
- Level.RemoveObject ( source )
- if player.score == 1 then
- Hud.Message ( "You Found a Dollar!\n\n There are More Left", 1.5)
- end
- end
- if player.score == 50 then
- Hud.Message ( "Every Dollar Has Been Found!", 3 )
- end
- end
- function BushBite ( target, source )
- if target == player.object and player.beenBitten == false then
- player.health = player.health - 1
- Sound.Play ( sounds.stab )
- --Level.RemoveObject ( enemy )
- --Timer.Start ( "BiteAgain", 1, true)
- --Timer.Start ( "RegainHealth", 20, true )
- --Timer.Start ( "SpawnEnemy",5, false )
- end
- if player.health <= 0 then
- PlayerDied ()
- end
- end
- function LeaveMaze ( target, source )
- if target == player.object then
- Level.RemoveObject ( player.object )
- player.pause = true
- Hud.Message ( "You Made It Out!",5 )
- Timer.Start ( "GameOver" ,5,false )
- end
- end
- -- TimeOuts
- function Begin ()
- player.pause = false
- Hud.Message ("Run!!!", 1 )
- end
- function HitAgain ()
- player.beenHit = false
- end
- function GameOver ()
- if player.pause == true then
- Hud.Message ( "Exit And Restart Game To Try Again.", 100 )
- end
- end
- function canFireAgain ()
- if player.ammo > 0 then
- player.canFire = true
- end
- if player.ammo == 0 then
- player.ammo = player.ammo + 9
- player.canFire = true
- end
- end
- function SpawnEnemy()
- if not player.pause then
- if move == false then
- spawning = false
- spawning = Level.Spawn ( "Enemy", (64), math.random ( 32*20, 32*25 ),math.random ( 32*23, 32*28 ), "BushBite" )
- if spawning then
- Sound.Play ( sounds.teleportIn )
- end
- end
- end
- Timer.Start ( "KillEnemy", 7, false )
- end
- function KillEnemy ()
- if not player.pause then
- if Level.RemoveObject ( enemy ) then
- teleportout = Sound.Play ( sounds.teleportOut )
- end
- if enemies.health ==0 then
- enemies.health = enemies.health + 2
- end
- Timer.Start ( "SpawnEnemy",10 , false )
- end
- end
- function PlayerDied ()
- Level.RemoveObject ( player.object )
- --Level.RemoveObject ( enemy )
- Level.RemoveObject ( bullet )
- Sound.Play ( sounds.dying )
- Sound.Stop ( Sound.Play ( sounds.heartbeat ) )
- Timer.Stop ( Timer.Start( "SpawnEnemy", 1.0, true ))
- Hud.Message ( "GAME OVER\n\n You Have Died",5 )
- player.pause = true
- Timer.Start ( "GameOver", 5, false )
- end
- --function RegainHealth ()
- --player.health = player.health + 1
- --if player.health == 40 then
- --Timer.Stop ( Timer.Start ( "RegainHealth", 20, true ) )
- --end
- --end
- --function BiteAgain ()
- --player.beenBitten = false
- --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement