Class MovableEntity
- java.lang.Object
-
- com.badlogic.gdx.graphics.g3d.Renderable
-
- com.bombinggames.wurfelengine.core.gameobjects.AbstractGameObject
-
- com.bombinggames.wurfelengine.core.gameobjects.AbstractEntity
-
- com.bombinggames.wurfelengine.core.gameobjects.MovableEntity
-
- Direct Known Subclasses:
BenchmarkBall,Bullet,DestructionParticle,Particle,UserControlledShooter
public class MovableEntity extends AbstractEntity
A clas used mainly for characters or object which can walk around. To control the character you should use aControllableor modify the movemnet viasetMovement(com.badlogic.gdx.math.Vector3).- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.bombinggames.wurfelengine.core.gameobjects.AbstractEntity
colissionRadius
-
Fields inherited from class com.bombinggames.wurfelengine.core.gameobjects.AbstractGameObject
sprite
-
-
Constructor Summary
Constructors Constructor Description MovableEntity(byte id)Simple MovableEntity with no animation.MovableEntity(byte id, int spritesPerDir)Constructor of MovableEntity.MovableEntity(MovableEntity entity)copy constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMovement(float x, float y, float z)Adds speed and direction.voidaddMovement(com.badlogic.gdx.math.Vector2 movement)Adds speed and direction.voidaddMovement(com.badlogic.gdx.math.Vector3 movement)Adds speed and direction.voidaddToHor(float speed)Adds speed to horizontal moving directio.booleancollidesWithWorld(Point pos, float colissionRadius)check for horizontal colission (x and y)
O(1)voiddispose()Deletes the object from the map and every other container.com.badlogic.gdx.math.Vector3getAiming()Defines the direction of the gun - if no gun available - the direction of the head.floatgetFriction()The factor which slows donw movement.com.badlogic.gdx.math.Vector3getMovement()Get the movement vector as the product of direction and speed.com.badlogic.gdx.math.Vector2getMovementHor()Get the movement vector as the product of direction and speed.com.badlogic.gdx.math.Vector2getOrientation()Direction of movement.floatgetSpeed()get the speed of the object in m/s.floatgetSpeedHor()get the horizontal speed of the object in m/s.booleanhandleMessage(com.badlogic.gdx.ai.msg.Telegram msg)booleanisColiding()indicates whether this objects does collide with the blocksbooleanisFloating()Is the object be affected by gravity?booleanisInLiquid()Is the character standing in a liquid?booleanisOnCeil(Point pos)Check if the top is coliding with a block.booleanisOnGround()Is the entity laying/standing on the ground?voidjump()This method should define what happens when the object jumps.voidjump(float velo, boolean playSound)Jump with a specific speed.voidpauseMovementAnimation()Pauses the movement animation.voidplayMovementAnimation()Continues the movement animation when it was stopped before withpauseMovementAnimation().voidsetColiding(boolean coliding)indicates whether this objects does collide with the blocksvoidsetContinuousWalkingAnimation(float walkOnTheSpot)Enable this to have a walking cycle even if not movingvoidsetFallingSound(java.lang.String fallingSound)Sets the sound to be played when falling.voidsetFloating(boolean floating)Should the object be affected by gravity?voidsetFriction(float friction)Automatically slows speed down.voidsetHorMovement(com.badlogic.gdx.math.Vector2 movement)Set the horizontal movement and keeps zvoidsetJumpingSound(java.lang.String jumpingSound)Set the value of jumpingSoundvoidsetMovement(com.badlogic.gdx.math.Vector2 movement)Sets speed and direction combined in one vector.voidsetMovement(com.badlogic.gdx.math.Vector3 movement)Sets speed and direction values.voidsetOrientation(com.badlogic.gdx.math.Vector2 orientation)Turns an object in a different direction.voidsetRunningSound(java.lang.String runningSound)Set the sound to be played when running.voidsetSpeedHorizontal(float speed)Set the speed and only take x and y into account.voidsetSpeedIncludingZ(float speed)Set the speed.voidsetStepSound1Grass(java.lang.String sound)voidsetWalkingAnimationCycling(boolean cycle)Bounce back and forth (1,2,3,2,1,2 etc.) or cycle (1,2,3,1,2,3 etc.)voidsetWalkingStepMode(boolean stepmode)Set step mode or disable step mode. if no step mode plays animation back and forth.static voidsetWaterSound(java.lang.String waterSound)Set the value of waterSoundMovableEntityspawn(Point point)Add this entity to the map-> let it spawnvoidstep()performs a step.voidupdate(float dt)Updates the character.voidupdateSprite()-
Methods inherited from class com.bombinggames.wurfelengine.core.gameobjects.AbstractEntity
addComponent, collidesWith, getCollidingEntities, getCollidingEntities, getComponents, getComponents, getCoord, getCoveredBlocks, getDimensionZ, getHealth, getLightlevelB, getLightlevelG, getLightlevelR, getMass, getName, getPoint, getPosition, getRegisteredEntities, getSpriteCategory, getSpriteId, getSpriteValue, hasPosition, heal, isIndestructible, isInMemoryArea, isMarkedDS, isSavedPersistent, markAsVisitedDS, registerEngineEntities, registerEntity, removeComponent, removeFromMap, requestChunk, setDamageSounds, setDimensionZ, setHealth, setIndestructible, setLightlevel, setMass, setName, setPosition, setPosition, setSavePersistent, setSpriteCategory, setSpriteId, setSpriteValue, setUseRawDelta, shouldBeDisposed, takeDamage, useRawDelta
-
Methods inherited from class com.bombinggames.wurfelengine.core.gameobjects.AbstractGameObject
getColor, getDepth, getPixmap, getRotation, getScaling, getSprite, getSprite, getSpritesheet, getSpritesheetPath, getTextureDiffuse, getTextureNormal, isHidden, loadSheet, render, render, setColor, setCustomSpritesheet, setHidden, setRotation, setScaling, shouldBeRendered, staticDispose, updateSpriteCache
-
-
-
-
Constructor Detail
-
MovableEntity
public MovableEntity(byte id)
Simple MovableEntity with no animation.- Parameters:
id-
-
MovableEntity
public MovableEntity(byte id, int spritesPerDir)Constructor of MovableEntity.- Parameters:
id-spritesPerDir- The number of animation sprites per walking direction. if 0 then it only uses the value 0
-
MovableEntity
public MovableEntity(MovableEntity entity)
copy constructor- Parameters:
entity-
-
-
Method Detail
-
setWaterSound
public static void setWaterSound(java.lang.String waterSound)
Set the value of waterSound- Parameters:
waterSound- new value of waterSound
-
spawn
public MovableEntity spawn(Point point)
Description copied from class:AbstractEntityAdd this entity to the map-> let it spawn- Overrides:
spawnin classAbstractEntity- Parameters:
point- the point in the game world where the object is. If it was previously set this is ignored.- Returns:
- returns itself
-
dispose
public void dispose()
Description copied from class:AbstractEntityDeletes the object from the map and every other container. The opposite to spawn() but also sets a flag to remove it completely.- Overrides:
disposein classAbstractEntity- See Also:
AbstractEntity.shouldBeDisposed(),AbstractEntity.removeFromMap()
-
setWalkingAnimationCycling
public void setWalkingAnimationCycling(boolean cycle)
Bounce back and forth (1,2,3,2,1,2 etc.) or cycle (1,2,3,1,2,3 etc.)- Parameters:
cycle- true if cycle, false if bounce
-
setContinuousWalkingAnimation
public void setContinuousWalkingAnimation(float walkOnTheSpot)
Enable this to have a walking cycle even if not moving- Parameters:
walkOnTheSpot- the speed of the animation. Faktor without unit ~1. To disable pass 0.
-
setWalkingStepMode
public void setWalkingStepMode(boolean stepmode)
Set step mode or disable step mode. if no step mode plays animation back and forth. If step mode then some strange pattern which looks god for walking animations.- Parameters:
stepmode- stepmode = true,
-
jump
public void jump()
This method should define what happens when the object jumps. It should call super.jump(int velo)- See Also:
jump(float, boolean)
-
jump
public void jump(float velo, boolean playSound)Jump with a specific speed. Can jump if in air.- Parameters:
velo- the velocity in m/splaySound- plays jump sound if true
-
getAiming
public com.badlogic.gdx.math.Vector3 getAiming()
Defines the direction of the gun - if no gun available - the direction of the head.- Returns:
- If not overwriten returning orientation. copy save
-
update
public void update(float dt)
Updates the character. Applies gravitation.- Overrides:
updatein classAbstractEntity- Parameters:
dt- time since last update in ms
-
updateSprite
public void updateSprite()
-
collidesWithWorld
public boolean collidesWithWorld(Point pos, float colissionRadius)
check for horizontal colission (x and y)
O(1)- Parameters:
pos- the new position, not modifiedcolissionRadius-- Returns:
- true if colliding horizontal
-
isOnCeil
public boolean isOnCeil(Point pos)
Check if the top is coliding with a block. O(1)- Parameters:
pos- the position to check- Returns:
-
setFallingSound
public void setFallingSound(java.lang.String fallingSound)
Sets the sound to be played when falling.- Parameters:
fallingSound-
-
setRunningSound
public void setRunningSound(java.lang.String runningSound)
Set the sound to be played when running.- Parameters:
runningSound-
-
setJumpingSound
public void setJumpingSound(java.lang.String jumpingSound)
Set the value of jumpingSound- Parameters:
jumpingSound- new value of jumpingSound
-
setStepSound1Grass
public void setStepSound1Grass(java.lang.String sound)
- Parameters:
sound-
-
getOrientation
public final com.badlogic.gdx.math.Vector2 getOrientation()
Direction of movement. Normalized.- Returns:
- unit vector for x and y component. copy safe
-
getMovement
public final com.badlogic.gdx.math.Vector3 getMovement()
Get the movement vector as the product of direction and speed. Don't use this method to change values. UsesetMovement(Vector3).- Returns:
- in m/s. returns reference
-
getMovementHor
public final com.badlogic.gdx.math.Vector2 getMovementHor()
Get the movement vector as the product of direction and speed.- Returns:
- in m/s. copy safe
-
setMovement
public void setMovement(com.badlogic.gdx.math.Vector2 movement)
Sets speed and direction combined in one vector.- Parameters:
movement- containing direction and speed (length) in m/s.
-
setMovement
public void setMovement(com.badlogic.gdx.math.Vector3 movement)
Sets speed and direction values.- Parameters:
movement- containing direction and speed in m/s without the unit e.g. for 5m/s use just 5 and not 5*RenderCell.GAME_EDGELENGTH.
-
addMovement
public void addMovement(com.badlogic.gdx.math.Vector2 movement)
Adds speed and direction.- Parameters:
movement- containing direction and speed in m/s without the unit e.g. for 5m/s use just 5 and not 5*RenderCell.GAME_EDGELENGTH.
-
addMovement
public void addMovement(com.badlogic.gdx.math.Vector3 movement)
Adds speed and direction.- Parameters:
movement- containing direction and speed in m/s without the unit e.g. for 5m/s use just 5 and not 5*RenderCell.GAME_EDGELENGTH.
-
addMovement
public void addMovement(float x, float y, float z)Adds speed and direction.- Parameters:
x-y-z-
-
addToHor
public void addToHor(float speed)
Adds speed to horizontal moving directio.- Parameters:
speed- speed in m/s without the unit so no "5*RenderCell.GAME_EDGELENGTH" for 5 m/s but just "5".
-
setHorMovement
public void setHorMovement(com.badlogic.gdx.math.Vector2 movement)
Set the horizontal movement and keeps z- Parameters:
movement-
-
setSpeedHorizontal
public void setSpeedHorizontal(float speed)
Set the speed and only take x and y into account.- Parameters:
speed- in m/s
-
setSpeedIncludingZ
public void setSpeedIncludingZ(float speed)
Set the speed. Uses x, y and z.- Parameters:
speed- in m/s
-
getSpeedHor
public float getSpeedHor()
get the horizontal speed of the object in m/s.- Returns:
-
getSpeed
public float getSpeed()
get the speed of the object in m/s.- Returns:
-
setOrientation
public void setOrientation(com.badlogic.gdx.math.Vector2 orientation)
Turns an object in a different direction. Keeps the momentum.- Parameters:
orientation- the new orientation. Must be normalized.
-
isColiding
public boolean isColiding()
indicates whether this objects does collide with the blocks- Returns:
-
setColiding
public void setColiding(boolean coliding)
indicates whether this objects does collide with the blocks- Parameters:
coliding- true if collides with environment
-
isFloating
public boolean isFloating()
Is the object be affected by gravity?- Returns:
-
setFloating
public void setFloating(boolean floating)
Should the object be affected by gravity?- Parameters:
floating- if true then not affacted
-
isOnGround
public boolean isOnGround()
Description copied from class:AbstractEntityIs the entity laying/standing on the ground?- Overrides:
isOnGroundin classAbstractEntity- Returns:
- true when on the ground. False if in air or not in memory.
-
isInLiquid
public boolean isInLiquid()
Is the character standing in a liquid?- Returns:
-
getFriction
public float getFriction()
The factor which slows donw movement.- Returns:
-
setFriction
public void setFriction(float friction)
Automatically slows speed down.- Parameters:
friction- The higher the value, the less "slide". If =0 friciton is disabled. Value should be ~0.01f
-
step
public void step()
performs a step. Plays a sound.
-
pauseMovementAnimation
public void pauseMovementAnimation()
Pauses the movement animation. A use case is when you want to play a different animation then walking while the object may still move.- See Also:
playMovementAnimation()
-
playMovementAnimation
public void playMovementAnimation()
Continues the movement animation when it was stopped before withpauseMovementAnimation().
-
handleMessage
public boolean handleMessage(com.badlogic.gdx.ai.msg.Telegram msg)
-
-