|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Sprite
The Sprite class defines a game object, including its shape, position, movement and rotation. It also can detemine if two objects collide. We have a number of derived classes for the special kinds of sprites.
Field Summary | |
(package private) Vector2 |
acceleration
The acceleration vector. |
(package private) boolean |
active
A flag to indicate if the sprite is currently alive and visible. |
(package private) double |
age
Measure the sprite's age in seconds to time things like explosions, hyperjumps and waits between bullet shots. |
(package private) double |
ageDone
Sprites can use the updateCounter to time things like explosions or a fade to black. |
(package private) double |
angle
The current rotation aspect. |
(package private) double |
angularAcceleration
The "acceleration" or speed at which the sprite is rotating. |
boolean |
bounce
What to do when the asteroids hit the edge of the screen - initially false |
(package private) java.awt.Color |
edgecolor
The color to use for the sprite's outline. |
(package private) java.awt.Color |
fillcolor
The color to fill in the sprite with. |
(package private) boolean |
fillflag
Whether or not to fill the sprite in. |
(package private) AsteroidsGame |
game
The "owner" game. |
private double |
mass
We'll maintain the mass as the cube of the radius, setting it in the same fixRadius function that fixes the radius. |
(package private) double |
maxspeed
The maximum speed. |
(package private) Asteroids |
ownerApp
The "owner" applet or application. |
(package private) Vector2 |
position
The screen pixel position. |
(package private) Vector2 |
positiontransform
The pixel position. |
private double |
radius
The size of the thing. |
(package private) java.awt.Polygon |
shape
The basic shape which gets translated, rotated, and pixeld. |
(package private) java.awt.Polygon |
shapetransform
The transformed shape polygon, after the rotation and the translation. |
(package private) boolean |
soundplaying
Is the sound currently on? |
(package private) Vector2 |
velocity
The velocity vector. |
Constructor Summary | |
Sprite(RealPixelConverter rtopc)
The Sprite constructor sets everything to 0, except for the fillcolor, which gets randomized. |
Method Summary | |
boolean |
advance(double dt)
Update the rotation and position coordinates based on the delta values. |
void |
draw(java.awt.Graphics g,
boolean detail)
Use the fillPolygon and drawPolygon functions to draw. |
void |
explode(RealPixelConverter rtopc)
Create sprites for explosion animation. |
void |
fixRadius()
First sets the centroid to be the average of the shape vertices, then translatees the shape so that its centroid is at the origin, then sets the radius value as the maximum distance from the origin to one of the shape vertices. |
boolean |
isColliding(Sprite s)
Just look at the distances between the positions of the two and compare to the sum of the radii. |
boolean |
isTouching(Sprite s)
This is more accurate than isColliding, but a bit slower. |
void |
loopsound(boolean onoff)
The base method bails out if the the Asteroids soundsloaded isn't true, and it won't turn on a sound if Asteroids soundflag is off. |
double |
mass()
Accessor |
double |
radius()
We need an accessor for radius. |
void |
randomizeFillcolor()
|
void |
render(RealPixelConverter rtopc)
Applies the rotation and the position translation to the shape to get the shapetransform polygon. |
abstract void |
reset(RealPixelConverter rtopc)
The abstract reset method is called by the child sprite constructors, and may also be called when resetting a sprite's state. |
void |
setFakeRadius(double fakeradius)
Use this to set a fake radius to make something hard to hit. |
void |
stop()
The stop method sets active to false and turns off the sound. |
abstract void |
update(RealPixelConverter rtopc)
The update method can be overloaded by the child sprite. |
boolean |
wrapandbounce()
Handles the wrapping or bouncing. |
Methods inherited from class java.lang.Object |
|
Field Detail |
java.awt.Polygon shape
boolean active
double age
public boolean bounce
double angle
private double radius
private double mass
double angularAcceleration
Vector2 position
Vector2 positiontransform
Vector2 velocity
double maxspeed
Vector2 acceleration
java.awt.Polygon shapetransform
boolean fillflag
java.awt.Color fillcolor
java.awt.Color edgecolor
double ageDone
boolean soundplaying
AsteroidsGame game
Asteroids ownerApp
Constructor Detail |
public Sprite(RealPixelConverter rtopc)
Method Detail |
public double radius()
public void setFakeRadius(double fakeradius)
public double mass()
public void randomizeFillcolor()
public void fixRadius()
public boolean advance(double dt)
public boolean wrapandbounce()
public void render(RealPixelConverter rtopc)
public boolean isColliding(Sprite s)
public boolean isTouching(Sprite s)
public abstract void reset(RealPixelConverter rtopc)
public abstract void update(RealPixelConverter rtopc)
public void loopsound(boolean onoff)
public void stop()
public void explode(RealPixelConverter rtopc)
public void draw(java.awt.Graphics g, boolean detail)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |