Class EntityListArray
java.lang.Object
model.EntityListArray
- All Implemented Interfaces:
EventListener,EntityListInterface,EntityEventListener
- Direct Known Subclasses:
AlienArmyArray
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSets up the array entities and removeEntities of MAX_SIZE set numEntities and numRemoveEntities to 0 -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd one entity to the entities arrayvoidManage event listener registrationvoidclear()Clear the array by creating a new array of entities and removeEntities and reset numEntities and numRemoveEntitiescollidesWith(Entity other) Check if this entity collides with any entity in this entity array.voidvoiddraw(Graphics2D g) draw all entities in the array using drawvoidvoidintNumber of entitiesif there are no entities in the list return null return one of the entities in the array - choosing it randomlyvoidincreaseSpeed(int percentIncrease) Increase the speed of all members of the array by a certain percentagevoidmoveAndDraw(long delta, Graphics2D g) Move and drawvoidRegisters an entity for removal next time the state of the list is updatedvoidRemove an entity from the arraytoString()voidupdateState(long delta) Move all entities in the array according to time passed delta using updateState
-
Field Details
-
MAX_SIZE
public static final int MAX_SIZE- See Also:
-
entities
The entities in the array. Make it protected to allow sub-classes access but noone else. -
removeEntities
The entities to be removed on next game cycle -
numEntities
protected int numEntities -
numRemoveEntities
protected int numRemoveEntities
-
-
Constructor Details
-
EntityListArray
public EntityListArray()Sets up the array entities and removeEntities of MAX_SIZE set numEntities and numRemoveEntities to 0- Parameters:
entities-removeEntities-
-
-
Method Details
-
clear
public void clear()Clear the array by creating a new array of entities and removeEntities and reset numEntities and numRemoveEntities- Specified by:
clearin interfaceEntityListInterface
-
add
Add one entity to the entities array- Specified by:
addin interfaceEntityListInterface- Parameters:
e- the entity to be added to the array increase the number of entities
-
draw
draw all entities in the array using draw- Specified by:
drawin interfaceEntityListInterface- Parameters:
g- The graphics context to draw to
-
moveAndDraw
Description copied from interface:EntityListInterfaceMove and draw- Specified by:
moveAndDrawin interfaceEntityListInterface- Parameters:
delta- Time passed since last updateState (ms)g- The graphics context to draw to
-
addEntityEventListener
Manage event listener registration- Specified by:
addEntityEventListenerin interfaceEntityListInterface- Parameters:
l- the listener to add
-
updateState
public void updateState(long delta) Move all entities in the array according to time passed delta using updateState- Specified by:
updateStatein interfaceEntityListInterface- Parameters:
delta- Time passed since last updateState (ms)
-
increaseSpeed
public void increaseSpeed(int percentIncrease) Increase the speed of all members of the array by a certain percentage- Specified by:
increaseSpeedin interfaceEntityListInterface- Parameters:
percentIncrease- as whole number
-
collidesWith
Check if this entity collides with any entity in this entity array.- Specified by:
collidesWithin interfaceEntityListInterface- Parameters:
other- The entity to check collision against- Returns:
- null if there is no collision, return the entity if there is a collision
-
remove
Remove an entity from the array- Specified by:
removein interfaceEntityListInterface- Parameters:
e- The entity to remove
-
getNumEntities
public int getNumEntities()Number of entities- Specified by:
getNumEntitiesin interfaceEntityListInterface- Returns:
- numEntities
-
getRandom
if there are no entities in the list return null return one of the entities in the array - choosing it randomly- Specified by:
getRandomin interfaceEntityListInterface- Returns:
- Entity
-
registerEntityForRemoval
Description copied from interface:EntityListInterfaceRegisters an entity for removal next time the state of the list is updated- Specified by:
registerEntityForRemovalin interfaceEntityListInterface- Parameters:
e- The entity to register for removal next time the upDateState is called on the list
-
collisionHasOccured
- Specified by:
collisionHasOccuredin interfaceEntityEventListener
-
entityMoved
- Specified by:
entityMovedin interfaceEntityEventListener
-
entityDied
- Specified by:
entityDiedin interfaceEntityEventListener
-
toString
-