Permalink
Browse files

Lesson 26: music! and sound toggle button

  • Loading branch information...
vladimirslav committed Dec 29, 2016
1 parent e93739a commit 223be4e0ecd6518608e0207196b28642b755f8e0
@@ -1,96 +1,124 @@
game.png
size: 256,32
size: 64,128
format: RGBA8888
filter: Nearest,Nearest
repeat: none
attack
rotate: false
xy: 2, 8
xy: 2, 110
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
base
rotate: false
xy: 2, 2
xy: 20, 32
size: 16, 4
orig: 16, 4
offset: 0, 0
index: -1
bat
rotate: false
xy: 20, 8
xy: 2, 92
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
coin
rotate: false
xy: 38, 8
xy: 20, 110
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
ghost
rotate: false
xy: 56, 8
xy: 2, 74
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
ground
rotate: false
xy: 74, 8
xy: 20, 92
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
health
rotate: false
xy: 200, 10
xy: 38, 58
size: 14, 14
orig: 14, 14
offset: 0, 0
index: -1
player
rotate: false
xy: 92, 8
xy: 38, 110
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
skeleton
rotate: false
xy: 110, 8
xy: 2, 56
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
slime
rotate: false
xy: 128, 8
xy: 20, 74
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
sound0
rotate: false
xy: 38, 92
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
sound1
rotate: false
xy: 2, 38
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
sound2
rotate: false
xy: 20, 56
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
sound3
rotate: false
xy: 38, 74
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
spider
rotate: false
xy: 146, 8
xy: 2, 20
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
wall
rotate: false
xy: 164, 8
xy: 2, 2
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
warning
rotate: false
xy: 182, 8
xy: 20, 38
size: 16, 16
orig: 16, 16
offset: 0, 0
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
@@ -5,6 +5,7 @@
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.coldwild.dodginghero.logic.objects.Character;
import com.coldwild.dodginghero.logic.objects.CharacterRecord;
@@ -39,6 +40,8 @@
public Sprite healthBonus;
public Sprite coinBonus;
public TextureRegionDrawable soundBtn[];
public static final int TILE_SIZE = 16;
public Resources()
@@ -71,6 +74,12 @@ public Resources()
attackBonus = gameSprites.createSprite("attack");
healthBonus = gameSprites.createSprite("health");
coinBonus = gameSprites.createSprite("coin");
soundBtn = new TextureRegionDrawable[4];
for (int i = 0; i < 4; i++)
{
soundBtn[i] = new TextureRegionDrawable(gameSprites.findRegion("sound" + i));
}
}
public void dispose()
@@ -2,8 +2,10 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.math.MathUtils;
import com.coldwild.dodginghero.logic.GameProgress;
/**
* Created by comrad_gremlin on 12/28/2016.
@@ -26,6 +28,7 @@
*/
public static AssetManager assets = new AssetManager();
private static Music bMusic = null;
public static void LoadSounds()
{
@@ -50,7 +53,7 @@ private static void playSoundRandomVolume(Sound sound, float min, float max)
{
if (sound != null)
{
sound.play(MathUtils.random(min, max));
sound.play(MathUtils.random(min, max) * GameProgress.soundVolume / GameProgress.MAX_SOUND_VOLUME);
}
}
@@ -77,4 +80,30 @@ public static void PlayHealSound()
Sound heal = assets.get("music/heal.ogg", Sound.class);
playSoundRandomVolume(heal, 0.9f, 1.0f);
}
public static void StopBattleMusic()
{
if (bMusic != null)
{
bMusic.stop();
bMusic = null;
}
}
public static void PlayBattleMusic()
{
bMusic = Gdx.audio.newMusic(Gdx.files.internal("music/music" + MathUtils.random(5) + ".mp3"));
bMusic.setLooping(true);
bMusic.setVolume((float)GameProgress.soundVolume / GameProgress.MAX_SOUND_VOLUME);
bMusic.play();
}
public static void AdjustVolume()
{
GameProgress.ToggleVolume();
if (bMusic != null)
{
bMusic.setVolume((float)GameProgress.soundVolume / GameProgress.MAX_SOUND_VOLUME);
}
}
}
@@ -10,9 +10,12 @@
public class GameProgress {
public static final int MAX_SOUND_VOLUME = 3;
public static int playerLives = 3;
public static int currentCharacter = 0;
public static int currentGold = 0;
public static int soundVolume = MAX_SOUND_VOLUME;
public static final int CHARACTER_PRICE = 1000;
public static int levels[]; // level of each character, 0 = locked
@@ -24,6 +27,7 @@
private static final String SAVE_KEY_PLAYER_LEVEL = "playerlevel";
private static final String SAVE_KEY_PLAYER_STAGE = "playerstage";
private static final String SAVE_KEY_PLAYER_GOLD = "playergold";
private static final String SAVE_KEY_SOUND_VOLUME = "soundvolume";
public static int getEnemyLives()
{
@@ -41,6 +45,7 @@ public static void Save()
prefs.putInteger(SAVE_KEY_LIVES, playerLives);
prefs.putInteger(SAVE_KEY_PLAYER_GOLD, currentGold);
prefs.putInteger(SAVE_KEY_SOUND_VOLUME, soundVolume);
for (int i = 0; i < CharacterRecord.CHARACTERS.length; i++)
{
@@ -59,6 +64,7 @@ public static void Load()
Preferences prefs = Gdx.app.getPreferences(PROGRESS_SAVE_NAME);
playerLives = prefs.getInteger(SAVE_KEY_LIVES, 3);
currentGold = prefs.getInteger(SAVE_KEY_PLAYER_GOLD, 0);
soundVolume = prefs.getInteger(SAVE_KEY_SOUND_VOLUME, MAX_SOUND_VOLUME);
for (int i = 0; i < CharacterRecord.CHARACTERS.length; i++)
{
@@ -113,4 +119,13 @@ public static void increaseStage() {
currentGold += 1 + stages[currentCharacter] / 4;
stages[currentCharacter]++;
}
public static void ToggleVolume()
{
soundVolume += 1;
if (soundVolume > MAX_SOUND_VOLUME)
{
soundVolume = 0;
}
}
}
Oops, something went wrong.

0 comments on commit 223be4e

Please sign in to comment.