Repository navigation
Expand file tree
/
Copy pathHandler.java
More file actions
149 lines (123 loc) · 2.49 KB
/
Copy pathHandler.java
File metadata and controls
149 lines (123 loc) · 2.49 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package main;
import java.awt.Graphics;
import java.util.LinkedList;
/**
* Adds, removes, and renders game objects within the game instance.
*/
public class Handler
{
LinkedList<GameObject> objects = new LinkedList<GameObject>();
private boolean up = false, down = false, right = false, left = false;
private boolean upPriority = false, downPriority = false, rightPriority = false, leftPriority = false;
/**
* Updates the game per frame by updating each game object.
*/
public void tick()
{
objects.parallelStream().forEach((object) ->
{
object.tick();
});
}
/**
* Renders the graphics for each game object.
*
* @param g
*/
public void render(Graphics g)
{
// objects.parallelStream().forEach((object) ->
// {
// object.render(g);
// });
// TODO Figure out how to safely iterate and modify in parallel stream
for (int i = 0; i < objects.size(); i++)
{
GameObject tempObject = objects.get(i);
tempObject.render(g);
}
}
/**
* Adds the passed game object into game handler.
*
* @param tempObject
*/
public void addObject(GameObject tempObject)
{
objects.add(tempObject);
}
/**
* Removes the game object from the game handler.
*
* @param tempObject
*/
public void removeObject(GameObject tempObject)
{
objects.remove(tempObject);
}
// Getters and Setters//
public boolean isUp()
{
return up;
}
public void setUp(boolean up)
{
this.up = up;
}
public boolean isDown()
{
return down;
}
public void setDown(boolean down)
{
this.down = down;
}
public boolean isRight()
{
return right;
}
public void setRight(boolean right)
{
this.right = right;
}
public boolean isLeft()
{
return left;
}
public void setLeft(boolean left)
{
this.left = left;
}
public boolean isUpPriority()
{
return upPriority;
}
public void setUpPriority(boolean upPriority)
{
this.upPriority = upPriority;
}
public boolean isDownPriority()
{
return downPriority;
}
public void setDownPriority(boolean downPriority)
{
this.downPriority = downPriority;
}
public boolean isRightPriority()
{
return rightPriority;
}
public void setRightPriority(boolean rightPriority)
{
this.rightPriority = rightPriority;
}
public boolean isLeftPriority()
{
return leftPriority;
}
public void setLeftPriority(boolean leftPriority)
{
this.leftPriority = leftPriority;
}
}