[client] added SoundManager
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz;
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import ru.m.tankz.sound.SoundManager;
|
||||||
import flash.events.KeyboardEvent;
|
import flash.events.KeyboardEvent;
|
||||||
import flash.text.Font;
|
import flash.text.Font;
|
||||||
import flash.ui.Keyboard;
|
import flash.ui.Keyboard;
|
||||||
@@ -86,6 +87,7 @@ class Client implements IConnectionHandler {
|
|||||||
Provider.setFactory(IConfigBundle, ConfigBundle);
|
Provider.setFactory(IConfigBundle, ConfigBundle);
|
||||||
Provider.setFactory(ILevelBundle, LevelBundle);
|
Provider.setFactory(ILevelBundle, LevelBundle);
|
||||||
Provider.setFactory(SaveStorage, SaveStorage);
|
Provider.setFactory(SaveStorage, SaveStorage);
|
||||||
|
Provider.setFactory(SoundManager, SoundManager);
|
||||||
Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE);
|
Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE);
|
||||||
Provider.setFactory(Game, DotaGame, DotaGame.TYPE);
|
Provider.setFactory(Game, DotaGame, DotaGame.TYPE);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.frame;
|
package ru.m.tankz.frame;
|
||||||
|
|
||||||
|
import ru.m.tankz.sound.SoundManager;
|
||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
import haxe.ds.Option;
|
import haxe.ds.Option;
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
@@ -45,6 +46,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
|||||||
throw 'Unsupported game type "${save.state.type}"';
|
throw 'Unsupported game type "${save.state.type}"';
|
||||||
}
|
}
|
||||||
game.engine.listeners.push(render);
|
game.engine.listeners.push(render);
|
||||||
|
game.engine.listeners.push(Provider.get(SoundManager));
|
||||||
game.start(save).then(onGameStateChange).endThen(onGameComplete);
|
game.start(save).then(onGameStateChange).endThen(onGameComplete);
|
||||||
content.addEventListener(Event.ENTER_FRAME, redraw);
|
content.addEventListener(Event.ENTER_FRAME, redraw);
|
||||||
//Provider.get(IConnection).packetHandler.addListener(this);
|
//Provider.get(IConnection).packetHandler.addListener(this);
|
||||||
|
|||||||
59
src/client/haxe/ru/m/tankz/sound/SoundManager.hx
Normal file
59
src/client/haxe/ru/m/tankz/sound/SoundManager.hx
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package ru.m.tankz.sound;
|
||||||
|
|
||||||
|
import ru.m.tankz.core.EntityType;
|
||||||
|
import ru.m.tankz.engine.Engine;
|
||||||
|
import flash.media.Sound;
|
||||||
|
import openfl.utils.Assets;
|
||||||
|
|
||||||
|
|
||||||
|
class SoundManager implements EngineListener {
|
||||||
|
private static var TAG(default, never):String = 'SoundManager';
|
||||||
|
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function play(id:String):Void {
|
||||||
|
L.d(TAG, 'player: ${id}');
|
||||||
|
var sound:Sound = Assets.getSound('resources/sounds/${id}.mp3');
|
||||||
|
sound.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onSpawn(entity:EntityType):Void {
|
||||||
|
switch entity {
|
||||||
|
case EntityType.BULLET(_.tank.playerId.team => 'human'):
|
||||||
|
play('shot');
|
||||||
|
case EntityType.BONUS(_):
|
||||||
|
play('bonus_add');
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onChange(entity:EntityType, ?change:EntityChange):Void {
|
||||||
|
switch [entity, change] {
|
||||||
|
case [EntityType.TANK(_), EntityChange.HIT]:
|
||||||
|
play('bullet_hit');
|
||||||
|
case [EntityType.TANK(_), EntityChange.LIVE_UP]:
|
||||||
|
play('live');
|
||||||
|
case [EntityType.EAGLE(_), EntityChange.DEATH]:
|
||||||
|
play('boom_player');
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onCollision(entity:EntityType, with:EntityType):Void {
|
||||||
|
switch [entity, with] {
|
||||||
|
case [EntityType.BULLET(_), EntityType.CELL(cell)]:
|
||||||
|
//play('bullet_wall');
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onDestroy(entity:EntityType):Void {
|
||||||
|
switch entity {
|
||||||
|
case EntityType.TANK(_):
|
||||||
|
play('boom_bot');
|
||||||
|
case EntityType.BONUS(_):
|
||||||
|
play('bonus_get');
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,10 +9,12 @@ import ru.m.tankz.Type;
|
|||||||
class Bullet extends MobileEntity {
|
class Bullet extends MobileEntity {
|
||||||
public var playerId(default, null):PlayerId;
|
public var playerId(default, null):PlayerId;
|
||||||
public var tankId(default, null):Int;
|
public var tankId(default, null):Int;
|
||||||
|
public var tank(default, null):Tank;
|
||||||
public var config(default, null):BulletConfig;
|
public var config(default, null):BulletConfig;
|
||||||
|
|
||||||
public function new(tank:Tank) {
|
public function new(tank:Tank) {
|
||||||
this.playerId = tank.playerId;
|
this.playerId = tank.playerId;
|
||||||
|
this.tank = tank;
|
||||||
this.config = tank.config.bullet;
|
this.config = tank.config.bullet;
|
||||||
super(new Rectangle(0, 0, config.width, config.height), config.speed, Direction.RIGHT);
|
super(new Rectangle(0, 0, config.width, config.height), config.speed, Direction.RIGHT);
|
||||||
this.tankId = tank.id;
|
this.tankId = tank.id;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import ru.m.tankz.map.LevelMap;
|
|||||||
enum EntityChange {
|
enum EntityChange {
|
||||||
DEATH;
|
DEATH;
|
||||||
HIT;
|
HIT;
|
||||||
|
LIVE_UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user