[common] multiple weapon support

This commit is contained in:
2019-08-13 16:41:57 +03:00
parent 314f5a480c
commit 48f9c433e2
19 changed files with 120 additions and 86 deletions

View File

@@ -1,7 +1,5 @@
package ru.m.tankz;
import haxework.color.Color;
import haxework.view.utils.DrawUtil.FillType;
import flash.text.TextFormatAlign;
import haxework.color.Color;
import haxework.view.geometry.Box;
@@ -10,6 +8,7 @@ import haxework.view.geometry.SizeValue;
import haxework.view.geometry.VAlign;
import haxework.view.theme.ITheme;
import haxework.view.theme.Theme;
import haxework.view.utils.DrawUtil;
import openfl.Assets;
import ru.m.skin.ButtonSVGSkin;

View File

@@ -20,7 +20,7 @@ class HumanControl extends Control {
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
private var moveQueue:Array<Direction>;
private var shotTimer:Timer;
private var shotTimers:Map<Int, Timer>;
public function new(playerId:PlayerId, controlIndex:Int) {
super(playerId);
@@ -34,6 +34,7 @@ class HumanControl extends Control {
binding.get(bind.device).set(bind.action, action);
}
moveQueue = [];
shotTimers = new Map();
}
public function hasDevice(device:DeviceType):Bool {
@@ -60,10 +61,10 @@ class HumanControl extends Control {
super.stop();
bus.signal.disconnect(onDeviceAction);
moveQueue = [];
if (shotTimer != null) {
shotTimer.stop();
shotTimer = null;
for (timer in shotTimers) {
timer.stop();
}
shotTimers = new Map();
}
public function toggleAction(action:TankAction, on:Bool):Void {
@@ -77,17 +78,18 @@ class HumanControl extends Control {
moveQueue.remove(direction);
}
updateMove();
case TankAction.SHOT:
case TankAction.SHOT(weapon):
if (on) {
if (shotTimer == null) {
shotTimer = new Timer(300);
shotTimer.run = shot;
shot();
if (!shotTimers.exists(weapon)) {
var timer = new Timer(300);
timer.run = shooter(weapon);
timer.run();
shotTimers.set(weapon, timer);
}
} else {
if (shotTimer != null) {
shotTimer.stop();
shotTimer = null;
if (shotTimers.exists(weapon)) {
shotTimers.get(weapon).stop();
shotTimers.remove(weapon);
}
}
case TankAction.STOP:
@@ -107,7 +109,9 @@ class HumanControl extends Control {
}
}
private function shot():Void {
action(SHOT);
private function shooter(weapon:Int):Void -> Void {
return function():Void {
action(SHOT(weapon));
}
}
}

View File

@@ -20,7 +20,7 @@ class RenderUtil {
}
public static function bulletImage(piercing:Int = 0):BitmapData {
var type = piercing > 0 ? 'piercing' : 'normal';
var type = piercing > 1 ? 'piercing' : 'normal';
return Assets.getBitmapData('resources/image/bullet/${type}.png');
}
}

View File

@@ -24,6 +24,8 @@ class BitmapRenderItem extends RenderItem {
if (image != value) {
image = value;
bitmap.bitmapData = image;
bitmap.width = rect.width;
bitmap.height = rect.height;
}
return image;
}

View File

@@ -11,7 +11,7 @@ import ru.m.tankz.control.Control;
class SettingsStorage extends SharedObjectStorage {
private static inline var VERSION = 3;
private static inline var VERSION = 4;
public function new() {
super('settings_${VERSION}');
@@ -36,7 +36,8 @@ class SettingsStorage extends SharedObjectStorage {
MOVE(Direction.LEFT) => {device: device, action: DIRECTION(Direction.LEFT)},
MOVE(Direction.BOTTOM) => {device: device, action: DIRECTION(Direction.BOTTOM)},
MOVE(Direction.RIGHT) => {device: device, action: DIRECTION(Direction.RIGHT)},
SHOT => {device: device, action: KEY(0)},
SHOT(0) => {device: device, action: KEY(0)},
SHOT(1) => {device: device, action: KEY(1)},
];
}
@@ -46,7 +47,8 @@ class SettingsStorage extends SharedObjectStorage {
MOVE(Direction.LEFT) => null,
MOVE(Direction.BOTTOM) => null,
MOVE(Direction.RIGHT) => null,
SHOT => null,
SHOT(0) => null,
SHOT(1) => null,
];
}
@@ -60,14 +62,16 @@ class SettingsStorage extends SharedObjectStorage {
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)},
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.S)},
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.D)},
SHOT => {device: KEYBOARD, action: KEY(Keyboard.SPACE)},
SHOT(0) => {device: KEYBOARD, action: KEY(Keyboard.SPACE)},
SHOT(1) => {device: KEYBOARD, action: KEY(Keyboard.Q)},
],
1 => [
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.UP)},
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.LEFT)},
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.DOWN)},
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.RIGHT)},
SHOT => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_0)},
SHOT(0) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_0)},
SHOT(1) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_DECIMAL)},
],
];
}

