12
12
import com .badlogic .gdx .graphics .g2d .Sprite ;
13
13
import com .badlogic .gdx .graphics .g2d .SpriteBatch ;
14
14
import com .badlogic .gdx .graphics .glutils .ShapeRenderer ;
15
- import com .badlogic .gdx .math .MathUtils ;
16
15
import com .badlogic .gdx .math .Rectangle ;
17
16
import com .badlogic .gdx .utils .ScreenUtils ;
18
17
import com .badlogic .gdx .utils .viewport .FitViewport ;
36
35
* ✔️ Respawnable
37
36
* ✔️ Death Sequence
38
37
* ✔️ GUI Bar
39
- * Counter
38
+ * ✔️ Counter
40
39
* Make things smoother (rotate bird)
41
40
* Make Exe
42
41
*/
@@ -104,8 +103,11 @@ Difficulty.HARD, new Settings("Hard",65f, 1.5f, 240f, 120f, 80f)
104
103
float playerJumpStrength = 250 ;
105
104
float playerDeathTimer = 0 ;
106
105
float playerDeathTimerMax = 2.0f ;
106
+ float playerLastScoreTimer = 0 ; // when the player hits a score gate, they cant score again until
107
+ float playerLastScoreTimerMax = 1.0f ; // the timer reaches this threshhold
107
108
boolean playerDead = false ;
108
109
boolean playerCanRespawn = false ;
110
+ boolean playerCanScore = false ;
109
111
int playerScore = 0 ;
110
112
int playerHighScore = 0 ;
111
113
int playerLastScore = 0 ;
@@ -170,6 +172,8 @@ private void applySettings() {
170
172
private void startStartMenu () {
171
173
gameState = GameState .MENU ;
172
174
activeMenu = Menu .START ;
175
+ playerCanScore = true ;
176
+ playerLastScoreTimer = 0 ;
173
177
}
174
178
175
179
private void startGame () {
@@ -186,12 +190,19 @@ private void respawn() {
186
190
player .setRotation (0 );
187
191
playerVelocity = 0 ;
188
192
pipeSpawnTimer = 0 ;
189
- playerScore = 0 ;
190
193
playerDeathTimer = 0 ;
194
+ playerLastScoreTimer = 0 ;
195
+ playerCanScore = true ;
191
196
playerDead = false ;
192
197
playerCanRespawn = false ;
193
198
pipeOffsets .clear ();
194
199
gameState = GameState .GAME ;
200
+
201
+ playerLastScore = playerScore ;
202
+ if (playerLastScore > playerHighScore ) {
203
+ playerHighScore = playerLastScore ;
204
+ }
205
+ playerScore = 0 ;
195
206
}
196
207
197
208
@ Override
@@ -255,11 +266,15 @@ public void render () {
255
266
for (Rectangle bbox : deathBoxes ) {
256
267
shapeRenderer .rect (bbox .x , bbox .y , bbox .width , bbox .height );
257
268
}
269
+ shapeRenderer .setColor (Color .BLUE );
270
+ for (Rectangle bbox : scoreBoxes ) {
271
+ shapeRenderer .rect (bbox .x , bbox .y , bbox .width , bbox .height );
272
+ }
258
273
shapeRenderer .end ();
259
274
}
260
275
261
276
262
- // UI goes on top of everything else so it must be rendered last
277
+ // UI goes on top of everything else, so it must be rendered last
263
278
batch .begin ();
264
279
font .getData ().setScale (1.2f );
265
280
@@ -353,6 +368,7 @@ public void render () {
353
368
354
369
public void update (float delta ) {
355
370
deathBoxes .clear (); // empty the death boxes
371
+ scoreBoxes .clear ();
356
372
357
373
if (gameState == GameState .DEATH ) {
358
374
@@ -395,6 +411,14 @@ else if(gameState == GameState.GAME) {
395
411
pipeSpawnTimer = 0 ;
396
412
}
397
413
414
+ // score update
415
+ if (!playerCanScore ) {
416
+ playerLastScoreTimer += delta ;
417
+ if (playerLastScoreTimer > playerLastScoreTimerMax ) {
418
+ playerCanScore = true ;
419
+ }
420
+ }
421
+
398
422
// update floor position
399
423
floorOffsets .replaceAll (aFloat -> aFloat - floorMovementConst * delta );
400
424
if (floorOffsets .get (0 ) <= -floorSprite .getWidth ()) {
@@ -443,6 +467,9 @@ else if(gameState == GameState.GAME) {
443
467
// create the bounding boxes
444
468
deathBoxes .add ((new Rectangle ()).set (val [0 ], offset , greenPipeHigh .getWidth (), greenPipeHigh .getHeight ()));
445
469
deathBoxes .add ((new Rectangle ()).set (val [0 ], offset - greenPipeLow .getHeight () - pipeGapSize , greenPipeLow .getWidth (), greenPipeLow .getHeight ()));
470
+ if (playerCanScore ) {
471
+ scoreBoxes .add ((new Rectangle ()).set (val [0 ] + greenPipeHigh .getWidth (), offset - pipeGapSize , 2.0f , pipeGapSize ));
472
+ }
446
473
}
447
474
448
475
// deal with input and calculate new position
@@ -485,6 +512,13 @@ else if(gameState == GameState.GAME) {
485
512
triggerDeath ();
486
513
}
487
514
}
515
+ for (Rectangle bbox : scoreBoxes ) {
516
+ if (bbox .overlaps (player .getBoundingRectangle ())) {
517
+ System .out .println ("Score" );
518
+ triggerScore ();
519
+ }
520
+ }
521
+
488
522
}
489
523
} else if (gameState == GameState .MENU ) {
490
524
@@ -519,6 +553,12 @@ private void triggerDeath() {
519
553
gameState = GameState .DEATH ;
520
554
}
521
555
556
+ private void triggerScore () {
557
+ playerScore ++;
558
+ playerLastScoreTimer = 0 ;
559
+ playerCanScore = false ;
560
+ }
561
+
522
562
private void spawnPipe () {
523
563
float screenWidth = (float ) Gdx .graphics .getWidth ();
524
564
@@ -545,42 +585,16 @@ public void dispose () {
545
585
546
586
@ Override
547
587
public boolean keyDown (int keycode ) {
548
- switch (keycode ) {
549
- // case com.badlogic.gdx.Input.Keys.W:
550
- // iUp = true;
551
- // break;
552
- // case com.badlogic.gdx.Input.Keys.S:
553
- // iDown = true;
554
- // break;
555
- // case com.badlogic.gdx.Input.Keys.A:
556
- // iLeft = true;
557
- // break;
558
- // case com.badlogic.gdx.Input.Keys.D:
559
- // iRight = true;
560
- // break;
561
- case com .badlogic .gdx .Input .Keys .SPACE :
562
- iSpace = true ;
563
- break ;
564
- }
588
+ if (keycode == Input .Keys .SPACE ) {
589
+ iSpace = true ;
590
+ }
565
591
566
592
return true ;
567
593
}
568
594
569
595
@ Override
570
596
public boolean keyUp (int keycode ) {
571
597
switch (keycode ) {
572
- // case Input.Keys.W:
573
- // iUp = false;
574
- // break;
575
- // case Input.Keys.S:
576
- // iDown = false;
577
- // break;
578
- // case Input.Keys.A:
579
- // iLeft = false;
580
- // break;
581
- // case Input.Keys.D:
582
- // iRight = false;
583
- // break;
584
598
case Input .Keys .J :
585
599
cheat_freemove = !cheat_freemove ;
586
600
break ;
0 commit comments