[common] tanks spawn types
This commit is contained in:
@@ -11,6 +11,7 @@ class BotControl extends Control {
|
||||
|
||||
private var shotTimer:Timer;
|
||||
private var turnTimer:Timer;
|
||||
private var turnDelayTimer:Timer;
|
||||
|
||||
public function new(index:Int) {
|
||||
super({type:TYPE, index:index});
|
||||
@@ -18,22 +19,22 @@ class BotControl extends Control {
|
||||
|
||||
override public function onCollision(with:EntityType):Void {
|
||||
switch (with) {
|
||||
case EntityType.TANK(_): turn();
|
||||
case EntityType.CELL(_): turn();
|
||||
case EntityType.TANK(_): turnAfter(300);
|
||||
case EntityType.CELL(_): turnAfter(300);
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
override public function start():Void {
|
||||
//var tank = handler.entities.get(tankId);
|
||||
//action(TankAction.MOVE(tank.rect.direction));
|
||||
action(TankAction.MOVE(Direction.BOTTOM)); // ToDo: hardcode bot start direction
|
||||
if (handler == null) return;
|
||||
var tank = handler.entities.get(tankId);
|
||||
action(TankAction.MOVE(tank.rect.direction));
|
||||
if (shotTimer == null) {
|
||||
shotTimer = new Timer(1000);
|
||||
shotTimer.run = shot;
|
||||
}
|
||||
if (turnTimer == null) {
|
||||
turnTimer = new Timer(3000);
|
||||
turnTimer = new Timer(2000);
|
||||
turnTimer.run = turn;
|
||||
}
|
||||
}
|
||||
@@ -53,6 +54,17 @@ class BotControl extends Control {
|
||||
action(TankAction.SHOT);
|
||||
}
|
||||
|
||||
public function turnAfter(delay:Int):Void {
|
||||
if (turnDelayTimer == null) {
|
||||
turnDelayTimer = new Timer(delay);
|
||||
turnDelayTimer.run = function() {
|
||||
turnDelayTimer.stop();
|
||||
turnDelayTimer = null;
|
||||
turn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function turn():Void {
|
||||
action(TankAction.MOVE(randomDirection()));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package ru.m.tankz.config;
|
||||
|
||||
|
||||
typedef GameConfig = {
|
||||
var levels: Int;
|
||||
var friendlyFire:Bool;
|
||||
}
|
||||
|
||||
typedef SpawnPoint = {
|
||||
var type:String;
|
||||
var index:Int;
|
||||
@@ -41,6 +46,11 @@ typedef TankConfig = { > TankType,
|
||||
var speed:Float;
|
||||
var bullet:BulletConfig;
|
||||
var bullets:Int;
|
||||
var hits:Int;
|
||||
}
|
||||
|
||||
typedef TankSpawn = { > TankType,
|
||||
var rate: Float;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,13 +58,14 @@ typedef TeamConfig = {
|
||||
var id:String;
|
||||
var size:Int;
|
||||
var spawnInterval:Int;
|
||||
var tanks:Array<TankSpawn>;
|
||||
var points:Array<SpawnPoint>;
|
||||
}
|
||||
|
||||
|
||||
class Config {
|
||||
public var type(default, null):String;
|
||||
public var levels(default, null):Int;
|
||||
public var game(default, null):GameConfig;
|
||||
public var map(default, null):MapConfig;
|
||||
public var bricks(default, null):Array<BrickConfig>;
|
||||
public var tanks(default, null):Array<TankConfig>;
|
||||
@@ -64,9 +75,9 @@ class Config {
|
||||
private var tankMap:Map<String, Map<String, TankConfig>>;
|
||||
private var teamMap:Map<String, TeamConfig>;
|
||||
|
||||
public function new(type:String, levels:Int, map:MapConfig, bricks:Array<BrickConfig>, teams:Array<TeamConfig>, tanks:Array<TankConfig>) {
|
||||
public function new(type:String, game:GameConfig, map:MapConfig, bricks:Array<BrickConfig>, teams:Array<TeamConfig>, tanks:Array<TankConfig>) {
|
||||
this.type = type;
|
||||
this.levels = levels;
|
||||
this.game = game;
|
||||
this.map = map;
|
||||
this.bricks = bricks;
|
||||
this.teams = teams;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package ru.m.tankz.config;
|
||||
|
||||
import ru.m.tankz.game.ClassicGame;
|
||||
import yaml.Parser;
|
||||
import openfl.Assets;
|
||||
import yaml.Yaml;
|
||||
@@ -8,7 +7,7 @@ import ru.m.tankz.config.Config;
|
||||
|
||||
|
||||
typedef ConfigSource = {
|
||||
var levels:Int;
|
||||
var game:GameConfig;
|
||||
var map: MapConfig;
|
||||
var bricks: Array<BrickConfig>;
|
||||
var teams: Array<TeamConfig>;
|
||||
@@ -31,6 +30,6 @@ class ConfigBundle {
|
||||
tanks.push(item);
|
||||
}
|
||||
}
|
||||
return new Config(type, source.levels, source.map, source.bricks, source.teams, tanks);
|
||||
return new Config(type, source.game, source.map, source.bricks, source.teams, tanks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import ru.m.geom.Direction;
|
||||
class Tank extends MobileEntity {
|
||||
public var playerId(default, null):PlayerId;
|
||||
public var config(default, set):TankConfig;
|
||||
public var hits(default, default):Int;
|
||||
|
||||
private var bulletsCounter:Int = 0;
|
||||
|
||||
@@ -18,6 +19,7 @@ class Tank extends MobileEntity {
|
||||
super(new Rectangle(0, 0, config.width, config.height), config.speed, Direction.RIGHT);
|
||||
this.playerId = playerId;
|
||||
this.config = config;
|
||||
this.hits = config.hits;
|
||||
this.layer = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,16 @@ class CollisionProcessor implements EngineListener {
|
||||
public function onSpawn(entity:EntityType):Void {}
|
||||
|
||||
private function checkTankBullet(tank:Tank, bullet:Bullet):Bool {
|
||||
return tank.playerId.team != bullet.playerId.team;
|
||||
if (bullet.tankId == tank.id) return false;
|
||||
return engine.config.game.friendlyFire || tank.playerId.team != bullet.playerId.team;
|
||||
}
|
||||
|
||||
private function hitTank(tank:Tank):Void {
|
||||
if (tank.hits > 0) {
|
||||
tank.hits--;
|
||||
} else {
|
||||
engine.destroy(tank);
|
||||
}
|
||||
}
|
||||
|
||||
public function onCollision(entity:EntityType, with:EntityType):Void {
|
||||
@@ -42,7 +51,7 @@ class CollisionProcessor implements EngineListener {
|
||||
tank1.rect.lean(tank2.rect);
|
||||
case EntityType.BULLET(bullet2):
|
||||
if (checkTankBullet(tank1, bullet2)) {
|
||||
engine.destroy(tank1);
|
||||
hitTank(tank1);
|
||||
engine.destroy(bullet2);
|
||||
}
|
||||
case EntityType.EAGLE(eagle):
|
||||
@@ -55,7 +64,7 @@ class CollisionProcessor implements EngineListener {
|
||||
case EntityType.TANK(tank2):
|
||||
if (checkTankBullet(tank2, bullet1)) {
|
||||
engine.destroy(bullet1);
|
||||
engine.destroy(tank2);
|
||||
hitTank(tank2);
|
||||
}
|
||||
case EntityType.BULLET(bullet2):
|
||||
engine.destroy(bullet1);
|
||||
|
||||
@@ -59,7 +59,7 @@ class ClassicGame extends Game {
|
||||
override public function next():Option<GameState> {
|
||||
if (!state.teams[HUMAN].lose) {
|
||||
state.level++;
|
||||
if (state.level >= config.levels) state.level = 0;
|
||||
if (state.level >= config.game.levels) state.level = 0;
|
||||
state.teams[BOT].lose = false;
|
||||
state.teams[BOT].life = BOT_LIFE;
|
||||
for (ps in state.teams[HUMAN].players) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import haxe.ds.Option;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.game.GameState;
|
||||
|
||||
@@ -53,4 +54,10 @@ class DotaGame extends Game {
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
override public function next():Option<GameState> {
|
||||
state.level++;
|
||||
if (state.level >= config.game.levels) state.level = 0;
|
||||
return Option.Some(buildState(state.level, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +54,11 @@ class Game implements EngineListener {
|
||||
return teams.get(playerId.team).players[playerId.index];
|
||||
}
|
||||
|
||||
private function buildTank(playerId:PlayerId, config:TankConfig, point:SpawnPoint):Tank {
|
||||
var tank = new Tank(playerId, config);
|
||||
private function buildTank(playerId:PlayerId, point:SpawnPoint):Tank {
|
||||
var types:Array<TankSpawn> = teams[playerId.team].config.tanks;
|
||||
var type:TankSpawn = types[Math.floor(Math.random() * types.length)];
|
||||
var tankConfig:TankConfig = config.getTank(type.group, type.type);
|
||||
var tank = new Tank(playerId, tankConfig);
|
||||
applyPoint(tank, point);
|
||||
return tank;
|
||||
}
|
||||
@@ -114,7 +117,7 @@ class Game implements EngineListener {
|
||||
private function spawn(task:SpawnTask):Void {
|
||||
getPlayer(task.playerId).tankId = 0;
|
||||
if (trySpawn(task.playerId, true)) {
|
||||
var tank = buildTank(task.playerId, config.getTank(task.playerId.team, '0'), task.point);
|
||||
var tank = buildTank(task.playerId, task.point);
|
||||
var player:Player = getPlayer(task.playerId);
|
||||
engine.spawn(tank);
|
||||
player.tankId = tank.id;
|
||||
|
||||
Reference in New Issue
Block a user