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/GameEngine/GameEngine.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Space Invaders/GameEngine') diff --git a/Space Invaders/GameEngine/GameEngine.cs b/Space Invaders/GameEngine/GameEngine.cs index 6c5c5b0..bba5838 100644 --- a/Space Invaders/GameEngine/GameEngine.cs +++ b/Space Invaders/GameEngine/GameEngine.cs @@ -132,6 +132,16 @@ namespace GameEngine { // This method is called after the frame is rendered } + public bool CollidingWith(GameObject other) { + // This method checks if 'this' collides with another GameObject + // TODO Make this check if the position contains '\0', if so we are not colliding. This will make hitboxes more natural + int x1 = other.xPos; + int x2 = other.xPos + other.Sprite.GetLength(1); + int y1 = other.yPos; + int y2 = other.yPos + other.Sprite.GetLength(0); + return (x1 < xPos && xPos < x2 && y1 < yPos && yPos < y2); + } + public void ScaleSprite() { // This is called after the Update method, and scales the sprite if it has changed if (RenderedSprite == Sprite) { return; } -- cgit v1.2.3