Skip to content
Snippets Groups Projects
Commit d401db70 authored by Turid Cecilie Dahl's avatar Turid Cecilie Dahl
Browse files

#100 Adds comments about game loop & update method and removes interface

parent e890cdd1
Branches
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import com.badlogic.gdx.ApplicationAdapter; ...@@ -4,6 +4,7 @@ import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Json; import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonReader; import com.badlogic.gdx.utils.JsonReader;
...@@ -27,9 +28,10 @@ import java.util.Map; ...@@ -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. 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 { public class GameWare extends ApplicationAdapter {
...@@ -89,6 +91,8 @@ public class GameWare extends ApplicationAdapter { ...@@ -89,6 +91,8 @@ public class GameWare extends ApplicationAdapter {
@Override @Override
public void render () { public void render () {
// Game loop
// Clearing the screen // Clearing the screen
Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
......
...@@ -3,9 +3,8 @@ package com.gameware.game.models; ...@@ -3,9 +3,8 @@ package com.gameware.game.models;
/* /*
Data model interface for converting json objects to Java objects 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. 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. Data models used for the filters input/output ports in the QueryIntermediate's pipe-and-filter implementation.
......
...@@ -7,7 +7,7 @@ import com.badlogic.gdx.math.Vector3; ...@@ -7,7 +7,7 @@ import com.badlogic.gdx.math.Vector3;
Abstract super class/union for game-sprites. Super class instead of interface because of Abstract super class/union for game-sprites. Super class instead of interface because of
necessary variables all sprites needs to have necessary variables all sprites needs to have
Patterns: Union Patterns: Union, Update method
*/ */
public abstract class Sprite { public abstract class Sprite {
......
...@@ -7,7 +7,7 @@ import java.util.Stack; ...@@ -7,7 +7,7 @@ import java.util.Stack;
/* /*
GameStateManager keeps track of which state is the current one. Delegates to the correct state. 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 { public class GameStateManager {
...@@ -40,6 +40,7 @@ public class GameStateManager { ...@@ -40,6 +40,7 @@ public class GameStateManager {
states.push(state); states.push(state);
} }
// Update method (delegates to current state)
public void update(float dt){ public void update(float dt){
states.peek().update(dt); states.peek().update(dt);
} }
......
...@@ -11,9 +11,9 @@ import com.gameware.game.GameWare; ...@@ -11,9 +11,9 @@ import com.gameware.game.GameWare;
State is the super class/union of all the states in the application. 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 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 { public abstract class State {
...@@ -45,6 +45,7 @@ public abstract class State { ...@@ -45,6 +45,7 @@ public abstract class State {
// Abstract state methods // Abstract state methods
protected abstract void handleInput(); protected abstract void handleInput();
// Requires all states to have the update method
public abstract void update(float dt); public abstract void update(float dt);
public abstract void render(SpriteBatch sb); public abstract void render(SpriteBatch sb);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment