Skip to content

Commit 0b80215

Browse files
committed
ambient sounds
1 parent 7210c2b commit 0b80215

16 files changed

Lines changed: 195 additions & 62 deletions

File tree

Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://uppbeat.io/sfx/heavy-rain-shower/10257/26429
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://uppbeat.io/sfx/wind-blowing-trees-in-woods/7784/23795

Common/src/main/java/ru/arifolth/anjrpg/interfaces/CombatTracker.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,31 @@ public CombatTracker() {
3838
public void update(float tpf) {
3939
inCombat = !enemies.isEmpty();
4040

41-
if(inCombat && !GameState.BATTLE.equals(gameLogicCore.getGameStateManager().getCurrentGameState())) {
42-
gameLogicCore.getGameStateManager().setGameState(GameState.BATTLE);
43-
}
41+
isNotInBattle();
42+
43+
isInBattle();
44+
}
4445

46+
private void isInBattle() {
4547
if(!inCombat && GameState.BATTLE.equals(gameLogicCore.getGameStateManager().getCurrentGameState())) {
46-
gameLogicCore.getGameStateManager().setGameState(GameState.CALM);
48+
leaveBattle();
49+
}
50+
}
51+
52+
private void isNotInBattle() {
53+
if(inCombat && !GameState.BATTLE.equals(gameLogicCore.getGameStateManager().getCurrentGameState())) {
54+
joinBattle();
4755
}
4856
}
4957

58+
private void leaveBattle() {
59+
gameLogicCore.getGameStateManager().setGameState(GameState.CALM);
60+
}
61+
62+
private void joinBattle() {
63+
gameLogicCore.getGameStateManager().setGameState(GameState.BATTLE);
64+
}
65+
5066
@Override
5167
public void decCounter(CharacterInterface enemy) {
5268
enemies.remove(enemy);

Common/src/main/java/ru/arifolth/anjrpg/interfaces/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class Constants {
3636
public static final int MODEL_ADJUSTMENT = 3;
3737

3838
public static final float SOUND_VOLUME = 0.5f;
39-
public static final float MUSIC_VOLUME_MULTIPLIER = 0.25f;
39+
public static final float MUSIC_VOLUME_MULTIPLIER = 0.225f;
4040

4141
public static final float SOUND_PITCH = 0.5f;
4242
public static final SSAOFilter SSAO_FILTER_BASIC = new SSAOFilter(1f, 1.5f, 5.8f, 0.9f);

Common/src/main/java/ru/arifolth/anjrpg/interfaces/GameState.java

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,88 +24,175 @@ public enum GameState {
2424
public MusicTypeEnum getMusicType() {
2525
return MusicTypeEnum.MENU;
2626
}
27+
@Override
28+
public SoundTypeEnum getAmbientSound() {
29+
return null;
30+
}
2731
},
2832
BATTLE {
2933
@Override
3034
public MusicTypeEnum getMusicType() {
3135
return MusicTypeEnum.BATTLE;
3236
}
37+
@Override
38+
public SoundTypeEnum getAmbientSound() {
39+
return null;
40+
}
3341
},
3442
EXPLORATION {
3543
@Override
3644
public MusicTypeEnum getMusicType() {
3745
return MusicTypeEnum.EXPLORATION;
3846
}
47+
@Override
48+
public SoundTypeEnum getAmbientSound() {
49+
return null;
50+
}
3951
},
4052
DAY {
4153
@Override
4254
public MusicTypeEnum getMusicType() {
4355
return MusicTypeEnum.DAY;
4456
}
57+
@Override
58+
public SoundTypeEnum getAmbientSound() {
59+
return SoundTypeEnum.WIND;
60+
}
4561
},
4662
CALM {
4763
@Override
4864
public MusicTypeEnum getMusicType() {
4965
return MusicTypeEnum.CALM;
5066
}
67+
@Override
68+
public SoundTypeEnum getAmbientSound() {
69+
return null;
70+
}
5171
},
5272
MOUNTAINS {
5373
@Override
5474
public MusicTypeEnum getMusicType() {
5575
return MusicTypeEnum.MOUNTAINS;
5676
}
77+
@Override
78+
public SoundTypeEnum getAmbientSound() {
79+
return null;
80+
}
5781
},
5882
VILLAGE {
5983
@Override
6084
public MusicTypeEnum getMusicType() {
6185
return MusicTypeEnum.VILLAGE;
6286
}
87+
@Override
88+
public SoundTypeEnum getAmbientSound() {
89+
return null;
90+
}
6391
},
6492
DEATH {
6593
@Override
6694
public MusicTypeEnum getMusicType() {
6795
return MusicTypeEnum.DEATH;
6896
}
97+
@Override
98+
public SoundTypeEnum getAmbientSound() {
99+
return null;
100+
}
69101
},
70102
NIGHT {
71103
@Override
72104
public MusicTypeEnum getMusicType() {
73105
return MusicTypeEnum.NIGHT;
74106
}
75-
},
76-
FEAR {
77107
@Override
78-
public MusicTypeEnum getMusicType() {
79-
return null;
108+
public SoundTypeEnum getAmbientSound() {
109+
return SoundTypeEnum.NIGHT;
80110
}
81111
},
82-
SNOW {
112+
FEAR {
83113
@Override
84114
public MusicTypeEnum getMusicType() {
85-
return MusicTypeEnum.SNOW;
115+
return null;
86116
}
87-
},
88-
RAIN {
89117
@Override
90-
public MusicTypeEnum getMusicType() {
91-
return MusicTypeEnum.SNOW;
118+
public SoundTypeEnum getAmbientSound() {
119+
return null;
92120
}
93121
},
94122
DAWN {
95123
@Override
96124
public MusicTypeEnum getMusicType() {
97125
return MusicTypeEnum.DAWN;
98126
}
127+
@Override
128+
public SoundTypeEnum getAmbientSound() {
129+
return SoundTypeEnum.WIND;
130+
}
99131
},
100132
DUSK {
101133
@Override
102134
public MusicTypeEnum getMusicType() {
103135
return MusicTypeEnum.DUSK;
104136
}
137+
@Override
138+
public SoundTypeEnum getAmbientSound() {
139+
return SoundTypeEnum.WIND;
140+
}
105141
};
106142
public abstract MusicTypeEnum getMusicType();
107143

108-
public boolean isNextAcceptable() {
109-
return (this.equals(GameState.CALM) || !this.equals(GameState.DEATH));
144+
public boolean isNextAcceptable(GameState gameState) {
145+
boolean result = false;
146+
147+
if(!this.equals(gameState)) {
148+
switch (this) {
149+
case MENU -> {
150+
result = switch (gameState) {
151+
case CALM, NIGHT, DAY, DAWN, DUSK -> true;
152+
default -> false;
153+
};
154+
}
155+
case NIGHT -> {
156+
result = switch (gameState) {
157+
case DAWN, BATTLE -> true;
158+
default -> false;
159+
};
160+
}
161+
case DAY -> {
162+
result = switch (gameState) {
163+
case DUSK, BATTLE -> true;
164+
default -> false;
165+
};
166+
}
167+
case DAWN -> {
168+
result = switch (gameState) {
169+
case DAY, BATTLE -> true;
170+
default -> false;
171+
};
172+
}
173+
case DUSK -> {
174+
result = switch (gameState) {
175+
case NIGHT, BATTLE -> true;
176+
default -> false;
177+
};
178+
}
179+
case CALM -> {
180+
result = switch (gameState) {
181+
case NIGHT, DAY, DAWN, DUSK, BATTLE -> true;
182+
default -> false;
183+
};
184+
}
185+
case BATTLE -> {
186+
result = gameState.equals(CALM) || gameState.equals(DEATH);
187+
}
188+
case DEATH -> {
189+
result = gameState.equals(CALM);
190+
}
191+
}
192+
}
193+
194+
return result;
110195
}
196+
197+
public abstract SoundTypeEnum getAmbientSound();
111198
}

Common/src/main/java/ru/arifolth/anjrpg/interfaces/GameStateManager.java

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class GameStateManager implements GameStateManagerInterface {
2727
final private static Logger LOGGER = Logger.getLogger(GameStateManager.class.getName());
2828

2929
private GameLogicCoreInterface gameLogicCore;
30-
private GameState currentGameState = GameState.MENU;;
30+
private GameState currentGameState = GameState.MENU;
3131
private GameState nextGameState;
3232

3333
public GameStateManager(GameLogicCoreInterface gameLogicCore) {
@@ -37,47 +37,16 @@ public GameStateManager(GameLogicCoreInterface gameLogicCore) {
3737
@Override
3838
public void update(float tpf) {
3939
if(nextGameState != null) {
40-
LOGGER.log(Level.INFO, "next GameState:" + nextGameState);
41-
42-
switch (nextGameState) {
43-
case CALM: {
44-
checkTime();
45-
changeState(Constants.CHANGE_GAME_STATE_TPF);
46-
break;
47-
}
48-
case NIGHT:
49-
case DAWN:
50-
case DAY:
51-
case DUSK:
52-
case DEATH:
53-
{
54-
changeState(Constants.CHANGE_GAME_STATE_TPF);
55-
break;
56-
}
57-
case BATTLE: {
58-
changeState(Constants.CHANGE_GAME_STATE_TPF);
59-
break;
60-
}
61-
default: {
62-
if(AudioSource.Status.Stopped.equals(gameLogicCore.getSoundManager().getCurrentMusicNode().getStatus())) {
63-
checkTime();
64-
changeState(Constants.CHANGE_GAME_STATE_TPF);
65-
}
66-
}
67-
}
40+
changeState(Constants.CHANGE_GAME_STATE_TPF);
6841
} else {
69-
if(AudioSource.Status.Stopped.equals(gameLogicCore.getSoundManager().getCurrentMusicNode().getStatus())) {
70-
checkTime();
71-
changeState(Constants.CHANGE_GAME_STATE_TPF);
72-
}
42+
checkTime();
7343
}
7444
}
7545

7646
@Override
7747
public void setGameState(GameState gameState) {
78-
if(!gameState.equals(nextGameState) && !gameState.equals(currentGameState)) {
79-
if(gameState.isNextAcceptable())
80-
this.nextGameState = gameState;
48+
if(currentGameState.isNextAcceptable(gameState)) {
49+
this.nextGameState = gameState;
8150
}
8251
}
8352

@@ -91,9 +60,15 @@ public void changeState(float tpf) {
9160
if(nextGameState == null)
9261
return;
9362

94-
gameLogicCore.getSoundManager().fadeMusicOut(tpf, nextGameState.getMusicType());
63+
if(AudioSource.Status.Stopped.equals(gameLogicCore.getSoundManager().getCurrentMusicNode().getStatus()) ||
64+
nextGameState.equals(GameState.BATTLE) ||
65+
nextGameState.equals(GameState.CALM) ||
66+
nextGameState.equals(GameState.DEATH)) {
67+
gameLogicCore.getSoundManager().fadeMusicOut(tpf, nextGameState.getMusicType());
68+
}
69+
LOGGER.log(Level.INFO, "Change GameState: " + currentGameState + " to " + nextGameState);
9570
currentGameState = nextGameState;
96-
LOGGER.log(Level.INFO, "change GameState:" + currentGameState);
71+
gameLogicCore.getSoundManager().changeAmbientSound(tpf, nextGameState.getAmbientSound());
9772
nextGameState = null;
9873
}
9974
@Override

Common/src/main/java/ru/arifolth/anjrpg/interfaces/SoundManagerInterface.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public interface SoundManagerInterface {
3636
AudioNode getCurrentMusicNode();
3737

3838
void fadeMusicOut(float tpf, MusicTypeEnum nextMusicType);
39+
void changeAmbientSound(float tpf, SoundTypeEnum nextAmbientSound);
3940

4041
void initialize();
4142

Common/src/main/java/ru/arifolth/anjrpg/interfaces/SoundTypeEnum.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public enum SoundTypeEnum implements AudioType {
3131
private boolean positional = false;
3232
private boolean looping = true;
3333

34+
private static float volumeMultiplier = 0.75f;
35+
3436
@Override
3537
public void init() {
3638
createAudioNode(this,
@@ -40,7 +42,24 @@ public void init() {
4042
positional,
4143
pitch, volumeMultiplier);
4244
}
45+
},
46+
NIGHT {
47+
private AudioData.DataType stream = AudioData.DataType.Stream;
48+
private Float pitch = null;
49+
private boolean positional = false;
50+
private boolean looping = true;
4351

52+
private static float volumeMultiplier = 0.45f;
53+
54+
@Override
55+
public void init() {
56+
createAudioNode(this,
57+
"Sounds/ambient/wind/wind-blowing-trees-in-woods-ivo-vicic-1-02-49.ogg",
58+
stream,
59+
looping,
60+
positional,
61+
pitch, volumeMultiplier);
62+
}
4463
},
4564
RAIN {
4665
private AudioData.DataType stream = AudioData.DataType.Stream;

0 commit comments

Comments
 (0)