Top Description Fields Constructors Methods
org.lwjgl.examples.spaceinvaders

public abstract Class Entity

extends Object
Class Inheritance
Known Direct Subclasses
org.lwjgl.examples.spaceinvaders.ShipEntity, org.lwjgl.examples.spaceinvaders.ShotEntity, org.lwjgl.examples.spaceinvaders.AlienEntity
Imports
java.awt.Rectangle

An entity represents any element that appears in the game. The entity is responsible for resolving collisions and movement based on a set of properties defined either by subclass or externally. Note that doubles are used for positions. This may seem strange given that pixels locations are integers. However, using double means that an entity can move a partial pixel. It doesn't of course mean that they will be display half way through a pixel but allows us not lose accuracy as we move.
Author
Kevin Glass

Field Summary

Modifier and TypeField and Description
protected float
dx

The current speed of this entity horizontally (pixels/sec)

protected float
dy

The current speed of this entity vertically (pixels/sec)

private Rectangle
him

The rectangle used for other entities during collision resolution

private Rectangle
me

The rectangle used for this entity during collisions resolution

protected Sprite
sprite

The sprite that represents this entity

protected float
x

The current x location of this entity

protected float
y

The current y location of this entity

Constructor Summary

AccessConstructor and Description
protected
Entity(Sprite
The reference to the image to be displayed for this entity
sprite
,
int
The initial x location of this entity
x
,
int
The initial y location of this entity
y
)

Construct a entity based on a sprite image and a location.

Method Summary

Modifier and TypeMethod and Description
public abstract void
collidedWith(Entity
The entity with which this entity collided.
other
)

Notification that this entity collided with another.

public boolean

Returns:

True if the entities collide with each other
collidesWith
(Entity
The other entity to check collision against
other
)

Check if this entity collised with another.

public void
doLogic()

Do the logic associated with this entity.

public void
draw()

Draw this entity to the graphics context provided

public float

Returns:

The horizontal speed of this entity (pixels/sec)
getHorizontalMovement
()

Get the horizontal speed of this entity

public float

Returns:

The vertical speed of this entity (pixels/sec)
getVerticalMovement
()

Get the vertical speed of this entity

public int

Returns:

The x location of this entity
getX
()

Get the x location of this entity

public int

Returns:

The y location of this entity
getY
()

Get the y location of this entity

public void
move(long
The ammount of time that has passed in milliseconds
delta
)

Request that this entity move itself based on a certain ammount of time passing.

public void
setHorizontalMovement(float
The horizontal speed of this entity (pixels/sec)
dx
)

Set the horizontal speed of this entity

public void
setVerticalMovement(float
The vertical speed of this entity (pixels/sec)
dy
)

Set the vertical speed of this entity

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dxback to summary
protected float dx

The current speed of this entity horizontally (pixels/sec)

dyback to summary
protected float dy

The current speed of this entity vertically (pixels/sec)

himback to summary
private Rectangle him

The rectangle used for other entities during collision resolution

meback to summary
private Rectangle me

The rectangle used for this entity during collisions resolution

spriteback to summary
protected Sprite sprite

The sprite that represents this entity

xback to summary
protected float x

The current x location of this entity

yback to summary
protected float y

The current y location of this entity

Constructor Detail

Entityback to summary
protected Entity(Sprite sprite, int x, int y)

Construct a entity based on a sprite image and a location.

Parameters
sprite:Sprite

The reference to the image to be displayed for this entity

x:int

The initial x location of this entity

y:int

The initial y location of this entity

Method Detail

collidedWithback to summary
public abstract void collidedWith(Entity other)

Notification that this entity collided with another.

Parameters
other:Entity

The entity with which this entity collided.

collidesWithback to summary
public boolean collidesWith(Entity other)

Check if this entity collised with another.

Parameters
other:Entity

The other entity to check collision against

Returns:boolean

True if the entities collide with each other

doLogicback to summary
public void doLogic()

Do the logic associated with this entity. This method will be called periodically based on game events

drawback to summary
public void draw()

Draw this entity to the graphics context provided

getHorizontalMovementback to summary
public float getHorizontalMovement()

Get the horizontal speed of this entity

Returns:float

The horizontal speed of this entity (pixels/sec)

getVerticalMovementback to summary
public float getVerticalMovement()

Get the vertical speed of this entity

Returns:float

The vertical speed of this entity (pixels/sec)

getXback to summary
public int getX()

Get the x location of this entity

Returns:int

The x location of this entity

getYback to summary
public int getY()

Get the y location of this entity

Returns:int

The y location of this entity

moveback to summary
public void move(long delta)

Request that this entity move itself based on a certain ammount of time passing.

Parameters
delta:long

The ammount of time that has passed in milliseconds

setHorizontalMovementback to summary
public void setHorizontalMovement(float dx)

Set the horizontal speed of this entity

Parameters
dx:float

The horizontal speed of this entity (pixels/sec)

setVerticalMovementback to summary
public void setVerticalMovement(float dy)

Set the vertical speed of this entity

Parameters
dy:float

The vertical speed of this entity (pixels/sec)