public Debris(MatrixCoords topLeft, int lifeTime) : base(topLeft, new [,] {{'*'}}, new MatrixCoords(0,0)) { if (lifeTime < 0) { throw new IndexOutOfRangeException("Debris life time can not be negative"); } this.lifeTime = lifeTime; }
public NuclearMissile(MatrixCoords topLeft, char[,] body, int directionVertical, int directionHorizontal) : base(topLeft, new char[,] {{}}, directionVertical, directionHorizontal) { this.body = new[,] { { '^', '^' }, { '|', '|' }, { '/', '\\' } }; }
public CollisionData(MatrixCoords collisionForceDirection, List<string> hitObjectsCollisionGroupStrings) { this.CollisionForceDirection = collisionForceDirection; this.hitObjectsCollisionGroupStrings = new List<string>(); foreach (var str in hitObjectsCollisionGroupStrings) { this.hitObjectsCollisionGroupStrings.Add(str); } }
protected GameObject(MatrixCoords topLeft, char[,] body) { this.TopLeft = topLeft; int imageRows = body.GetLength(0); int imageCols = body.GetLength(1); this.body = this.CopyBodyMatrix(body); this.IsDestroyed = false; }
protected override void UpdatePosition() { this.count--; if (count == 0) { this.shootingMoment++; this.count = aggression; if (this.shootingMoment % 5 == 0) { this.Shoot(); } if (this.shootingMoment % 12 == 0) { this.ShootRocket(); } this.Speed = this.direction; if (this.topLeft.Col >= SpaceWarsMain.WorldCols - 5) { this.direction = new MatrixCoords(RandomDirection(), -1); } else if (this.topLeft.Col <= 3) { this.direction = new MatrixCoords(RandomDirection(), 1); } else if (this.topLeft.Row >= SpaceWarsMain.WorldRows - 12) { this.direction = new MatrixCoords(-1, RandomDirection()); } else if (this.topLeft.Row <= 2) { this.direction = new MatrixCoords(1, RandomDirection()); } base.UpdatePosition(); } }
public void EnqueueForRendering(IRenderable obj) { char[,] objImage = obj.GetImage(); int imageRows = objImage.GetLength(0); int imageCols = objImage.GetLength(1); MatrixCoords objTopLeft = obj.GetTopLeft(); int lastRow = Math.Min(objTopLeft.Row + imageRows, this.renderContextMatrixRows); int lastCol = Math.Min(objTopLeft.Col + imageCols, this.renderContextMatrixCols); for (int row = obj.GetTopLeft().Row; row < lastRow; row++) { for (int col = obj.GetTopLeft().Col; col < lastCol; col++) { if (row >= 0 && row < renderContextMatrixRows && col >= 0 && col < renderContextMatrixCols) { renderContextMatrix[row, col] = objImage[row - obj.GetTopLeft().Row, col - obj.GetTopLeft().Col]; } } } }
public EnemyBullet(MatrixCoords topLeft, int direction) : base(topLeft, new [, ] { { '.' } }, direction) { }
private static void HandleMovingWithStaticCollisions(List<MovingObject> movingObjects, List<GameObject> staticObjects) { foreach (var movingObject in movingObjects) { int verticalIndex = VerticalCollisionIndex(movingObject, staticObjects); int horizontalIndex = HorizontalCollisionIndex(movingObject, staticObjects); MatrixCoords movingCollisionForceDirection = new MatrixCoords(0, 0); if (verticalIndex != -1) { movingCollisionForceDirection.Row = -movingObject.Speed.Row; staticObjects[verticalIndex].RespondToCollision( new CollisionData(new MatrixCoords(movingObject.Speed.Row, 0), movingObject.GetCollisionGroupString()) ); } if (horizontalIndex != -1) { movingCollisionForceDirection.Col = -movingObject.Speed.Col; staticObjects[horizontalIndex].RespondToCollision( new CollisionData(new MatrixCoords(0, movingObject.Speed.Col), movingObject.GetCollisionGroupString()) ); } int diagonalIndex = -1; if (horizontalIndex == -1 && verticalIndex == -1) { diagonalIndex = DiagonalCollisionIndex(movingObject, staticObjects); if (diagonalIndex != -1) { movingCollisionForceDirection.Row = -movingObject.Speed.Row; movingCollisionForceDirection.Col = -movingObject.Speed.Col; staticObjects[diagonalIndex].RespondToCollision( new CollisionData(new MatrixCoords(movingObject.Speed.Row, 0), movingObject.GetCollisionGroupString()) ); } } List<string> hitByMovingCollisionGroups = new List<string>(); if(verticalIndex != -1) { hitByMovingCollisionGroups.Add(staticObjects[verticalIndex].GetCollisionGroupString()); } if(horizontalIndex != -1) { hitByMovingCollisionGroups.Add(staticObjects[horizontalIndex].GetCollisionGroupString()); } if(diagonalIndex != -1) { hitByMovingCollisionGroups.Add(staticObjects[diagonalIndex].GetCollisionGroupString()); } if (verticalIndex != -1 || horizontalIndex != -1 || diagonalIndex != -1) { movingObject.RespondToCollision( new CollisionData(movingCollisionForceDirection, hitByMovingCollisionGroups) ); } } }
public EnemyWeapons(MatrixCoords topLeft, char[,] body, int direction) : base(topLeft, body,new MatrixCoords(direction,0)) { }
public PlayerRocket(MatrixCoords topLeft, char[,] body, int directionVertical, int directionHorizontal) : base(topLeft, new[,] { { '|' } }, directionVertical, directionHorizontal) { }
public LeftBlaster(MatrixCoords topLeft, int directionVertical, int directionHorizontal) : base(topLeft, new[, ] { { '\\' } }, directionVertical, directionHorizontal) { }
public MovingObject(MatrixCoords topLeft, char[,] body, MatrixCoords speed) : base(topLeft, body) { this.Speed = speed; }
public PlayerWeapons(MatrixCoords topLeft, char[,] body, int directionVertical,int directionHorizontal) : base(topLeft, body,new MatrixCoords(directionVertical, directionHorizontal)) { }
private static void HandleMovingWithStaticCollisions(List <MovingObject> movingObjects, List <GameObject> staticObjects) { foreach (var movingObject in movingObjects) { int verticalIndex = VerticalCollisionIndex(movingObject, staticObjects); int horizontalIndex = HorizontalCollisionIndex(movingObject, staticObjects); MatrixCoords movingCollisionForceDirection = new MatrixCoords(0, 0); if (verticalIndex != -1) { movingCollisionForceDirection.Row = -movingObject.Speed.Row; staticObjects[verticalIndex].RespondToCollision( new CollisionData(new MatrixCoords(movingObject.Speed.Row, 0), movingObject.GetCollisionGroupString()) ); } if (horizontalIndex != -1) { movingCollisionForceDirection.Col = -movingObject.Speed.Col; staticObjects[horizontalIndex].RespondToCollision( new CollisionData(new MatrixCoords(0, movingObject.Speed.Col), movingObject.GetCollisionGroupString()) ); } int diagonalIndex = -1; if (horizontalIndex == -1 && verticalIndex == -1) { diagonalIndex = DiagonalCollisionIndex(movingObject, staticObjects); if (diagonalIndex != -1) { movingCollisionForceDirection.Row = -movingObject.Speed.Row; movingCollisionForceDirection.Col = -movingObject.Speed.Col; staticObjects[diagonalIndex].RespondToCollision( new CollisionData(new MatrixCoords(movingObject.Speed.Row, 0), movingObject.GetCollisionGroupString()) ); } } List <string> hitByMovingCollisionGroups = new List <string>(); if (verticalIndex != -1) { hitByMovingCollisionGroups.Add(staticObjects[verticalIndex].GetCollisionGroupString()); } if (horizontalIndex != -1) { hitByMovingCollisionGroups.Add(staticObjects[horizontalIndex].GetCollisionGroupString()); } if (diagonalIndex != -1) { hitByMovingCollisionGroups.Add(staticObjects[diagonalIndex].GetCollisionGroupString()); } if (verticalIndex != -1 || horizontalIndex != -1 || diagonalIndex != -1) { movingObject.RespondToCollision( new CollisionData(movingCollisionForceDirection, hitByMovingCollisionGroups) ); } } }
public CollisionData(MatrixCoords collisionForceDirection, string objectCollisionGroupString) { this.CollisionForceDirection = collisionForceDirection; this.hitObjectsCollisionGroupStrings = new List <string>(); this.hitObjectsCollisionGroupStrings.Add(objectCollisionGroupString); }
public EnemyRocket(MatrixCoords topLeft, int direction) : base(topLeft, new [,] {{'v'}}, direction) { }
public CollisionData(MatrixCoords collisionForceDirection, string objectCollisionGroupString) { this.CollisionForceDirection = collisionForceDirection; this.hitObjectsCollisionGroupStrings = new List<string>(); this.hitObjectsCollisionGroupStrings.Add(objectCollisionGroupString); }
public Battlecruiser(MatrixCoords topLeft, int life) : base(topLeft, new char[,] { { 'b' }, { 'c' } }, life, 5) { this.body = this.GetSpaceShipBody(); }
public override bool Equals(object obj) { MatrixCoords objAsMatrixCoords = obj as MatrixCoords; return(objAsMatrixCoords.Row == this.Row && objAsMatrixCoords.Col == this.Col); }
public SpaceShip(MatrixCoords topLeft, char [,] body, MatrixCoords speed, int life) : base(topLeft, body, speed) { this.life = life; this.startingLife = life; }
public EnemyFighters(MatrixCoords topLeft, char[,] body, int life, int aggression) : base(topLeft, body, new MatrixCoords(0, 0), life) { this.aggression = aggression; this.count = aggression; }
public PlayerBullet(MatrixCoords topLeft, int directionVertical, int directionHorizontal) : base(topLeft, new [,] {{'.'}}, directionVertical, directionHorizontal) { }
public PlayerBullet(MatrixCoords topLeft, int directionVertical, int directionHorizontal) : base(topLeft, new [, ] { { '.' } }, directionVertical, directionHorizontal) { }
public Gift(MatrixCoords topLeft) : base(topLeft, new [,] {{'G'}}, new MatrixCoords(1, 0)) { this.body = this.GetGiftBody(); }
public PlayerWeapons(MatrixCoords topLeft, char[,] body, int directionVertical, int directionHorizontal) : base(topLeft, body, new MatrixCoords(directionVertical, directionHorizontal)) { }
public LeftBlaster(MatrixCoords topLeft, int directionVertical, int directionHorizontal) : base(topLeft, new[,] { { '\\' } }, directionVertical, directionHorizontal) { }
public PlayerRocket(MatrixCoords topLeft, char[,] body, int directionVertical, int directionHorizontal) : base(topLeft, new[, ] { { '|' } }, directionVertical, directionHorizontal) { }
public EnemyRocket(MatrixCoords topLeft, int direction) : base(topLeft, new [, ] { { 'v' } }, direction) { }
public EnemyWeapons(MatrixCoords topLeft, char[,] body, int direction) : base(topLeft, body, new MatrixCoords(direction, 0)) { }
protected override void UpdatePosition() { this.count--; if (count == 0) { this.shootingMoment++; this.count = aggression; if (this.shootingMoment % 5 == 0) { this.Shoot(); } if (this.shootingMoment % 12 == 0) { this.ShootRocket(); } this.Speed = this.direction; if (this.topLeft.Col >= SpaceWarsMain.WorldCols - 5) { this.direction = new MatrixCoords(RandomDirection(), -1); } else if (this.topLeft.Col <= 3) { this.direction = new MatrixCoords(RandomDirection(), 1); } else if(this.topLeft.Row >= SpaceWarsMain.WorldRows - 12) { this.direction = new MatrixCoords(-1, RandomDirection()); } else if (this.topLeft.Row <= 2) { this.direction = new MatrixCoords(1, RandomDirection()); } base.UpdatePosition(); } }
public PlayerShip(MatrixCoords topLeft) : base(topLeft, new char[,]{{'='}},new MatrixCoords(0,0), 30) { this.body = GetSpaceShipBody(); }
public EnemyFighters(MatrixCoords topLeft, char[,] body,int life, int aggression) : base(topLeft, body, new MatrixCoords(0, 0), life) { this.aggression = aggression; this.count = aggression; }
public Raider(MatrixCoords topLeft, int aggression) : base(topLeft, new char[,] { { 'g' }, { 'd' } }, aggression, 10) { this.body = this.GetSpaceShipBody(); }
public EnemyBullet(MatrixCoords topLeft, int direction) : base(topLeft, new [,] {{'.'}}, direction) { }
public SpaceShip(MatrixCoords topLeft, char [,] body,MatrixCoords speed, int life) : base(topLeft, body, speed) { this.life = life; this.startingLife = life; }