From cc151322d82ef844f613a98420b2ed1356aa0697 Mon Sep 17 00:00:00 2001 From: shmyga Date: Tue, 6 Aug 2019 17:47:00 +0300 Subject: [PATCH] [common] add ice brick logic --- CHANGELOG.md | 1 + WORK.md | 6 ++-- src/common/haxe/ru/m/tankz/config/Config.hx | 3 +- src/common/haxe/ru/m/tankz/engine/Engine.hx | 35 +++++++++++++------ src/common/haxe/ru/m/tankz/engine/IEngine.hx | 4 +-- src/common/haxe/ru/m/tankz/game/GameRunner.hx | 5 ++- src/common/haxe/ru/m/tankz/game/GameUtil.hx | 5 ++- .../level/classic/standard/level036.txt | 4 +++ 8 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 src/common/level/classic/standard/level036.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 442fc3a..a6c5e06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 0.17.0 ------ * Improved `ResultFrame` +* Improved bonuses 0.16.0 ------ diff --git a/WORK.md b/WORK.md index 0ff95a3..23b8700 100644 --- a/WORK.md +++ b/WORK.md @@ -1,8 +1,8 @@ -* **shovel** bonus with armor bricks * bonuses in dota/death mod * tanks and bullets speed balancing * network game series * map packs (create in editor, import in game, save imported in local storage) -* update bots -* improve bonuses system +* improve bots * save human state in classic game +* [engine] process ice brick +* screen gamepad as default on mobile diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index e670dbb..dbe4adf 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -5,8 +5,9 @@ import ru.m.tankz.control.Controller; import ru.m.tankz.Type; typedef GameConfig = { - var levels: Int; + var levels:Int; var friendlyFire:Bool; + @:optional var alignToGrid:Bool; } typedef SpawnPoint = { diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index 6036b71..d2b1269 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -60,8 +60,19 @@ import ru.m.tankz.map.LevelMap; } public function stop(entityId:Int):Void { - if (entities.exists(entityId)) { - cast(entities.get(entityId), MobileEntity).stop(); + var entity:MobileEntity = getEntity(entityId); + if (entity != null) { + var center = entity.rect.center; + var brick = map.getPointBrick(center); + if (brick.config.type == "ace") { + ticker.emit(function() { + entity.stop(); + moveSignal.emit(EntityTypeResolver.of(entity), false); + }, 300, 'slide.tank.${entity.id}'); + } else { + entity.stop(); + moveSignal.emit(EntityTypeResolver.of(entity), false); + } } } @@ -72,14 +83,16 @@ import ru.m.tankz.map.LevelMap; var entityType:EntityType = EntityTypeResolver.of(ent); var entity:MobileEntity = cast ent; - /*if (Std.is(entity, Tank)) { - if (entity.rect.direction.x != 0) { - entity.rect.y = Math.round((entity.rect.y + entity.rect.height / 2) / map.cellHeight) * map.cellHeight - entity.rect.height / 2; + if (config.game.alignToGrid) { + if (Std.is(entity, Tank)) { + if (entity.rect.direction.x != 0) { + entity.rect.y = Math.round((entity.rect.y + entity.rect.height / 2) / map.cellHeight) * map.cellHeight - entity.rect.height / 2; + } + if (entity.rect.direction.y != 0) { + entity.rect.x = Math.round((entity.rect.x + entity.rect.width / 2) / map.cellWidth) * map.cellWidth - entity.rect.width / 2; + } } - if (entity.rect.direction.y != 0) { - entity.rect.x = Math.round((entity.rect.x + entity.rect.width / 2) / map.cellWidth) * map.cellWidth - entity.rect.width / 2; - } - }*/ + } if (entity.mx != 0 || entity.my != 0) { var side:Line = entity.rect.getSide(entity.rect.direction.reverse()); @@ -107,7 +120,7 @@ import ru.m.tankz.map.LevelMap; var d = entity.rect.center.x - cell.rect.center.x; entity.rect.x += d / Math.abs(d); } - moveSignal.emit(entityType); + moveSignal.emit(entityType, true); } break; } @@ -126,7 +139,7 @@ import ru.m.tankz.map.LevelMap; entity.rect.x += entity.mx * (d / 30); entity.rect.y += entity.my * (d / 30); - moveSignal.emit(entityType); + moveSignal.emit(entityType, true); if (withCollision != null) { collisionSignal.emit(entityType, withCollision); diff --git a/src/common/haxe/ru/m/tankz/engine/IEngine.hx b/src/common/haxe/ru/m/tankz/engine/IEngine.hx index 030706b..a4e7a92 100644 --- a/src/common/haxe/ru/m/tankz/engine/IEngine.hx +++ b/src/common/haxe/ru/m/tankz/engine/IEngine.hx @@ -16,7 +16,7 @@ interface IEngine { public var spawnSignal(default, null):Signal1; public var collisionSignal(default, null):Signal2; - public var moveSignal(default, null):Signal1; + public var moveSignal(default, null):Signal2; public var destroySignal(default, null):Signal1; public function getEntity(entityId:Int):T; @@ -45,6 +45,6 @@ interface IEngine { interface EngineListener { public function onSpawn(entity:EntityType):Void; public function onCollision(entity:EntityType, with:EntityType):Void; - public function onMove(entity:EntityType):Void; + public function onMove(entity:EntityType, move:Bool):Void; public function onDestroy(entity:EntityType):Void; } diff --git a/src/common/haxe/ru/m/tankz/game/GameRunner.hx b/src/common/haxe/ru/m/tankz/game/GameRunner.hx index d800060..0c6dd8c 100644 --- a/src/common/haxe/ru/m/tankz/game/GameRunner.hx +++ b/src/common/haxe/ru/m/tankz/game/GameRunner.hx @@ -205,10 +205,10 @@ class GameRunner extends Game implements EngineListener { } } - public function onMove(entity:EntityType):Void { + public function onMove(entity:EntityType, move:Bool):Void { switch entity { case TANK(tank): - emitTankMove(tank); + emitTankMove(tank, move); case BULLET(bullet): gameEventSignal.emit(MOVE(BULLET(bullet.id, {x:bullet.rect.x, y:bullet.rect.y, direction:bullet.rect.direction}))); case _: @@ -271,7 +271,6 @@ class GameRunner extends Game implements EngineListener { case ACTION(tankId, MOVE(direction)): engine.move(tankId, direction); case ACTION(tankId, STOP): - gameEventSignal.emit(STOP(TANK(tankId))); engine.stop(tankId); case SPAWN(EAGLE(id, rect, teamId)): var team = getTeam(teamId); diff --git a/src/common/haxe/ru/m/tankz/game/GameUtil.hx b/src/common/haxe/ru/m/tankz/game/GameUtil.hx index 9d3501b..50e7435 100644 --- a/src/common/haxe/ru/m/tankz/game/GameUtil.hx +++ b/src/common/haxe/ru/m/tankz/game/GameUtil.hx @@ -19,8 +19,11 @@ class GameUtil { return function(tank:Tank):Bool return team != tank.playerId.team; } - public static inline function emitTankMove(game:IGame, tank:Tank):Void { + public static inline function emitTankMove(game:IGame, tank:Tank, move:Bool = true):Void { game.gameEventSignal.emit(MOVE(TANK(tank.id, {x:tank.rect.x, y:tank.rect.y, direction:tank.rect.direction}))); + if (!move) { + game.gameEventSignal.emit(STOP(TANK(tank.id))); + } } public static inline function emitTankChange(game:IGame, tank:Tank):Void { diff --git a/src/common/level/classic/standard/level036.txt b/src/common/level/classic/standard/level036.txt new file mode 100644 index 0000000..bf98c67 --- /dev/null +++ b/src/common/level/classic/standard/level036.txt @@ -0,0 +1,4 @@ +name: Ice test +points: [{direction: right, index: -1, x: 12, y: 24, team: human, type: eagle}, {direction: top, index: 0, x: 8, y: 24, team: human, type: tank}, {direction: top, index: 1, x: 16, y: 24, team: human, type: tank}, {direction: bottom, index: -1, x: 0, y: 0, team: bot, type: tank}, {direction: bottom, index: -2, x: 12, y: 0, team: bot, type: tank}, {direction: bottom, index: -3, x: 24, y: 0, team: bot, type: tank}] +size: null +data: "0000000000000000000000000000000000000000000000000000444433444444444444443344444444334444444444444433444400000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111001111111111111111111111000011111111111111111111110000111111111111111111111100001111111111111111111111000000111111111111111111000000001111111111111111110000000000000000000000000000000000000000000000000000000011001111111111111111110011110011111111111111111100110000000000000000000000000000000000000000000000000000110011000005555000001100111100110000050050000011001100000000000500500000000000"