-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement SoundSource Entities. Allow individual falloff ranges for S…
…FXPlaybacks.
- Loading branch information
1 parent
ab5529a
commit 2840217
Showing
11 changed files
with
299 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package de.gurkenlabs.litiengine.entities; | ||
|
||
import de.gurkenlabs.litiengine.Game; | ||
import de.gurkenlabs.litiengine.environment.tilemap.MapObjectType; | ||
import de.gurkenlabs.litiengine.environment.tilemap.TmxType; | ||
import de.gurkenlabs.litiengine.graphics.RenderType; | ||
import de.gurkenlabs.litiengine.physics.Collision; | ||
import de.gurkenlabs.litiengine.resources.Resources; | ||
import de.gurkenlabs.litiengine.sound.SFXPlayback; | ||
import de.gurkenlabs.litiengine.sound.Sound; | ||
|
||
@EntityInfo(renderType = RenderType.OVERLAY) | ||
@CollisionInfo(collision = false, collisionType = Collision.NONE) | ||
@TmxType(MapObjectType.SOUNDSOURCE) | ||
public class SoundSource extends Entity { | ||
|
||
private int volume; | ||
private int range; | ||
|
||
private boolean loop; | ||
private Sound sound; | ||
private SFXPlayback playback; | ||
|
||
public SoundSource() { | ||
} | ||
|
||
public SoundSource(Sound sound) { | ||
this.setSound(sound); | ||
} | ||
|
||
public SoundSource(String name) { | ||
this.setSound(name); | ||
} | ||
|
||
public SoundSource(double x, double y) { | ||
this.setX(x); | ||
this.setY(y); | ||
} | ||
|
||
public SoundSource(double x, double y, double width, double height) { | ||
this(x, y); | ||
this.setWidth(width); | ||
this.setHeight(height); | ||
} | ||
|
||
public int getVolume() { | ||
return volume; | ||
} | ||
|
||
public void setVolume(int volume) { | ||
this.volume = volume; | ||
} | ||
|
||
public boolean isLoop() { | ||
return loop; | ||
} | ||
|
||
public void setLoop(boolean loop) { | ||
this.loop = loop; | ||
} | ||
|
||
public Sound getSound() { | ||
return sound; | ||
} | ||
|
||
public SFXPlayback getPlayback() { | ||
return this.playback; | ||
} | ||
|
||
public String getSoundName() { | ||
return this.sound.getName(); | ||
} | ||
|
||
public int getRange() { | ||
return range; | ||
} | ||
|
||
public void setRange(int range) { | ||
this.range = range; | ||
} | ||
|
||
public void setSound(String name) { | ||
this.sound = Resources.sounds().get(name); | ||
} | ||
|
||
public void setSound(Sound sound) { | ||
this.sound = sound; | ||
} | ||
|
||
public void play() { | ||
this.playback = Game.audio().playSound(this.getSound(), this, this.isLoop(), this.getRange()); | ||
} | ||
|
||
public void pause() { | ||
this.getPlayback().pausePlayback(); | ||
} | ||
|
||
public void resume() { | ||
this.getPlayback().resumePlayback(); | ||
} | ||
|
||
public void stop() { | ||
this.getPlayback().cancel(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/de/gurkenlabs/litiengine/environment/SoundSourceMapObjectLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package de.gurkenlabs.litiengine.environment; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
import de.gurkenlabs.litiengine.entities.IEntity; | ||
import de.gurkenlabs.litiengine.entities.SoundSource; | ||
import de.gurkenlabs.litiengine.environment.tilemap.IMapObject; | ||
import de.gurkenlabs.litiengine.environment.tilemap.MapObjectProperty; | ||
import de.gurkenlabs.litiengine.environment.tilemap.MapObjectType; | ||
|
||
public class SoundSourceMapObjectLoader extends MapObjectLoader { | ||
|
||
protected SoundSourceMapObjectLoader() { | ||
super(MapObjectType.SOUNDSOURCE); | ||
} | ||
|
||
@Override | ||
public Collection<IEntity> load(Environment environment, IMapObject mapObject) { | ||
Collection<IEntity> entities = new ArrayList<>(); | ||
if (!this.isMatchingType(mapObject)) { | ||
return entities; | ||
} | ||
|
||
final SoundSource sound = this.createSoundSource(mapObject); | ||
loadDefaultProperties(sound, mapObject); | ||
|
||
entities.add(sound); | ||
|
||
return entities; | ||
} | ||
|
||
protected SoundSource createSoundSource(IMapObject mapObject) { | ||
SoundSource sound = new SoundSource(); | ||
sound.setSound(mapObject.getStringValue(MapObjectProperty.SOUND_NAME)); | ||
sound.setVolume(mapObject.getIntValue(MapObjectProperty.SOUND_VOLUME)); | ||
sound.setLoop(mapObject.getBoolValue(MapObjectProperty.SOUND_LOOP)); | ||
sound.setRange(mapObject.getIntValue(MapObjectProperty.SOUND_RANGE)); | ||
|
||
return sound; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
2840217
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This resolves #217.