public void takeDamage(int damage) { if (state != PsiEmitterState.FIRING) { return; } Health -= damage; if (Health <= 0) { recoverTime = 3f; state = PsiEmitterState.RECOVERING; Health = 100; ScrollingShooterGame.GameObjectManager.CreateExplosion(ID); } }
/// <summary> /// Handles collisions /// </summary> private void checkForCollisions() { foreach (CollisionPair pair in ScrollingShooterGame.GameObjectManager.Collisions) { if (pair.A == this.ID || pair.B == this.ID) { uint colliderID = (pair.A == this.ID) ? pair.B : pair.A; GameObject collider = ScrollingShooterGame.GameObjectManager.GetObject(colliderID); Projectile projectile = collider as Projectile; if (projectile != null && projectile as EnemyPsiBall == null) { //TODO: implement health this.state = PsiEmitterState.RECOVERING; ScrollingShooterGame.GameObjectManager.DestroyObject(colliderID); } } } }
/// <summary> /// Updates the psi emitter /// </summary> /// <param name="elapsedTime">Time passed since last frame</param> public override void Update(float elapsedTime) { if (state == PsiEmitterState.DESTROYED) return; this.psiOrbRotation += (float)Math.PI * elapsedTime; if (state == PsiEmitterState.INACTIVE) return; if (timeUntilDirectionSwitch <= 0) { targetRotationSpeed *= -1; timeUntilDirectionSwitch = 15 + rand.Next(15); } else { timeUntilDirectionSwitch -= elapsedTime; } checkForCollisions(); switch (state) { case PsiEmitterState.INACTIVE: break; case PsiEmitterState.FIRING: timeUntilNextShot -= elapsedTime; if (currentShotSpeed < targetShotSpeed) currentShotSpeed += 50 * elapsedTime; else currentShotSpeed = targetShotSpeed; if (shotDelay > targetShotDelay) shotDelay -= 0.015f * elapsedTime; else shotDelay = targetShotDelay; if (rotationSpeed < targetRotationSpeed) rotationSpeed += (float)(Math.PI / 10 * elapsedTime); else rotationSpeed -= (float)(Math.PI/10 * elapsedTime); armRotation += rotationSpeed * elapsedTime; if (timeUntilNextShot > 0) return; else timeUntilNextShot = shotDelay; float armAngle; EnemyPsiBall projectile; for (int i = 0; i < numArms; i++) { armAngle = (float)((Math.PI * 2) * (i / (float) (numArms))) + armRotation; projectile = ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.EnemyPsyBall, position) as EnemyPsiBall; projectile.Initialize(armAngle, (int) currentShotSpeed); ApplyProjectileColor(projectile); } break; case PsiEmitterState.RECOVERING: //TODO: add recover time between fire stages, make emblem/orb look disabled during recovery //TODO: change orb/emblem color/size for each fire stage numArms++; if (numArms > 5) { numArms = 0; state = PsiEmitterState.DESTROYED; } else { rotationSpeed = 0; currentShotSpeed = 20; updateShotValues(); state = PsiEmitterState.FIRING; } break; } }
/// <summary> /// Awakens the psi emitter so it will start fighting /// </summary> public void startAttacking() { this.state = PsiEmitterState.FIRING; updateShotValues(); }
/// <summary> /// Updates the psi emitter /// </summary> /// <param name="elapsedTime">Time passed since last frame</param> public override void Update(float elapsedTime) { if (state == PsiEmitterState.DESTROYED) return; this.psiOrbRotation += (float)Math.PI * elapsedTime; if (state == PsiEmitterState.INACTIVE) return; if (timeUntilDirectionSwitch <= 0) { targetRotationSpeed *= -1; timeUntilDirectionSwitch = 15 + rand.Next(15); } else { timeUntilDirectionSwitch -= elapsedTime; } switch (state) { case PsiEmitterState.INACTIVE: break; case PsiEmitterState.FIRING: timeUntilNextShot -= elapsedTime; if (currentShotSpeed < targetShotSpeed) currentShotSpeed += 25 * elapsedTime; else currentShotSpeed = targetShotSpeed; if (shotDelay > targetShotDelay) shotDelay -= 0.015f * elapsedTime; else shotDelay = targetShotDelay; if (rotationSpeed < targetRotationSpeed) rotationSpeed += (float)(Math.PI / 10 * elapsedTime); else rotationSpeed -= (float)(Math.PI/10 * elapsedTime); armRotation += rotationSpeed * elapsedTime; if (timeUntilNextShot > 0) return; else timeUntilNextShot = shotDelay; float armAngle; EnemyPsiBall projectile; for (int i = 0; i < numArms; i++) { armAngle = (float)((Math.PI * 2) * (i / (float) (numArms))) + armRotation; projectile = ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.EnemyPsyBall, position) as EnemyPsiBall; projectile.Initialize(armAngle, (int) currentShotSpeed); ApplyProjectileColor(projectile); } break; case PsiEmitterState.RECOVERING: recoverTime -= elapsedTime; tintColor.R = (byte) rand.Next(255); tintColor.G = (byte) rand.Next(255); tintColor.B = (byte) rand.Next(255); if (recoverTime > 0) return; numArms++; if (numArms > 5) { numArms = 0; Health = 0; state = PsiEmitterState.DESTROYED; } else { rotationSpeed = 0; updateShotValues(); tintColor = Color.White; state = PsiEmitterState.FIRING; } break; } }
public void takeDamage(int damage) { if (state != PsiEmitterState.FIRING) return; Health -= damage; if (Health <= 0) { recoverTime = 3f; state = PsiEmitterState.RECOVERING; Health = 100; ScrollingShooterGame.GameObjectManager.CreateExplosion(ID); } }
/// <summary> /// Updates the psi emitter /// </summary> /// <param name="elapsedTime">Time passed since last frame</param> public override void Update(float elapsedTime) { if (state == PsiEmitterState.DESTROYED) { return; } this.psiOrbRotation += (float)Math.PI * elapsedTime; if (state == PsiEmitterState.INACTIVE) { return; } if (timeUntilDirectionSwitch <= 0) { targetRotationSpeed *= -1; timeUntilDirectionSwitch = 15 + rand.Next(15); } else { timeUntilDirectionSwitch -= elapsedTime; } switch (state) { case PsiEmitterState.INACTIVE: break; case PsiEmitterState.FIRING: timeUntilNextShot -= elapsedTime; if (currentShotSpeed < targetShotSpeed) { currentShotSpeed += 25 * elapsedTime; } else { currentShotSpeed = targetShotSpeed; } if (shotDelay > targetShotDelay) { shotDelay -= 0.015f * elapsedTime; } else { shotDelay = targetShotDelay; } if (rotationSpeed < targetRotationSpeed) { rotationSpeed += (float)(Math.PI / 10 * elapsedTime); } else { rotationSpeed -= (float)(Math.PI / 10 * elapsedTime); } armRotation += rotationSpeed * elapsedTime; if (timeUntilNextShot > 0) { return; } else { timeUntilNextShot = shotDelay; } float armAngle; EnemyPsiBall projectile; for (int i = 0; i < numArms; i++) { armAngle = (float)((Math.PI * 2) * (i / (float)(numArms))) + armRotation; projectile = ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.EnemyPsyBall, position) as EnemyPsiBall; projectile.Initialize(armAngle, (int)currentShotSpeed); ApplyProjectileColor(projectile); } break; case PsiEmitterState.RECOVERING: recoverTime -= elapsedTime; tintColor.R = (byte)rand.Next(255); tintColor.G = (byte)rand.Next(255); tintColor.B = (byte)rand.Next(255); if (recoverTime > 0) { return; } numArms++; if (numArms > 5) { numArms = 0; Health = 0; state = PsiEmitterState.DESTROYED; } else { rotationSpeed = 0; updateShotValues(); tintColor = Color.White; state = PsiEmitterState.FIRING; } break; } }