7. public void collideWith(Unit caller, List<? extends Thing> things) {
}
public void collideWith(Unit caller, Thing target) {
if (caller.getRec().intersects(target.getRec())) {
…
gameEvents.setValue(caller, target, katch.getX(), …);
}
}
@Override
public void update(Observable obj, Object arg) {
GameEvents ge = (GameEvents) arg;
if (2 == ge.getType() && this == ge.getTarget()) {
int number = ge.getNumber(); // get the information from gameEvents,
// not interact with other classes
…
super.setDamaged(true); // do it by itself
…
}
}
CollisionDetector
Observer
8. Some Mistakes I made
which gave me Experiences
• collideWith(Thing thing), not collideWithTank()
• override and overload: collideWith(List<Thing> things),
and collideWith(Thing thing)
• Iterator: CurrentModifiedException
• A bullet shoot 2 blocks: test if damaged in the collision
detector
• Jar file did not work: how to get the path name, how to
read from a URL, pay attention to the upper case and
lower case, e.g: Bigleg_strip24.png vs BigLeg_strip24.png
9. What should be Improved
• Polish the game:
• Bounding box or bounding circle should get smaller to
get more accurate collision.
• After tank get a new life, additional weapon should be
clear.
• Create more levels
• Add more weapons to make the game more stimulating