[client] added ogg sounds

This commit is contained in:
2018-02-20 22:20:55 +03:00
parent 22e7965442
commit 8d3308d74a
25 changed files with 41 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
package ru.m.tankz;
import openfl.Assets;
import ru.m.tankz.sound.SoundManager;
import flash.events.KeyboardEvent;
import flash.text.Font;
@@ -91,6 +92,11 @@ class Client implements IConnectionHandler {
Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE);
Provider.setFactory(Game, DotaGame, DotaGame.TYPE);
L.d(TAG, 'resources');
for (resource in Assets.list()) {
L.d(TAG, '\t${resource}');
}
view.switcher.change(StartFrame.ID);
}

View File

@@ -54,6 +54,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
timer = new Timer(10);
timer.run = updateEngine;
state.text = stateString(game);
Provider.get(SoundManager).play('start');
}
private function stop():Void {

View File

@@ -37,7 +37,13 @@ class StartFrame extends VGroupView implements ViewBuilder implements StartFrame
}
public function onShow():Void {
classic_load.visible = Provider.get(SaveStorage).read(ClassicGame.TYPE) != null;
var save:GameSave = Provider.get(SaveStorage).read(ClassicGame.TYPE);
if (save != null) {
classic_load.visible = true;
classic_load.text = 'Load (Level ${save.state.level})';
} else {
classic_load.visible = false;
}
}
public function onPress(view:ButtonView):Void {

View File

@@ -2,19 +2,29 @@ package ru.m.tankz.sound;
import ru.m.tankz.core.EntityType;
import ru.m.tankz.engine.Engine;
import flash.media.Sound;
import openfl.media.Sound;
import openfl.utils.Assets;
class SoundManager implements EngineListener {
private static var TAG(default, never):String = 'SoundManager';
#if flash
private static var type:String = 'mp3';
#else
private static var type:String = 'ogg';
#end
public function new() {}
public function play(id:String):Void {
L.d(TAG, 'player: ${id}');
var sound:Sound = Assets.getSound('resources/sounds/${id}.mp3');
L.d(TAG, 'play: ${id}');
var sound:Sound = Assets.getSound('resources/sounds/${id}.${type}');
if (sound != null) {
sound.play();
} else {
L.w(TAG, 'Sound "${id}" not found');
}
}
public function onSpawn(entity:EntityType):Void {

View File

@@ -43,7 +43,7 @@ presets:
- {<<: *human, index: 0, color: 0xFFFF00}
- id: bot
spawnInterval: 3000
life: 20
life: 1
players:
- {<<: *bot, index: 0}
- {<<: *bot, index: 1}

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.

View File

@@ -0,0 +1,4 @@
#!/bin/bash
for file in *.mp3
do avconv -i "${file}" "`echo ${file%.mp3}.ogg`";
done

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.

View File

@@ -16,6 +16,7 @@ enum EntityChange {
DEATH;
HIT;
LIVE_UP;
TYPE;
}
@@ -54,6 +55,7 @@ class CollisionProcessor implements EngineListener {
if (!tank.protect.active) {
if (tank.config.downgrade != null) {
tank.config = engine.config.getTank(tank.config.downgrade);
engine.change(tank, EntityChange.TYPE);
} else if (tank.hits > 0) {
tank.hits--;
engine.change(tank, EntityChange.HIT);
@@ -138,6 +140,7 @@ class Engine implements ControlHandler {
case TankAction.UPGRADE:
if (tank.config.upgrade != null) {
tank.config = config.getTank(tank.config.upgrade);
change(tank, EntityChange.TYPE);
}
case TankAction.STOP:
tank.stop();

View File

@@ -178,6 +178,8 @@ class Game implements EngineListener {
tank.bonus = false;
spawnBonus();
}
case [EntityType.TANK(tank), EntityChange.TYPE]:
getPlayer(tank.playerId).state.tank = tank.config.type;
case _:
}
}
@@ -257,10 +259,11 @@ class Game implements EngineListener {
case 'star':
if (tank.config.upgrade != null) {
tank.config = config.getTank(tank.config.upgrade);
engine.change(tank, EntityChange.TYPE);
} else {
tank.hits++;
engine.change(tank, EntityChange.HIT);
}
engine.change(tank);
case 'grenade':
for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
engine.destroy(t);
@@ -291,6 +294,7 @@ class Game implements EngineListener {
for (team in teams) {
for (player in team.players) {
if (player.config.control == Control.HUMAN) {
player.state.life++;
save.addPlayerState(player.id, player.state);
}
}