[common] add GameEvent.MOVE

This commit is contained in:
2019-05-15 15:15:07 +03:00
parent 686c659c84
commit cd7dd1984b
8 changed files with 41 additions and 22 deletions

View File

@@ -5,7 +5,7 @@ project_user: holop
deploy_user: "{{ project_user }}" deploy_user: "{{ project_user }}"
deploy_project: "{{ project_name }}" deploy_project: "{{ project_name }}"
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git" deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
deploy_repo_version: staging deploy_repo_version: master
deploy_npm: yes deploy_npm: yes
service_name: "{{ project_name }}" service_name: "{{ project_name }}"

View File

@@ -175,6 +175,14 @@ class Render extends SpriteView implements IRender {
showScore(rect.center, shot.score); showScore(rect.center, shot.score);
} }
} }
case MOVE(TANK(id, position)) | MOVE(BULLET(id, position)):
if (items.exists(id)) {
var item = items[id];
item.value.rect.x = position.x;
item.value.rect.y = position.y;
item.value.rect.direction = position.direction;
item.update();
}
case _: case _:
} }
} }

View File

@@ -24,6 +24,7 @@ import ru.m.tankz.game.record.GameRecord;
@yield return read(id); @yield return read(id);
} catch (error:Dynamic) { } catch (error:Dynamic) {
L.w("RecordStorage", 'read ', error); L.w("RecordStorage", 'read ', error);
delete(id);
} }
} }
} }

View File

@@ -1,7 +1,7 @@
package ru.m.tankz.view; package ru.m.tankz.view;
import haxework.view.frame.FrameSwitcher; import haxework.view.frame.FrameSwitcher;
import haxework.view.list.ListView.IListItemView; import haxework.view.list.ListView;
import haxework.view.list.VListView; import haxework.view.list.VListView;
import haxework.view.VGroupView; import haxework.view.VGroupView;
import ru.m.tankz.game.record.GameRecord; import ru.m.tankz.game.record.GameRecord;
@@ -18,7 +18,7 @@ import ru.m.tankz.storage.RecordStorage;
public function onShow():Void { public function onShow():Void {
var data = Lambda.array(recordStorage); var data = Lambda.array(recordStorage);
data.sort(function(a:GameRecord, b:GameRecord) return Std.int(a.date.getTime() - b.date.getTime())); data.sort(function(a:GameRecord, b:GameRecord) return Std.int(b.date.getTime() - a.date.getTime()));
this.data.data = data; this.data.data = data;
} }

View File

@@ -114,6 +114,7 @@ import ru.m.tankz.map.LevelMap;
var d = entity.rect.center.x - cell.rect.center.x; var d = entity.rect.center.x - cell.rect.center.x;
entity.rect.x += d / Math.abs(d); entity.rect.x += d / Math.abs(d);
} }
moveSignal.emit(entityType);
} }
break; break;
} }

View File

