private void Collision(Entity hitEnt) { var hitObj = GamePool.GetMoveableByEntityId(hitEnt.ID); // Check if one of the objects is already dead. if (IsAlive && hitObj != null) { OnCollision(hitObj); } }
public static Gun Create(Vec3 firingDirection) { // We need an ID. Otherwise we can not add this to pool. var gun = Entity.Instantiate <Gun>(Vec3.Zero, Quat.Identity); gun.Speed = firingDirection; // This is currently used to register Gun for receiving update calls (Move) which decreases the cool-downtimer. GamePool.AddObjectToPool(gun); return(gun); }
protected override void OnCollision(DestroyableBase hitEnt) { // Always remove projectile on collision. GamePool.FlagForPurge(ID); // Kill particle trail (bullet) if (WeaponBulletParticleEffect != null) { GetParticleEmitter(1).Kill(); } }
public override void OnCollision(CollisionEvent collisionEvent) { // Always remove projectile on collision. GamePool.FlagForPurge(Entity.Id); // Kill particle trail (bullet) if (WeaponBulletParticleEffect != null) { Entity.GetParticleEmitter(1).Kill(); } }
public void OnDestroy() { AudioManager.PlayTrigger("game_stop"); // Un-Hook Key input event. Input.OnKey -= Input_OnKey; GamePool.Clear(); // Store highscore. Highscore.CurrentScore.StoreToFile(); }
public override Vec3 Move() { if (LifeTime > 0) { LifeTime -= FrameTime.Current; } else { GamePool.FlagForPurge(ID); // Let destroy current projectile. } return(base.Move()); }
public override Vector3 Move() { if (LifeTime > 0) { LifeTime -= FrameTime.Delta; } else { GamePool.FlagForPurge(Entity.Id); // Let destroy current projectile. } return(base.Move()); }
public static LightGun Create(Vec3 firingDirection) { var lightGun = Entity.Instantiate <LightGun> (Vec3.Zero, Quat.Identity); lightGun.Speed = firingDirection; // Weapon is usded by enemy. Prevent from firing immediatelly after spawn. lightGun.CoolDownTime = 0.3f; // This is currently used to register Gun for receiving update calls (Move) which decreases the cool-downtimer. GamePool.AddObjectToPool(lightGun); return(lightGun); }
public void Dispose() { AudioManager.PlayTrigger("game_stop"); // Un-Hook Key input event. Input.OnKey -= Input_OnKey; GamePool.Clear(); GameFramework.UnregisterFromUpdate(this); // Store highscore. //Highscore.CurrentScore.StoreToFile(); }
public static DefaultAmmo Create(Vec3 pos, Vec3 speed, bool isHostile, IParticleEffect weaponTrailParticleEffect, IParticleEffect weaponSmokeParticleEffect) { var ammo = Entity.Instantiate <DefaultAmmo> (pos, Quat.Identity, 0.5f, "objects/default/primitive_sphere.cgf"); ammo.LifeTime = 3f; ammo.Speed = speed; ammo.IsHostile = isHostile; ammo.WeaponSmokeParticleEffect = weaponSmokeParticleEffect; ammo.WeaponBulletParticleEffect = weaponTrailParticleEffect; // Causes geometry not to be rendered, as the entity particle effect is used as bullet ammo.SetSlotFlag(0, EEntitySlotFlags.ENTITY_SLOT_RENDER_NEAREST); ammo.SpawnParticles(); GamePool.AddObjectToPool(ammo); return(ammo); }
private void ExitRunningGame(string name, double score, bool saveScore) { if (saveScore) { Highscore.CurrentScore.TryAddScore(new GameData() { Score = score, Name = name }); } _totalGameTime = 0; Hud.CurrentHud.Hide(); GamePool.Clear(); State = GameState.Finished; if (GameOver != null) { GameOver(saveScore); } }
/// <summary> /// Spawn this instance. /// </summary> public static Player Create(Vec3 pos) { var player = Entity.Instantiate <Player>(pos, Quat.Identity, 10, PlayerSkin.Geometry); var particleEffect = Env.ParticleManager.FindEffect("spaceship.Trails.fire_trail"); player.LoadParticleEmitter(1, particleEffect, 0.03f); // Get position where to spawn the particle effect. Vec3 jetPosition = player.GetHelperPos(0, "particle_01"); // Rotate particle effect to ensure it's shown at the back of the ship. player.SetTM(1, Matrix34.Create(Vec3.One, Quat.CreateRotationX(Utils.Deg2Rad(270f)), jetPosition)); // Rotate Z-Axis of player ship in degrees. player.Rotation = new Quat(Matrix34.CreateRotationZ(Utils.Deg2Rad(180.0f))); Hud.CurrentHud.SetEnergy(player.MaxLife); GamePool.AddObjectToPool(player); return(player); }
public static DefaultAmmo Create(Vector3 pos, Vector3 speed, bool isHostile, IParticleEffect weaponTrailParticleEffect, IParticleEffect weaponSmokeParticleEffect) { var ammo = Entity.SpawnWithComponent <DefaultAmmo> (pos, Quaternion.Identity, 0.5f); ammo.Entity.LoadGeometry(0, "objects/default/primitive_sphere.cgf"); ammo.Entity.Physics.Physicalize(0, 1, EPhysicalizationType.ePT_Rigid); ammo.LifeTime = 3f; ammo.Speed = speed; ammo.IsHostile = isHostile; ammo.WeaponSmokeParticleEffect = weaponSmokeParticleEffect; ammo.WeaponBulletParticleEffect = weaponTrailParticleEffect; // Causes geometry not to be rendered, as the entity particle effect is used as bullet ammo.Entity.SetSlotFlag(0, EEntitySlotFlags.ENTITY_SLOT_RENDER_NEAREST); ammo.SpawnParticles(); GamePool.AddObjectToPool(ammo); return(ammo); }
public void ProcessHit(bool lethal = false) { if (_impactCoolDownFrameCount > 0) { return; } DrainLife(HitDamage); DestroyParticleEffect.Spawn(Position); if (lethal) { DrainLife(MaxLife); } Hud.CurrentHud.SetEnergy(Life); if (Life == 0) { GamePool.FlagForPurge(ID); for (int i = 0; i < _weapons.Count; i++) { GamePool.FlagForPurge(_weapons [i].ID); } Destroy(); } else { // Based on the previous frametime, calculate how many frames might be needed before 2 more seconds are over _impactCoolDownFrameCount = (int)(2f / FrameTime.Delta); int framesForEachBlink = _impactCoolDownFrameCount / 10; // Set individual frames used to start- & stop blinking effects for (int i = 0; i < _impactCoolDownFrames.Length; i++) { _impactCoolDownFrames[i] = _impactCoolDownFrameCount - (framesForEachBlink * (i - 1)); } } }
public virtual void OnUpdate() { // Ensures physics won't kick in while paused. if (State == GameState.Paused) { GamePool.UpdatePoolForPausedGame(); } if (State != GameState.Running) { return; } // Increase level every 30 seconds. _totalGameTime += FrameTime.Current; Hud.CurrentHud.SetStage((int)_totalGameTime / 30 + 1); // Go Game Over if player destroyed. if (_player.IsAlive == false) { // Avoid counting scores. State = GameState.Paused; if (_gameOverTime == DateTime.MinValue) { _gameOverTime = DateTime.Now; Mouse.ShowCursor(); Hud.CurrentHud.ShowGameOverDialog(); } } // Handle dynamic spawning of tunnels, doors and lights (does not handle tunnel movement). _levelElements.UpdateGeometry(); // Check Key input and update player speed. if (_player.Exists) { _player.CheckCoolDown(); _player.UpdateSpeed(); // Rotation while moving makes the game more dynamic. // Might be explained in an advanced tutorial. _player.UpdateRotation(); } // Update position of game objects including player. GamePool.UpdatePool(); Hud.CurrentHud.SetScore(_gameData.Score); // Add frame time and check if greater than or equal timer. _spawnTimer += FrameTime.Current; if (_spawnTimer >= SPAWN_EVERY_SECONDS) { // Reset spawn timer. _spawnTimer = 0; int waveType = Rand.NextInt(3); int enemyType = Rand.NextInt(3); // Increase speed for each difficulty level. Vec3 waveSpeed = new Vec3(0f, -11f - (Hud.CurrentHud.Stage * 2), 0f); if ((Enemy.WaveType)waveType == Enemy.WaveType.VerticalLine) { Enemy.SpawnWave(new Vec3(65, 660, 79), enemyType, Enemy.WaveType.VerticalLine, waveSpeed); } else if ((Enemy.WaveType)waveType == Enemy.WaveType.HorizontalLine) { var waveOffset = Rand.NextInt(3); Enemy.SpawnWave(new Vec3(65, 664, 72 + waveOffset), enemyType, Enemy.WaveType.HorizontalLine, waveSpeed); Enemy.SpawnWave(new Vec3(65, 664, 64 + waveOffset), enemyType, Enemy.WaveType.HorizontalLine, waveSpeed); } else if ((Enemy.WaveType)waveType == Enemy.WaveType.Diagonal) { Enemy.SpawnWave(new Vec3(65, 660, 79), enemyType, Enemy.WaveType.Diagonal, waveSpeed); } } }