Browse Source

creation of the game Element class

pull/1/head
jrtechs 8 years ago
parent
commit
3d2f0d654a
1 changed files with 37 additions and 5 deletions
  1. +37
    -5
      src/tanks/GameElement.java

+ 37
- 5
src/tanks/GameElement.java View File

@ -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();
}
}

Loading…
Cancel
Save