Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scene@ scene_;
- Node@ cameraNode;
- Node@ playerNode;
- int zombie_spawn_time = 333;
- int maxZombies = 300;
- int numZombies = 0;
- float zombie_agrDist = 25;
- bool drawDebug = false;
- Text@ uiHealth;
- Text@ uiZombies;
- bool dead = false;
- bool fpscap = false;
- float charge = 3;
- Text@ uiCharge;
- Node@ wpNode;
- bool ok = true;
- int score = 0;
- Text@ uiScore;
- float health = 100;
- int maxChain = 0;
- int chainTimer = 0;
- Text@ uiChain;
- Text@ helpText;
- int helpTimer = 800;
- Material@ powmat;
- Sprite@ splash;
- int splashtimer = 400;
- void Start()
- {
- CreateConsoleAndDebugHud();
- scene_ = Scene();
- initStuff();
- SubscribeToEvent("KeyDown", "HandleKeyDown");
- SubscribeToEvent("PostRenderUpdate", "HandlePostRenderUpdate");
- powmat = cache.GetResource("Material", "Materials/pow.xml");
- ValueAnimation@ ColorAnimation = ValueAnimation();
- ColorAnimation.SetKeyFrame(0.0f, Variant(Color(0.6, 0.8, 1, 1)));
- ColorAnimation.SetKeyFrame(0.2f, Variant(Color(0.0f, 0.1f, 0.3f, 1.0f)));
- powmat.SetShaderParameterAnimation("MatDiffColor", ColorAnimation);
- Texture2D@ splashTex = cache.GetResource("Texture2D", "Textures/splash.png");
- splash = Sprite();
- splash.texture = splashTex;
- splash.size = IntVector2(1024,512);
- splash.hotSpot = IntVector2(512, 512);
- splash.verticalAlignment = VA_CENTER;
- splash.horizontalAlignment = HA_CENTER;
- ui.root.AddChild(splash);
- uiHealth = ui.root.CreateChild("Text");
- uiHealth.text = "100";
- uiHealth.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 75);
- uiHealth.SetPosition(-20, -20);
- uiHealth.horizontalAlignment = HA_RIGHT;
- uiHealth.verticalAlignment = VA_BOTTOM;
- Text@ uiHealth2 = ui.root.CreateChild("Text");
- uiHealth2.text = "Health";
- uiHealth2.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 25);
- uiHealth2.SetPosition(-20, -120);
- uiHealth2.horizontalAlignment = HA_RIGHT;
- uiHealth2.verticalAlignment = VA_BOTTOM;
- uiZombies = ui.root.CreateChild("Text");
- uiZombies.text = "0";
- uiZombies.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 75);
- uiZombies.SetPosition(20, -20);
- uiZombies.horizontalAlignment = HA_LEFT;
- uiZombies.verticalAlignment = VA_BOTTOM;
- Text@ uiZombies2 = ui.root.CreateChild("Text");
- uiZombies2.text = "Zombies";
- uiZombies2.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 25);
- uiZombies2.SetPosition(20, -120);
- uiZombies2.horizontalAlignment = HA_LEFT;
- uiZombies2.verticalAlignment = VA_BOTTOM;
- Text@ uiGamover = ui.root.CreateChild("Text");
- uiGamover.text = "You are DEAD!";
- uiGamover.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 125);
- uiGamover.horizontalAlignment = HA_CENTER;
- uiGamover.verticalAlignment = VA_CENTER;
- uiGamover.color = RED;
- uiGamover.visible = false;
- uiGamover.name = "TextGamover";
- Text@ uiGamover2 = ui.root.CreateChild("Text");
- uiGamover2.text = "Press F5 to restart.";
- uiGamover2.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 35);
- uiGamover2.horizontalAlignment = HA_CENTER;
- uiGamover2.verticalAlignment = VA_CENTER;
- uiGamover2.SetPosition(0,100);
- uiGamover2.color = RED;
- uiGamover2.visible = false;
- uiGamover2.name = "TextGamover2";
- Text@ crosshair = ui.root.CreateChild("Text");
- crosshair.text = "+";
- crosshair.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 25);
- crosshair.horizontalAlignment = HA_CENTER;
- crosshair.verticalAlignment = VA_CENTER;
- crosshair.color = Color(1,1,1,0.5);
- uiCharge = ui.root.CreateChild("Text");
- uiCharge.text = "3";
- uiCharge.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 75);
- uiCharge.SetPosition(300, -20);
- uiCharge.horizontalAlignment = HA_LEFT;
- uiCharge.verticalAlignment = VA_BOTTOM;
- Text@ uiCharge2 = ui.root.CreateChild("Text");
- uiCharge2.text = "Charge";
- uiCharge2.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 25);
- uiCharge2.SetPosition(300, -120);
- uiCharge2.horizontalAlignment = HA_LEFT;
- uiCharge2.verticalAlignment = VA_BOTTOM;
- uiScore = ui.root.CreateChild("Text");
- uiScore.text = "0";
- uiScore.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 75);
- uiScore.SetPosition(-20, 20);
- uiScore.horizontalAlignment = HA_RIGHT;
- uiScore.verticalAlignment = VA_TOP;
- Text@ uiScore2 = ui.root.CreateChild("Text");
- uiScore2.text = "Score";
- uiScore2.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 25);
- uiScore2.SetPosition(-20, 120);
- uiScore2.horizontalAlignment = HA_RIGHT;
- uiScore2.verticalAlignment = VA_TOP;
- uiChain = ui.root.CreateChild("Text");
- uiChain.text = "";
- uiChain.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 75);
- uiChain.horizontalAlignment = HA_CENTER;
- uiChain.verticalAlignment = VA_TOP;
- uiChain.SetPosition(0,100);
- uiChain.color = YELLOW;
- helpText = ui.root.CreateChild("Text");
- helpText.text =
- "* Your weapon charges only when zombies are nearby.\n"
- "* Gather a hoard, then kill em with one shot, to get\n"
- "more score points and restore health.\n"
- "* Hop uphill to gain momentum. Move straight to keep it.\n"
- "Controls:\n"
- "SPACE - show help\n"
- "WASD - hop around\n"
- "LMB - shoot the zapper\n"
- "F5 - restart\n"
- "F1 - console (nothing to see here)\n"
- "F2 - show profiler\n"
- "F3 - enable SUPAHAKER vision\n"
- "F9 - spawn more zombies\n"
- "F12 - take screenshot\n";
- helpText.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 15);
- helpText.horizontalAlignment = HA_CENTER;
- helpText.verticalAlignment = VA_CENTER;
- helpText.SetPosition(0,200);
- helpText.color = YELLOW;
- }
- void initStuff()
- {
- scene_.LoadXML(cache.GetFile("Scenes/scene_1.xml"));
- //scene_.CreateComponent("PhysicsWorld");
- cameraNode = Node();
- Camera@ camera = cameraNode.CreateComponent("Camera");
- renderer.viewports[0] = Viewport(scene_, camera);
- camera.fov = 80.0f;
- audio.listener = cameraNode.CreateComponent("SoundListener");
- //cameraNode.position = Vector3(0,1,-10);
- Node@ SpawnerNode = scene_.CreateChild("spawner");
- Spawner@ spawner = cast<Spawner>(SpawnerNode.CreateScriptObject(scriptFile, "Spawner"));
- spawner.Init();
- scene_.physicsWorld.gravity = Vector3( 0 , -9.8 * 2 , 0 );
- playerNode = scene_.CreateChild("player");
- playerNode.position = Vector3(0,6,0);
- //playerNode.rotation = Quaternion(180, Vector3(0,1,0));
- Player@ player = cast<Player>(playerNode.CreateScriptObject(scriptFile, "Player"));
- player.Init();
- engine.maxFps = 60;
- }
- void Restart()
- {
- scene_.RemoveAllChildren();
- initStuff();
- dead = false;
- ui.root.GetChild("TextGamover").visible = false;
- ui.root.GetChild("TextGamover2").visible = false;
- charge = 3;
- numZombies = 0;
- ok = true;
- health = 100;
- }
- void CreateConsoleAndDebugHud()
- {
- // Get default style
- XMLFile@ xmlFile = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
- if (xmlFile is null)
- return;
- // Create console
- Console@ console = engine.CreateConsole();
- console.defaultStyle = xmlFile;
- console.background.opacity = 0.8f;
- // Create debug HUD
- DebugHud@ debugHud = engine.CreateDebugHud();
- debugHud.defaultStyle = xmlFile;
- }
- void HandleKeyDown(StringHash eventType, VariantMap& eventData)
- {
- int key = eventData["Key"].GetInt();
- // Close console (if open) or exit when ESC is pressed
- if (key == KEY_ESC)
- {
- if (!console.visible)
- engine.Exit();
- else
- console.visible = false;
- }
- // Toggle console with F1
- else if (key == KEY_F1)
- console.Toggle();
- // Toggle debug HUD with F2
- else if (key == KEY_F2)
- debugHud.ToggleAll();
- // Take screenshot
- else if (key == KEY_F12)
- {
- Image@ screenshot = Image();
- graphics.TakeScreenShot(screenshot);
- // Here we save in the Data folder with date and time appended
- screenshot.SavePNG(fileSystem.programDir + "Data/Screenshot_" +
- time.timeStamp.Replaced(':', '_').Replaced('.', '_').Replaced(' ', '_') + ".png");
- }
- // Toggle physics debug
- else if (key == KEY_F3)
- drawDebug = !drawDebug;
- else if (key == KEY_F5) Restart();
- else if (key == KEY_SPACE)
- {
- helpText.visible = true;
- helpTimer = 300;
- }
- }
- void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)
- {
- // If draw debug mode is enabled, draw physics debug geometry. Use depth test to make the result easier to interpret
- // Note the convenience accessor to the physics world component
- if (drawDebug)
- scene_.physicsWorld.DrawDebugGeometry(true);
- uiZombies.text = numZombies;
- uiScore.text = score;
- }
- class Player : ScriptObject
- {
- RigidBody@ body;
- Vector3 dir = Vector3(0,0,1);
- Vector2 walk = Vector2(0,0);
- float speed = 30;
- float jump = 40;
- int jumpTime = 10;
- int jumpTimer = 0;
- Vector2 mouseInput = Vector2(180,0);
- float sens = 0.2;
- int stunTime = 60;
- int stunTimer = 62;
- void Init()
- {
- StaticModel@ plModel = node.CreateComponent("StaticModel");
- plModel.model = cache.GetResource("Model", "Models/hatman.mdl");
- plModel.material = cache.GetResource("Material", "Materials/hatman.xml");
- plModel.castShadows = true;
- body = node.CreateComponent("RigidBody");
- CollisionShape@ ColShape = node.CreateComponent("CollisionShape");
- ColShape.SetCapsule(1,2);
- body.mass = 10;
- body.linearDamping = 0.4;
- body.angularFactor = Vector3(0.0f, 0.0f, 0.0f);
- body.collisionLayer = 2;
- node.AddChild(cameraNode);
- cameraNode.position = Vector3(0,0.6,0);
- wpNode = playerNode.CreateChild('wpNode');
- StaticModel@ wpMpdel = wpNode.CreateComponent("StaticModel");
- wpMpdel.model = cache.GetResource("Model", "Models/zapper.mdl");
- wpMpdel.material = cache.GetResource("Material", "Materials/zapper.xml");
- wpMpdel.castShadows = true;
- wpNode.position = Vector3(0.5,0,-0.1);
- }
- void Update(float timeStep)
- {
- if (health > 0 && stunTimer>stunTime)
- {
- //body.rotation = Quaternion(Vector3(0,0,-1), Vector3(dir.x,0,dir.z));
- body.angularVelocity = Vector3(0,0,0);
- walk = Vector2(0,0);
- if (input.keyDown['w']) walk.y = -1;
- if (input.keyDown['a']) walk.x = 1;
- if (input.keyDown['d']) walk.x = -1;
- if (input.keyDown['s']) walk.y = 1;
- walk.Normalize();
- mouseInput.x += input.mouseMoveX * sens;
- mouseInput.y += input.mouseMoveY * sens;
- mouseInput.y = Clamp( mouseInput.y , -90.0f, 90.0f);
- cameraNode.rotation = Quaternion(mouseInput.y , Vector3(1,0,0));
- //cameraNode.rotation = cameraNode.rotation * Quaternion(mouseInput.x , Vector3(0,1,0));
- body.rotation = Quaternion(mouseInput.x , Vector3(0,1,0));
- if (charge>3) charge = 3;
- if (charge < 1)
- {
- uiCharge.color = RED;
- ok = false;
- }
- else if (!ok)
- {
- uiCharge.color = WHITE;
- Sound@ sound = cache.GetResource("Sound", "Sounds/ok.wav");
- SoundSource@ soundSource = node.CreateComponent("SoundSource");
- soundSource.Play(sound);
- soundSource.gain = 0.7f;
- soundSource.autoRemove = true;
- ok = true;
- }
- uiCharge.text = Floor(charge * 1000)/1000;
- wpNode.rotation = cameraNode.rotation;
- wpNode.position = Vector3(0.5,body.linearVelocity.y * -0.006,-0.1);
- }
- }
- void PostUpdate(float timeStep)
- {
- //body.rotation = Quaternion(mouseInput.x , Vector3(0,1,0));
- //body.angularVelocity = Vector3(0,0,0);
- //cameraNode.position = node.position + node.up * 0.6f;
- }
- void FixedUpdate(float timeStep)
- {
- if (health > 0)
- {
- if (stunTimer>stunTime)
- {
- //Quaternion rot = cameraNode.rotation;
- //body.rotation = Quaternion(rot.yaw, Vector3(0,1,0));
- body.angularVelocity = Vector3(0,0,0);
- body.angularFactor = Vector3(0.0f, 0.0f, 0.0f);
- if (input.mouseButtonPress[MOUSEB_LEFT] && charge>=1) ThrowWeapon();
- } else {
- body.angularFactor = Vector3(1.0f, 1.0f, 1.0f);
- }
- if(body.collidingBodies.length>0)
- {
- if (jumpTimer>jumpTime && stunTimer>stunTime)
- {
- jumpTimer = 0;
- if (walk.length>0.1f)
- {
- //body.linearVelocity = Vector3(0,0,0);
- body.ApplyImpulse(body.rotation * Vector3(-1 * speed * walk.x , jump , -1 * speed * walk.y));
- //Audio: PCM 44100Hz mono 705kbps [output]
- Sound@ sound = cache.GetResource("Sound", "Sounds/step.wav");
- SoundSource@ soundSource = node.CreateComponent("SoundSource");
- soundSource.Play(sound);
- soundSource.gain = 0.3f;
- soundSource.autoRemove = true;
- }
- }
- for (uint i=0; i<body.collidingBodies.length ; i++)
- {
- RigidBody@ body2 = body.collidingBodies[i];
- if (body2.node.name == "Zombie" && stunTimer>stunTime)
- {
- Zombie@ obj = cast<Zombie>(body2.node.GetScriptObject("Zombie"));
- if (obj.dead == false)
- {
- Vector3 vec = node.position - body2.node.position;
- vec.Normalize();
- stunTimer = 0;
- health = health - 15;
- charge = charge + 0.5;
- body.ApplyImpulse(Vector3(vec.x * 150, vec.y * 30 +20, vec.z * 150),Vector3(Random(-0.2,0.2),0.003,Random(-0.2,0.2)));
- //dir = node.rotation * Vector3(0,0,1);
- mouseInput = Vector2(0,0);
- Sound@ sound = cache.GetResource("Sound", "Sounds/hit.wav");
- SoundSource@ soundSource = node.CreateComponent("SoundSource");
- soundSource.Play(sound);
- soundSource.gain = 0.7f;
- soundSource.autoRemove = true;
- }
- }
- }
- }
- uiHealth.text = Floor(health);
- if (health<30) uiHealth.color = RED;
- else if (health<50) uiHealth.color = Color(1,0.5,0);
- else if (health<80) uiHealth.color = YELLOW;
- else uiHealth.color = WHITE;
- //if (health < 100) health = health + 0.01;
- if (maxChain > 5)
- {
- uiChain.text = maxChain + "x chain!";
- chainTimer++;
- if (chainTimer > 120)
- {
- maxChain = 0;
- uiChain.text = "";
- }
- }
- } else if (!dead) {
- ui.root.GetChild("TextGamover").visible = true;
- ui.root.GetChild("TextGamover2").visible = true;
- dead = true;
- body.angularFactor = Vector3(1.0f, 1.0f, 1.0f);
- body.friction = 2;
- body.angularDamping = 0.7;
- Sound@ sound = cache.GetResource("Sound", "Sounds/death.wav");
- SoundSource@ soundSource = node.CreateComponent("SoundSource");
- soundSource.Play(sound);
- soundSource.gain = 0.7f;
- soundSource.autoRemove = true;
- }
- jumpTimer++;
- stunTimer++;
- if (node.position.y<-10) health = -1;
- helpTimer--;
- if (helpTimer<1) helpText.visible = false;
- splashtimer--;
- if (splashtimer<1) splash.visible = false;
- }
- void ThrowWeapon()
- {
- Vector3 camdir = cameraNode.worldRotation * Vector3(0,0,1);
- PhysicsRaycastResult result = scene_.physicsWorld.RaycastSingle(Ray(cameraNode.worldPosition, camdir),50,1);
- if (result.body !is null)
- {
- if (result.body.node.name == "Zombie")
- {
- result.body.ApplyImpulse(result.normal * -200,result.position - result.body.position);
- Zombie@ obj = cast<Zombie>(result.body.node.GetScriptObject("Zombie"));
- obj.dead = true;
- obj.PowaTimer = 0;
- obj.DeadTimer = 0;
- charge--;
- Node@ beamNode = scene_.CreateChild('beam');
- Beam@ beam = cast<Beam>(beamNode.CreateScriptObject(scriptFile, "Beam"));
- beam.target = result.body.node;
- //beam.tgPos = result.position - result.body.node.position;
- beam.Init();
- Sound@ sound = cache.GetResource("Sound", "Sounds/shot.wav");
- SoundSource@ soundSource = node.CreateComponent("SoundSource");
- soundSource.Play(sound);
- soundSource.gain = 0.7f;
- soundSource.autoRemove = true;
- }
- }
- }
- }
- class Beam : ScriptObject
- {
- Node@ target;
- //Vector3 tgPos;
- int ttl = 30;
- void Init()
- {
- StaticModel@ beamModel = node.CreateComponent("StaticModel");
- beamModel.model = cache.GetResource("Model", "Models/beam.mdl");
- beamModel.material = powmat;
- Vector3 tgVec = target.worldPosition - node.worldPosition;
- node.rotation = Quaternion(Vector3(0,0,1) , tgVec.Normalized());
- node.Roll(Random(360));
- node.position = wpNode.worldPosition + (wpNode.worldRotation * Vector3(0,0,1) );
- }
- void Update(float timeStep)
- {
- Vector3 tgVec = target.worldPosition - node.worldPosition;
- node.rotation = Quaternion(Vector3(0,0,1) , tgVec.Normalized());
- node.Roll(Random(360));
- node.position = wpNode.worldPosition + (wpNode.worldRotation * Vector3(0,0,1) );
- node.scale = Vector3((35-ttl)/20.0f,(35-ttl)/20.0f,tgVec.length/5); //
- }
- void FixedUpdate(float timeStep)
- {
- ttl--;
- if (ttl<1) node.Remove();
- }
- }
- class Zombie : ScriptObject
- {
- RigidBody@ Zbody;
- Vector2 dir = Vector2(1,0);
- float speed = 20;
- float jump = 50;
- float roam = 0.6;
- int jumpTime = 50;
- int jumpTimer = 0;
- bool dead = false;
- int DeadTime = 800;
- int DeadTimer = 0;
- Node@ powanode;
- int PowaTime = 300;
- int PowaTimer = 0;
- int chain = 1;
- void Init()
- {
- StaticModel@ zombieModel = node.CreateComponent("StaticModel");
- zombieModel.model = cache.GetResource("Model", "Models/capsule.mdl");
- zombieModel.material = cache.GetResource("Material", "Materials/zombie.xml");
- zombieModel.castShadows = true;
- Zbody = node.CreateComponent("RigidBody");
- CollisionShape@ ColShape = node.CreateComponent("CollisionShape");
- ColShape.SetCapsule(1,2);
- Zbody.mass = 10;
- Zbody.linearDamping = 0.6;
- Zbody.angularFactor = Vector3(1,0.3,1);
- dir = Vector2(1-2*Random(),1-2*Random());
- dir.Normalize();
- powanode = node.CreateChild();
- StaticModel@ powaModel = powanode.CreateComponent("StaticModel");
- powaModel.model = cache.GetResource("Model", "Models/pow.mdl");
- powaModel.material = powmat;
- powanode.enabled = false;
- }
- void Update()
- {
- }
- void FixedUpdate(float timeStep)
- {
- if (node.position.y<-10) Remove();
- if (!dead){
- Zbody.rotation = Quaternion(Vector3(0,0,-1), Vector3(dir.x,0,dir.y));
- Zbody.angularVelocity = Vector3(0,0,0);
- if(Zbody.collidingBodies.length>0 && jumpTimer>jumpTime)
- {
- jumpTimer = 0;
- Zbody.ApplyImpulse(Vector3(speed * dir.x , jump , speed * dir.y));
- Sound@ sound = cache.GetResource("Sound", "Sounds/zombStep.wav");
- SoundSource3D @ soundSource = node.CreateComponent("SoundSource3D");
- soundSource.gain = 0.2f;
- soundSource.SetDistanceAttenuation(2, 15, 1);
- soundSource.Play(sound);
- soundSource.autoRemove = true;
- Vector3 playerVec = node.position - playerNode.position;
- if (playerVec.length < zombie_agrDist)
- {
- dir = Vector2(-1 * playerVec.x, -1 * playerVec.z);
- dir.Normalize();
- speed = 40;
- jump = 35;
- jumpTime = 20;
- roam = 0.3;
- charge = charge + 0.01;
- } else {
- speed = 20;
- jump = 50;
- roam = 0.6;
- jumpTime = 50;
- }
- dir = Vector2(dir.x + Random(-1*roam,roam),dir.y + Random(-1*roam,roam));
- dir.Normalize();
- }
- } else {
- DeadTimer++;
- if (DeadTimer > DeadTime) Remove();
- PowaTimer++;
- if (PowaTimer < PowaTime)
- {
- powanode.enabled = true;
- powanode.rotation = Quaternion(Random(360),Vector3(0,1,0));
- Vector3 randomVec = Vector3(Random(-1,1),0,Random(-1,1));
- randomVec.Normalize();
- Zbody.ApplyImpulse(randomVec * Random(0,10), Vector3(0,Random(-2,2),0));
- if(Zbody.collidingBodies.length>0)
- {
- for (uint i=0; i<Zbody.collidingBodies.length ; i++)
- {
- RigidBody@ body2 = Zbody.collidingBodies[i];
- if (body2.node.name == "Zombie")
- {
- Zombie@ obj = cast<Zombie>(body2.node.GetScriptObject("Zombie"));
- Vector3 vec = Zbody.position - body2.position;
- body2.ApplyImpulse(vec * -20, Vector3(0,Random(-2,2),0));
- Sound@ sound = cache.GetResource("Sound", "Sounds/pow.wav");
- SoundSource3D @ soundSource = node.CreateComponent("SoundSource3D");
- soundSource.gain = 0.2f;
- soundSource.SetDistanceAttenuation(2, 30, 1);
- soundSource.Play(sound);
- soundSource.autoRemove = true;
- if (!obj.dead)
- {
- obj.chain = chain + 1;
- score = score + chain * (DeadTimer +10);
- if (health < 100) health = health + chain/4;
- obj.dead = true;
- if (chain > maxChain)
- {
- maxChain = chain;
- chainTimer = 0;
- }
- }
- }
- }
- }
- } else {
- powanode.enabled = false;
- }
- }
- jumpTimer++;
- }
- void Remove()
- {
- numZombies--;
- node.Remove();
- }
- }
- class Spawner : ScriptObject
- {
- int zombie_timer;
- Array<Vector3> spots;
- void Init()
- {
- // for (uint i=0; i< scene_.children.length; i++)
- // {
- // Node@ tnode = scene_.children[i];
- // if (tnode.name = "spawner")
- // {
- //
- // }
- // }
- }
- void FixedUpdate(float timeStep)
- {
- zombie_timer++;
- if (zombie_timer > zombie_spawn_time){
- if (numZombies<maxZombies)
- {
- SpawnZombie();
- }
- zombie_timer = 0;
- }
- if (input.keyPress[KEY_F9])SpawnZombie();
- }
- void SpawnZombie()
- {
- Node@ zombieNode = scene_.CreateChild("Zombie");
- zombieNode.position = node.position;
- Zombie@ zombie = cast<Zombie>(zombieNode.CreateScriptObject(scriptFile, "Zombie"));
- zombie.Init();
- numZombies++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement