33import java .io .IOException ;
44import java .net .Socket ;
55import java .util .ArrayList ;
6+ import java .util .Random ;
67import java .util .UUID ;
78import java .util .concurrent .ConcurrentHashMap ;
89import java .util .concurrent .CopyOnWriteArrayList ;
@@ -24,6 +25,11 @@ public class Rectangles extends PApplet {
2425 public static CopyOnWriteArrayList <GameObj > objects = new CopyOnWriteArrayList <GameObj >();
2526 public static CopyOnWriteArrayList <GameObj > movObjects = new CopyOnWriteArrayList <GameObj >();
2627 public static ConcurrentHashMap <UUID , GameObj > objectMap = new ConcurrentHashMap <UUID , GameObj >();
28+ public static Spawn [] spawnPoints = new Spawn [2 ];
29+ public static Random generator = new Random ();
30+ public static int deathPoints = 0 ;
31+
32+
2733 public static Player player ;
2834
2935 private boolean isServer ;
@@ -54,9 +60,27 @@ public void setup() {
5460
5561 // Setup Server
5662 if (this .isServer ) {
57- // Player
63+
5864 float sqrDim = 50 ;
59- player = new Player (this , sqrDim , height - sqrDim - 2 , 1 );
65+
66+ // Spawn Points
67+ spawnPoints [0 ] = new Spawn (this , width - sqrDim , 0 + sqrDim );
68+ spawnPoints [1 ] = new Spawn (this , width - sqrDim , height - sqrDim );
69+
70+ for (Spawn s : spawnPoints ) {
71+ objects .add (s );
72+ objectMap .put (s .getUUID (), s );
73+ }
74+
75+ // Death Zone
76+ DeathZone dz_1 = new DeathZone (this , 0 , 0 );
77+ objects .add (dz_1 );
78+ objectMap .put (dz_1 .getUUID (), dz_1 );
79+
80+ // Player
81+ Spawn rand = spawnPoints [generator .nextInt (2 )];
82+ player = new Player (this , sqrDim , rand .getPy ().getLocation ().x ,
83+ rand .getPy ().getLocation ().y );
6084
6185 this .server = new Server (this , 9200 , this .threadPool , player );
6286 this .localClient = this .server .getLocalClient ();
@@ -97,23 +121,30 @@ public void setup() {
97121 ArrayList <Platform > staticPlatforms = new ArrayList <Platform >();
98122 ArrayList <Platform > movPlatforms = new ArrayList <Platform >();
99123
100- for (Platform p : movPlatforms ) {
101- p .getPy ().setTopSpeed (5 );
102- p .getPy ().setVelocity (new PVector (5 , 0 ));
103- }
104-
124+ //Platform static_1 = new Platform(this, pWidth, pHeight, width - 4*pWidth, 500, false);
105125 Platform static_1 = new Platform (this , pWidth , pHeight , width - pWidth , 100 , false );
106- Platform static_2 = new Platform ( this , pWidth , pHeight , pWidth , 100 , false );
126+
107127
108128 staticPlatforms .add (static_1 );
109- staticPlatforms .add (static_2 );
110129
111- Platform mov_1 = new Platform (this , pWidth , pHeight , width - pWidth , 300 , false );
112- Platform mov_2 = new Platform (this , pWidth , pHeight , pWidth , 300 , false );
130+ Platform mov_1 = new Platform (this , pWidth , pHeight , width - 3 *pWidth , 150 , false );
131+ Platform mov_2 = new Platform (this , pWidth , pHeight , width - 5 *pWidth , 250 , false );
132+
113133
114134 movPlatforms .add (mov_1 );
115135 movPlatforms .add (mov_2 );
116136
137+ for (Platform p : movPlatforms ) {
138+ p .getPy ().setTopSpeed (2 );
139+ p .getPy ().setVelocity (new PVector (2 , 0 ));
140+ }
141+
142+ Platform mov_3 = new Platform (this , pWidth , pHeight , 0 , 100 , false );
143+ mov_3 .getPy ().setTopSpeed (2 );
144+ mov_3 .getPy ().setVelocity (new PVector (0 , 2 ));
145+ movPlatforms .add (mov_3 );
146+
147+
117148 for (Platform p : staticPlatforms ) {
118149 objects .add (p );
119150 objectMap .put (p .getUUID (), p );
@@ -143,7 +174,10 @@ public void setup() {
143174
144175 public void draw () {
145176 background (0 );
146-
177+ if (this .isServer ) {
178+ text ("Deaths: " + deathPoints , 110 , 40 );
179+ }
180+
147181 this .renderAll (objects );
148182
149183
@@ -171,10 +205,7 @@ private void renderAll(CopyOnWriteArrayList<GameObj> objects) {
171205 }
172206
173207 public void render (GameObj obj ) {
174- if (obj .getType ().equals ("boundary" )) {
175- rect ((float ) obj .getPy ().getBounds2D ().getX (), (float ) obj .getPy ().getBounds2D ().getY (),
176- (float ) obj .getPy ().getBounds2D ().getWidth (), (float ) obj .getPy ().getBounds2D ().getHeight ());
177- } else {
208+ if (obj .getRend () != null ) {
178209 shape (obj .getRend ().getShape (), obj .getPy ().getLocation ().x , obj .getPy ().getLocation ().y );
179210 }
180211 }
0 commit comments