-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHandler.java
41 lines (35 loc) · 1.12 KB
/
Handler.java
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
import java.awt.Graphics;
import java.util.LinkedList;
public class Handler {
LinkedList<GameObject> object = new LinkedList<GameObject>();
//Handles processing of objects
public void tick() {
//If the object is off the screen, remove it from the list to prevent lag
for (int i = 0; i < object.size(); i++) {
GameObject temp = object.get(i);
if (temp.x > 800) {
object.remove(i);
}
}
//Update each object
for (int i = 0; i < object.size(); i++) {
GameObject temp = object.get(i);
temp.tick();
}
}
//Calls each objects corresponding render method
public void render(Graphics g) {
for (int i = 0; i < object.size(); i++) {
GameObject temp = object.get(i);
temp.render(g);
}
}
//Allows objects to be added
public void addObject(GameObject object) {
this.object.add(0,object);
}
//Allows objects to be removed
public void removeObject(GameObject object) {
this.object.remove(object);
}
}