[common] build bonus with EntityBuilder
This commit is contained in:
@@ -25,7 +25,7 @@ import ru.m.tankz.map.LevelMap;
|
||||
public function new(config:Config) {
|
||||
this.config = config;
|
||||
map = new LevelMap(config.map);
|
||||
entities = new Map<Int, Entity>();
|
||||
entities = new Map();
|
||||
time = Date.now().getTime();
|
||||
}
|
||||
|
||||
@@ -62,10 +62,10 @@ import ru.m.tankz.map.LevelMap;
|
||||
var entity:MobileEntity = cast ent;
|
||||
|
||||
/*if (Std.is(entity, Tank)) {
|
||||
if (entity.direction.x != 0) {
|
||||
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.direction.y != 0) {
|
||||
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;
|
||||
}
|
||||
}*/
|
||||
@@ -152,7 +152,11 @@ import ru.m.tankz.map.LevelMap;
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
entities = new Map();
|
||||
entities = null;
|
||||
map = null;
|
||||
spawnSignal.dispose();
|
||||
collisionSignal.dispose();
|
||||
moveSignal.dispose();
|
||||
}
|
||||
|
||||
public function iterTanks(filter:Tank->Bool):Iterator<Tank> {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.core.Bonus;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import ru.m.tankz.core.Eagle;
|
||||
import ru.m.tankz.core.Tank;
|
||||
import ru.m.tankz.Type;
|
||||
@@ -35,5 +36,11 @@ class EntityBuilder {
|
||||
var bullet = new Bullet(playerId, tankConfig.bullet);
|
||||
return bullet;
|
||||
}
|
||||
|
||||
public function buildBonus(type:BonusType):Bonus {
|
||||
var bonusConfig = config.getBonus(type);
|
||||
var bonus = new Bonus(bonusConfig);
|
||||
return bonus;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,10 @@ import ru.m.tankz.Type;
|
||||
bullet.rect.center = rect.center.add(new Point(rect.width / 4 * rect.direction.x, rect.height / 4 * rect.direction.y));
|
||||
bullet.move(rect.direction);
|
||||
engine.spawn(bullet);
|
||||
case GameEvent.SPAWN(BONUS(bonus)):
|
||||
case GameEvent.SPAWN(BONUS(type, point)):
|
||||
var bonus = builder.buildBonus(type);
|
||||
bonus.rect.x = point.x * config.map.cellWidth;
|
||||
bonus.rect.y = point.y * config.map.cellHeight;
|
||||
engine.spawn(bonus);
|
||||
case GameEvent.DESTROY(TANK(tank, who, wherewith, score)):
|
||||
engine.destroy(tank.id);
|
||||
|
||||
@@ -13,7 +13,7 @@ enum SpawnEvent {
|
||||
EAGLE(teamId:TeamId, point:SpawnPoint);
|
||||
TANK(playerId:PlayerId, type:TankType, point:SpawnPoint);
|
||||
BULLET(playerId:PlayerId);
|
||||
BONUS(bonus:Bonus);
|
||||
BONUS(type:BonusType, point:{x:Int, y:Int});
|
||||
}
|
||||
|
||||
enum HitEvent {
|
||||
|
||||
@@ -193,12 +193,13 @@ class GameRunner implements EngineListener implements GameListener {
|
||||
|
||||
}
|
||||
|
||||
private function spawnBonus(?type:BonusType):Void {
|
||||
var bonusConfig:BonusConfig = type != null ? game.config.getBonus(type) : game.config.bonuses[Math.floor(Math.random() * game.config.bonuses.length)];
|
||||
var bonus = new Bonus(bonusConfig);
|
||||
bonus.rect.x = Math.round(Math.random() * game.engine.map.width / game.engine.map.cellWidth) * game.engine.map.cellWidth;
|
||||
bonus.rect.y = Math.round(Math.random() * game.engine.map.height/ game.engine.map.cellHeight) * game.engine.map.cellHeight;
|
||||
gameEventSignal.emit(GameEvent.SPAWN(BONUS(bonus)));
|
||||
private function spawnBonus():Void {
|
||||
var type = game.config.bonuses[Math.floor(Math.random() * game.config.bonuses.length)].type;
|
||||
var point = {
|
||||
x: Math.floor(Math.random() * (game.engine.map.gridWidth - 1)),
|
||||
y: Math.floor(Math.random() * (game.engine.map.gridHeight - 1)),
|
||||
}
|
||||
gameEventSignal.emit(GameEvent.SPAWN(BONUS(type, point)));
|
||||
}
|
||||
|
||||
private inline function alienTank(team:TeamId):Tank->Bool {
|
||||
|
||||
@@ -163,7 +163,7 @@ presets:
|
||||
- {<<: *team_human}
|
||||
- id: bot
|
||||
spawnInterval: 3000
|
||||
life: 1
|
||||
life: 10
|
||||
players:
|
||||
- {<<: *bot, index: 0, control: bot-stupid}
|
||||
- {<<: *bot, index: 1, control: bot-stupid}
|
||||
|
||||
Reference in New Issue
Block a user