private void handleDamage(DamageEvent evt) { if (entity.IsDead || entity[Key_IsInvulnerable]) { return; } int health = entity[Key_Health]; health -= evt.Damage; entity[Key_Health] = health; if (health <= 0) { int lifes = entity[Key_Lifes]; lifes -= 1; entity[Key_Lifes] = lifes; entity.State = EntityState.Dying; if (entity.Type == "player") { HudEvent hudEvent = HudEvent.UpdateLifes(lifes); eventManager.Queue(hudEvent); CreateEntityEvent createEvt = CreateEntityEvent.New("player_death"); Vector2D position = entity[SpatialBehavior.Key_Position]; position.X -= 90; position.Y -= 90; createEvt.AddAttribute(SpatialBehavior.Key_Position, position); eventManager.Queue(createEvt); entity[RenderBehavior.Key_IsRenderable] = false; } if (lifes <= 0) { Entity projectile = entity.Game.World.Entities[evt.SourceEntityID]; Entity projectileOwner = projectile[ProjectileBehavior.Key_ProjectileOwner]; int destroyedByEntityID = projectile.ID; if (projectileOwner != null) { destroyedByEntityID = projectileOwner.ID; } eventManager.Queue(DestroyEntityEvent.Destroy(entity.ID, destroyedByEntityID)); Console.WriteLine("[" + this.GetType().Name + "] Entity " + entity + " died a horrible death!"); } else { RespawnEntityEvent respawnEvent = RespawnEntityEvent.Respawn(entity.ID); eventManager.Queue(respawnEvent); Console.WriteLine("[" + this.GetType().Name + "] Entity " + entity + " lost a life. " + lifes + " lifes remaining. Respawning..."); } } }
private void createAndInitializeAlien(string type, float x, float y) { CreateEntityEvent evt = CreateEntityEvent.New(type); Vector2D position = new Vector2D(x, y); evt.AddAttribute(SpatialBehavior.Key_Position, position); EventManager.Queue(evt); }
private void createAndInitializePlayer() { CreateEntityEvent evt = CreateEntityEvent.New("player"); float startX = Width / 2f - (75f / 2f); float startY = 75 - (75f / 2f); Vector2D position = new Vector2D(startX, startY); evt.AddAttribute(SpatialBehavior.Key_Position, position); EventManager.Queue(evt); }