[client] update SoundManager
This commit is contained in:
@@ -5,24 +5,30 @@ import flash.media.Sound;
|
||||
import flash.media.SoundChannel;
|
||||
import flash.media.SoundTransform;
|
||||
import openfl.utils.Assets;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.IGame;
|
||||
|
||||
class SoundManager implements GameListener {
|
||||
private static var TAG(default, never):String = 'SoundManager';
|
||||
private static var TAG(default, never):String = "SoundManager";
|
||||
|
||||
#if flash
|
||||
private static var type:String = 'mp3';
|
||||
private static var type:String = "mp3";
|
||||
#else
|
||||
private static var type:String = 'ogg';
|
||||
private static var type:String = "ogg";
|
||||
#end
|
||||
|
||||
public var config(default, default):Config;
|
||||
public var volume(default, set):Float = 1;
|
||||
public var mute(default, set):Bool = false;
|
||||
|
||||
private var channels:Array<SoundChannel>;
|
||||
private var transform:SoundTransform;
|
||||
|
||||
private var humanTanks:Array<Int>;
|
||||
private var humanBullets:Array<Int>;
|
||||
private var liveBonuses:Array<Int>;
|
||||
|
||||
public function new() {
|
||||
channels = [];
|
||||
updateSoundTransform();
|
||||
@@ -77,30 +83,44 @@ class SoundManager implements GameListener {
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(_):
|
||||
play('start');
|
||||
case SPAWN(BULLET(_)):
|
||||
if (false /*ToDo: human tank*/) {
|
||||
play('shot');
|
||||
play("start");
|
||||
humanTanks = [];
|
||||
liveBonuses = [];
|
||||
humanBullets = [];
|
||||
case SPAWN(BULLET(id, _, playerId, _)):
|
||||
if (config.isHuman(playerId)) {
|
||||
play("shot");
|
||||
humanBullets.push(id);
|
||||
}
|
||||
case SPAWN(TANK(id, _, playerId, _)):
|
||||
if (config.isHuman(playerId)) {
|
||||
humanTanks.push(id);
|
||||
}
|
||||
case SPAWN(BONUS(id, _, type)):
|
||||
play("bonus_add");
|
||||
if (type == "live") {
|
||||
liveBonuses.push(id);
|
||||
}
|
||||
case SPAWN(BONUS(_, _)):
|
||||
play('bonus_add');
|
||||
case HIT(TANK(_, _)):
|
||||
play('bullet_hit');
|
||||
case DESTROY(TANK(_, _)):
|
||||
if (true /*ToDo: human tank*/) {
|
||||
play('boom_player');
|
||||
play("bullet_hit");
|
||||
case HIT(CELL(_, _, shot)):
|
||||
if (humanBullets.indexOf(shot.bulletId) > -1) {
|
||||
//play("bullet_block");
|
||||
}
|
||||
case DESTROY(TANK(id, _)):
|
||||
if (humanTanks.indexOf(id) > -1) {
|
||||
play("boom_player");
|
||||
} else {
|
||||
play('boom_bot');
|
||||
play("boom_bot");
|
||||
}
|
||||
case DESTROY(EAGLE(_, _)):
|
||||
play('boom_player');
|
||||
case DESTROY(BONUS(_, _)):
|
||||
// ToDo: bonus type
|
||||
play('bonus_get');
|
||||
if (false /*ToDo: bonus.type == 'life'*/) {
|
||||
play('live');
|
||||
play("boom_player");
|
||||
case DESTROY(BONUS(id, _)):
|
||||
play("bonus_get");
|
||||
if (liveBonuses.indexOf(id) > -1) {
|
||||
play("live");
|
||||
} else {
|
||||
play('bonus_get');
|
||||
play("bonus_get");
|
||||
}
|
||||
case _:
|
||||
}
|
||||
|
||||
@@ -47,37 +47,31 @@ import ru.m.tankz.view.game.GameView;
|
||||
}
|
||||
}
|
||||
|
||||
private function start(state:GameState):Void {
|
||||
private function buildGame(state:GameState):Void {
|
||||
gameView.type = state.type;
|
||||
game = new Game(state);
|
||||
soundManager.config = game.config;
|
||||
gameView.render.config = game.config;
|
||||
game.connect(gameView.render);
|
||||
game.connect(soundManager);
|
||||
game.connect(this);
|
||||
if (gameView.panel != null) {
|
||||
game.connect(gameView.panel);
|
||||
}
|
||||
//game.connect(new GameTracer());
|
||||
}
|
||||
|
||||
private function start(state:GameState):Void {
|
||||
buildGame(state);
|
||||
game.connect(this);
|
||||
recorder = new GameRecorder();
|
||||
game.connect(recorder);
|
||||
runner = new GameRunner(game);
|
||||
runner.start(state);
|
||||
gameView.render.draw();
|
||||
}
|
||||
|
||||
private function play(record:GameRecord):Void {
|
||||
gameView.type = record.info.type;
|
||||
game = new Game(record.state);
|
||||
gameView.render.config = game.config;
|
||||
game.connect(gameView.render);
|
||||
game.connect(soundManager);
|
||||
//game.connect(this);
|
||||
if (gameView.panel != null) {
|
||||
game.connect(gameView.panel);
|
||||
}
|
||||
buildGame(record.state);
|
||||
player = new GamePlayer(game, record);
|
||||
player.start();
|
||||
gameView.render.draw();
|
||||
}
|
||||
|
||||
private function stop():Void {
|
||||
|
||||
Reference in New Issue
Block a user