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,
- music = nil,
- health = 40,
- score = 0,
- beenBitten = false,
- beenHit = false,
- canFire = true,
- obstacle1 = nil,
- obstacle2 = nil,
- obstacle3 = nil,
- obstacle4 = nil,
- keys = 0,
- gate = nil,
- pause = false,
- items = 0,
- exit = nil,
- }
- enemies= {
- objects = nil,
- health = 2
- }
- sounds = {
- 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 ),
- reload = Sound.Load ( "Reload.wav", false, false ),
- dying = Sound.Load ( "Scream.wav", false, false),
- stabing
- }
- 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" )
- gates = Level.GetObjects ( "Gate" )
- exit = Level.GetObjects ( "Exit" )
- Hud.Message ( "Run!!\n\nYou're Being Hunted!", 4 )
- Timer.Start ( "SpawnEnemy",5 , false )
- end
- function Update ()
- if not player.pause then
- DoPlayer ()
- DoEnemy ()
- DoHud ()
- DoCamera ()
- DoFiring ()
- DoGate ()
- --DoExit ()
- end
- end
- function DoPlayer ()
- move = Controller.Wasd (player.object, 3)
- if not move then
- if not Sound.IsPlaying ( playingBump ) then
- playingBump = Sound.Play ( sounds.bump )
- end
- end
- end
- function DoEnemy ()
- enemies.objects = Level.GetObjects ( "Enemy" )
- for i = 1, #enemies.objects do
- enemy = enemies.objects [ i ]
- move = Controller.Chase ( enemy, player.object, 1 )
- end
- end
- function DoHud ()
- Hud.Score ( "Dollars: "..player.score )
- Hud.Health ( "Health: "..player.health )
- 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.canFire = false
- Timer.Start ("canFireAgain" , 2, false)
- if player.canFire == false then
- playingReload = Sound.Play ( sounds.reload )
- 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 -- Do not completely understand this part.
- gate = gates [ i ]
- Level.RemoveObject ( gate )
- end
- end
- end
- --function DoExit ()
- --if Level.InRange ( player.observer, player.exit, 2 ) then
- --GameOver ()
- --end
- --end
- --Triggers
- function Hit ( target, source )
- name = Object.GetName ( target )
- if name == "Enemy" then
- --if target == enemy and player.beenHit == false then
- Debug.Log ("HIT")
- enemies.health = enemies.health - 1
- Timer.Start ( "HitAgain", 0.1, false )
- player.beenHit = true
- end
- if enemies.health == 0 then
- Hud.Message ( "You Killed Jason.\n\nBut Watch Out!\n He May Yet Return...", 3 )
- KillEnemy ()
- end
- end
- function CollectKey1 ( target, source )
- if target == player.object then
- player.items = player.items + 1
- Level.RemoveObject ( source )
- Hud.Message ( "You've collected the First Key...\nMake sure you collect all six!", 2 )
- end
- end
- function CollectKey2 ( target, source )
- if target == player.object then
- player.items = player.items + 1
- Level.RemoveObject ( source )
- Hud.Message ( "You've collected the Second Key...\nMake sure you collect all six!", 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've collected the Third Key...\nMake sure you collect all six!", 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've collected the Fourth Key...\nMake sure you collect all six!", 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've collected the Fifth Key...\nMake sure you collect all six!", 3 )
- for i = 1, #obstacles5 do -- Do not completely understand this part.
- 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've collected the Sixth Key...\nMake sure you collect all six!", 3 )
- for i = 1, #obstacles6 do -- Do not completely understand this part.
- obstacle6 = obstacles6 [ i ]
- Level.RemoveObject ( obstacle6 )
- end
- end
- end
- function CollectCoin ( target, source )
- if target == player.object then
- player.score = player.score + 1
- coins = Level.GetObjects ( "D" )
- Level.RemoveObject ( source )
- Hud.Message ( "You Found A Dollar!", 1.5)
- end
- if player.score == 1 then
- Hud.Message ( "Every Dollar Has Been Found!", 3 )
- end
- end
- function BushBite ( target, source )
- if target == player.object then
- if player.beenBitten == false then
- player.health = player.health - 20
- Level.RemoveObject ( enemy )
- Timer.Start ( "BiteAgain", 1, true)
- Timer.Start ( "RegainHealth", 20, true )
- Timer.Start ( "SpawnEnemy",1 , false )
- end
- end
- if player.health == 0 then
- Level.RemoveObject ( player.object )
- Sound.Play ( sounds.dying )
- Timer.Stop ( Timer.Start( "SpawnEnemy", 1.0, true ))
- Hud.Message ( "GAME OVER\n\n You Have Died",5 )
- player.pause = true
- --Timer.Start ( "GameOver", 1, true )
- GameOver ()
- end
- end
- -- TimeOuts
- 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
- function HitAgain ()
- player.beenHit = false
- end
- function GameOver ()
- if player.pause == true then
- Hud.Message ( "Exit and restart game to retry.\n\n\nNo use staring at the screen...\nNothing is gonna happen.", 100 )
- end
- end
- function canFireAgain ()
- player.canFire = true
- end
- function SpawnEnemy()
- if not player.pause then
- if not walkable then
- spawning = Level.Spawn ( "Enemy", 64, math.random ( 700, 800 ),math.random ( 700, 800 ), "BushBite" )
- if enemies.health == 0 then
- enemies.health = enemies.health + 2
- end
- end
- Timer.Start ( "KillEnemy", 5, true )
- end
- end
- function KillEnemy ()
- Level.RemoveObject ( enemy )
- Timer.Start ( "SpawnEnemy",3 , false )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement