[common] add tank weapon array

This commit is contained in:
2019-08-12 22:02:28 +03:00
parent 46f2abab05
commit 314f5a480c
11 changed files with 65 additions and 48 deletions

View File

@@ -7,3 +7,6 @@ indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
[*.yaml]
indent_size = 2

View File

@@ -4,3 +4,4 @@
* map packs (create in editor, import in game, save imported in local storage)
* improve bots
* save human state in classic game
* game config macro

View File

@@ -20,7 +20,7 @@ class HardBotControl extends BotControl {
shot();
}
case CELL(cell):
if (cell.layer == 2 && cell.armor > -1 && cell.armor <= tank.config.bullet.piercing) {
if (cell.layer == 2 && cell.armor > -1 && cell.armor <= tank.weapon.config.bullet.piercing) {
shot();
}
case EAGLE(eagle):

View File

@@ -48,13 +48,17 @@ typedef BulletConfig = {
var piercing:Int;
}
typedef WeaponConfig = {
var bullet:BulletConfig;
var count:Int;
}
typedef TankConfig = {
var type:TankType;
var width:Float;
var height:Float;
var speed:Float;
var bullet:BulletConfig;
var bullets:Int;
var weapons:Array<WeaponConfig>;
var skin:String;
@:optinal var hits:Int;
@:optinal var upgrade:TankType;

View File

@@ -17,6 +17,8 @@ class Tank extends MobileEntity {
public var protect(default, default):Bool;
public var freezing(default, default):Bool;
public var weapons(default, null):Array<Weapon>;
public var weapon(get, null):Weapon;
public var info(get, null):TankInfo;
public function new(id:Int, rect:Rectangle, playerId:PlayerId, config:TankConfig) {
@@ -28,6 +30,10 @@ class Tank extends MobileEntity {
this.layer = 1;
}
private function get_weapon():Weapon {
return weapons[0];
}
private function set_config(value:TankConfig):TankConfig {
var d = rect.direction;
rect = new Rectangle(rect.x, rect.y, value.width, value.height);
@@ -35,6 +41,7 @@ class Tank extends MobileEntity {
speed = value.speed;
config = value;
hits = config.hits;
weapons = config.weapons.map(function(weaponConfig) return new Weapon(weaponConfig));
return value;
}

View File

@@ -0,0 +1,12 @@
package ru.m.tankz.core;
import ru.m.tankz.config.Config;
class Weapon {
public var config(default, null):WeaponConfig;
public function new(config:WeaponConfig) {
this.config = config;
}
}

View File

@@ -58,7 +58,7 @@ class EntityBuilder {
public function buildBullet(point:Point, direction:Direction, playerId:PlayerId, type:TankType):Bullet {
var tankConfig = config.getTank(type);
var bulletConfig = tankConfig.bullet;
var bulletConfig = tankConfig.weapons[0].bullet;
var bullet = new Bullet(++entityId, new Rectangle(point.x - bulletConfig.width / 2, point.y - bulletConfig.height / 2, bulletConfig.width, bulletConfig.height, direction), playerId, bulletConfig);
return bullet;
}

View File

@@ -259,7 +259,7 @@ class GameRunner extends Game implements EngineListener {
case ACTION(tankId, SHOT):
var tank:Tank = cast engine.entities.get(tankId);
var player = getPlayer(tank.playerId);
if (!tank.freezing && player.bullets < tank.config.bullets) {
if (!tank.freezing && player.bullets < tank.weapon.config.count) {
var rect = tank.rect;
var point = rect.center.add(new Point(rect.width / 4 * rect.direction.x, rect.height / 4 * rect.direction.y));
var bullet = builder.buildBullet(point, rect.direction, player.id, tank.config.type);

View File

@@ -61,90 +61,83 @@ tanks:
width: 36
height: 36
speed: 2.5
bullet:
<<: *bullet
speed: 8.0
bullets: 1
skin: pa
weapons:
- bullet: {<<: *bullet, speed: 8.0}
count: 1
- type: human1
upgrade: human2
width: 40
height: 36
speed: 3.0
bullet:
<<: *bullet
speed: 8.5
bullets: 1
skin: pb
weapons:
- bullet: {<<: *bullet, speed: 8.5}
count: 1
- type: human2
upgrade: human3
width: 40
height: 36
speed: 3.0
bullet:
<<: *bullet
speed: 9.0
bullets: 2
skin: pc
weapons:
- bullet: {<<: *bullet, speed: 9.0}
count: 2
- type: human3
downgrade: human2
width: 42
height: 38
speed: 2.9
bullet:
<<: *bullet
speed: 9.0
piercing: 3
bullets: 2
skin: pd
weapons:
- bullet: {<<: *bullet, speed: 9.0, piercing: 3}
count: 2
- type: bot0
width: 38
height: 36
speed: 2.0
bullet:
<<: *bullet
speed: 7.0
bullets: 1
score: 100
skin: ba
weapons:
- bullet: {<<: *bullet, speed: 7.0}
count: 1
- type: bot1
width: 40
height: 36
speed: 4.0
bullet:
<<: *bullet
speed: 7.0
bullets: 1
score: 200
skin: bb
weapons:
- bullet: {<<: *bullet, speed: 7.0}
count: 1
- type: bot2
width: 38
height: 36
speed: 2.0
bullet:
<<: *bullet
speed: 9.0
bullets: 1
score: 300
skin: bc
weapons:
- bullet: {<<: *bullet, speed: 9.0}
count: 1
- type: bot3
width: 40
height: 36
speed: 1.8
bullet:
<<: *bullet
speed: 8.0
bullets: 1
score: 400
hits: 3
skin: bd
weapons:
- bullet: {<<: *bullet, speed: 8.0}
count: 1
bonuses:
- {score: 500, factory: freeze.team, type: clock, duration: 10}

View File

@@ -81,11 +81,10 @@ tanks:
width: 38
height: 36
speed: 2.3
bullet:
<<: *bullet
speed: 12.0
bullets: 2
score: 100
skin: pc
weapons:
- bullet: {<<: *bullet, speed: 12.0}
count: 2
bonuses: []

View File

@@ -88,23 +88,21 @@ tanks:
width: 38
height: 36
speed: 2.3
bullet:
<<: *bullet
speed: 12.0
bullets: 1
score: 100
skin: bc
weapons:
- bullet: {<<: *bullet, speed: 12.0}
count: 1
- type: fast
width: 40
height: 36
speed: 4.0
bullet:
<<: *bullet
speed: 8.0
bullets: 1
score: 100
skin: bb
weapons:
- bullet: {<<: *bullet, speed: 8.0}
count: 1
bonuses:
- {score: 100, factory: freeze.team, type: clock, duration: 10}