Skip to content

Commit 1fd63af

Browse files
three difficulty modes (needs more testing and tweaking)
1 parent b727afe commit 1fd63af

File tree

1 file changed

+47
-17
lines changed

1 file changed

+47
-17
lines changed

core/src/com/ninjaghost/flappy/MyGdxGame.java

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.badlogic.gdx.ApplicationAdapter;
44
import com.badlogic.gdx.Gdx;
5+
import com.badlogic.gdx.Input;
56
import com.badlogic.gdx.InputProcessor;
67
import com.badlogic.gdx.graphics.Color;
78
import com.badlogic.gdx.graphics.Texture;
@@ -34,35 +35,37 @@
3435

3536

3637
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-
4938
enum Difficulty {
5039
EASY, MEDIUM, HARD
5140
};
5241
private record Settings(
5342
String name,
5443
float pipeGap,
5544
float pipeSpawnFreq,
56-
float pipeMoveFactor
45+
float pipeMoveFactor,
46+
float groundMoveFactor,
47+
float bgMoveFactor
5748
) {}
5849
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)
6253
);
6354

6455
Difficulty difficulty = Difficulty.EASY;
6556

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+
6669
ArrayList<Rectangle> deathBoxes = new ArrayList<>();
6770
ArrayList<Float> floorOffsets = new ArrayList<>();
6871
ArrayList<Float> bgOffsets = new ArrayList<>();
@@ -123,6 +126,14 @@ public void create () {
123126
respawn();
124127
}
125128

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+
126137
private void respawn() {
127138
player.setPosition(100f, Gdx.graphics.getHeight() / 2);
128139
playerDead = false;
@@ -188,13 +199,18 @@ public void render () {
188199
batch.begin();
189200
font.getData().setScale(1.2f);
190201

202+
// Show settings
203+
font.draw(batch, "Mode: " + difficultySettingsMap.get(difficulty).name, Gdx.graphics.getWidth() - 100, Gdx.graphics.getHeight() - 20);
204+
191205
// Show activated cheats
192206
List<String> cheats = new ArrayList<>();
193207
if(cheat_freemove) cheats.add(" FreeMove");
194208
if(cheat_noclip) cheats.add(" NoClip");
195209
if(cheat_drawboxes) cheats.add(" BBoxes");
196-
if(!cheats.isEmpty())
210+
211+
if(!cheats.isEmpty()) {
197212
font.draw(batch, "Cheats:\n" + String.join("\n", cheats), Gdx.graphics.getWidth() - 100, Gdx.graphics.getHeight() - 50);
213+
}
198214
batch.end();
199215

200216
}
@@ -385,6 +401,20 @@ public boolean keyUp(int keycode) {
385401
case com.badlogic.gdx.Input.Keys.L:
386402
cheat_drawboxes = !cheat_drawboxes;
387403
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;
388418

389419
}
390420
return true;

0 commit comments

Comments
 (0)