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 booleanFlag that is used to signal if theGameElementis supposed to be deleted or not.protected longThe latest deltaTime inlogicLoop().protected TeamTheTeamtheGameElementis in that mainly specifies behavior upon collision.protected booleanFlag that is used to signal if theGameElementis supposed to be rendered or not. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGameElement(Team team) Prototype constructor.protectedGameElement(Vec startPos, Vec vel, Vec size, Team team) Standard constructor that should be used in every extending class. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidCheck for collision with another element and invoke necessary methods.Stub Factory method that everyGameElementmust implement in order to being able to be instantiated dynamically by the level creation.voiddestroy()Method that, upon call, signals that thisGameElementis supposed to be deleted in the next logicLoop of theIScene.final booleanGetter for the flag that specifies if theGameElementis waiting for deletion.getFrame()Returns aFramethat represents the collision box theGameElementwill be using.final VecgetPos()Getter for theGameElementsabsolute position.final ILevelScenegetScene()Get the current scene.final VecgetSize()Getter for theGameElementssize.final TeamgetTeam()Getter for theGameElementsTeamthat mainly specifies behavior upon collision.final VecgetVel()Getter for theGameElementsvelocity.final bytegetZ()Getter for an imaginary z-position of theGameElement.getZHint()voidinit()(Re-)Initialize the GameElement.protected voidTemplate method that will be called periodically after being added to aIScene.booleanThis method indicates whether this entity can be added to it's group.protected booleanReturns if theGameElementis currently supposed to be rendered or not.voidBehavior after this GameElement hit an enemyvoidTemplate method that will be called periodically after being added to aIScene.voidreactToCollision(GameElement element, Direction dir) Notification that this GameElement has been collided with from another GameElement element from the given direction dir.final voidMethod that will be called periodically after being added to aIScene.final voidSetter for theGameElementsabsolute position.final voidsetScene(ILevelScene value) Setter for theIScenethisGameElementbelongs to.voidSet the size of the GameElement.final voidSetter for theGameElementsvelocity.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface rekit.logic.Collidable
addDamage, collidedWithSolid, getLives
-
Field Details
-
visible
protected boolean visibleFlag that is used to signal if theGameElementis supposed to be rendered or not. -
deleteMe
protected boolean deleteMeFlag that is used to signal if theGameElementis supposed to be deleted or not. -
team
TheTeamtheGameElementis 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- theTeamof the GameElement
-
GameElement
Standard constructor that should be used in every extending class.- Parameters:
startPos- the absoluteVecthat points to theGameElementsinitial position.vel- theVecthat represents the initial velocity of theGameElementsize- theVecthat represents the size of theGameElementteam- theTeamthat is used for determining if twoGameElementscan 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
GameElementis supposed to be rendered.- Parameters:
f- theGameGridthat 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- theGameGridthat represents the games field and supplies primitive drawing operations.
-
create
Stub Factory method that every
GameElementmust 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
GameElementcan define and use is supplied. These are used make level creation able to determine theGameElementsbehavior. 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 theGameElementis currently supposed to be rendered or not.- Returns:
- true if the
GameElementshould be rendered, false otherwise.
-
getPos
Getter for the
GameElementsabsolute position.Note: the position points to the center of the
GameElement.- Returns:
- the current position of the
GameElement.
-
setPos
Setter for the
GameElementsabsolute position.Note: the position points to the center of the
GameElement.- Parameters:
value- the new position theGameElementis supposed to have.
-
getVel
Getter for the
GameElementsvelocity.- Returns:
- the current velocity of the
GameElement.
-
setVel
Setter for the
GameElementsvelocity.- Parameters:
newVel- the new velocity theGameElementis supposed to have.
-
getSize
Getter for the
GameElementssize.- Returns:
- the current size of the
GameElement.
-
setSize
Set the size of the GameElement.- Parameters:
size- the size
-
reactToCollision
Description copied from interface:CollidableNotification 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:
reactToCollisionin interfaceCollidable- Parameters:
element- the GameElement that collided with this GameElementdir- the Direction this GameElement has been collided from.
-
getFrame
Returns aFramethat represents the collision box theGameElementwill be using. Is dependent of theGameElementsposition and size.- Returns:
- the
GameElementscollision box
-
setScene
Setter for theIScenethisGameElementbelongs to.- Parameters:
value- the newIScenethe GameElement is in.
-
getScene
Get the current scene.- Returns:
- the current scene
-
getTeam
Getter for theGameElementsTeamthat mainly specifies behavior upon collision.- Returns:
- the
GameElementsTeam
-
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
GameElementsrendering-order
-
getZHint
- Returns:
nullif no hint, otherwise the expected position
-
destroy
public void destroy()Method that, upon call, signals that this
GameElementis supposed to be deleted in the next logicLoop of theIScene.Note: The underlying
GameElementmight 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 theGameElementis waiting for deletion.- Returns:
- true if the
GameElementis 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:
trueif addable to a group,falseotherwise
-