Game Development Reference
In-Depth Information
public PolygonSprite() {
this.shape = new Polygon();
this.active = false;
this.angle = 0.0;
this.deltaAngle = 0.0;
this.x = 0;
this.y = 0;
this.deltaX = 0.0;
this.deltaY = 0.0;
this.sprite = new Polygon();
}
public void render(int width, int height) {
int i;
// Render the sprite's shape and location by rotating it's
// base shape and moving it to its proper screen position.
this.sprite = new Polygon();
for (i = 0; i < this.shape.npoints; i++) {
this.sprite.addPoint((int) Math.round(this.shape.xpoints[i]
* Math.cos(this.angle) + this.shape.ypoints[i]
* Math.sin(this.angle))
+ (int) Math.round(this.x) + width / 2,
(int) Math.round(this.shape.ypoints[i]
* Math.cos(this.angle) - this.shape.xpoints[i]
* Math.sin(this.angle))
+ (int) Math.round(this.y) + height / 2);
}
}
public boolean isColliding(PolygonSprite s) {
int i;
// Determine if one sprite overlaps with another, i.e., if any vertice
// of one sprite lands inside the other.
for (i = 0; i < s.sprite.npoints; i++) {
if (this.sprite.contains(s.sprite.xpoints[i],
s.sprite.ypoints[i])) {
return true;
}
}
for (i = 0; i < this.sprite.npoints; i++) {
if (s.sprite.contains(this.sprite.xpoints[i],
this.sprite.ypoints[i])) {
return true;
}
Search WWH ::




Custom Search