[Home]Marshmallow/CodeSnippets

Robo Home | Marshmallow | Changes | Preferences | AllPages

Showing revision 3
How Marshmallow checks if its VirtualBullets has hit

Marshmallow has a very close (to the decimal percentage) relation between virtual bullet hit ratio and real bullet hit ratio. This might or might not be common. Here's the relevant code anyway:

private Point2D enemyLocation;
private Point2D bulletLocation;
private Ellipse2D vincinity = new Ellipse2D.Double();
private double precision = 20.0;
...
boolean hasHit() {
    ...
    vincinity.setFrameFromCenter(enemyLocation, 
        new Point2D.Double(enemyLocation.getX() - precision, enemyLocation.getY() - precision));
    if (vincinity.contains(bulletLocation)) {
        ...
        return true;
    }
    else {
        return false;
    }
}
The code not shown isn't TopSecret? as such, its just not relevant to the example. Feel free to use this code. Give me credit if you think I deserve it. -- PEZ

Robo Home | Marshmallow | Changes | Preferences | AllPages
Edit revision 3 of this page | View other revisions | View current revision
Edited March 7, 2003 13:03 EST by Bienator (diff)
Search: