Skip to content
Snippets Groups Projects
Commit 4527f219 authored by Luboš Horáček's avatar Luboš Horáček
Browse files

#31 Shooting and hit sound

parent bff60884
Branches
Tags
No related merge requests found
......@@ -27,6 +27,7 @@ import com.badlogic.gdx.audio.Sound;
import java.util.HashMap;
import cz.nic.tablexia.game.AbstractTablexiaGame;
import cz.nic.tablexia.util.Log;
/**
......@@ -34,16 +35,17 @@ import cz.nic.tablexia.game.AbstractTablexiaGame;
*/
public class SfxLibrary extends HashMap<AssetDescription, String> {
private static final String SOUNDS_DIR = "mfx/";
private static final String SOUNDS_DIR = "sfx/";
public static final String SOUNDS_EXTENSION = ".mp3";
private AbstractTablexiaGame abstractTablexiaGame;
public SfxLibrary(AbstractTablexiaGame abstractTablexiaGame, AssetDescription[] assetDescriptions) {
this.abstractTablexiaGame = abstractTablexiaGame;
for (AssetDescription sound : assetDescriptions) {
String path = SOUNDS_DIR + sound.getResource() + SOUNDS_EXTENSION;
put(sound, path);
for (AssetDescription assetDescription : assetDescriptions) {
String path = SOUNDS_DIR + assetDescription.getResource() + SOUNDS_EXTENSION;
Log.info(getClass(), "Adding sound " + path);
put(assetDescription, path);
}
}
......
package cz.nic.tablexia.game.games.shooting_range;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import java.util.List;
import java.util.Map;
......@@ -36,6 +39,14 @@ public class ShootingRangeGame extends AbstractTablexiaGame<GameState> {
private List<Target>[] waves;
private TargetGenerator targetGenerator;
private TargetPositionController targetPositionController;
private ClickListener clickListener = new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
Actor target = event.getTarget();
sfxLibrary.getSound(SoundType.HIT_1).play();
}
};
@Override
......@@ -56,7 +67,7 @@ public class ShootingRangeGame extends AbstractTablexiaGame<GameState> {
super.gameLoaded(gameState);
initScene();
targetGenerator = new TargetGenerator(getGameDifficulty(), getRandom(), gfxLibrary);
targetGenerator = new TargetGenerator(getGameDifficulty(), getRandom(), gfxLibrary, clickListener);
targetPositionController = new TargetPositionController(scene, targetGenerator, getRandom(), getStage().getWidth());
for (Row row : scene.getRows()) {
row.setWave(Wave.getWave(getGameDifficulty(), row.getRowIndex()));
......
package cz.nic.tablexia.game.games.shooting_range.actors;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import cz.nic.tablexia.game.games.shooting_range.media.Textures;
......@@ -8,7 +9,7 @@ import cz.nic.tablexia.game.games.shooting_range.media.Textures;
* Created by lhoracek on 6/26/15.
*/
public class Flower extends Target {
public Flower(TextureRegion texture, Float startTime, Row row, Textures textureType) {
super(texture, startTime, row, textureType);
public Flower(TextureRegion texture, Float startTime, Row row, Textures textureType, ClickListener listener) {
super(texture, startTime, row, textureType, listener);
}
}
package cz.nic.tablexia.game.games.shooting_range.actors;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import java.util.ArrayList;
......@@ -28,6 +29,7 @@ public class Scene extends Group {
rows = new Row[]{row1, row2, row3};
addActor(frame = new Image(gfxLibrary.getTextureRegion(Textures.FRAME)));
frame.setTouchable(Touchable.disabled);
}
@Override
......
......@@ -3,6 +3,7 @@ package cz.nic.tablexia.game.games.shooting_range.actors;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import cz.nic.tablexia.game.games.shooting_range.media.Textures;
......@@ -28,11 +29,12 @@ public class Target extends Image {
};
}
public Target(TextureRegion texture, Float startTime, Row row, Textures textureType) {
public Target(TextureRegion texture, Float startTime, Row row, Textures textureType, ClickListener listener) {
super(texture);
this.startTime = startTime;
this.textureType = textureType;
this.row = row;
addListener(listener);
}
public float getStartTime() {
......@@ -107,7 +109,7 @@ public class Target extends Image {
public String toString() {
return "Target{" +
"textureType=" + textureType +
", row=" + row +
//", row=" + row +
", shot=" + shot +
'}';
}
......
package cz.nic.tablexia.game.games.shooting_range.tools;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
......@@ -27,15 +29,17 @@ public class TargetGenerator {
public static final float MEDIUM_GOOD_PROBABILITY = 0.5f;
public static final float HARD_GOOD_PROBABILITY = 0.3f;
private GameDifficulty gameDifficulty;
private Random random;
private GfxLibrary gfxLibrary;
private final GameDifficulty gameDifficulty;
private final Random random;
private final GfxLibrary gfxLibrary;
private final ClickListener clickListener;
public TargetGenerator(GameDifficulty gameDifficulty, Random random, GfxLibrary gfxLibrary) {
public TargetGenerator(GameDifficulty gameDifficulty, Random random, GfxLibrary gfxLibrary, ClickListener clickListener) {
super();
this.random = random;
this.gameDifficulty = gameDifficulty;
this.gfxLibrary = gfxLibrary;
this.clickListener = clickListener;
}
......@@ -111,7 +115,7 @@ public class TargetGenerator {
int random = (int) (Math.random() * textureTypeBag.size());
textureType = textureTypeBag.get(random);
}
return new Target(gfxLibrary.getTextureRegion(textureType), startTime, row, textureType);
return new Target(gfxLibrary.getTextureRegion(textureType), startTime, row, textureType, clickListener);
}
private float getBoxProbability() {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment