public override void CollidedWith(GameObject otherObject) { current = State.Dying; DIContainer.Get <Collider>("Collider").UnRegister(this); Collision?.Invoke(this, null); Destroy(); }
public void Kill() { current = State.Dying; DIContainer.Get <Collider>("Collider").UnRegister(this); currentSprite = explosionSprite; explosionSprite.Position = commanderSprite.Position; commanderSprite.Hide(); explosionSprite.Show(); }
public Bullet(Point startPosition, int id) { bulletSprite = new AnimatedSprite("bullet", 1, 1, 1, true, startPosition, null); bulletSprite.Position.X -= bulletSprite.Width / 2; var collider = DIContainer.Get <Collider>("Collider"); var aliens = DIContainer.Get <AlienBag>("AlienBag"); collider.Register(this, aliens.Aliens.Values.ToArray()); Id = id; }
public Commander(int id) { commanderSprite = new AnimatedSprite("commander", 3, 1, 12, true, Point.Zero, null); explosionSprite = new AnimatedSprite("commander_explosion", 7, 1, 14, false, Point.Zero, () => Destroy()); explosionSprite.Hide(); currentSprite = commanderSprite; commanderSprite.Position = new Point(Env.Screen.Width / 2 + commanderSprite.Width / 2, Env.Screen.Height - 100); Id = id; addQueue = DIContainer.Get <Queue <Tuple <int, GameObject> > >("AddQueue"); removeQueue = DIContainer.Get <Queue <Tuple <int, GameObject> > >("RemoveQueue"); sounds.Add("shoot_sound", DIContainer.Get <AssetLoader>("AssetLoader").Content.Load <SoundEffect>("shoot_sound")); }
public AnimatedSprite(string spriteId, int rows, int cols, int frameRate, bool shouldLoop, Point startPosition, Action animationEnd) { this.id = spriteId; this.texture = DIContainer.Get <AssetLoader>("AssetLoader").LoadTexture(id); this.rows = rows; this.cols = cols; this.width = texture.Width; this.height = texture.Height / rows; this.FrameRate = frameRate; this.Position = startPosition; this.lastElapsedTime = TimeSpan.FromMilliseconds(0); this.totalFrames = rows * cols; this.shouldLoop = shouldLoop; this.animationEnd = animationEnd; }
private void ResetGame() { lives = 4; score = 0; DIContainer.Add <Dictionary <int, GameObject> >("GameObjects", GameObjects); DIContainer.Add <Queue <Tuple <int, GameObject> > >("AddQueue", addQueue); DIContainer.Add <Queue <Tuple <int, GameObject> > >("RemoveQueue", removeQueue); collider = new Collider(); DIContainer.Add <Collider>("Collider", collider); alienBag = new AlienBag(); DIContainer.Add <AlienBag>("AlienBag", alienBag); alienBag.AllDead += (o, e) => NextLevel(currentLevel++); alienBag.AlienDead += (o, e) => updateScore(e); alienBag.AlienVictory += (o, e) => { isAlienVictorious = true; commander.Kill(); }; font = DIContainer.Get <AssetLoader>("AssetLoader").Content.Load <SpriteFont>("courier"); }
public AlienBag() { gameObjects = DIContainer.Get <Dictionary <int, GameObject> >("GameObjects"); addQueue = DIContainer.Get <Queue <Tuple <int, GameObject> > >("AddQueue"); }
public void BeforeStart(GameStageSettings settings = null) { font = DIContainer.Get <AssetLoader>("AssetLoader").Content.Load <SpriteFont>("courier"); }