[common] weapon delay param

This commit is contained in:
2019-10-07 17:29:20 +03:00
parent e7d031db58
commit d670722674
18 changed files with 74 additions and 33 deletions

View File

@@ -11,12 +11,8 @@
* A star
* game config validate
* additional weapon
* mine
* display count
* bonus ammo
* screen gamepad (button enabled, count label)
* ui:
* game frame layouts
* fix:
* ice brick fix
* shot delay

View File

@@ -122,16 +122,22 @@ class AppTheme extends Theme {
var red:Color = 0xff0000;
register(new Style("result.winner", [
"skin.border.color" => green,
"skin.border.alpha" => 0.5,
"skin.border.thickness" => 5,
"skin.round" => 10,
], ["light"]));
register(new Style("result.loser", [
"skin.border.color" => red,
"skin.border.alpha" => 0.5,
"skin.border.thickness" => 5,
"skin.round" => 10,
], ["light"]));
register(new Style("player.winner", [
"skin.background.alpha" => 0.1,
"skin.background.alpha" => 0.2,
"skin.background.color" => green,
]));
register(new Style("player.loser", [
"skin.background.alpha" => 0.1,
"skin.background.alpha" => 0.2,
"skin.background.color" => red,
]));

View File

@@ -81,7 +81,8 @@ class HumanControl extends Control {
case TankAction.SHOT(weapon):
if (on) {
if (!shotTimers.exists(weapon)) {
var timer = new Timer(300);
// ToDo: weapon.config.delay
var timer = new Timer(350);
timer.run = shooter(weapon);
timer.run();
shotTimers.set(weapon, timer);

View File

@@ -150,8 +150,10 @@ class Render extends SpriteView implements IRender {
entryLayer.addChild(item.view);
item.update();
playAnimate(item.rect.center, AnimateBundle.tankSpawn());
case SPAWN(BULLET(id, rect, playerId, skin)):
var item = new BulletRenderItem(rect, skin);
case SPAWN(BULLET(id, rect, playerId, skin, color)):
var item = new BulletRenderItem(rect);
item.color = color;
item.skin = skin;
items.set(id, item);
entryLayer.addChild(item.view);
item.update();

View File

@@ -1,20 +1,26 @@
package ru.m.tankz.render.item;
import haxework.color.Color;
import haxework.view.utils.BitmapUtil;
import ru.m.geom.Rectangle;
class BulletRenderItem extends BitmapRenderItem {
public var color(default, default):Null<Color>;
public var skin(default, set):String;
public function new(rect:Rectangle, skin:String) {
public function new(rect:Rectangle) {
super(rect);
this.skin = skin;
move(rect.position);
}
private function set_skin(value:String):String {
if (skin != value) {
skin = value;
image = RenderUtil.bulletImage(skin);
var image = RenderUtil.bulletImage(skin);
if (color != null) {
image = BitmapUtil.colorize(image, color);
}
this.image = image;
}
return skin;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

@@ -113,7 +113,8 @@ abstract Rectangle(Array<Float>) {
}
public function intersection2(line:Line):Bool {
return contain(line.point1) || contain(line.point2);
// ToDo: line to rect?
return contain(line.point1) || contain(line.point2) || contain(line.center);
}
public function lean(rect:Rectangle):Void {

View File

@@ -55,6 +55,7 @@ typedef WeaponConfig = {
var bullet:BulletConfig;
var count:Int;
var queue:Int;
var delay:Int;
}
typedef TankConfig = {

View File

@@ -1,5 +1,6 @@
package ru.m.tankz.core;
import haxework.color.Color;
import ru.m.geom.Direction;
import ru.m.geom.Rectangle;
import ru.m.tankz.config.Config;
@@ -11,6 +12,7 @@ class Bullet extends MobileEntity {
public var tank(default, default):Tank;
public var weapon(default, default):Weapon;
public var config(default, null):BulletConfig;
public var color(default, default):Color;
public function new(id:Int, rect:Rectangle, playerId:PlayerId, config:BulletConfig) {
super(id, rect, config.speed, Direction.RIGHT);

View File

@@ -4,7 +4,6 @@ import haxework.color.Color;
import ru.m.geom.Direction;
import ru.m.geom.Rectangle;
import ru.m.tankz.config.Config;
import ru.m.tankz.game.GameEvent;
import ru.m.tankz.Type;
class Tank extends MobileEntity {

View File

@@ -1,5 +1,6 @@
package ru.m.tankz.core;
import ru.m.tankz.engine.ITicker;
import ru.m.tankz.config.Config;
class Weapon {
@@ -9,21 +10,29 @@ class Weapon {
public var queue(default, default):Int;
public var available(get, null):Bool;
private var lastShotTime:Int;
public function new(config:WeaponConfig) {
this.config = config;
this.count = this.config.count;
this.queue = 0;
this.lastShotTime = 0;
}
private function get_available():Bool {
return (count < 0 || count > 0) && (config.queue < 0 || queue < config.queue);
}
public function use():Void {
queue++;
if (count > 0) {
count--;
public function use(ticker:ITicker):Bool {
if (available && ticker.time > lastShotTime + config.delay) {
lastShotTime = ticker.time;
queue++;
if (count > 0) {
count--;
}
return true;
}
return false;
}
public function release():Void {

View File

@@ -56,6 +56,7 @@ import ru.m.tankz.map.LevelMap;
public function move(entityId:Int, direction:Direction):Void {
if (entities.exists(entityId)) {
ticker.cancel('slide.tank.${entityId}');
cast(entities.get(entityId), MobileEntity).move(direction);
}
}

View File

@@ -50,7 +50,7 @@ class EventUtil {
}
public static function buildBulletSpawn(bullet:Bullet):GameEvent {
return SPAWN(BULLET(bullet.id, bullet.rect.clone(), bullet.playerId, bullet.config.skin));
return SPAWN(BULLET(bullet.id, bullet.rect.clone(), bullet.playerId, bullet.config.skin, bullet.color));
}
public static function buildMove(entity:Entity):GameEvent {

View File

@@ -1,5 +1,6 @@
package ru.m.tankz.game;
import haxework.color.Color;
import ru.m.geom.Position;
import ru.m.geom.Rectangle;
import ru.m.tankz.config.Config;
@@ -29,7 +30,7 @@ enum SpawnEvent {
BRICK(bricks:Array<BrickInfo>);
EAGLE(id:Int, rect:Rectangle, teamId:TeamId);
TANK(id:Int, rect:Rectangle, playerId:PlayerId, info:TankInfo);
BULLET(id:Int, rect:Rectangle, playerId:PlayerId, skin:String);
BULLET(id:Int, rect:Rectangle, playerId:PlayerId, skin:String, color:Color);
BONUS(id:Int, rect:Rectangle, type:BonusType);
}

View File

@@ -283,16 +283,22 @@ class GameRunner extends Game implements EngineListener {
case ACTION(tankId, SHOT(index)):
var tank:Tank = cast engine.entities.get(tankId);
var player = getPlayer(tank.playerId);
var weapon:Weapon = tank.weapons.length > index - 1 ? tank.weapons[index] : null;
if (weapon != null && !tank.freezing && weapon.available) {
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, weapon.config.bullet);
bullet.tank = tank;
bullet.weapon = weapon;
bullet.move(bullet.rect.direction);
engine.spawn(bullet);
gameEventSignal.emit(EventUtil.buildBulletSpawn(bullet));
if (!tank.freezing) {
var weapon:Weapon = tank.weapons.length > index - 1 ? tank.weapons[index] : null;
if (weapon != null && weapon.use(ticker)) {
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, weapon.config.bullet);
// ToDo: mine color
if (bullet.config.skin == "mine") {
bullet.color = config.getColor(player.id);
}
bullet.tank = tank;
bullet.weapon = weapon;
bullet.move(bullet.rect.direction);
engine.spawn(bullet);
gameEventSignal.emit(EventUtil.buildBulletSpawn(bullet));
}
}
case ACTION(tankId, MOVE(direction)):
engine.move(tankId, direction);
@@ -305,9 +311,6 @@ class GameRunner extends Game implements EngineListener {
var player = getPlayer(playerId);
player.tankId = id;
player.state.tank = info;
case SPAWN(BULLET(id, _, _, _)):
var bullet:Bullet = engine.getEntity(id);
bullet.weapon.use();
case CHANGE(BRICK(id, type)):
engine.map.bricksById[id].config = config.getBrick(type);
case CHANGE(TANK(id, type, hits, bonus, boat)):

View File

@@ -71,6 +71,7 @@ tanks:
- bullet: {<<: *bullet, speed: 8.0}
queue: 1
count: -1
delay: 300
- type: human1
upgrade: human2
@@ -83,6 +84,7 @@ tanks:
- bullet: {<<: *bullet, speed: 8.5}
queue: 1
count: -1
delay: 300
- type: human2
upgrade: human3
@@ -94,6 +96,7 @@ tanks:
- bullet: {<<: *bullet, speed: 9.0}
queue: 2
count: -1
delay: 300
- type: human3
downgrade: human2
@@ -105,6 +108,7 @@ tanks:
- bullet: {<<: *bullet, speed: 9.0, piercing: 3, skin: piercing}
queue: 2
count: -1
delay: 300
- type: bot0
width: 38
@@ -116,6 +120,7 @@ tanks:
- bullet: {<<: *bullet, speed: 7.0}
queue: 1
count: -1
delay: 300
- type: bot1
width: 40
@@ -127,6 +132,7 @@ tanks:
- bullet: {<<: *bullet, speed: 7.0}
queue: 1
count: -1
delay: 300
- type: bot2
width: 38
@@ -138,6 +144,7 @@ tanks:
- bullet: {<<: *bullet, speed: 9.0}
queue: 1
count: -1
delay: 300
- type: bot3
width: 40
@@ -150,6 +157,7 @@ tanks:
- bullet: {<<: *bullet, speed: 8.0}
queue: 1
count: -1
delay: 300
bonuses:
- {score: 500, factory: freeze.team, type: clock, duration: 10}

View File

@@ -81,11 +81,14 @@ tanks:
- bullet: {width: 12, height: 12, speed: 12.0, piercing: 1, layer: 2, skin: normal}
queue: 2
count: -1
delay: 300
- bullet: {width: 16, height: 16, speed: 4.0, piercing: 4, layer: 4, skin: rocket}
queue: 1
count: 3
delay: 300
- bullet: {width: 20, height: 20, speed: 0.0, piercing: 1, layer: 0, skin: mine}
queue: -1
count: 3
delay: 300
bonuses: []

View File

@@ -97,6 +97,7 @@ tanks:
- bullet: {<<: *bullet, speed: 12.0}
queue: 1
count: -1
delay: 300
- type: fast
width: 40
@@ -108,6 +109,7 @@ tanks:
- bullet: {<<: *bullet, speed: 8.0}
queue: 1
count: -1
delay: 300
bonuses:
- {score: 100, factory: freeze.team, type: clock, duration: 10}