/// <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); }
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(); }
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); }
/// <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); } }
public PhysicalEntity(Vector2 position, Vector2 size) { this.Size = size; this.Position = position; }
public Ship(Vector2 position, Vector2 size, float speed) : base(position, size) { Speed = speed; }
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); } } }
public MovingEntity(Vector2 position, Vector2 size, Vector2 speed) : base(position, size) { this.Speed = speed; }
/// <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); } }
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); }
public void Move(Vector2 distance) { this.Position += distance; }
public Alien(AlienColumn column, AlienType type, Vector2 position, Vector2 size) : base(position, size) { Column = column; Type = type; }
public ShotEnemy(Vector2 pos) : base(pos, new Vector2(.01f, .02f), new Vector2(.0f, -.05f)) { }