Exemplo n.º 1
0
 public override void CollidedWith(GameObject otherObject)
 {
     current = State.Dying;
     DIContainer.Get <Collider>("Collider").UnRegister(this);
     Collision?.Invoke(this, null);
     Destroy();
 }
Exemplo n.º 2
0
 public void Kill()
 {
     current = State.Dying;
     DIContainer.Get <Collider>("Collider").UnRegister(this);
     currentSprite            = explosionSprite;
     explosionSprite.Position = commanderSprite.Position;
     commanderSprite.Hide();
     explosionSprite.Show();
 }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        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"));
        }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
        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");
        }
Exemplo n.º 7
0
 public AlienBag()
 {
     gameObjects = DIContainer.Get <Dictionary <int, GameObject> >("GameObjects");
     addQueue    = DIContainer.Get <Queue <Tuple <int, GameObject> > >("AddQueue");
 }
Exemplo n.º 8
0
 public void BeforeStart(GameStageSettings settings = null)
 {
     font = DIContainer.Get <AssetLoader>("AssetLoader").Content.Load <SpriteFont>("courier");
 }