|
2 | 2 |
|
3 | 3 | import com.badlogic.gdx.ApplicationAdapter;
|
4 | 4 | import com.badlogic.gdx.Gdx;
|
| 5 | +import com.badlogic.gdx.Input; |
5 | 6 | import com.badlogic.gdx.InputProcessor;
|
6 | 7 | import com.badlogic.gdx.graphics.Color;
|
7 | 8 | import com.badlogic.gdx.graphics.Texture;
|
|
34 | 35 |
|
35 | 36 |
|
36 | 37 | public class MyGdxGame extends ApplicationAdapter implements InputProcessor {
|
37 |
| - SpriteBatch batch; |
38 |
| - |
39 |
| - Sprite backgroundSprite; |
40 |
| - float backgroundMovementConst = 20f; |
41 |
| - Sprite floorSprite; |
42 |
| - float floorMovementConst = 60f; |
43 |
| - |
44 |
| - Sprite greenPipeHigh; |
45 |
| - Sprite greenPipeLow; |
46 |
| - |
47 |
| - Bird bird; |
48 |
| - |
49 | 38 | enum Difficulty {
|
50 | 39 | EASY, MEDIUM, HARD
|
51 | 40 | };
|
52 | 41 | private record Settings(
|
53 | 42 | String name,
|
54 | 43 | float pipeGap,
|
55 | 44 | float pipeSpawnFreq,
|
56 |
| - float pipeMoveFactor |
| 45 | + float pipeMoveFactor, |
| 46 | + float groundMoveFactor, |
| 47 | + float bgMoveFactor |
57 | 48 | ) {}
|
58 | 49 | Map<Difficulty, Settings> difficultySettingsMap = Map.of(
|
59 |
| - Difficulty.EASY, new Settings("Easy",85f, 4f, 120f), |
60 |
| - Difficulty.MEDIUM, new Settings("Medium",85f, 4f, 120f), |
61 |
| - Difficulty.HARD, new Settings("Hard",85f, 1f, 240f) |
| 50 | + Difficulty.EASY, new Settings("Easy",85f, 4f, 120f, 60f, 20f), |
| 51 | + Difficulty.MEDIUM, new Settings("Medium",75f, 3f, 180f, 80f, 40f), |
| 52 | + Difficulty.HARD, new Settings("Hard",65f, 1.5f, 240f, 120f, 80f) |
62 | 53 | );
|
63 | 54 |
|
64 | 55 | Difficulty difficulty = Difficulty.EASY;
|
65 | 56 |
|
| 57 | + SpriteBatch batch; |
| 58 | + |
| 59 | + Sprite backgroundSprite; |
| 60 | + Sprite floorSprite; |
| 61 | + float backgroundMovementConst = difficultySettingsMap.get(difficulty).bgMoveFactor; |
| 62 | + float floorMovementConst = difficultySettingsMap.get(difficulty).groundMoveFactor; |
| 63 | + |
| 64 | + Sprite greenPipeHigh; |
| 65 | + Sprite greenPipeLow; |
| 66 | + |
| 67 | + Bird bird; |
| 68 | + |
66 | 69 | ArrayList<Rectangle> deathBoxes = new ArrayList<>();
|
67 | 70 | ArrayList<Float> floorOffsets = new ArrayList<>();
|
68 | 71 | ArrayList<Float> bgOffsets = new ArrayList<>();
|
@@ -123,6 +126,14 @@ public void create () {
|
123 | 126 | respawn();
|
124 | 127 | }
|
125 | 128 |
|
| 129 | + private void applySettings() { |
| 130 | + pipeSpawnTimerMax = difficultySettingsMap.get(difficulty).pipeSpawnFreq; |
| 131 | + pipeGapSize = difficultySettingsMap.get(difficulty).pipeGap; |
| 132 | + pipeMovementConst = difficultySettingsMap.get(difficulty).pipeMoveFactor; |
| 133 | + backgroundMovementConst = difficultySettingsMap.get(difficulty).bgMoveFactor; |
| 134 | + floorMovementConst = difficultySettingsMap.get(difficulty).groundMoveFactor; |
| 135 | + } |
| 136 | + |
126 | 137 | private void respawn() {
|
127 | 138 | player.setPosition(100f, Gdx.graphics.getHeight() / 2);
|
128 | 139 | playerDead = false;
|
@@ -188,13 +199,18 @@ public void render () {
|
188 | 199 | batch.begin();
|
189 | 200 | font.getData().setScale(1.2f);
|
190 | 201 |
|
| 202 | + // Show settings |
| 203 | + font.draw(batch, "Mode: " + difficultySettingsMap.get(difficulty).name, Gdx.graphics.getWidth() - 100, Gdx.graphics.getHeight() - 20); |
| 204 | + |
191 | 205 | // Show activated cheats
|
192 | 206 | List<String> cheats = new ArrayList<>();
|
193 | 207 | if(cheat_freemove) cheats.add(" FreeMove");
|
194 | 208 | if(cheat_noclip) cheats.add(" NoClip");
|
195 | 209 | if(cheat_drawboxes) cheats.add(" BBoxes");
|
196 |
| - if(!cheats.isEmpty()) |
| 210 | + |
| 211 | + if(!cheats.isEmpty()) { |
197 | 212 | font.draw(batch, "Cheats:\n" + String.join("\n", cheats), Gdx.graphics.getWidth() - 100, Gdx.graphics.getHeight() - 50);
|
| 213 | + } |
198 | 214 | batch.end();
|
199 | 215 |
|
200 | 216 | }
|
@@ -385,6 +401,20 @@ public boolean keyUp(int keycode) {
|
385 | 401 | case com.badlogic.gdx.Input.Keys.L:
|
386 | 402 | cheat_drawboxes = !cheat_drawboxes;
|
387 | 403 | break;
|
| 404 | + case Input.Keys.UP: |
| 405 | + switch (difficulty) { |
| 406 | + case EASY -> difficulty = Difficulty.MEDIUM; |
| 407 | + case MEDIUM -> difficulty = Difficulty.HARD; |
| 408 | + } |
| 409 | + applySettings(); |
| 410 | + break; |
| 411 | + case Input.Keys.DOWN: |
| 412 | + switch (difficulty) { |
| 413 | + case HARD -> difficulty = Difficulty.MEDIUM; |
| 414 | + case MEDIUM -> difficulty = Difficulty.EASY; |
| 415 | + } |
| 416 | + applySettings(); |
| 417 | + break; |
388 | 418 |
|
389 | 419 | }
|
390 | 420 | return true;
|
|
0 commit comments