/// <summary> /// This method is called once to set the initial positions for the game objects /// </summary> private void SetupGame() { // Sets the ship initial position ship = new PlayerShip(shipTexture, new Vector2(460, 700), playerLives, shipSpeed); objects.Add(ship); // Creates the first enemy wave objects.AddRange(enemyGenerator.GenerateNextEnemyWave()); }
public override void OnCollision(GameObject2D other) { if (other is Shot) { if ((other as Shot).WasGeneratedBy == Shot.ShotType.Player) { // TODO play sound this.Destroy(); } } }
public override void OnCollision(GameObject2D other) { if (other is Shot) { if ((other as Shot).WasGeneratedBy == Shot.ShotType.Enemy) { // TODO play sound lives--; } } }
/// <summary> /// This method checks if any objects have collided and informs them if they did /// </summary> private void CheckForCollisions() { for (int i = 0; i < objects.Count; i++) { GameObject2D obj = objects[i]; for (int j = i + 1; j < objects.Count; j++) { GameObject2D other = objects[j]; if (obj.BoundingBox.Intersects(other.BoundingBox)) { obj.OnCollision(other); other.OnCollision(obj); } } } }
public override void OnCollision(GameObject2D other) { this.Destroy(); }
/// <summary> /// Abstract method that will define the behavior of the object upon collision. /// Must be implemented by each subclass. /// </summary> /// <param name="other">The object that has collided with this one</param> public virtual void OnCollision(GameObject2D other) { }