Skip to content
Snippets Groups Projects
Commit c56596b6 authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko Committed by Matyáš Latner
Browse files

#344 Added looping vehicle sound while animation is lasted.

parent 24a83001
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@ import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.pursuit.action.RotateAndMovePieceInPosition;
import cz.nic.tablexia.game.games.pursuit.action.RotatePieceToClosestAngle;
import cz.nic.tablexia.game.games.pursuit.action.VehicleMoveAction;
import cz.nic.tablexia.game.games.pursuit.assets.PursuitAssets;
import cz.nic.tablexia.game.games.pursuit.helper.ArithmeticsHelper;
import cz.nic.tablexia.game.games.pursuit.helper.GameRulesHelper;
......@@ -50,7 +51,6 @@ import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.Point;
import cz.nic.tablexia.util.ScaleUtil;
import cz.nic.tablexia.util.Utility;
import cz.nic.tablexia.util.actions.MoveAlongAction;
import cz.nic.tablexia.util.listener.DragAndRotateActorListener;
import cz.nic.tablexia.util.ui.AnimatedImage;
import cz.nic.tablexia.util.ui.TablexiaNoBlendingImage;
......@@ -405,20 +405,9 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
final Point vehiclePosition = new Point(0, 0);
Point vehicleSize = new Point(vehicleType.getVehicleSize().x, vehicleType.getVehicleSize().y);
Music[] vehicleSounds = getVehicleSounds(vehicleType);
final Music[] vehicleSounds = getVehicleSounds(vehicleType);
vehicle = new Vehicle(getScreenTextureRegion(vehicleType.getTextureName()), vehiclePosition, vehicleSize);
// vehicle.addListener(new VehicleDragListener(vehicle, vehicleSounds, getData(), new Point(roadMap.getWidth(), roadMap.getHeight()), finishFlag, new VehicleDragListener.OnVehicleDragCompleteListener() {
// @Override
// public void onVehicleDragComplete() {
// showGameResultDialog();
// remove all actor listeners
// vehicle.clear();
// vehicle.remove();
// finishFlag.clear();
// finishFlag.remove();
// }
// }));
vehicle.addListener(new ClickListener(){
......@@ -427,7 +416,6 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
start = new Point(x,y);
return super.touchDown(event, x, y, pointer, button);
}
......@@ -444,24 +432,18 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
if (Math.abs(touchAngle - vehicleToFlagAngle) < 20 && distance > 20) {
final CatmullRomSpline<Vector2> path = new CatmullRomSpline<Vector2>(Maps.values()[mapNumber].getPursuitPositionDefinition().getPointsWithRotation(grid.getRotation(), vehiclePosition.x,vehiclePosition.y),false);
path.approxLength(100);
MoveAlongAction moveAlongAction = new MoveAlongAction(path, 5f){
@Override
protected void update(float percent) {
Vector2 value = new Vector2();
path.valueAt(value, percent);
actor.setPosition(grid.getWidth()*value.x-actor.getWidth()/2,grid.getHeight()*value.y - grid.getY() - actor.getHeight()/2);
actor.setRotation(path.derivativeAt(value, percent).angle() - 90);
}
};
moveAlongAction.setRotate(true);
vehicle.addAction(Actions.sequence(moveAlongAction,new RunnableAction() {
// TODO: 24.6.16 add moving sound
// FIXME: 24.6.16 touching anything during animation
VehicleMoveAction vehicleMoveAlongAction = new VehicleMoveAction(path, 5f, grid.getWidth(), vehicleSounds);
vehicle.addAction(Actions.sequence(vehicleMoveAlongAction,new RunnableAction() {
@Override
public void run() {
for(Music snd : vehicleSounds) {
snd.stop();
snd.dispose();
}
showGameResultDialog();
vehicle.clear();
vehicle.remove();
......
package cz.nic.tablexia.game.games.pursuit.action;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Path;
import com.badlogic.gdx.math.Vector2;
import cz.nic.tablexia.util.actions.MoveAlongAction;
/**
* Created by Vitaliy Vashchenko on 24.6.16.
*/
public class VehicleMoveAction extends MoveAlongAction {
private float parentSize;
private Path<Vector2> path;
private float duration;
private Music[] vehicleMusic;
private int soundIndex;
public VehicleMoveAction(Path<Vector2> path, float duration, float parentSize, Music[] vehicleMusic) {
super(path, duration);
setRotate(true);
this.path = path;
this.duration = duration;
this.parentSize = parentSize;
this.vehicleMusic = vehicleMusic;
soundIndex = MathUtils.random(0,vehicleMusic.length-1);
}
@Override
protected void update(float percent) {
Vector2 value = new Vector2();
path.valueAt(value, percent);
actor.setPosition(parentSize*value.x-actor.getWidth()/2,parentSize*value.y - actor.getHeight()/2);
actor.setRotation(path.derivativeAt(value, percent).angle() - 90);
}
@Override
protected void begin() {
vehicleMusic[soundIndex].setVolume(1);
vehicleMusic[soundIndex].setLooping(true);
vehicleMusic[soundIndex].play();
super.begin();
}
@Override
protected void end() {
vehicleMusic[soundIndex].stop();
super.end();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment