Skip to content

Commit

Permalink
Refactor GameSound
Browse files Browse the repository at this point in the history
  • Loading branch information
artemdevel committed Jan 13, 2018
1 parent 52cb770 commit 37fcacc
Show file tree
Hide file tree
Showing 102 changed files with 234 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Game.music.enable(Game.prefs.getMusic());
GameSound.INSTANCE.enable(Game.prefs.getSoundFx());
Game.sound.enable(Game.prefs.getSoundFx());

GameSound.INSTANCE.load(
Game.sound.load(
Assets.SND_CLICK,
Assets.SND_BADGE,
Assets.SND_GOLD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
import android.app.Application;

import com.github.artemdevel.pixeldungeon.game.common.audio.GameMusic;
import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;

public final class PixelDungeonApp extends Application {

private Preferences preferences;
private GameMusic gameMusic;
private GameSound gameSound;

@Override
public void onCreate() {
super.onCreate();
preferences = new Preferences(getApplicationContext());
gameMusic = new GameMusic(getApplicationContext());
gameSound = new GameSound(getApplicationContext());
}

public Preferences getPreferences() {
Expand All @@ -30,4 +33,11 @@ public GameMusic getGameMusic() {
return gameMusic;
}

public GameSound getGameSound() {
if (gameSound == null) {
gameSound = new GameSound(getApplicationContext());
}
return gameSound;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package com.github.artemdevel.pixeldungeon;

import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.game.common.audio.GameMusic;
import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.scenes.GameScene;
import com.github.artemdevel.pixeldungeon.scenes.TitleScene;

Expand Down Expand Up @@ -83,7 +81,7 @@ public boolean getSoundFx() {

public void setSoundFx(boolean value) {
put(KEY_SOUND_FX, value);
GameSound.INSTANCE.enable(value);
Game.sound.enable(value);
}

public boolean getBrightness() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.HashSet;

import com.github.artemdevel.pixeldungeon.game.common.Camera;
import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.Dungeon;
import com.github.artemdevel.pixeldungeon.ResultDescriptions;
Expand Down Expand Up @@ -148,7 +148,7 @@ public boolean attack(Char enemy) {
enemy.damage(effectiveDamage, this);

if (visibleFight) {
GameSound.INSTANCE.play(Assets.SND_HIT, 1, 1, Random.Float(0.8f, 1.25f));
Game.sound.play(Assets.SND_HIT, 1, 1, Random.Float(0.8f, 1.25f));
}

if (enemy == Dungeon.hero) {
Expand Down Expand Up @@ -186,7 +186,7 @@ public boolean attack(Char enemy) {
GLog.logInfo(TXT_SMB_MISSED, enemy.name, defense, name);
}

GameSound.INSTANCE.play(Assets.SND_MISS);
Game.sound.play(Assets.SND_MISS);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.github.artemdevel.pixeldungeon.actors.blobs;

import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.Dungeon;
import com.github.artemdevel.pixeldungeon.DungeonTilemap;
Expand Down Expand Up @@ -67,7 +67,7 @@ protected void evolve() {
if (ch != null) {
if (Dungeon.visible[pos] && ch.buff(Marked.class) == null) {
ch.sprite.emitter().burst(SacrificialParticle.FACTORY, 20);
GameSound.INSTANCE.play(Assets.SND_BURNING);
Game.sound.play(Assets.SND_BURNING);
}
Buff.prolong(ch, Marked.class, Marked.DURATION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.github.artemdevel.pixeldungeon.actors.blobs;

import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.Badges;
import com.github.artemdevel.pixeldungeon.Dungeon;
Expand Down Expand Up @@ -46,7 +46,7 @@ public class WaterOfAwareness extends WellWater {
@Override
protected boolean affectHero(Hero hero) {

GameSound.INSTANCE.play(Assets.SND_DRINK);
Game.sound.play(Assets.SND_DRINK);
emitter.parent.add(new Identification(DungeonTilemap.tileCenterToWorld(pos)));

hero.belongings.observe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.github.artemdevel.pixeldungeon.actors.blobs;

import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.Dungeon;
import com.github.artemdevel.pixeldungeon.Journal;
Expand All @@ -40,7 +40,7 @@ public class WaterOfHealth extends WellWater {
@Override
protected boolean affectHero(Hero hero) {

GameSound.INSTANCE.play(Assets.SND_DRINK);
Game.sound.play(Assets.SND_DRINK);

PotionOfHealing.heal(hero);
hero.belongings.uncurseEquipped();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.github.artemdevel.pixeldungeon.actors.buffs;

import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.Dungeon;
import com.github.artemdevel.pixeldungeon.actors.Char;
Expand Down Expand Up @@ -46,7 +46,7 @@ public void restoreFromBundle(Bundle bundle) {
@Override
public boolean attachTo(Char target) {
if (super.attachTo(target)) {
GameSound.INSTANCE.play(Assets.SND_MELD);
Game.sound.play(Assets.SND_MELD);
Dungeon.observe();
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import com.github.artemdevel.pixeldungeon.game.common.Camera;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.Badges;
import com.github.artemdevel.pixeldungeon.Bones;
Expand Down Expand Up @@ -567,13 +566,13 @@ private boolean actOpenChest(HeroAction.OpenChest action) {

switch (heap.type) {
case TOMB:
GameSound.INSTANCE.play(Assets.SND_TOMB);
Game.sound.play(Assets.SND_TOMB);
Camera.main.shake(1, 0.5f);
break;
case SKELETON:
break;
default:
GameSound.INSTANCE.play(Assets.SND_UNLOCK);
Game.sound.play(Assets.SND_UNLOCK);
}

spend(Key.TIME_TO_UNLOCK);
Expand Down Expand Up @@ -606,7 +605,7 @@ private boolean actUnlock(HeroAction.Unlock action) {
if (theKey != null) {
spend(Key.TIME_TO_UNLOCK);
sprite.operate(doorCell);
GameSound.INSTANCE.play(Assets.SND_UNLOCK);
Game.sound.play(Assets.SND_UNLOCK);
} else {
GLog.logWarning(TXT_LOCKED_DOOR);
ready();
Expand Down Expand Up @@ -909,7 +908,7 @@ public void earnExp(int exp) {
if (levelUp) {
GLog.logPositive(TXT_NEW_LEVEL, lvl);
sprite.showStatus(CharSprite.POSITIVE, TXT_LEVEL_UP);
GameSound.INSTANCE.play(Assets.SND_LEVELUP);
Game.sound.play(Assets.SND_LEVELUP);

Badges.validateLevelReached();
}
Expand Down Expand Up @@ -1085,9 +1084,9 @@ public void move(int step) {

if (!flying) {
if (Level.water[pos]) {
GameSound.INSTANCE.play(Assets.SND_WATER, 1, 1, Random.Float(0.8f, 1.25f));
Game.sound.play(Assets.SND_WATER, 1, 1, Random.Float(0.8f, 1.25f));
} else {
GameSound.INSTANCE.play(Assets.SND_STEP);
Game.sound.play(Assets.SND_STEP);
}
Dungeon.level.press(pos, this);
}
Expand Down Expand Up @@ -1134,7 +1133,7 @@ public void onOperateComplete() {

Heap heap = Dungeon.level.heaps.get(((HeroAction.OpenChest) curAction).dst);
if (heap.type == Type.SKELETON) {
GameSound.INSTANCE.play(Assets.SND_BONES);
Game.sound.play(Assets.SND_BONES);
}
heap.open(this);
}
Expand Down Expand Up @@ -1229,7 +1228,7 @@ public boolean search(boolean intentional) {

if (smthFound) {
GLog.logWarning(TXT_NOTICED_SMTH);
GameSound.INSTANCE.play(Assets.SND_SECRET);
Game.sound.play(Assets.SND_SECRET);
interrupt();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.HashSet;

import com.github.artemdevel.pixeldungeon.game.common.Camera;
import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.Badges;
import com.github.artemdevel.pixeldungeon.Dungeon;
Expand Down Expand Up @@ -119,7 +119,7 @@ public void move(int step) {
if (Dungeon.visible[cell]) {
CellEmitter.get(cell).start(Speck.factory(Speck.ROCK), 0.07f, 10);
Camera.main.shake(3, 0.7f);
GameSound.INSTANCE.play(Assets.SND_ROCKS);
Game.sound.play(Assets.SND_ROCKS);

if (Level.water[cell]) {
GameScene.ripple(cell);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.HashSet;

import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.Badges;
import com.github.artemdevel.pixeldungeon.Dungeon;
Expand Down Expand Up @@ -167,7 +167,7 @@ private void summon() {
nextPedestal = !nextPedestal;

sprite.centerEmitter().start(Speck.factory(Speck.SCREAM), 0.4f, 2);
GameSound.INSTANCE.play(Assets.SND_CHALLENGE);
Game.sound.play(Assets.SND_CHALLENGE);

boolean[] passable = Level.passable.clone();
for (Actor actor : Actor.all()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.HashSet;
import java.util.List;

import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.Dungeon;
import com.github.artemdevel.pixeldungeon.actors.Actor;
Expand Down Expand Up @@ -170,7 +170,7 @@ public static Mimic spawnAt(int pos, List<Item> items) {

if (Dungeon.visible[m.pos]) {
CellEmitter.get(pos).burst(Speck.factory(Speck.STAR), 10);
GameSound.INSTANCE.play(Assets.SND_MIMIC);
Game.sound.play(Assets.SND_MIMIC);
}

return m;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.HashSet;

import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.Dungeon;
import com.github.artemdevel.pixeldungeon.ResultDescriptions;
Expand Down Expand Up @@ -76,7 +76,7 @@ public void die(Object cause) {
}

if (Dungeon.visible[pos]) {
GameSound.INSTANCE.play(Assets.SND_BONES);
Game.sound.play(Assets.SND_BONES);
}

if (heroKilled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.HashSet;

import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.actors.Actor;
import com.github.artemdevel.pixeldungeon.actors.Char;
Expand Down Expand Up @@ -79,7 +79,7 @@ public int attackProc(Char enemy, int damage) {
if (Random.Int(3) == 0) {
Buff.affect(enemy, Charm.class, Charm.durationFactor(enemy) * Random.IntRange(3, 7)).object = id();
enemy.sprite.centerEmitter().start(Speck.factory(Speck.HEART), 0.2f, 5);
GameSound.INSTANCE.play(Assets.SND_CHARMS);
Game.sound.play(Assets.SND_CHARMS);
}

return damage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.HashSet;

import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.Badges;
import com.github.artemdevel.pixeldungeon.Statistics;
Expand Down Expand Up @@ -169,7 +169,7 @@ private void jump() {

if (Dungeon.visible[newPos]) {
CellEmitter.get(newPos).burst(Speck.factory(Speck.WOOL), 6);
GameSound.INSTANCE.play(Assets.SND_PUFF);
Game.sound.play(Assets.SND_PUFF);
}

spend(1 / speed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.github.artemdevel.pixeldungeon.actors.blobs.ToxicGas;
import com.github.artemdevel.pixeldungeon.actors.buffs.Buff;
import com.github.artemdevel.pixeldungeon.actors.buffs.Paralysis;
import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.game.utils.Random;
import com.github.artemdevel.pixeldungeon.items.weapon.enchantments.Death;
import com.github.artemdevel.pixeldungeon.sprites.UndeadSprite;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void die(Object cause) {
super.die(cause);

if (Dungeon.visible[pos]) {
GameSound.INSTANCE.play(Assets.SND_BONES);
Game.sound.play(Assets.SND_BONES);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.Collection;

import com.github.artemdevel.pixeldungeon.game.common.audio.GameSound;
import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.Assets;
import com.github.artemdevel.pixeldungeon.Badges;
import com.github.artemdevel.pixeldungeon.Dungeon;
Expand Down Expand Up @@ -186,7 +186,7 @@ public static void upgrade(Item item1, Item item2) {
second = item2;
}

GameSound.INSTANCE.play(Assets.SND_EVOKE);
Game.sound.play(Assets.SND_EVOKE);
ScrollOfUpgrade.upgrade(Dungeon.hero);
Item.evoke(Dungeon.hero);

Expand Down
Loading

0 comments on commit 37fcacc

Please sign in to comment.