Skip to content

Commit 5b9a1e8

Browse files
committed
Collisions broken
1 parent bdbff7e commit 5b9a1e8

4 files changed

Lines changed: 21 additions & 27 deletions

File tree

rectangles/engine/GameObj.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ public abstract class GameObj extends PApplet {
1212
private float objWidth;
1313
private float objHeight;
1414
private boolean isFloor;
15-
private UUID uuid;
15+
16+
private UUID uuid = UUID.randomUUID();
1617

1718
public GameObj(float objWidth, float objHeight, float mass, float x, float y, PShape shape,
1819
boolean isFloor, boolean isGrav) {
1920
this.isFloor = isFloor;
2021
this.objHeight = height;
2122
this.objWidth = width;
2223
this.py = new Physics(x, y, objWidth, objHeight, mass, 20, isGrav);
23-
this.uuid = UUID.randomUUID();
24+
2425
try {
2526
this.shape = shape;
2627
} catch (NullPointerException e) {

rectangles/engine/Rectangles.java

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,24 @@ public void setup() {
5050
frameRate(60);
5151
textSize(32);
5252

53-
53+
5454
// Setup Server
5555
if (this.isServer) {
56+
// Player
57+
float sqrDim = 50;
58+
PShape sqr = createShape(RECT, 0, 0, sqrDim, sqrDim);
59+
sqr.setFill(color(random(255), random(255), random(255)));
60+
sqr.setStroke(false);
61+
this.player = new Player(sqr, height - sqrDim - 2, 1);
62+
this.objects.add(this.player);
63+
this.objectMap.put(this.player.getUUID(), this.player);
64+
this.movObjects.add(this.player);
65+
5666
this.server = new Server(9200, this.threadPool, this.player);
5767
this.localClient = this.server.getLocalClient();
5868
new Thread(this.server).start();
69+
70+
this.server.newPacket(Packet.PACKET_CREATE, this.player);
5971

6072

6173
// Add screen boundaries
@@ -126,15 +138,6 @@ public void setup() {
126138
this.server.newPacket(Packet.PACKET_CREATE, p);
127139
}
128140

129-
// Player
130-
float sqrDim = 50;
131-
PShape sqr = createShape(RECT, 0, 0, sqrDim, sqrDim);
132-
sqr.setFill(color(random(255), random(255), random(255)));
133-
sqr.setStroke(false);
134-
this.player = new Player(sqr, height - sqrDim - 2, 1);
135-
this.objectMap.put(this.player.getUUID(), this.player);
136-
this.movObjects.add(this.player);
137-
this.server.newPacket(Packet.PACKET_CREATE, this.player);
138141

139142
} else {
140143
try {
@@ -150,17 +153,9 @@ public void setup() {
150153

151154
public void draw() {
152155
background(0);
153-
154-
this.renderAll(objects);
155-
// Walls
156-
rect((float) this.floor.getPy().getBounds2D().getX(), (float) this.floor.getPy().getBounds2D().getY(),
157-
(float) this.floor.getPy().getBounds2D().getWidth(), (float) this.floor.getPy().getBounds2D().getHeight());
158-
rect((float) this.ceiling.getPy().getBounds2D().getX(), (float) this.ceiling.getPy().getBounds2D().getY(),
159-
(float) this.ceiling.getPy().getBounds2D().getWidth(), (float) this.ceiling.getPy().getBounds2D().getHeight());
160-
rect((float) this.leftWall.getPy().getBounds2D().getX(), (float) this.leftWall.getPy().getBounds2D().getY(),
161-
(float) this.leftWall.getPy().getBounds2D().getWidth(), (float) this.leftWall.getPy().getBounds2D().getHeight());
162-
rect((float) this.rightWall.getPy().getBounds2D().getX(), (float) this.rightWall.getPy().getBounds2D().getY(),
163-
(float) this.rightWall.getPy().getBounds2D().getWidth(), (float) this.rightWall.getPy().getBounds2D().getHeight());
156+
157+
this.renderAll(this.objects);
158+
164159

165160
// Dummy Renderer?
166161
if (isServer) {
@@ -169,10 +164,6 @@ public void draw() {
169164
obj.getPy().update(obj, this.objects);
170165
}
171166
}
172-
// Render
173-
shape(this.localClient.getPlayer().getShape(), this.localClient.getPlayer().getPy().getLocation().x,
174-
this.localClient.getPlayer().getPy().getLocation().y);
175-
176167

177168
// Only run update to clients 3fps?
178169
if (this.isServer && (frameCount % 20 == 0)) {

rectangles/networking/Client.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class Client implements Runnable {
3131
public Client(ExecutorService threadPool, Player player) {
3232
this.threadPool = threadPool;
3333
this.player = player;
34+
this.state = new ConcurrentHashMap<UUID, GameObj>();
3435
this.state.put(player.getUUID(), player);
3536
}
3637

rectangles/networking/Packet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class Packet {
1919
public Packet(int type, GameObj obj) {
2020
this.type = type;
2121
this.uuid = obj.getUUID();
22+
this.data = new HashMap<>();
2223

2324
switch (this.type) {
2425
case (PACKET_REGISTER):

0 commit comments

Comments
 (0)