From 3d2f0d654a7b37852e7977e13f3b70a9af164d3e Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sat, 21 May 2016 16:46:50 -0400 Subject: [PATCH] creation of the game Element class --- src/tanks/GameElement.java | 42 +++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/tanks/GameElement.java b/src/tanks/GameElement.java index 79fbb6e..4c06774 100644 --- a/src/tanks/GameElement.java +++ b/src/tanks/GameElement.java @@ -1,9 +1,41 @@ -package tanks; - /* -class that provides functinality for game elements interacting with each other. + jeffery R + 5-21-16 + Gives every sub-class a width and a height + every GameElement is able to check for a collision with another gameElement */ -public class GameElement +package tanks; + +import java.awt.geom.Area; + +public abstract class GameElement extends DrawableElement { + //generic information about the game element + public int width, height; + + + //geometry variable used for collisions + public Area shape; + + + /* + checks for collision against another game element + will only work if both shape variables are set + depending on the object the shape are will be set differently + + returnes true if there was a collision, false otherwise + */ + public boolean checkCollision(GameElement e) + { + //sets the areas of the two elements being compared + this.setShape(); + e.setShape(); + //checks to see if there is an overlape in the two areas + shape.intersect(e.shape); + return !(shape.isEmpty()); + } + + //method that ensures that every sub-class will set their shape accordingly + public abstract void setShape(); -} +} \ No newline at end of file