-
Notifications
You must be signed in to change notification settings - Fork 7
Terrain Movement Modifiers
The TerrainTile
class contains a private float speedModifier variable which is used to represent a speed modifier to be applied to entities traversing on top of the tile. It is to act as a simple multiplier which should be used to scale the velocity vector of entities. The speedModifier attribute is accessed through the GameMap
class using the getTile method to return a TerrainTile and the getSpeedModifier method to get the speed modifier.
The TerrainTile
class also contains a private boolean isTraversable value which is used to determine if a tile is traversable or not. Non-traversable tiles are enforced via the spawning of 'invisible' entities which have collision boxes to prevent players from moving onto the tiles. The spawning of these entities is handled in the SpaceGameArea
class, using the getNonTraversableTileCoordinates() from the GameMap
class to get a list of non-traversable tiles and spawning an invisible entity using the createInvisibleObstacle() method from the ObstacleFactory
for each non-traversable coordinate.
Movement modifiers are applied to the player entity through the PlayerActions
class using the updateSpeed() method. Firstly, the Vector2
representing the player entity's position on the map is retrieved and transformed so that it is pointing to the bottom of the player entity's sprite feet. Then, the speed modifier for the tile at the transformed Vector2
coordinate (retrieved using getTile() and then getSpeedModifier() methods) is used to scale the existing velocityScale. This velocityScale is used scale the speed of the player entity, resulting in the terrain speed modifier being applied to the movement speed of the player entity.
Movement modifiers are applied to non-player entities through the PhysicsMovementComponent
class. However, it was not implemented during Sprint2. This is because the PhysicsMovementComponent
and none of it's variables stored a pointer to the GameMap
class, preventing the use of the getTile methods to get the speedModifier value. This will be fixed next sprint after the GameMap
class has been slightly overhauled to allow for easier access of variables.
The following tiles are traversable.
The following tiles are not traversable and hence have no movement modifier.