[common] weapon queue & bullet layer

This commit is contained in:
2019-08-13 21:53:47 +03:00
parent 48f9c433e2
commit 636be8611f
10 changed files with 61 additions and 31 deletions

View File

@@ -27,6 +27,8 @@ views:
text: DeathMatch
- $type: haxework.view.SpriteView
style: line
geometry.width: 250
geometry.margin: [0, 10]
- $type: haxework.view.form.ButtonView
style: button.menu
+onPress: ~switcher.change('record')

View File

@@ -46,11 +46,13 @@ typedef BulletConfig = {
var height:Float;
var speed:Float;
var piercing:Int;
var layer:Int;
}
typedef WeaponConfig = {
var bullet:BulletConfig;
var count:Int;
var queue:Int;
}
typedef TankConfig = {

View File

@@ -16,7 +16,7 @@ class Bullet extends MobileEntity {
super(id, rect, config.speed, Direction.RIGHT);
this.playerId = playerId;
this.config = config;
this.layer = 2;
this.layer = this.config.layer;
}
private inline function get_tankId():Int {

View File

@@ -6,9 +6,27 @@ class Weapon {
public var config(default, null):WeaponConfig;
public var count(default, default):Int;
public var queue(default, default):Int;
public var available(get, null):Bool;
public function new(config:WeaponConfig) {
this.config = config;
this.count = 0;
this.count = this.config.count;
this.queue = 0;
}
private function get_available():Bool {
return (count < 0 || count > 0) && queue < config.queue;
}
public function use():Void {
queue++;
if (count > 0) {
count--;
}
}
public function release():Void {
queue--;
}
}

View File

@@ -263,7 +263,7 @@ class GameRunner extends Game implements EngineListener {
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.count < weapon.config.count) {
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);
@@ -286,7 +286,7 @@ class GameRunner extends Game implements EngineListener {
player.state.tank = info;
case SPAWN(BULLET(id, _, _, _)):
var bullet:Bullet = engine.getEntity(id);
bullet.weapon.count++;
bullet.weapon.use();
case CHANGE(BRICK(id, type)):
engine.map.bricksById[id].config = config.getBrick(type);
case DESTROY(EAGLE(id, shot)):
@@ -350,7 +350,7 @@ class GameRunner extends Game implements EngineListener {
engine.destroy(id);
case DESTROY(BULLET(id)):
var bullet:Bullet = engine.getEntity(id);
bullet.weapon.count--;
bullet.weapon.release();
var side:Line = bullet.rect.getSide(bullet.rect.direction.reverse()).move(
// ToDo: move
new Point(bullet.rect.direction.x * 5, bullet.rect.direction.y * 5)

View File

@@ -35,7 +35,7 @@ class GridCell {
}
public inline function getCollision(layer:Int):Bool {
return this.layer >= layer && this.layer < 3;
return this.layer == -1 || (this.layer >= layer && this.layer < 3);
}
}
@@ -59,7 +59,7 @@ class Grid {
}
private function buildBorderCell(cellX:Int, cellY:Int):GridCell {
return new GridCell(cellX, cellY, cellWidth, cellHeight, 2, -1);
return new GridCell(cellX, cellY, cellWidth, cellHeight, -1, -1);
}
public function getCells(line:Line):Array<GridCell> {

View File

@@ -10,7 +10,7 @@ map:
height: 26
bricks:
- {type: border, index: -1, layer: 2, armor: -1}
- {type: border, index: -1, layer: -1, armor: -1}
- {type: none, index: 0, layer: 0, armor: 0}
- {type: ace, index: 1, layer: 0, armor: 0}
- {type: bush, index: 2, layer: 3, armor: 0}
@@ -54,6 +54,7 @@ bullet: &bullet
height: 12
speed: 0
piercing: 1
layer: 2
tanks:
- type: human0
@@ -65,7 +66,8 @@ tanks:
skin: pa
weapons:
- bullet: {<<: *bullet, speed: 8.0}
count: 1
queue: 1
count: -1
- type: human1
upgrade: human2
@@ -76,7 +78,8 @@ tanks:
skin: pb
weapons:
- bullet: {<<: *bullet, speed: 8.5}
count: 1
queue: 1
count: -1
- type: human2
upgrade: human3
@@ -86,7 +89,8 @@ tanks:
skin: pc
weapons:
- bullet: {<<: *bullet, speed: 9.0}
count: 2
queue: 2
count: -1
- type: human3
downgrade: human2
@@ -96,7 +100,8 @@ tanks:
skin: pd
weapons:
- bullet: {<<: *bullet, speed: 9.0, piercing: 3}
count: 2
queue: 2
count: -1
- type: bot0
width: 38
@@ -106,7 +111,8 @@ tanks:
skin: ba
weapons:
- bullet: {<<: *bullet, speed: 7.0}
count: 1
queue: 1
count: -1
- type: bot1
width: 40
@@ -116,7 +122,8 @@ tanks:
skin: bb
weapons:
- bullet: {<<: *bullet, speed: 7.0}
count: 1
queue: 1
count: -1
- type: bot2
width: 38
@@ -126,7 +133,8 @@ tanks:
skin: bc
weapons:
- bullet: {<<: *bullet, speed: 9.0}
count: 1
queue: 1
count: -1
- type: bot3
width: 40
@@ -137,7 +145,8 @@ tanks:
skin: bd
weapons:
- bullet: {<<: *bullet, speed: 8.0}
count: 1
queue: 1
count: -1
bonuses:
- {score: 500, factory: freeze.team, type: clock, duration: 10}

View File

@@ -10,7 +10,7 @@ map:
height: 20
bricks:
- {type: border, index: -1, layer: 2, armor: -1}
- {type: border, index: -1, layer: -1, armor: -1}
- {type: none, index: 0, layer: 0, armor: 0}
- {type: ace, index: 1, layer: 0, armor: 0}
- {type: bush, index: 2, layer: 3, armor: 0}
@@ -70,12 +70,6 @@ points:
- {team: eta, type: tank, index: 0, direction: right, x: 4, y: 2}
- {team: theta, type: tank, index: 0, direction: right, x: 6, y: 2}
bullet: &bullet
width: 12
height: 12
speed: 0
piercing: 1
tanks:
- type: default
width: 38
@@ -84,9 +78,11 @@ tanks:
score: 100
skin: pc
weapons:
- bullet: {<<: *bullet, speed: 12.0}
count: 2
- bullet: {<<: *bullet, speed: 4.0, width: 16, height: 16, piercing: 4}
count: 1
- bullet: {width: 12, height: 12, speed: 12.0, piercing: 1, layer: 2}
queue: 2
count: -1
- bullet: {width: 16, height: 16, speed: 4.0, piercing: 4, layer: 4}
queue: 1
count: 3
bonuses: []

View File

@@ -10,7 +10,7 @@ map:
height: 30
bricks:
- {type: border, index: -1, layer: 2, armor: -1}
- {type: border, index: -1, layer: -1, armor: -1}
- {type: none, index: 0, layer: 0, armor: 0}
- {type: ace, index: 1, layer: 0, armor: 0}
- {type: bush, index: 2, layer: 3, armor: 0}
@@ -82,6 +82,7 @@ bullet: &bullet
height: 12
speed: 0
piercing: 1
layer: 2
tanks:
- type: slow
@@ -92,7 +93,8 @@ tanks:
skin: bc
weapons:
- bullet: {<<: *bullet, speed: 12.0}
count: 1
queue: 1
count: -1
- type: fast
width: 40
@@ -102,7 +104,8 @@ tanks:
skin: bb
weapons:
- bullet: {<<: *bullet, speed: 8.0}
count: 1
queue: 1
count: -1
bonuses:
- {score: 100, factory: freeze.team, type: clock, duration: 10}