[render] bricks and cells from GameEvent
This commit is contained in:
@@ -32,7 +32,7 @@ class BotControl extends Control {
|
||||
shotTimer.stop();
|
||||
shotTimer = null;
|
||||
}
|
||||
//action(SHOT);
|
||||
action(SHOT);
|
||||
}
|
||||
|
||||
public function shot(delay:Int = 100):Void {
|
||||
|
||||
@@ -11,7 +11,16 @@ typedef TankInfo = {
|
||||
var bonus:Bool;
|
||||
}
|
||||
|
||||
typedef BrickInfo = {
|
||||
var id:Int;
|
||||
var x:Int;
|
||||
var y:Int;
|
||||
var rect:Rectangle;
|
||||
var type:BrickType;
|
||||
}
|
||||
|
||||
enum SpawnEvent {
|
||||
BRICK(bricks:Array<BrickInfo>);
|
||||
EAGLE(id:Int, rect:Rectangle, teamId:TeamId);
|
||||
TANK(id:Int, rect:Rectangle, playerId:PlayerId, info:TankInfo);
|
||||
BULLET(id:Int, rect:Rectangle, playerId:PlayerId, piercing:Int);
|
||||
@@ -34,7 +43,8 @@ enum DestroyEvent {
|
||||
TANK(id:Int, shot:Shot);
|
||||
BONUS(id:Int, shot:Shot);
|
||||
BULLET(id:Int);
|
||||
CELL(cellX:Int, cellY:Int, shot:Shot);
|
||||
CELL(id:Int, x:Int, y:Int, shot:Shot);
|
||||
BRICK(id:Int, shot:Shot);
|
||||
}
|
||||
|
||||
enum MoveEvent {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.map.Grid.GridCell;
|
||||
import ru.m.tankz.map.Brick;
|
||||
import haxe.ds.Option;
|
||||
import haxe.Timer;
|
||||
import haxework.signal.Signal;
|
||||
@@ -85,6 +87,16 @@ class GameRunner implements EngineListener implements GameListener {
|
||||
gameEventSignal.emit(GameEvent.SPAWN(EAGLE(eagle.id, eagle.rect, eagle.team)));
|
||||
}
|
||||
}
|
||||
var bricks = game.engine.map.bricks.map(function(item:Brick):BrickInfo {
|
||||
return {
|
||||
id: item.id,
|
||||
x: item.cellY,
|
||||
y: item.cellY,
|
||||
rect: item.rect,
|
||||
type: item.config.type,
|
||||
}
|
||||
});
|
||||
gameEventSignal.emit(GameEvent.SPAWN(BRICK(bricks)));
|
||||
gameEventSignal.emit(GameEvent.START(state));
|
||||
}
|
||||
|
||||
@@ -102,7 +114,7 @@ class GameRunner implements EngineListener implements GameListener {
|
||||
private function spawn(task:SpawnTask):Void {
|
||||
var tank = builder.buildTank(++entityId, task.point, task.playerId, task.tankType);
|
||||
game.engine.spawn(tank);
|
||||
gameEventSignal.emit(GameEvent.SPAWN(TANK(tank.id, tank.rect, tank.playerId, {type:tank.config.type, hits:tank.hits, bonus:tank.bonus})));
|
||||
gameEventSignal.emit(GameEvent.SPAWN(TANK(tank.id, tank.rect.clone(), tank.playerId, {type:tank.config.type, hits:tank.hits, bonus:tank.bonus})));
|
||||
}
|
||||
|
||||
private function checkComplete():Void {
|
||||
@@ -241,7 +253,7 @@ class GameRunner implements EngineListener implements GameListener {
|
||||
}
|
||||
var bonus = builder.buildBonus(++entityId, point, type);
|
||||
game.engine.spawn(bonus);
|
||||
gameEventSignal.emit(GameEvent.SPAWN(BONUS(bonus.id, bonus.rect, bonus.config.type)));
|
||||
gameEventSignal.emit(GameEvent.SPAWN(BONUS(bonus.id, bonus.rect.clone(), bonus.config.type)));
|
||||
}
|
||||
|
||||
private inline function alienTank(team:TeamId):Tank->Bool {
|
||||
@@ -331,7 +343,7 @@ class GameRunner implements EngineListener implements GameListener {
|
||||
bullet.tank = tank;
|
||||
bullet.move(bullet.rect.direction);
|
||||
game.engine.spawn(bullet);
|
||||
gameEventSignal.emit(GameEvent.SPAWN(BULLET(bullet.id, bullet.rect, bullet.playerId, bullet.config.piercing)));
|
||||
gameEventSignal.emit(GameEvent.SPAWN(BULLET(bullet.id, bullet.rect.clone(), bullet.playerId, bullet.config.piercing)));
|
||||
}
|
||||
case GameEvent.ACTION(tankId, MOVE(direction)):
|
||||
game.engine.move(tankId, direction);
|
||||
@@ -396,15 +408,17 @@ class GameRunner implements EngineListener implements GameListener {
|
||||
var cells = game.engine.map.grid.getCells(side.setLength(game.engine.map.grid.cellWidth * 3));
|
||||
for (cell in cells) {
|
||||
if (cell.armor > 0) {
|
||||
var shot = buildShot(bullet);
|
||||
if (cell.armor == bullet.config.piercing) {
|
||||
game.engine.destroyCell(cell.cellX, cell.cellY);
|
||||
gameEventSignal.emit(GameEvent.DESTROY(CELL(cell.cellX, cell.cellY, buildShot(bullet))));
|
||||
var brick = game.engine.map.getBrick(cell.position);
|
||||
gameEventSignal.emit(GameEvent.DESTROY(CELL(brick.id, cell.cellX - brick.cellX * 2, cell.cellY - brick.cellY * 2, shot)));
|
||||
} else if (cell.armor < bullet.config.piercing) {
|
||||
var brick = game.engine.map.getBrick(cell.position);
|
||||
for (cell in brick.cells) {
|
||||
game.engine.destroyCell(cell.cellX, cell.cellY);
|
||||
gameEventSignal.emit(GameEvent.DESTROY(CELL(cell.cellX, cell.cellY, buildShot(bullet))));
|
||||
}
|
||||
gameEventSignal.emit(GameEvent.DESTROY(BRICK(brick.id, shot)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user