From 76d19004e770c360feecd7a0f5c9b1c875d44bf1 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Sun, 12 Nov 2017 19:52:46 +0100 Subject: [a] Moved the CollideCheck into a method on the GameObject class --- Space Invaders/GameObjects.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'Space Invaders/GameObjects.cs') diff --git a/Space Invaders/GameObjects.cs b/Space Invaders/GameObjects.cs index f7297a1..26533d6 100644 --- a/Space Invaders/GameObjects.cs +++ b/Space Invaders/GameObjects.cs @@ -5,6 +5,10 @@ namespace SpaceInvaders { class GameLogic : GameObject { + public override void Start() { + + } + public override void Update() { if (Input.KeyPressed(ConsoleKey.Escape)) { @@ -44,22 +48,14 @@ namespace SpaceInvaders { GameObject other = Parent.GameObjects[i]; if (other.Tag == "Enemy") { - int x1 = other.xPos; - int x2 = other.xPos + other.Sprite.GetLength(1); - int y1 = other.yPos; - int y2 = other.yPos + other.Sprite.GetLength(0); - if (x1 <= xPos && xPos <= x2 && y1 <= yPos && yPos <= y2) { + if (CollidingWith(other)) { other.isDead = true; isDead = true; } } if (other.Tag == "Obstacle") { - int x1 = other.xPos; - int x2 = other.xPos + other.Sprite.GetLength(1); - int y1 = other.yPos; - int y2 = other.yPos + other.Sprite.GetLength(0); - if (x1 <= xPos && xPos <= x2 && y1 <= yPos && yPos <= y2) { + if (CollidingWith(other)) { isDead = true; } } -- cgit v1.2.3