Skip to content

Terrain Properties

SamarthDevVaish edited this page Oct 19, 2023 · 10 revisions

There are many different textures for the ground the player moves over, and these textures may have special properties to them that affect gameplay.

Speed Modification

In the Tiled map editor, there is a section for defining custom properties for each tile in the tileset. The basic ground tiles (grass and path) have a property called speedMult. This property will affect the player's movement speed as they pass over it. The grass tiles will multiply the speed by 0.85x, slightly slowing the player down from their maximum speed, while path tiles have a value of 1.0, meaning the player will move at regular speed.

These properties are retrieved using a function getSpeedMult() in GameArea.java.

public static float getSpeedMult() {
    TiledMapTileLayer collisionLayer = (TiledMapTileLayer) terrain.getMap().getLayers().get("Base");
    Vector2 playerPos = getPlayer().getPosition();
    TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) (playerPos.x * 2), (int) (playerPos.y * 2));
    Object speedMult = cell.getTile().getProperties().get("speedMult");

    return speedMult != null ? (float)speedMult : 1f;
}

The function finds the tile the player is currently standing on, and if it has a speedMult property in the .tsx file, will return the floating point number listed. If not, the multiplication factor will be assumed to be 1.0.

The speedMult value is then retrieved by updateSpeed() in PlayerActions.java, where the player's walkDirection vector is scaled in the x and y direction using the speedMult value before it is applied as a linear impulse.

Portals

We've defined a class for dynamically placeable portal entities that allow you to teleport the player to arbitrary destinations. To do this we've implemented a portal class that works with proximity activations, and also a portal factory to spawn these portals, and bind properties to them.

public Portal(Entity player) {
    super();
    addComponent(new ProximityActivationComponent(0.5f, player, this::teleport, this::teleport));
}

public void teleport(Entity player) {
    player.setPosition(x, y);
}

@Override
public void setPosition(float x, float y) {
    this.x = x;
    this.y = y;
}
public static Entity createPortal(float x, float y, Entity player) {

        Entity portal = new Portal(player)
                .addComponent(new PhysicsComponent())
                .addComponent(new ColliderComponent().setLayer(PhysicsLayer.OBSTACLE))
                .addComponent(new TextureRenderComponent("map/portal.png"));
        portal.getComponent(PhysicsComponent.class).setBodyType(BodyDef.BodyType.StaticBody);
        portal.setScale(1.0f, 1.0f);
        portal.setPosition(x, y);
        return portal;
    }

Over all, we think this addition will address the increasing complexity of maps we're planning for the future, as well as provide some exciting opportunities for cool features like secret areas and fun shortcuts.

2023-09-14 09-58-09 (1)

Treetop Layering Feature

The Treetop Layering feature allows for the creation of a visual layer in the game that represents treetops. This layer is rendered on top of the player and other game elements to give the appearance of the player being below the treetops.

In the Tiled map editor, a separate layer named "Tree Top" is created to represent the treetops. This layer contains the visual elements (tiles) that will be rendered as treetops. Each tile in this layer should have the appropriate texture or image that represents a treetop. A factory method is implemented to create entities that represent treetops. These entities are placed in the game world based on the tiles in the "Tree Top" layer of the Tiled map.

public static Entity createTreeTop() {
    Entity treeTop =
            new Entity()
                    .addComponent(new TextureRenderComponent("map/treetop.png")) // Replace with the path to your tree top texture
                    .addComponent(new PhysicsComponent())
                    .addComponent(new ColliderComponent().setLayer(PhysicsLayer.NONE));

    treeTop.getComponent(PhysicsComponent.class).setBodyType(BodyType.StaticBody);
    treeTop.getComponent(TextureRenderComponent.class).scaleEntity();
    treeTop.scaleHeight(30f);
    PhysicsUtils.setScaledCollider(treeTop, 0.5f, 0.2f);
    return treeTop;
  }

To spawn treetops in the game world, a method called spawnTreeTopLayer is implemented. This method iterates through the tiles in the "Tree Top" layer of the Tiled map and creates treetop entities based on their positions.

Map Feature UML Diagram - Sprint 2

As you can see in the image below, the UML diagram features different branches showing all the classes which were modified by the team members of the map team. The UML diagram also shows the new functions that were added in their respective classes keeping in mind the visibility status they have. Some of the functions in the classes were also modified a little but did not reflect in the actual code as such. The other branches also feature the cross team collaborations which were done and what functions and classes were added by the members of the map team.

image

Sliding

When walking over an ice tile, the player won't come to a complete stop when they stop moving. Instead, they will slide for a short time. Like with the speedMult property, ice tiles have a sliding property, which when the player stops moving (handled by stopWalking() in PlayerActions.java), whether the player is on a tile with the sliding property is checked. If they are, when updateSpeed() is called, instead of setting the player's velocity to 0, it is instead scaled to 95% of it's current value, until the magnitude of the velocity is less than 0.01.

if(sliding) {
    velocity.scl(0.95f);
    if(velocity.isZero(0.01f)){
        sliding = false;
    }
}
else {
    Vector2 impulse = desiredVelocity.sub(velocity).scl(body.getMass());
    body.applyLinearImpulse(impulse, body.getWorldCenter(), true);
}

Map Team UML Diagram - Sprint 3

sprint 3 map uml

Map Team UML Diagram - Sprint 4

image

Clone this wiki locally