Class GameElement
- All Implemented Interfaces:
Collidable
- Direct Known Subclasses:
BackgroundElement
,Entity
,Inanimate
,Particle
Abstract class that represents an Element that is a visual part of a
IScene
, eg. a level.
Its situation in the level is defined by the attributes pos (=position), vel (=velocity) and size.
To implement a GameElement, note these important steps:
- Use super constructor GameElement(Vec startPos, Vec vel, Vec size, Team team)
- Implement factory method create(Vec startPos, String[] modifiers) for dynamic creation
- Implement template method logicLoop() to add custom logic.
- Implement template method internalRender(Field field) to add custom visualization.
- Author:
- Angelo Aracri, Dominik Fuchss
-
Nested Class Summary
Nested classes/interfaces inherited from interface rekit.logic.Collidable
Collidable.Optional
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Flag that is used to signal if theGameElement
is supposed to be deleted or not.protected long
The latest deltaTime inlogicLoop()
.protected Team
TheTeam
theGameElement
is in that mainly specifies behavior upon collision.protected boolean
Flag that is used to signal if theGameElement
is supposed to be rendered or not. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
GameElement
(Team team) Prototype constructor.protected
GameElement
(Vec startPos, Vec vel, Vec size, Team team) Standard constructor that should be used in every extending class. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Check for collision with another element and invoke necessary methods.Stub Factory method that everyGameElement
must implement in order to being able to be instantiated dynamically by the level creation.void
destroy()
Method that, upon call, signals that thisGameElement
is supposed to be deleted in the next logicLoop of theIScene
.final boolean
Getter for the flag that specifies if theGameElement
is waiting for deletion.getFrame()
Returns aFrame
that represents the collision box theGameElement
will be using.final Vec
getPos()
Getter for theGameElements
absolute position.final ILevelScene
getScene()
Get the current scene.final Vec
getSize()
Getter for theGameElements
size.final Team
getTeam()
Getter for theGameElements
Team
that mainly specifies behavior upon collision.final Vec
getVel()
Getter for theGameElements
velocity.final byte
getZ()
Getter for an imaginary z-position of theGameElement
.getZHint()
void
init()
(Re-)Initialize the GameElement.protected void
Template method that will be called periodically after being added to aIScene
.boolean
This method indicates whether this entity can be added to it's group.protected boolean
Returns if theGameElement
is currently supposed to be rendered or not.void
Behavior after this GameElement hit an enemyvoid
Template method that will be called periodically after being added to aIScene
.void
reactToCollision
(GameElement element, Direction dir) Notification that this GameElement has been collided with from another GameElement element from the given direction dir.final void
Method that will be called periodically after being added to aIScene
.final void
Setter for theGameElements
absolute position.final void
setScene
(ILevelScene value) Setter for theIScene
thisGameElement
belongs to.void
Set the size of the GameElement.final void
Setter for theGameElements
velocity.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface rekit.logic.Collidable
addDamage, collidedWithSolid, getLives
-
Field Details
-
visible
protected boolean visibleFlag that is used to signal if theGameElement
is supposed to be rendered or not. -
deleteMe
protected boolean deleteMeFlag that is used to signal if theGameElement
is supposed to be deleted or not. -
team
TheTeam
theGameElement
is in that mainly specifies behavior upon collision. -
deltaTime
protected long deltaTimeThe latest deltaTime inlogicLoop()
.
-
-
Constructor Details
-
GameElement
Prototype constructor. Use the constructor GameElement(Vec startPos, Vec vel, Vec size, Team team) for regular use and extending.- Parameters:
team
- theTeam
of the GameElement
-
GameElement
Standard constructor that should be used in every extending class.- Parameters:
startPos
- the absoluteVec
that points to theGameElements
initial position.vel
- theVec
that represents the initial velocity of theGameElement
size
- theVec
that represents the size of theGameElement
team
- theTeam
that is used for determining if twoGameElements
can damage each other, etc.
-
-
Method Details
-
logicLoop
public void logicLoop()Template method that will be called periodically after being added to a
IScene
.Should be overwritten in sub classes for implementing custom logic, physics emulation, time-based actions, ...
-
render
Method that will be called periodically after being added to a
IScene
.Its only task is to call the template method internalRender(Field f) if the
GameElement
is supposed to be rendered.- Parameters:
f
- theGameGrid
that represents the games field and supplies primitive drawing operations.
-
internalRender
Template method that will be called periodically after being added to a
IScene
. Must be as performant as possible to keep the FPS low, since it will be called in every render-loop.Should be overwritten in sub classes for custom visualization using the
GameGrid
.- Parameters:
f
- theGameGrid
that represents the games field and supplies primitive drawing operations.
-
create
Stub Factory method that every
GameElement
must implement in order to being able to be instantiated dynamically by the level creation.A startPos must be supplied to position the new GameElement right.
Also, an array of modifiers that the extending
GameElement
can define and use is supplied. These are used make level creation able to determine theGameElements
behavior. Note: the modifiers are not checked in syntax, so it must be thoroughly checked.- Parameters:
startPos
- the initial position of the newGameElement
.options
- optional parameters that may determine additional behavior of theGameElement
.- Returns:
- the newly created
GameElement
.
-
isVisible
protected boolean isVisible()Returns if theGameElement
is currently supposed to be rendered or not.- Returns:
- true if the
GameElement
should be rendered, false otherwise.
-
getPos
Getter for the
GameElements
absolute position.Note: the position points to the center of the
GameElement
.- Returns:
- the current position of the
GameElement
.
-
setPos
Setter for the
GameElements
absolute position.Note: the position points to the center of the
GameElement
.- Parameters:
value
- the new position theGameElement
is supposed to have.
-
getVel
Getter for the
GameElements
velocity.- Returns:
- the current velocity of the
GameElement
.
-
setVel
Setter for the
GameElements
velocity.- Parameters:
newVel
- the new velocity theGameElement
is supposed to have.
-
getSize
Getter for the
GameElements
size.- Returns:
- the current size of the
GameElement
.
-
setSize
Set the size of the GameElement.- Parameters:
size
- the size
-
reactToCollision
Description copied from interface:Collidable
Notification that this GameElement has been collided with from another GameElement element from the given direction dir.
Can be overwritten for defining an optional reaction that the GameElement performs on the other GameElement and/or itself upon collision.
- Specified by:
reactToCollision
in interfaceCollidable
- Parameters:
element
- the GameElement that collided with this GameElementdir
- the Direction this GameElement has been collided from.
-
getFrame
Returns aFrame
that represents the collision box theGameElement
will be using. Is dependent of theGameElements
position and size.- Returns:
- the
GameElements
collision box
-
setScene
Setter for theIScene
thisGameElement
belongs to.- Parameters:
value
- the newIScene
the GameElement is in.
-
getScene
Get the current scene.- Returns:
- the current scene
-
getTeam
Getter for theGameElements
Team
that mainly specifies behavior upon collision.- Returns:
- the
GameElements
Team
-
getZ
public final byte getZ()Getter for an imaginary z-position of the
GameElement
.Is used to determine the rendering order of every
GameElement
.- Returns:
- a number that represents the
GameElements
rendering-order
-
getZHint
- Returns:
null
if no hint, otherwise the expected position
-
destroy
public void destroy()Method that, upon call, signals that this
GameElement
is supposed to be deleted in the next logicLoop of theIScene
.Note: The underlying
GameElement
might go through several collisions and be rendered multiple times before it is actually deleted. -
getDeleteMe
public final boolean getDeleteMe()Getter for the flag that specifies if theGameElement
is waiting for deletion.- Returns:
- true if the
GameElement
is supposed to be deleted, false otherwise.
-
init
public void init()(Re-)Initialize the GameElement. -
checkCollision
Check for collision with another element and invoke necessary methods.- Parameters:
e2
- the other element
-
killBoost
public void killBoost()Behavior after this GameElement hit an enemy -
isAddableToGroup
public boolean isAddableToGroup()This method indicates whether this entity can be added to it's group.- Returns:
true
if addable to a group,false
otherwise
-