@@ -1,6 +1,5 @@
package ru.m.tankz.game; package ru.m.tankz.game;
import haxe.Timer;
import ru.m.geom.Point; import ru.m.geom.Point;
import ru.m.tankz.bundle.IConfigBundle; import ru.m.tankz.bundle.IConfigBundle;
import ru.m.tankz.config.Config; import ru.m.tankz.config.Config;
@@ -28,7 +27,6 @@ import ru.m.tankz.Type;
public var state(default, null):GameState; public var state(default, null):GameState;
private var builder:EntityBuilder; private var builder:EntityBuilder;
private var timer:Timer;
@:provide var configBundle:IConfigBundle; @:provide var configBundle:IConfigBundle;
@@ -53,10 +51,6 @@ import ru.m.tankz.Type;
} }
} }
private function update():Void {
engine.update();
}
private function applyPosition(entity:Entity, position:Position):Void { private function applyPosition(entity:Entity, position:Position):Void {
entity.rect.center = new Point(position.x, position.y); entity.rect.center = new Point(position.x, position.y);
if (position.direction != null) { if (position.direction != null) {
@@ -76,15 +70,9 @@ import ru.m.tankz.Type;
switch event { switch event {
case GameEvent.START(state): case GameEvent.START(state):
this.state = state; this.state = state;
timer = new Timer(10);
timer.run = update;
case GameEvent.COMPLETE(state, winnerId): case GameEvent.COMPLETE(state, winnerId):
this.state = state; this.state = state;
this.winner = winnerId; this.winner = winnerId;
if (timer != null) {
timer.stop();
timer = null;
}
case GameEvent.SPAWN(EAGLE(id, position, teamId)): case GameEvent.SPAWN(EAGLE(id, position, teamId)):
var eagle = builder.buildEagle(id, teamId); var eagle = builder.buildEagle(id, teamId);
applyPosition(eagle, position); applyPosition(eagle, position);
@@ -133,10 +121,6 @@ import ru.m.tankz.Type;
} }
public function dispose():Void { public function dispose():Void {
if (timer != null) {
timer.stop();
timer = null;
}
gameEventSignal.dispose(); gameEventSignal.dispose();
engine.dispose(); engine.dispose();
} }

View File

@@ -36,6 +36,11 @@ enum DestroyEvent {
CELL(cellX:Int, cellY:Int, shot:Shot); CELL(cellX:Int, cellY:Int, shot:Shot);
} }
enum MoveEvent {
TANK(id:Int, position:Position);
BULLET(id:Int, position:Position);
}
enum ChangeEvent { enum ChangeEvent {
PLAYER_SCORE(playerId:PlayerId, value:Int); PLAYER_SCORE(playerId:PlayerId, value:Int);
PLAYER_LIFE(playerId:PlayerId, value:Int); PLAYER_LIFE(playerId:PlayerId, value:Int);
@@ -46,6 +51,7 @@ enum ChangeEvent {
enum GameEvent { enum GameEvent {
START(state:GameState); START(state:GameState);
SPAWN(event:SpawnEvent); SPAWN(event:SpawnEvent);
MOVE(event:MoveEvent);
HIT(event:HitEvent); HIT(event:HitEvent);
DESTROY(event:DestroyEvent); DESTROY(event:DestroyEvent);
CHANGE(event:ChangeEvent); CHANGE(event:ChangeEvent);

View File

@@ -5,7 +5,6 @@ import haxe.Timer;
import haxework.signal.Signal; import haxework.signal.Signal;
import ru.m.geom.Line; import ru.m.geom.Line;
import ru.m.geom.Point; import ru.m.geom.Point;
import ru.m.tankz.config.Config;
import ru.m.tankz.control.Control; import ru.m.tankz.control.Control;
import ru.m.tankz.control.Controller; import ru.m.tankz.control.Controller;
import ru.m.tankz.control.IControlFactory; import ru.m.tankz.control.IControlFactory;
@@ -26,6 +25,7 @@ class GameRunner implements EngineListener implements GameListener {
private var game(default, null):IGame; private var game(default, null):IGame;
private var gameEventSignal(get, null):Signal<GameEvent>; private var gameEventSignal(get, null):Signal<GameEvent>;
private var entityId:Int; private var entityId:Int;
private var timer:Timer;
public function new(game:IGame) { public function new(game:IGame) {
this.game = game; this.game = game;
@@ -38,7 +38,15 @@ class GameRunner implements EngineListener implements GameListener {
return game.gameEventSignal; return game.gameEventSignal;
} }
private function update():Void {
game.engine.update();
}
public function dispose():Void { public function dispose():Void {
if (timer != null) {
timer.stop();
timer = null;
}
game.disconnect(this); game.disconnect(this);
game.engine.disconnect(this); game.engine.disconnect(this);
} }
@@ -188,6 +196,13 @@ class GameRunner implements EngineListener implements GameListener {
} }
public function onMove(entity:EntityType):Void { public function onMove(entity:EntityType):Void {
switch entity {
case TANK(tank):
gameEventSignal.emit(GameEvent.MOVE(TANK(tank.id, {x:tank.rect.x, y:tank.rect.y, direction:tank.rect.direction})));
case BULLET(bullet):
gameEventSignal.emit(GameEvent.MOVE(BULLET(bullet.id, {x:bullet.rect.x, y:bullet.rect.y, direction:bullet.rect.direction})));
case _:
}
} }
public function onDestroy(entity:EntityType):Void { public function onDestroy(entity:EntityType):Void {
@@ -270,9 +285,13 @@ class GameRunner implements EngineListener implements GameListener {
public function onGameEvent(event:GameEvent):Void { public function onGameEvent(event:GameEvent):Void {
switch event { switch event {
case GameEvent.START(_): case GameEvent.START(_):
timer = new Timer(10);
timer.run = update;
case GameEvent.COMPLETE(_, _): case GameEvent.COMPLETE(_, _):
if (timer != null) {
timer.stop();
timer = null;
}
case GameEvent.ACTION(tankId, SHOT): case GameEvent.ACTION(tankId, SHOT):
var tank:Tank = cast game.engine.entities.get(tankId); var tank:Tank = cast game.engine.entities.get(tankId);
var player = game.getPlayer(tank.playerId); var player = game.getPlayer(tank.playerId);