[common] add ice brick logic

This commit is contained in:
2019-08-06 17:47:00 +03:00
parent de64e2813e
commit cc151322d8
8 changed files with 42 additions and 21 deletions

View File

@@ -1,6 +1,7 @@
0.17.0 0.17.0
------ ------
* Improved `ResultFrame` * Improved `ResultFrame`
* Improved bonuses
0.16.0 0.16.0
------ ------

View File

@@ -1,8 +1,8 @@
* **shovel** bonus with armor bricks
* bonuses in dota/death mod * bonuses in dota/death mod
* tanks and bullets speed balancing * tanks and bullets speed balancing
* network game series * network game series
* map packs (create in editor, import in game, save imported in local storage) * map packs (create in editor, import in game, save imported in local storage)
* update bots * improve bots
* improve bonuses system
* save human state in classic game * save human state in classic game
* [engine] process ice brick
* screen gamepad as default on mobile

View File

@@ -5,8 +5,9 @@ import ru.m.tankz.control.Controller;
import ru.m.tankz.Type; import ru.m.tankz.Type;
typedef GameConfig = { typedef GameConfig = {
var levels: Int; var levels:Int;
var friendlyFire:Bool; var friendlyFire:Bool;
@:optional var alignToGrid:Bool;
} }
typedef SpawnPoint = { typedef SpawnPoint = {

View File

@@ -60,8 +60,19 @@ import ru.m.tankz.map.LevelMap;
} }
public function stop(entityId:Int):Void { public function stop(entityId:Int):Void {
if (entities.exists(entityId)) { var entity:MobileEntity = getEntity(entityId);
cast(entities.get(entityId), MobileEntity).stop(); 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 entityType:EntityType = EntityTypeResolver.of(ent);
var entity:MobileEntity = cast ent; var entity:MobileEntity = cast ent;
/*if (Std.is(entity, Tank)) { if (config.game.alignToGrid) {
if (entity.rect.direction.x != 0) { if (Std.is(entity, Tank)) {
entity.rect.y = Math.round((entity.rect.y + entity.rect.height / 2) / map.cellHeight) * map.cellHeight - entity.rect.height / 2; 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) { if (entity.mx != 0 || entity.my != 0) {
var side:Line = entity.rect.getSide(entity.rect.direction.reverse()); 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; 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); moveSignal.emit(entityType, true);
} }
break; break;
} }
@@ -126,7 +139,7 @@ import ru.m.tankz.map.LevelMap;
entity.rect.x += entity.mx * (d / 30); entity.rect.x += entity.mx * (d / 30);
entity.rect.y += entity.my * (d / 30); entity.rect.y += entity.my * (d / 30);
moveSignal.emit(entityType); moveSignal.emit(entityType, true);
if (withCollision != null) { if (withCollision != null) {
collisionSignal.emit(entityType, withCollision); collisionSignal.emit(entityType, withCollision);

View File

@@ -16,7 +16,7 @@ interface IEngine {
public var spawnSignal(default, null):Signal1<EntityType>; public var spawnSignal(default, null):Signal1<EntityType>;
public var collisionSignal(default, null):Signal2<EntityType, EntityType>; public var collisionSignal(default, null):Signal2<EntityType, EntityType>;
public var moveSignal(default, null):Signal1<EntityType>; public var moveSignal(default, null):Signal2<EntityType, Bool>;
public var destroySignal(default, null):Signal1<EntityType>; public var destroySignal(default, null):Signal1<EntityType>;
public function getEntity<T:Entity>(entityId:Int):T; public function getEntity<T:Entity>(entityId:Int):T;
@@ -45,6 +45,6 @@ interface IEngine {
interface EngineListener { interface EngineListener {
public function onSpawn(entity:EntityType):Void; public function onSpawn(entity:EntityType):Void;
public function onCollision(entity:EntityType, with: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; public function onDestroy(entity:EntityType):Void;
} }

View File

@@ -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 { switch entity {
case TANK(tank): case TANK(tank):
emitTankMove(tank); emitTankMove(tank, move);
case BULLET(bullet): case BULLET(bullet):
gameEventSignal.emit(MOVE(BULLET(bullet.id, {x:bullet.rect.x, y:bullet.rect.y, direction:bullet.rect.direction}))); gameEventSignal.emit(MOVE(BULLET(bullet.id, {x:bullet.rect.x, y:bullet.rect.y, direction:bullet.rect.direction})));
case _: case _:
@@ -271,7 +271,6 @@ class GameRunner extends Game implements EngineListener {
case ACTION(tankId, MOVE(direction)): case ACTION(tankId, MOVE(direction)):
engine.move(tankId, direction); engine.move(tankId, direction);
case ACTION(tankId, STOP): case ACTION(tankId, STOP):
gameEventSignal.emit(STOP(TANK(tankId)));
engine.stop(tankId); engine.stop(tankId);
case SPAWN(EAGLE(id, rect, teamId)): case SPAWN(EAGLE(id, rect, teamId)):
var team = getTeam(teamId); var team = getTeam(teamId);

View File

@@ -19,8 +19,11 @@ class GameUtil {
return function(tank:Tank):Bool return team != tank.playerId.team; 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}))); 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 { public static inline function emitTankChange(game:IGame, tank:Tank):Void {

View File

@@ -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"