-
Notifications
You must be signed in to change notification settings - Fork 7
Alien Fauna ‐ Programming Guide
This wiki page will be a handbook on how animals/entities can be created into the game.
A key aspect of the gameplay is the presence of hostile animals, which affect the player's performance and contradict the game's victory conditions. However, due to the large scale of the map, it is important to make the players aware of the presence of hostile animals. In particular, players should be made aware of the existence of these enemy entities. These enemies do not target the player, but aim to affect the players progress in the game.
An indicator will be shown on the edge of the screen to direct the player in the direction of the off-screen entity. This will alert the player of the entity and thus will allow them to take the necessary actions to stop the hostile entity.
To detect if an entity is on the screen this function was implemented in CameraComponent
. This checks if the entities centre position is within the view of the camera
public boolean entityOnScreen(Entity entity) {
Vector2 position = entity.getCenterPosition();
return camera.frustum.pointInFrustum(position.x, position.y, 0);
}
In the EntityIndicator
class, the indicator will only be visible if EntityOnScreen()
returns false
public void update() {
if (cameraComponent.entityOnScreen(entity)) {
indicator.setVisible(false);
} else {
indicator.setVisible(true);
updateIndicator();
}
}
If the entity is not on the screen, then the indicator will need to be updated to point in the position of the entity.
public void updateIndicator() {
Vector2 entityPosition = entity.getCenterPosition();
Vector3 entityPos = new Vector3(entityPosition.x, entityPosition.y, 0);
cameraComponent.getCamera().project(entityPos);
indicatorPosX = MathUtils.clamp(entityPos.x - OFFSET, OFFSET,
Gdx.graphics.getWidth() - indicator.getWidth() - OFFSET);
indicatorPosY = MathUtils.clamp(entityPos.y - OFFSET, OFFSET,
Gdx.graphics.getHeight() - indicator.getHeight() - OFFSET);
indicator.setPosition(indicatorPosX, indicatorPosY);
}
It will convert the entities centre position to a 3D position and then project that on the camera component. This transforms the world coordinates of the entity into screen coordinates based on the cameras view. Next it will calculate the X and Y coordinates of the indicator by clamping the position to the screen. Note that OFFSET
is the offset of the indicator from the edge of screen so it is not touching the very edge of the screen.
This ensures that the position entityPos.X - OFFSET
is within the specified range. If the position is less than OFFSET
then it sets the indicator to OFFSET
. If its greater than Gdx.graphics.getWidth() - indicator.getWidth() - OFFSET
then it is set to Gdx.graphics.getWidth() - indicator.getWidth() - OFFSET
. This makes sure that the indicator only moves along the edge of the screen,
Please read https://github.com/UQcsse3200/2023-studio-1/wiki/Interaction-with-non%E2%80%90tile-entities