This repository was archived by the owner on Sep 17, 2021. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathScene.java
More file actions
99 lines (82 loc) · 2.3 KB
/
Copy pathScene.java
File metadata and controls
99 lines (82 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package Gprocessing.util;
import Gprocessing.ecs.GameObject;
import Gprocessing.graphics.Camera;
import Gprocessing.graphics.renderer.Renderer;
import java.util.ArrayList;
import static Gprocessing.util.Engine.deltaTime;
import static Gprocessing.util.Engine.init;
public abstract class Scene {
private Renderer renderer = new Renderer();
public Camera camera;
private boolean isRunning = false;
static protected ArrayList<GameObject> gameObjects = new ArrayList<>();
protected GameObject activeGameObject = null;
/**
* @param args
* Entry point to start the application
*/
public static void main(String[] args) {
init(1600, 900, "Gprocessing");
}
/**
* Runs only once on startup, useful for initializing gameObjects or for first time setup.
*/
public void awake () {
camera = new Camera();
}
/**
* This method is called every frame, and can be used to update objects.
*/
public void update() {}
/**
* This method is called from the ImGui layer, allowing the user to easily create imGui interfaces.
* The user is not restricted to using this method for GUIs, but it is encouraged.
*/
public void imgui () {}
// The following methods shouldn't be overridden.
/**
* Loops through all gameobjects already in the scene and calls their start methods.
*/
public void startGameObjects() {
for (GameObject gameObject : gameObjects) {
gameObject.start();
this.renderer.add(gameObject);
}
isRunning = true;
}
/**
* @return Returns an ArrayList of gameObjects in the scene.
*/
public ArrayList getGameObjects () {
return gameObjects;
}
/**
* @param gameObject GameObject to be added.
* Add a new gameObject to the scene and immediately call its start method.
*/
public static void addGameObjectToScene (GameObject gameObject) {
gameObjects.add(gameObject);
gameObject.start();
}
/**
* @return Returns the scene's instance of Camera
*/
public Camera camera () {
return this.camera;
}
/**
* Loops through all the gameObjects in the scene and calls their update methods.
*/
public void updateGameObjects () {
for (GameObject go : this.gameObjects) {
go.update((float) deltaTime);
}
this.renderer.render();
}
/**
* Loads the shader.
*/
public void loadEngineResources () {
Assets.getShader("src/assets/shaders/default.glsl");
}
}