From d401db70b34d19f01cc67711e138a243fd09bb35 Mon Sep 17 00:00:00 2001 From: Turid Dahl <turidcd@stud.ntnu.no> Date: Sat, 25 Apr 2020 08:33:41 +0200 Subject: [PATCH] #100 Adds comments about game loop & update method and removes interface --- frontend/core/src/com/gameware/game/GameWare.java | 8 ++++++-- .../core/src/com/gameware/game/models/ModelInterface.java | 3 +-- frontend/core/src/com/gameware/game/sprites/Sprite.java | 2 +- .../src/com/gameware/game/states/GameStateManager.java | 3 ++- frontend/core/src/com/gameware/game/states/State.java | 5 +++-- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/frontend/core/src/com/gameware/game/GameWare.java b/frontend/core/src/com/gameware/game/GameWare.java index a9278ad..7e1fa7d 100644 --- a/frontend/core/src/com/gameware/game/GameWare.java +++ b/frontend/core/src/com/gameware/game/GameWare.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.utils.Json; import com.badlogic.gdx.utils.JsonReader; @@ -27,9 +28,10 @@ import java.util.Map; /* GameWare is the main class, it is the first class to be created. It is called from the AndroidLauncher. - It extends LibGDX's ApplicationAdapter, and the render method delegates to the GameStateManager. + It extends LibGDX's ApplicationAdapter, and the render method (regarded as the game loop) + delegates to the GameStateManager. - Patterns: Singleton, Delegation + Patterns: Singleton, Delegation, Game Loop */ public class GameWare extends ApplicationAdapter { @@ -89,6 +91,8 @@ public class GameWare extends ApplicationAdapter { @Override public void render () { +// Game loop + // Clearing the screen Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); diff --git a/frontend/core/src/com/gameware/game/models/ModelInterface.java b/frontend/core/src/com/gameware/game/models/ModelInterface.java index b164ece..0646df7 100644 --- a/frontend/core/src/com/gameware/game/models/ModelInterface.java +++ b/frontend/core/src/com/gameware/game/models/ModelInterface.java @@ -3,9 +3,8 @@ package com.gameware.game.models; /* Data model interface for converting json objects to Java objects - Patterns: Interface pattern, pipe-and-filter pattern + Patterns: Pipe-and-filter - Implementation of the interface from the Interface pattern. When implemented the class must be a model, in other words a data oriented java object. Data models used for the filters input/output ports in the QueryIntermediate's pipe-and-filter implementation. diff --git a/frontend/core/src/com/gameware/game/sprites/Sprite.java b/frontend/core/src/com/gameware/game/sprites/Sprite.java index e966b46..1660c0c 100644 --- a/frontend/core/src/com/gameware/game/sprites/Sprite.java +++ b/frontend/core/src/com/gameware/game/sprites/Sprite.java @@ -7,7 +7,7 @@ import com.badlogic.gdx.math.Vector3; Abstract super class/union for game-sprites. Super class instead of interface because of necessary variables all sprites needs to have - Patterns: Union + Patterns: Union, Update method */ public abstract class Sprite { diff --git a/frontend/core/src/com/gameware/game/states/GameStateManager.java b/frontend/core/src/com/gameware/game/states/GameStateManager.java index 41dbc87..b99e009 100644 --- a/frontend/core/src/com/gameware/game/states/GameStateManager.java +++ b/frontend/core/src/com/gameware/game/states/GameStateManager.java @@ -7,7 +7,7 @@ import java.util.Stack; /* GameStateManager keeps track of which state is the current one. Delegates to the correct state. - Patterns: State, Delegation + Patterns: State, Delegation, Update method */ public class GameStateManager { @@ -40,6 +40,7 @@ public class GameStateManager { states.push(state); } +// Update method (delegates to current state) public void update(float dt){ states.peek().update(dt); } diff --git a/frontend/core/src/com/gameware/game/states/State.java b/frontend/core/src/com/gameware/game/states/State.java index 8526ec4..b638e8e 100644 --- a/frontend/core/src/com/gameware/game/states/State.java +++ b/frontend/core/src/com/gameware/game/states/State.java @@ -11,9 +11,9 @@ import com.gameware.game.GameWare; State is the super class/union of all the states in the application. A state has their own logic and rendering. State contains common variables between - MenuStateUnion and PlayStateUnion. + MenuStateUnion and PlayStateUnion. All states must have their own update method. - Patterns: State, Union Design + Patterns: State, Union Design, Update method */ public abstract class State { @@ -45,6 +45,7 @@ public abstract class State { // Abstract state methods protected abstract void handleInput(); +// Requires all states to have the update method public abstract void update(float dt); public abstract void render(SpriteBatch sb); -- GitLab