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..."); } } }
public void Initialize() { CreateEntityEvent evt = CreateEntityEvent.New("space"); EventManager.Queue(evt); createAndInitializePlayer(); createAndInitializeAliens(); }
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); }
private void createProjectileAtCurrentPosition() { string projectileType = entity[Key_ProjectileType]; var evt = CreateEntityEvent.New(projectileType); Entity owner = entity; evt.AddAttribute(ProjectileBehavior.Key_ProjectileOwner, owner); string faction = entity[CollisionBehavior.Key_Faction]; evt.AddAttribute(CollisionBehavior.Key_Faction, faction); Vector2D position = entity[SpatialBehavior.Key_Position]; Vector2D dimensions = entity[SpatialBehavior.Key_Dimensions]; float startX = position.X + (dimensions.X / 2f) - 2.5f; float startY = position.Y + (dimensions.Y / 2f); Vector2D pewpewPosition = new Vector2D(startX, startY); evt.AddAttribute(SpatialBehavior.Key_Position, pewpewPosition); eventManager.Queue(evt); }
private void handleMysteryShip(float deltaTime) { if (mysteryShip != null) { return; } timeSinceLastMysteryShipSpawn += deltaTime; if (timeSinceLastMysteryShipSpawn >= timeToNextMysteryShipSpawn) { var createEntity = CreateEntityEvent.New("mystery_ship"); bool isSpawningOnTheRight = rng.Next(2) == 1; if (isSpawningOnTheRight) { Vector2D position = new Vector2D(Game.World.Width, Game.World.Height - 100); createEntity.AddAttribute(SpatialBehavior.Key_Position, position); Vector2D direction = new Vector2D(-1, 0); createEntity.AddAttribute(SpatialBehavior.Key_MoveDirection, direction); } else { Vector2D position = new Vector2D(-70, Game.World.Height - 100); createEntity.AddAttribute(SpatialBehavior.Key_Position, position); Vector2D direction = new Vector2D(1, 0); createEntity.AddAttribute(SpatialBehavior.Key_MoveDirection, direction); } EventManager.Queue(createEntity); timeSinceLastMysteryShipSpawn = 0.0f; timeToNextMysteryShipSpawn = minMysteryShipSpawnTime + rng.Next(maxMysteryShipSpawnTime); } }