add some minimalistic documentation to "more complex" methods
This commit is contained in:
@@ -75,6 +75,9 @@ public class GdxGame extends Game {
|
|||||||
screenCache.remove(screen.getClass());
|
screenCache.remove(screen.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the current screen with performance monitoring.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
glProfiler.reset();
|
glProfiler.reset();
|
||||||
@@ -94,6 +97,9 @@ public class GdxGame extends Game {
|
|||||||
super.resize(width, height);
|
super.resize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleans up all game resources and services.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
for (Screen screen : screenCache.values()) {
|
for (Screen screen : screenCache.values()) {
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ public class LoadingScreen extends ScreenAdapter {
|
|||||||
this.assetService = game.getAssetService();
|
this.assetService = game.getAssetService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queues all required assets for loading.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
for (AtlasAsset atlasAsset : AtlasAsset.values()) {
|
for (AtlasAsset atlasAsset : AtlasAsset.values()) {
|
||||||
@@ -29,6 +32,9 @@ public class LoadingScreen extends ScreenAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates asset loading progress and transitions to menu when complete.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void render(float delta) {
|
public void render(float delta) {
|
||||||
if (assetService.update()) {
|
if (assetService.update()) {
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ public class AnimationSystem extends IteratingSystem {
|
|||||||
this.animationCache = new HashMap<>();
|
this.animationCache = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates animation state and sets graphic's component region.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void processEntity(Entity entity, float deltaTime) {
|
protected void processEntity(Entity entity, float deltaTime) {
|
||||||
Animation2D animation2D = Animation2D.MAPPER.get(entity);
|
Animation2D animation2D = Animation2D.MAPPER.get(entity);
|
||||||
@@ -49,6 +52,9 @@ public class AnimationSystem extends IteratingSystem {
|
|||||||
Graphic.MAPPER.get(entity).setRegion(keyFrame);
|
Graphic.MAPPER.get(entity).setRegion(keyFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates animation based on direction and type, using cached animations.
|
||||||
|
*/
|
||||||
private void updateAnimation(Animation2D animation2D, FacingDirection direction) {
|
private void updateAnimation(Animation2D animation2D, FacingDirection direction) {
|
||||||
AtlasAsset atlasAsset = animation2D.getAtlasAsset();
|
AtlasAsset atlasAsset = animation2D.getAtlasAsset();
|
||||||
String atlasKey = animation2D.getAtlasKey();
|
String atlasKey = animation2D.getAtlasKey();
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ public class AttackSystem extends IteratingSystem {
|
|||||||
this.attackDamage = 0f;
|
this.attackDamage = 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes attack logic including sound effects and damage detection.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void processEntity(Entity entity, float deltaTime) {
|
protected void processEntity(Entity entity, float deltaTime) {
|
||||||
Attack attack = Attack.MAPPER.get(entity);
|
Attack attack = Attack.MAPPER.get(entity);
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ public class CameraSystem extends IteratingSystem {
|
|||||||
this.targetPosition = new Vector2();
|
this.targetPosition = new Vector2();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates camera position with smooth following and boundary constraints.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void processEntity(Entity entity, float deltaTime) {
|
protected void processEntity(Entity entity, float deltaTime) {
|
||||||
Transform transform = Transform.MAPPER.get(entity);
|
Transform transform = Transform.MAPPER.get(entity);
|
||||||
@@ -39,8 +42,10 @@ public class CameraSystem extends IteratingSystem {
|
|||||||
camera.position.set(smoothedX, smoothedY, camera.position.z);
|
camera.position.set(smoothedX, smoothedY, camera.position.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates target camera position within map boundaries.
|
||||||
|
*/
|
||||||
private void calcTargetPosition(Vector2 entityPosition) {
|
private void calcTargetPosition(Vector2 entityPosition) {
|
||||||
// Keep the target position within map boundaries
|
|
||||||
float targetX = entityPosition.x;
|
float targetX = entityPosition.x;
|
||||||
float targetY = entityPosition.y + CAM_OFFSET_Y;
|
float targetY = entityPosition.y + CAM_OFFSET_Y;
|
||||||
float camHalfW = camera.viewportWidth * 0.5f;
|
float camHalfW = camera.viewportWidth * 0.5f;
|
||||||
@@ -58,6 +63,9 @@ public class CameraSystem extends IteratingSystem {
|
|||||||
this.targetPosition.set(targetX, targetY);
|
this.targetPosition.set(targetX, targetY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up camera for a new map and positions it at the target entity.
|
||||||
|
*/
|
||||||
public void setMap(TiledMap tiledMap) {
|
public void setMap(TiledMap tiledMap) {
|
||||||
int width = tiledMap.getProperties().get("width", 0, Integer.class);
|
int width = tiledMap.getProperties().get("width", 0, Integer.class);
|
||||||
int tileW = tiledMap.getProperties().get("tilewidth", 0, Integer.class);
|
int tileW = tiledMap.getProperties().get("tilewidth", 0, Integer.class);
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ public class ControllerSystem extends IteratingSystem {
|
|||||||
this.game = game;
|
this.game = game;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes input commands for the entity, handling movement and actions.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void processEntity(Entity entity, float deltaTime) {
|
protected void processEntity(Entity entity, float deltaTime) {
|
||||||
Controller controller = Controller.MAPPER.get(entity);
|
Controller controller = Controller.MAPPER.get(entity);
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ public class PhysicSystem extends IteratingSystem implements EntityListener, Con
|
|||||||
engine.removeEntityListener(this);
|
engine.removeEntityListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates physics simulation with fixed timestep and interpolation.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(float deltaTime) {
|
public void update(float deltaTime) {
|
||||||
this.accumulator += deltaTime;
|
this.accumulator += deltaTime;
|
||||||
@@ -61,12 +64,18 @@ public class PhysicSystem extends IteratingSystem implements EntityListener, Con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores previous position for interpolation.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void processEntity(Entity entity, float deltaTime) {
|
protected void processEntity(Entity entity, float deltaTime) {
|
||||||
Physic physic = Physic.MAPPER.get(entity);
|
Physic physic = Physic.MAPPER.get(entity);
|
||||||
physic.getPrevPosition().set(physic.getBody().getPosition());
|
physic.getPrevPosition().set(physic.getBody().getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interpolates entity position between physics steps.
|
||||||
|
*/
|
||||||
private void interpolateEntity(Entity entity, float alpha) {
|
private void interpolateEntity(Entity entity, float alpha) {
|
||||||
Transform transform = Transform.MAPPER.get(entity);
|
Transform transform = Transform.MAPPER.get(entity);
|
||||||
Physic physic = Physic.MAPPER.get(entity);
|
Physic physic = Physic.MAPPER.get(entity);
|
||||||
@@ -94,6 +103,9 @@ public class PhysicSystem extends IteratingSystem implements EntityListener, Con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles collision detection between entities and triggers.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void beginContact(Contact contact) {
|
public void beginContact(Contact contact) {
|
||||||
Fixture fixtureA = contact.getFixtureA();
|
Fixture fixtureA = contact.getFixtureA();
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ public class RenderSystem extends SortedIteratingSystem implements Disposable {
|
|||||||
this.bgdLayers = new ArrayList<>();
|
this.bgdLayers = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the scene with background, entities, and foreground layers.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(float deltaTime) {
|
public void update(float deltaTime) {
|
||||||
AnimatedTiledMapTile.updateAnimationBaseTime();
|
AnimatedTiledMapTile.updateAnimationBaseTime();
|
||||||
@@ -61,6 +64,9 @@ public class RenderSystem extends SortedIteratingSystem implements Disposable {
|
|||||||
batch.end();
|
batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a single entity with its transform and graphic components.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void processEntity(Entity entity, float deltaTime) {
|
protected void processEntity(Entity entity, float deltaTime) {
|
||||||
Transform transform = Transform.MAPPER.get(entity);
|
Transform transform = Transform.MAPPER.get(entity);
|
||||||
@@ -84,6 +90,9 @@ public class RenderSystem extends SortedIteratingSystem implements Disposable {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the map and organizes layers into background and foreground.
|
||||||
|
*/
|
||||||
public void setMap(TiledMap tiledMap) {
|
public void setMap(TiledMap tiledMap) {
|
||||||
this.tiledRenderer.setMap(tiledMap);
|
this.tiledRenderer.setMap(tiledMap);
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ public class TriggerSystem extends IteratingSystem {
|
|||||||
this.audioService = audioService;
|
this.audioService = audioService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes triggered entities and fires appropriate trigger effects.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void processEntity(Entity entity, float deltaTime) {
|
protected void processEntity(Entity entity, float deltaTime) {
|
||||||
Trigger trigger = Trigger.MAPPER.get(entity);
|
Trigger trigger = Trigger.MAPPER.get(entity);
|
||||||
@@ -41,6 +44,9 @@ public class TriggerSystem extends IteratingSystem {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Routes trigger events to appropriate handlers based on trigger name.
|
||||||
|
*/
|
||||||
private void fireTrigger(String triggerName, Entity triggeringEntity) {
|
private void fireTrigger(String triggerName, Entity triggeringEntity) {
|
||||||
switch (triggerName) {
|
switch (triggerName) {
|
||||||
case "trap_trigger" -> trapTrigger(triggeringEntity);
|
case "trap_trigger" -> trapTrigger(triggeringEntity);
|
||||||
@@ -48,6 +54,9 @@ public class TriggerSystem extends IteratingSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles trap trigger effects including animation and damage.
|
||||||
|
*/
|
||||||
private void trapTrigger(Entity triggeringEntity) {
|
private void trapTrigger(Entity triggeringEntity) {
|
||||||
Entity trapEntity = getByTiledId(15);
|
Entity trapEntity = getByTiledId(15);
|
||||||
if (trapEntity != null) {
|
if (trapEntity != null) {
|
||||||
|
|||||||
@@ -91,6 +91,9 @@ public class TiledAshleyConfigurator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and configures an entity from a Tiled map object with all necessary components.
|
||||||
|
*/
|
||||||
public void onLoadObject(TiledMapTileMapObject tileMapObject) {
|
public void onLoadObject(TiledMapTileMapObject tileMapObject) {
|
||||||
Entity entity = this.engine.createEntity();
|
Entity entity = this.engine.createEntity();
|
||||||
TiledMapTile tile = tileMapObject.getTile();
|
TiledMapTile tile = tileMapObject.getTile();
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ public class TiledService {
|
|||||||
this.loadTileConsumer = loadTileConsumer;
|
this.loadTileConsumer = loadTileConsumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads all map objects from different layers and creates map collision boundaries.
|
||||||
|
*/
|
||||||
public void loadMapObjects(TiledMap tiledMap) {
|
public void loadMapObjects(TiledMap tiledMap) {
|
||||||
for (MapLayer layer : tiledMap.getLayers()) {
|
for (MapLayer layer : tiledMap.getLayers()) {
|
||||||
if (layer instanceof TiledMapTileLayer tileLayer) {
|
if (layer instanceof TiledMapTileLayer tileLayer) {
|
||||||
@@ -89,8 +92,10 @@ public class TiledService {
|
|||||||
spawnMapBoundary(tiledMap);
|
spawnMapBoundary(tiledMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates physics boundaries around the map edges.
|
||||||
|
*/
|
||||||
private void spawnMapBoundary(TiledMap tiledMap) {
|
private void spawnMapBoundary(TiledMap tiledMap) {
|
||||||
// create four boxes for the map boundary (left, right, bottom and top edge)
|
|
||||||
int width = tiledMap.getProperties().get("width", 0, Integer.class);
|
int width = tiledMap.getProperties().get("width", 0, Integer.class);
|
||||||
int tileW = tiledMap.getProperties().get("tilewidth", 0, Integer.class);
|
int tileW = tiledMap.getProperties().get("tilewidth", 0, Integer.class);
|
||||||
int height = tiledMap.getProperties().get("height", 0, Integer.class);
|
int height = tiledMap.getProperties().get("height", 0, Integer.class);
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ public class GameView extends View<GameViewModel> {
|
|||||||
add(horizontalGroup);
|
add(horizontalGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the life display with appropriate heart icons.
|
||||||
|
*/
|
||||||
private void updateLife(int lifePoints) {
|
private void updateLife(int lifePoints) {
|
||||||
lifeGroup.clear();
|
lifeGroup.clear();
|
||||||
|
|
||||||
@@ -57,6 +60,9 @@ public class GameView extends View<GameViewModel> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows animated damage text at the specified position.
|
||||||
|
*/
|
||||||
private void showDamage(Map.Entry<Vector2, Integer> damAndPos) {
|
private void showDamage(Map.Entry<Vector2, Integer> damAndPos) {
|
||||||
Vector2 position = damAndPos.getKey();
|
Vector2 position = damAndPos.getKey();
|
||||||
int damage = damAndPos.getValue();
|
int damage = damAndPos.getValue();
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ public class MenuView extends View<MenuViewModel> {
|
|||||||
selectMenuItem(this.selectedItem);
|
selectMenuItem(this.selectedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects a menu item and animates the selection indicator.
|
||||||
|
*/
|
||||||
private void selectMenuItem(Group menuItem) {
|
private void selectMenuItem(Group menuItem) {
|
||||||
if (selectionImg.getParent() != null) {
|
if (selectionImg.getParent() != null) {
|
||||||
selectionImg.getParent().removeActor(selectionImg);
|
selectionImg.getParent().removeActor(selectionImg);
|
||||||
@@ -54,6 +57,9 @@ public class MenuView extends View<MenuViewModel> {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the main UI layout with banner and menu content.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void setupUI() {
|
protected void setupUI() {
|
||||||
setFillParent(true);
|
setFillParent(true);
|
||||||
@@ -68,6 +74,9 @@ public class MenuView extends View<MenuViewModel> {
|
|||||||
add(label).padRight(5.0f).padBottom(5f).expand().align(Align.bottomRight);
|
add(label).padRight(5.0f).padBottom(5f).expand().align(Align.bottomRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the menu content with buttons and volume sliders.
|
||||||
|
*/
|
||||||
private void setupMenuContent() {
|
private void setupMenuContent() {
|
||||||
Table contentTable = new Table();
|
Table contentTable = new Table();
|
||||||
contentTable.setBackground(skin.getDrawable("frame"));
|
contentTable.setBackground(skin.getDrawable("frame"));
|
||||||
@@ -114,6 +123,9 @@ public class MenuView extends View<MenuViewModel> {
|
|||||||
return slider;
|
return slider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves selection to the next menu item.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onDown() {
|
public void onDown() {
|
||||||
Group menuContentTable = this.selectedItem.getParent();
|
Group menuContentTable = this.selectedItem.getParent();
|
||||||
@@ -127,6 +139,9 @@ public class MenuView extends View<MenuViewModel> {
|
|||||||
selectMenuItem((Group) menuContentTable.getChild(currentIdx));
|
selectMenuItem((Group) menuContentTable.getChild(currentIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves selection to the previous menu item.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onUp() {
|
public void onUp() {
|
||||||
Group menuContentTable = this.selectedItem.getParent();
|
Group menuContentTable = this.selectedItem.getParent();
|
||||||
|
|||||||
Reference in New Issue
Block a user