View File

@@ -2,35 +2,41 @@
views:
- $type: haxework.view.group.VGroupView
style: container
layout.margin: 10
overflow.y: scroll
views:
- $type: haxework.view.form.LabelView
text: Tank'z
style: font
font.size: 100
geometry.margin.bottom: 30
- $type: haxework.view.form.ButtonView
style: button.menu
+onPress: ~startGame('classic')
text: Classic
- $type: haxework.view.form.ButtonView
style: button.menu
+onPress: ~startGame('dota')
text: DotA
- $type: haxework.view.form.ButtonView
style: button.menu
+onPress: ~startGame('death')
text: DeathMatch
- $type: haxework.view.form.ButtonView
style: button.menu
+onPress: ~switcher.change('record')
text: Records
- id: network
$type: haxework.view.form.ButtonView
style: button.menu
+onPress: ~startNetwork()
text: Network
- $type: haxework.view.group.VGroupView
layout.margin: 10
layout.hAlign: center
views:
- $type: haxework.view.form.LabelView
text: Tank'z
style: font
font.size: 100
geometry.margin.bottom: 30
- $type: haxework.view.form.ButtonView
style: button.menu
+onPress: ~startGame('classic')
text: Classic
- $type: haxework.view.form.ButtonView
style: button.menu
+onPress: ~startGame('dota')
text: DotA
- $type: haxework.view.form.ButtonView
style: button.menu
+onPress: ~startGame('death')
text: DeathMatch
- $type: haxework.view.SpriteView
style: line
- $type: haxework.view.form.ButtonView
style: button.menu
+onPress: ~switcher.change('record')
text: Records
visible: false
- id: network
$type: haxework.view.form.ButtonView
style: button.menu
+onPress: ~startNetwork()
text: Network
- $type: haxework.view.form.LabelView
geometry.hAlign: right
geometry.vAlign: top
@@ -42,23 +48,23 @@ views:
style: panel
layout.margin: 10
views:
- id: settings
$type: haxework.view.form.ButtonView
style: button.settings
+onPress: ~switcher.change('settings')
- $type: haxework.view.SpriteView
geometry.width: 50%
- id: username
$type: haxework.view.form.LabelView
style: text
- id: login
$type: haxework.view.form.ButtonView
style: button.login
+onPress: ~login()
- id: logout
$type: haxework.view.form.ButtonView
style: button.logout
+onPress: ~logout()
visible: false
- $type: haxework.view.SpriteView
geometry.width: 50%
- id: settings
$type: haxework.view.form.ButtonView
style: button.settings
+onPress: ~switcher.change('settings')
- $type: haxework.view.SpriteView
geometry.width: 50%
- id: username
$type: haxework.view.form.LabelView
style: text
- id: login
$type: haxework.view.form.ButtonView
style: button.login
+onPress: ~login()
- id: logout
$type: haxework.view.form.ButtonView
style: button.logout
+onPress: ~logout()
visible: false
- $type: haxework.view.SpriteView
geometry.width: 50%

View File

@@ -43,6 +43,7 @@ class ViewUtil {
public static function toActionLabel(action:TankAction):String {
return switch (action) {
case MOVE(d): 'MOVE_$d';
case SHOT(w): 'SHOT_$w';
case x: '$x';
}
}

View File

@@ -33,9 +33,15 @@ class SmartActionAreaBuilder implements IActionAreaBuilder {
DIRECTION(Direction.RIGHT),
new Rectangle(padding + size, height - size * 1.5 - padding, size, size)
));
// key 0
areas.push(new CircleActionArea(
KEY(0),
new Circle(width - size * 1 - padding, height - size * 1 - padding, size / 2)
new Circle(width - size * 1 - padding, height - size * 0.5 - padding, size / 2)
));
// key 1
areas.push(new CircleActionArea(
KEY(1),
new Circle(width - size * 1 - padding, height - size * 1.5 - padding, size / 2)
));
return areas;
}