Permalink
Browse files

Lesson 25: minor bugfixes; sounds implemented

  • Loading branch information...
vladimirslav committed Dec 28, 2016
1 parent 49e8b0f commit e93739a981ad6da90c2fe69bfce876ae1be045c9
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -17,12 +17,14 @@
public void create () {
res = new Resources();
GameProgress.Load();
SoundManager.LoadSounds();
setScreen(new CharacterSelectionScreen(this));
}
@Override
public void dispose () {
GameProgress.Save();
res.dispose();
SoundManager.ReleaseSounds();
}
}
@@ -0,0 +1,80 @@
package com.coldwild.dodginghero;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.math.MathUtils;
/**
* Created by comrad_gremlin on 12/28/2016.
*/
public class SoundManager {
/*
swing.wav -> swing0.ogg
swing2.wav -> swing1.ogg
swing3.wav -> swing2.ogg
coin.wav -> coin.ogg
bite-small.wav -> heal.ogg
fantozzi-sandl1 -> walk0.ogg
fantozzi-sandl2 -> walk1.ogg
Fantozzi-SandR1 -> walk2.ogg
Attack sounds: http://opengameart.org/content/rpg-sound-pack by artisticdude
Battle Music: http://opengameart.org/content/8-bit-music-pack-loopable#comment-55568 by CodeManu
Footsteps: http://opengameart.org/content/fantozzis-footsteps-grasssand-stone by Fantozzi (submitted by qubodup)
*/
public static AssetManager assets = new AssetManager();
public static void LoadSounds()
{
for (int i = 0; i < 3; i++)
{
assets.load(Gdx.files.internal("music/swing" + i + ".ogg").path(), Sound.class);
assets.load(Gdx.files.internal("music/walk" + i + ".ogg").path(), Sound.class);
}
assets.load(Gdx.files.internal("music/coin.ogg").path(), Sound.class);
assets.load(Gdx.files.internal("music/heal.ogg").path(), Sound.class);
assets.finishLoading();
}
public static void ReleaseSounds()
{
assets.dispose();
}
private static void playSoundRandomVolume(Sound sound, float min, float max)
{
if (sound != null)
{
sound.play(MathUtils.random(min, max));
}
}
public static void PlaySwingSound()
{
Sound s = assets.get("music/swing" + MathUtils.random(2) + ".ogg", Sound.class);
playSoundRandomVolume(s, 0.9f, 1.0f);
}
public static void PlayWalkSound()
{
Sound s = assets.get("music/walk" + MathUtils.random(2) + ".ogg", Sound.class);
playSoundRandomVolume(s, 0.5f, 0.6f);
}
public static void PlayCoinSound()
{
Sound coin = assets.get("music/coin.ogg", Sound.class);
playSoundRandomVolume(coin, 0.9f, 1.0f);
}
public static void PlayHealSound()
{
Sound heal = assets.get("music/heal.ogg", Sound.class);
playSoundRandomVolume(heal, 0.9f, 1.0f);
}
}
@@ -24,7 +24,8 @@
public interface GameEventListener
{
void OnGameEnd(boolean playerWon);
void OnGameEnd(final boolean playerWon);
void OnBonusPickup(byte bonusType);
}
Player player;
@@ -138,7 +139,7 @@ public void AssignPlayerPosition(int fx, int fy)
if (currentBonus.getFieldX() == fx &&
currentBonus.getFieldY() == fy)
{
eventListener.OnBonusPickup(currentBonus.getBonusType());
if (currentBonus.getBonusType() == Bonus.BONUS_TYPE_HEALTH)
{
player.addLives(GameProgress.getPlayerHealthRestored());
@@ -193,6 +194,7 @@ public void OnEffectOver(WarningEffect effect) {
player.takeDamage(GameProgress.getEnemyDamage());
if (player.getLives() <= 0)
{
eventListener.OnGameEnd(false);
GameProgress.Reset(true);
}
}
@@ -1,6 +1,7 @@
package com.coldwild.dodginghero.logic.objects;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.coldwild.dodginghero.SoundManager;
/**
* Created by comrad_gremlin on 10/6/2016.
@@ -45,6 +46,7 @@ public void postDraw()
public void takeDamage(int amount) {
SoundManager.PlaySwingSound();
timeOfDmgTaken = timeAlive;
lives -= amount;
if (lives < 0)
@@ -95,5 +95,6 @@ public void markVictorious()
{
winning = true;
winTime = timeAlive;
GameProgress.playerLives = lives;
}
}
@@ -71,6 +71,7 @@ public void touchUp (InputEvent event, float x, float y, int pointer, int button
{
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
GameProgress.Reset(false);
dispose();
game.setScreen(new GameScreen(game));
}
@@ -14,6 +14,7 @@
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.coldwild.dodginghero.DodgingHero;
import com.coldwild.dodginghero.Resources;
import com.coldwild.dodginghero.SoundManager;
import com.coldwild.dodginghero.graph.Background;
import com.coldwild.dodginghero.graph.SizeEvaluator;
import com.coldwild.dodginghero.graph.effects.WarningEffect;
@@ -238,6 +239,7 @@ public void AttempMove(int dx, int dy)
logic.getEnemy().getLives() > 0 &&
logic.CanMove(player.getFieldX() + dx, player.getFieldY() + dy))
{
SoundManager.PlayWalkSound();
logic.AssignPlayerPosition(player.getFieldX() + dx, player.getFieldY() + dy);
}
}
@@ -298,7 +300,7 @@ public boolean scrolled(int amount) {
}
@Override
public void OnGameEnd(boolean playerWon) {
public void OnGameEnd(final boolean playerWon) {
gameStage.addAction(
Actions.sequence(
new Action() {
@@ -318,11 +320,30 @@ public boolean act(float delta) {
@Override
public boolean act(float delta) {
dispose();
game.setScreen(new GameScreen(game));
if (playerWon)
{
game.setScreen(new GameScreen(game));
}
else
{
game.setScreen(new CharacterSelectionScreen(game));
}
return true;
}
}
)
);
}
@Override
public void OnBonusPickup(byte bonusType) {
if (bonusType == Bonus.BONUS_TYPE_COIN)
{
SoundManager.PlayCoinSound();
}
else if (bonusType == Bonus.BONUS_TYPE_HEALTH)
{
SoundManager.PlayHealSound();
}
}
}
View
@@ -1,4 +1,8 @@
Font Name: Megaman 10 byYahooXD;
Tiles: http://opengameart.org/content/tiny-16-basic
Made for Libgdx Tutorial;
Attack sounds: http://opengameart.org/content/rpg-sound-pack by artisticdude
Battle Music: http://opengameart.org/content/8-bit-music-pack-loopable#comment-55568 by CodeManu
Footsteps: http://opengameart.org/content/fantozzis-footsteps-grasssand-stone by Fantozzi (submitted by qubodup)
Made for Libgdx Tutorial;

0 comments on commit e93739a

Please sign in to comment.