Exemplo n.º 1
0
        /// <summary>
        /// Initiliaze a new alien army.
        /// </summary>
        /// <param name="centre">Centre of the army.</param>
        /// <param name="width">Number of columns composing the army.</param>
        /// <param name="height">Number of rows in each column.</param>
        /// <param name="alienSize">Size of aliens.</param>
        /// <param name="margin">Space to leave between aliens.</param>
        public void Initialize(Vector2 centre, int width, int height, Vector2 alienSize, Vector2 margin)
        {
            float armyWidth = width * (alienSize.X + margin.X) - margin.X;
              float armyHeight = height * (alienSize.Y + margin.Y) - margin.Y;

              float lowestPos = centre.Y - armyHeight * .5f;
              float rightMostPos = centre.X - armyWidth * .5f;
              float leftMostPos = centre.X + armyWidth * .5f;

              columns = new AlienColumn[width];

              for (int i = 0; i < width; ++i) {
            columns[i] = new AlienColumn();
            columns[i].Initialize(
              height,
              new Vector2(rightMostPos + alienSize.X * .5f + i * (alienSize.X + margin.X), lowestPos),
              alienSize,
              margin.Y);
              }

              Position = centre;
              Size = new Vector2(
            columns[width - 1].Area.TopRight.X - columns[0].Area.TopLeft.X,
            columns[0].Area.TopLeft.Y - columns[0].Area.BottomLeft.Y);

              Game.Updatables.Add(this);
        }
Exemplo n.º 2
0
        public void Initialize(int height, Vector2 firstPos, Vector2 alienSize, float margin)
        {
            aliens = new List<Alien>(height);
              for (int i = 0; i < height; ++i) {
            AlienType type;
            switch (height) {
            case 0:
            case 1:
              type = AlienType.Crab;
              break;
            case 2:
            case 3:
              type = AlienType.Ant;
              break;
            default:
              type = AlienType.Squid;
              break;
            }

            aliens.Add( new Alien(this, type, new Vector2(firstPos.X, firstPos.Y + i * (alienSize.Y + margin)), alienSize) );
              }

              FirstAlien = aliens[0];
              LastAlien = aliens[height - 1];

              UpdateDimensions();
        }
Exemplo n.º 3
0
        public Shot(Vector2 pos, Vector2 size, Vector2 speed)
            : base(pos, size, speed)
        {
            // TODO : Actually, this is a setup method. Use a shots pool.

              Game.Shots.Add(this);
              Game.Updatables.Add(this);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Move the whole column on space lower.
        /// </summary>
        /// <param name="y">Vertical distance to descend.</param>
        public void Descend(float y)
        {
            Vector2 delta = new Vector2(0, y);
              Position += delta;

              foreach (var alien in aliens) {
            alien.Move(delta);
              }
        }
Exemplo n.º 5
0
 public PhysicalEntity(Vector2 position, Vector2 size)
 {
     this.Size = size;
       this.Position = position;
 }
Exemplo n.º 6
0
 public Ship(Vector2 position, Vector2 size, float speed)
     : base(position, size)
 {
     Speed = speed;
 }
Exemplo n.º 7
0
        private void Move()
        {
            float movement = direction == Direction.Left ? movementDistance.X * -1 : movementDistance.X;

              if (Area.X + movement > 0 && Area.X + Area.Width + movement < 1) {
            Position += new Vector2(movement, 0);

            foreach (var column in columns) {
              column.Move(movement);
            }
              } else {
            Position += new Vector2(0, movementDistance.Y);
            direction = direction == Direction.Left ? Direction.Right : Direction.Left;

            foreach (var column in columns) {
              column.Descend(movementDistance.Y);
            }
              }
        }
Exemplo n.º 8
0
 public MovingEntity(Vector2 position, Vector2 size, Vector2 speed)
     : base(position, size)
 {
     this.Speed = speed;
 }
Exemplo n.º 9
0
        /// <summary>
        /// Move the whole column one step in the given direction.
        /// If the column exits its movement range, it moves down.
        /// </summary>
        /// <param name="x">Horizontal distance to move, if possible.</param>
        public void Move(float x)
        {
            Vector2 delta = new Vector2(x, 0);
              Position += delta;

              foreach (var alien in aliens) {
            alien.Move(delta);
              }
        }
Exemplo n.º 10
0
        private void UpdateDimensions()
        {
            if(null == FirstAlien && null == LastAlien) {
            Size = Vector2.zero;
            return;
              }

              Size = new Vector2(FirstAlien.Size.X, LastAlien.Area.TopRight.Y - FirstAlien.Area.BottomRight.Y);
              Position = new Vector2(FirstAlien.Position.X, FirstAlien.Position.Y + Size.Y * .5f);
        }
Exemplo n.º 11
0
 public void Move(Vector2 distance)
 {
     this.Position += distance;
 }
Exemplo n.º 12
0
 public Alien(AlienColumn column, AlienType type, Vector2 position, Vector2 size)
     : base(position, size)
 {
     Column = column;
     Type = type;
 }
Exemplo n.º 13
0
 public ShotEnemy(Vector2 pos)
     : base(pos, new Vector2(.01f, .02f), new Vector2(.0f, -.05f))
 {
 }