-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathSpecialSounds.java
More file actions
154 lines (142 loc) · 6.02 KB
/
SpecialSounds.java
File metadata and controls
154 lines (142 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Copyright 2020 The Terasology Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.destinationsol.assets.sound;
import com.badlogic.gdx.math.Vector2;
import org.destinationsol.Const;
import org.destinationsol.game.DmgType;
import org.destinationsol.game.SolGame;
import org.destinationsol.game.SolObject;
import org.destinationsol.material.MaterialType;
import java.util.Arrays;
public class SpecialSounds {
public final PlayableSound metalColl;
public final PlayableSound metalEnergyHit;
public final PlayableSound rockColl;
public final PlayableSound rockEnergyHit;
public final PlayableSound asteroidCrack;
public final PlayableSound shipExplosion;
public final PlayableSound forceBeaconWork;
public final PlayableSound doorMove;
public final PlayableSound abilityRecharged;
public final PlayableSound abilityRefused;
public final PlayableSound controlDisabled;
public final PlayableSound controlEnabled;
public final PlayableSound lootThrow;
public final PlayableSound transcendentCreated;
public final PlayableSound transcendentFinished;
public final PlayableSound metalBulletHit;
public final PlayableSound rockBulletHit;
public final PlayableSound burning;
public final PlayableSound transcendentMove;
public SpecialSounds(OggSoundManager soundManager) {
// OggSound
metalColl = soundManager.getSound("core:metalCollision");
metalEnergyHit = soundManager.getSound("core:empty");
rockColl = soundManager.getSound("core:rockCollision");
rockEnergyHit = soundManager.getSound("core:empty");
asteroidCrack = soundManager.getSound("core:asteroidCrack");
shipExplosion = soundManager.getSound("core:shipExplosion");
forceBeaconWork = soundManager.getSound("core:forceBeaconWork");
doorMove = soundManager.getSound("core:controlEnabled");
abilityRecharged = soundManager.getSound("core:abilityRecharged");
abilityRefused = soundManager.getSound("core:abilityRefused");
controlDisabled = soundManager.getSound("core:controlDisabled");
controlEnabled = soundManager.getSound("core:controlEnabled");
lootThrow = soundManager.getSound("core:rocketLauncherShoot");
transcendentCreated = soundManager.getSound("core:teleport");
transcendentFinished = soundManager.getSound("core:teleport");
// OggSoundSet
metalBulletHit = new OggSoundSet(soundManager, Arrays.asList("core:metalBulletHit0", "core:metalBulletHit1", "core:metalBulletHit2"), 1.1f);
rockBulletHit = new OggSoundSet(soundManager, Arrays.asList("core:rockBulletHit0", "core:rockBulletHit1"));
burning = new OggSoundSet(soundManager, Arrays.asList("core:burning2", "core:burning3", "core:burning4"));
transcendentMove = new OggSoundSet(soundManager, Arrays.asList("core:transcendentMove", "core:transcendentMove2", "core:transcendentMove3", "core:transcendentMove4"));
}
public PlayableSound hitSound(boolean forMetal, DmgType dmgType) {
if (dmgType == DmgType.ENERGY) {
return forMetal ? metalEnergyHit : rockEnergyHit;
}
if (dmgType == DmgType.BULLET) {
return forMetal ? metalBulletHit : rockBulletHit;
}
return null;
}
public void playHit(SolGame game, SolObject o, Vector2 position, DmgType dmgType) {
if (o == null) {
return;
}
Boolean metal = o.isMetal();
if (metal == null) {
return;
}
PlayableSound sound = hitSound(metal, dmgType);
if (sound == null) {
return;
}
game.getSoundManager().play(game, sound, position, o);
}
public void playColl(SolGame game, float absImpulse, SolObject o, Vector2 position) {
if (o == null || absImpulse < .1f) {
return;
}
Boolean metal = o.isMetal();
if (metal == null) {
return;
}
game.getSoundManager().play(game, metal ? metalColl : rockColl, position, o, absImpulse * Const.IMPULSE_TO_COLL_VOL);
}
/**
* Gets the damage sound associated with the given {@link MaterialType} and {@link DmgType}. If no sound is defined,
* null is returned.
*
* @param materialType the material type of the damaged entity
* @param damageType the type of damage done
* @return the sound of the damage
*/
public PlayableSound getHitSound(MaterialType materialType, DmgType damageType) {
if (damageType == DmgType.ENERGY) {
if (materialType == MaterialType.METAL) {
return metalEnergyHit;
}
if (materialType == MaterialType.ROCK) {
return rockEnergyHit;
}
}
if (damageType == DmgType.BULLET) {
if (materialType == MaterialType.METAL) {
return metalBulletHit;
}
if (materialType == MaterialType.ROCK) {
return rockBulletHit;
}
}
return null;
}
/**
* Gets the collision sound associated with the given {@link MaterialType}. If no sound is defined, null is returned.
*
* @param materialType the material type of the entity
* @return the sound of the collision
*/
public PlayableSound getCollisionSound(MaterialType materialType) {
if (materialType == MaterialType.METAL) {
return metalColl;
}
if (materialType == MaterialType.ROCK) {
return rockColl;
}
return null;
}
}