Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a1ed498bf5 | |||
| 41c5610f9a | |||
| 5c57454998 | |||
| a7effef412 | |||
| dd1014e230 | |||
| 89ac9fd225 | |||
| 3096fba7c5 | |||
| baf696a3e1 | |||
| 5daf4fafc7 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tankz",
|
||||
"version": "0.5.0",
|
||||
"version": "0.6.0",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"ansi-colors": "^1.0.1",
|
||||
|
||||
17
src/client/haxe/ru/m/draw/BitmapUtil.hx
Normal file
@@ -0,0 +1,17 @@
|
||||
package ru.m.draw;
|
||||
|
||||
import flash.geom.ColorTransform;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.display.BitmapData;
|
||||
|
||||
|
||||
class BitmapUtil {
|
||||
|
||||
public static function colorize(data: BitmapData, color: Color):BitmapData {
|
||||
if (color.zero) return data;
|
||||
var result = data.clone();
|
||||
var transform = new ColorTransform(color.red / 255, color.green / 255, color.blue / 255, 1, 0, 0, 0, 0);
|
||||
result.colorTransform(new Rectangle(0, 0, result.width, result.height), transform);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
47
src/client/haxe/ru/m/draw/Color.hx
Normal file
@@ -0,0 +1,47 @@
|
||||
package ru.m.draw;
|
||||
|
||||
abstract Color(Int) {
|
||||
public var alpha(get, never):Int;
|
||||
public var red(get, never):Int;
|
||||
public var green(get, never):Int;
|
||||
public var blue(get, never):Int;
|
||||
public var zero(get, never):Bool;
|
||||
|
||||
public inline function new(value:Int) {
|
||||
this = value;
|
||||
}
|
||||
|
||||
private inline function get_alpha():Int {
|
||||
return (this >> 24) & 255;
|
||||
}
|
||||
|
||||
private inline function get_red():Int {
|
||||
return (this >> 16) & 255;
|
||||
}
|
||||
|
||||
private inline function get_green():Int {
|
||||
return (this >> 8) & 255;
|
||||
}
|
||||
|
||||
private inline function get_blue():Int {
|
||||
return this & 255;
|
||||
}
|
||||
|
||||
private inline function get_zero():Bool {
|
||||
return this == 0;
|
||||
}
|
||||
|
||||
@:from
|
||||
static public inline function fromInt(value:Int):Color {
|
||||
return new Color(value);
|
||||
}
|
||||
|
||||
@:from
|
||||
static public inline function fromString(value:String):Color {
|
||||
return new Color(Std.parseInt('0x${value.split('#').pop()}'));
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
return 'Color(${red},${green},${blue})';
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
package ru.m.tankz.control;
|
||||
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.control.Control;
|
||||
import haxe.Timer;
|
||||
import ru.m.geom.Direction;
|
||||
import flash.events.FocusEvent;
|
||||
import flash.ui.Keyboard;
|
||||
import flash.events.KeyboardEvent;
|
||||
import flash.Lib;
|
||||
import flash.ui.Keyboard;
|
||||
import haxe.Timer;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
typedef KeyBinding = Map<Int, TankAction>;
|
||||
|
||||
|
||||
class HumanControl extends Control {
|
||||
|
||||
private var keyBinding:KeyBinding;
|
||||
@@ -44,7 +43,7 @@ class HumanControl extends Control {
|
||||
case _:
|
||||
}
|
||||
if (event.keyCode == Keyboard.U) {
|
||||
action(TankAction.LEVEL_UP(1));
|
||||
action(TankAction.UPGRADE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,11 @@ class Render extends SpriteView implements EngineListener {
|
||||
items.set(eagle.key, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
case EntityType.BONUS(bonus):
|
||||
var item = new BonusItem(bonus);
|
||||
items.set(bonus.key, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
case _:
|
||||
}
|
||||
}
|
||||
@@ -136,6 +141,11 @@ class Render extends SpriteView implements EngineListener {
|
||||
items.get(eagle.key).redraw();
|
||||
playTankBoom(eagle.rect.center);
|
||||
}
|
||||
case EntityType.BONUS(bonus):
|
||||
if (items.exists(bonus.key)) {
|
||||
entryLayer.removeChild(items.get(bonus.key).view);
|
||||
items.remove(bonus.key);
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import ru.m.tankz.control.Control;
|
||||
import flash.display.Sprite;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.tankz.core.Eagle;
|
||||
import openfl.display.BitmapData;
|
||||
import ru.m.draw.Color;
|
||||
import ru.m.tankz.core.Bonus;
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Shape;
|
||||
import flash.display.Sprite;
|
||||
import openfl.Assets;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.draw.BitmapUtil;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import ru.m.tankz.map.Brick;
|
||||
import openfl.Assets;
|
||||
import ru.m.tankz.core.Eagle;
|
||||
import ru.m.tankz.core.Tank;
|
||||
import flash.display.Bitmap;
|
||||
import ru.m.tankz.map.Brick;
|
||||
|
||||
|
||||
typedef TRectangle = {
|
||||
var rect(default, null):Rectangle;
|
||||
}
|
||||
|
||||
|
||||
class RenderItem<T:TRectangle, D:DisplayObject> {
|
||||
|
||||
public var value(default, null):T;
|
||||
@@ -121,6 +123,19 @@ class BrickItem extends RenderItem<Brick, Shape> {
|
||||
}
|
||||
|
||||
|
||||
class AnimateItem<T:TRectangle> extends RenderItem<T, Animate> {
|
||||
|
||||
public function new(value:T) {
|
||||
super(value);
|
||||
view = new Animate();
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
view.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TankItem extends RenderItem<Tank, Sprite> {
|
||||
|
||||
private var type:String;
|
||||
@@ -131,50 +146,24 @@ class TankItem extends RenderItem<Tank, Sprite> {
|
||||
public function new(value:Tank) {
|
||||
super(value);
|
||||
view = new Sprite();
|
||||
if (value.playerId.type == Control.HUMAN) {
|
||||
view.addChild(buildHumanMarkView(value));
|
||||
}
|
||||
tankView = new Animate();
|
||||
view.addChild(tankView);
|
||||
redraw();
|
||||
}
|
||||
|
||||
private static function buildHumanMarkView(tank:Tank):DisplayObject {
|
||||
var view = new Shape();
|
||||
view.graphics.beginFill(0x00aa00);
|
||||
view.graphics.lineStyle(2, 0x00ff00);
|
||||
view.graphics.drawCircle(0, 0, 23);
|
||||
view.graphics.endFill();
|
||||
view.x = tank.rect.width / 2;
|
||||
view.y = tank.rect.height / 2;
|
||||
view.alpha = 0.2;
|
||||
return view;
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
tankView.frames = getFrames().map(function(s) return Assets.getBitmapData(s));
|
||||
var colors:Array<Color> = [value.color, value.bonus ? 0xff00aa : value.color];
|
||||
var frames = [for (frame in getFrames()) BitmapUtil.colorize(Assets.getBitmapData(frame), colors.shift())];
|
||||
tankView.frames = [
|
||||
frames[0], frames[0], frames[0],
|
||||
frames[1], frames[1], frames[1],
|
||||
];
|
||||
}
|
||||
|
||||
private function getFrames():Array<String> {
|
||||
var team = value.playerId.team;
|
||||
var group = value.config.group;
|
||||
var index = value.playerId.index;
|
||||
if (team == 'radiant') {
|
||||
index = 0;
|
||||
}
|
||||
if (team == 'dire') {
|
||||
index = 1;
|
||||
}
|
||||
if (team == 'human' || team == 'radiant' || team == 'dire') {
|
||||
group = 'player';
|
||||
}
|
||||
if (team == 'bot') {
|
||||
index = value.hits;
|
||||
}
|
||||
return [
|
||||
'resources/images/tank/${group}/tank_${group.charAt(0)}${value.config.type}_${index}-0.png',
|
||||
'resources/images/tank/${group}/tank_${group.charAt(0)}${value.config.type}_${index}-1.png',
|
||||
];
|
||||
var frame0 = 'resources/image/tank/${value.config.skin}-0.png';
|
||||
var frame1 = 'resources/image/tank/${value.config.skin}-1.png';
|
||||
return [frame1, frame0];
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
@@ -214,3 +203,19 @@ class EagleItem extends BitmapItem<Eagle> {
|
||||
return 'resources/images/eagle/eagle-${destoyed ? 1 : 0}.png';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class BonusItem extends AnimateItem<Bonus> {
|
||||
|
||||
public function new(value:Bonus) {
|
||||
super(value);
|
||||
redraw();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
var image = Assets.getBitmapData('resources/image/bonus/${value.bonusType}.png');
|
||||
var empty = new BitmapData(image.width, image.height, true, 0x00000000);
|
||||
view.frames = [for (i in 0...15) image].concat([for (i in 0...15) empty]);
|
||||
view.playing = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package ru.m.tankz.view.frames;
|
||||
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.frame.IFrameSwitcher;
|
||||
import haxework.gui.VGroupView;
|
||||
import haxework.gui.ViewBuilder;
|
||||
import haxework.provider.Provider;
|
||||
import ru.m.tankz.game.ClassicGame;
|
||||
import ru.m.tankz.game.DotaGame;
|
||||
import haxework.gui.frame.IFrameSwitcher;
|
||||
import haxework.provider.Provider;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.ViewBuilder;
|
||||
import haxework.gui.VGroupView;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
interface StartFrameLayout {
|
||||
@@ -19,7 +19,6 @@ interface StartFrameLayout {
|
||||
var dota_2p_vs(default, null):ButtonView;
|
||||
}
|
||||
|
||||
|
||||
@:template("layout/frames/start.json", "layout/styles.json")
|
||||
class StartFrame extends VGroupView implements ViewBuilder implements StartFrameLayout {
|
||||
|
||||
|
||||
@@ -19,24 +19,23 @@ bricks:
|
||||
|
||||
teams:
|
||||
- id: human
|
||||
spawnInterval: 0
|
||||
tanks:
|
||||
- {group: human, type: 0, rate: 1}
|
||||
- {type: human0, rate: 1}
|
||||
- id: bot
|
||||
spawnInterval: 3000
|
||||
tanks:
|
||||
- {group: bot, type: 0, rate: 0.5}
|
||||
- {group: bot, type: 1, rate: 0.5}
|
||||
- {group: bot, type: 2, rate: 0.5}
|
||||
- {group: bot, type: 3, rate: 0.5}
|
||||
- {type: bot0, rate: 0.25, bonus: 0.25}
|
||||
- {type: bot1, rate: 0.25, bonus: 0.25}
|
||||
- {type: bot2, rate: 0.25, bonus: 0.25}
|
||||
- {type: bot3, rate: 0.25, bonus: 0.25}
|
||||
|
||||
points:
|
||||
- {team: human, type: eagle, index: -1, direction: right, x: 12, y: 24}
|
||||
- {team: human, type: tank, index: 0, direction: top, x: 8, y: 24}
|
||||
- {team: human, type: tank, index: 1, direction: top, x: 16, y: 24}
|
||||
- {team: bot, type: tank, index: -1, direction: bottom, x: 0, y: 0}
|
||||
- {team: bot, type: tank, index: -1, direction: bottom, x: 12, y: 0}
|
||||
- {team: bot, type: tank, index: -1, direction: bottom, x: 24, y: 0}
|
||||
- {team: bot, type: tank, index: -2, direction: bottom, x: 12, y: 0}
|
||||
- {team: bot, type: tank, index: -3, direction: bottom, x: 24, y: 0}
|
||||
|
||||
bullet: &bullet
|
||||
width: 12
|
||||
@@ -45,8 +44,8 @@ bullet: &bullet
|
||||
piercing: 1
|
||||
|
||||
tanks:
|
||||
human:
|
||||
- type: 0
|
||||
- type: human0
|
||||
upgrade: human1
|
||||
width: 36
|
||||
height: 36
|
||||
speed: 2.5
|
||||
@@ -54,8 +53,10 @@ tanks:
|
||||
<<: *bullet
|
||||
speed: 8.0
|
||||
bullets: 1
|
||||
skin: pa
|
||||
|
||||
- type: 1
|
||||
- type: human1
|
||||
upgrade: human2
|
||||
width: 40
|
||||
height: 36
|
||||
speed: 3.0
|
||||
@@ -63,8 +64,10 @@ tanks:
|
||||
<<: *bullet
|
||||
speed: 8.5
|
||||
bullets: 1
|
||||
skin: pb
|
||||
|
||||
- type: 2
|
||||
- type: human2
|
||||
upgrade: human3
|
||||
width: 40
|
||||
height: 36
|
||||
speed: 3.0
|
||||
@@ -72,8 +75,10 @@ tanks:
|
||||
<<: *bullet
|
||||
speed: 9.0
|
||||
bullets: 2
|
||||
skin: pc
|
||||
|
||||
- type: 3
|
||||
- type: human3
|
||||
upgrade: human3
|
||||
width: 42
|
||||
height: 38
|
||||
speed: 2.9
|
||||
@@ -82,9 +87,10 @@ tanks:
|
||||
speed: 9.0
|
||||
piercing: 3
|
||||
bullets: 2
|
||||
hits: 1
|
||||
skin: pd
|
||||
|
||||
bot:
|
||||
- type: 0
|
||||
- type: bot0
|
||||
width: 38
|
||||
height: 36
|
||||
speed: 2.0
|
||||
@@ -93,8 +99,9 @@ tanks:
|
||||
speed: 7.0
|
||||
bullets: 1
|
||||
score: 100
|
||||
skin: ba
|
||||
|
||||
- type: 1
|
||||
- type: bot1
|
||||
width: 40
|
||||
height: 36
|
||||
speed: 4.0
|
||||
@@ -103,8 +110,9 @@ tanks:
|
||||
speed: 7.0
|
||||
bullets: 1
|
||||
score: 200
|
||||
skin: bb
|
||||
|
||||
- type: 2
|
||||
- type: bot2
|
||||
width: 38
|
||||
height: 36
|
||||
speed: 2.0
|
||||
@@ -113,8 +121,9 @@ tanks:
|
||||
speed: 9.0
|
||||
bullets: 1
|
||||
score: 300
|
||||
skin: bc
|
||||
|
||||
- type: 3
|
||||
- type: bot3
|
||||
width: 40
|
||||
height: 36
|
||||
speed: 1.8
|
||||
@@ -124,3 +133,12 @@ tanks:
|
||||
bullets: 1
|
||||
score: 400
|
||||
hits: 3
|
||||
skin: bd
|
||||
|
||||
bonuses:
|
||||
- {type: clock}
|
||||
- {type: grenade}
|
||||
- {type: helmet}
|
||||
- {type: life}
|
||||
- {type: shovel}
|
||||
- {type: star}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
[keyboard]
|
||||
reset = 27 ;Escape
|
||||
pause = 80 ;P
|
||||
|
||||
[player0]
|
||||
key_left = 37 ;Left
|
||||
key_up = 38 ;Up
|
||||
key_right = 39 ;Rigth
|
||||
key_down = 40 ;Down
|
||||
key_shot = 96 ;Num0
|
||||
|
||||
[player1]
|
||||
key_left = 65 ;A
|
||||
key_up = 87 ;W
|
||||
key_right = 68 ;D
|
||||
key_down = 83 ;S
|
||||
key_shot = 32 ;Space
|
||||
|
||||
[bonus]
|
||||
score = 500
|
||||
freeztime = 10
|
||||
eagletime = 20
|
||||
protecttime = 15
|
||||
|
||||
[bots]
|
||||
count = 20 ;количество ботов на уровне
|
||||
respawntime = 2.5 ;задержка между появлением ботов в секундах
|
||||
shotdelay = 1.0 ;задержка между выстрелами
|
||||
turndelay = 0.3 ;задержка перед поворотом при столкновении
|
||||
rndturndelay = 2.0 ;задержка перед случайным поворотом
|
||||
turntoeagle = 0.75 ;вероятность поворота к Орлу
|
||||
bonus = 0.25 ;вероятность появления бонусного танка
|
||||
|
||||
|
||||
[tank_p0]
|
||||
movespeed = 2.5 ;скорость передвижения
|
||||
bulletspeed = 8.0 ;скорость полёта снаряда
|
||||
bullettype = 0 ;тип снаряда (0 - обычный, 1 - бронебойный)
|
||||
bulletcount = 1 ;количество снарядов
|
||||
hits = 1 ;количество хитпойнтов
|
||||
|
||||
[tank_p1]
|
||||
movespeed = 3.0
|
||||
bulletspeed = 8.5
|
||||
bullettype = 0
|
||||
bulletcount = 1
|
||||
hits = 1
|
||||
|
||||
[tank_p2]
|
||||
movespeed = 3.0
|
||||
bulletspeed = 9.0
|
||||
bullettype = 0
|
||||
bulletcount = 2
|
||||
hits = 1
|
||||
|
||||
[tank_p3]
|
||||
movespeed = 2.9
|
||||
bulletspeed = 9.0
|
||||
bullettype = 1
|
||||
bulletcount = 2
|
||||
hits = 2
|
||||
|
||||
|
||||
|
||||
[tank_b0]
|
||||
movespeed = 2.0
|
||||
bulletspeed = 7.0
|
||||
bullettype = 0
|
||||
bulletcount = 1
|
||||
hits = 1
|
||||
score = 100
|
||||
|
||||
[tank_b1]
|
||||
movespeed = 4.0
|
||||
bulletspeed = 7.0
|
||||
bullettype = 0
|
||||
bulletcount = 1
|
||||
hits = 1
|
||||
score = 200
|
||||
|
||||
[tank_b2]
|
||||
movespeed = 2.0
|
||||
bulletspeed = 9.0
|
||||
bullettype = 0
|
||||
bulletcount = 1
|
||||
hits = 1
|
||||
score = 300
|
||||
|
||||
[tank_b3]
|
||||
movespeed = 1.8
|
||||
bulletspeed = 8.0
|
||||
bullettype = 0
|
||||
bulletcount = 1
|
||||
hits = 4
|
||||
score = 400
|
||||
@@ -1,5 +1,5 @@
|
||||
game:
|
||||
levels: 3
|
||||
levels: 7
|
||||
friendlyFire: true
|
||||
|
||||
map:
|
||||
@@ -19,17 +19,16 @@ bricks:
|
||||
|
||||
team_tanks: &team_tanks
|
||||
tanks:
|
||||
- {group: any, type: 0, rate: 0.25}
|
||||
- {group: any, type: 1, rate: 0.25}
|
||||
- {group: any, type: 2, rate: 0.25}
|
||||
- {type: slow, rate: 0.5}
|
||||
- {type: fast, rate: 0.5}
|
||||
|
||||
teams:
|
||||
- <<: *team_tanks
|
||||
id: radiant
|
||||
spawnInterval: 0
|
||||
color: 0xff5555
|
||||
- <<: *team_tanks
|
||||
id: dire
|
||||
spawnInterval: 0
|
||||
color: 0x5555ff
|
||||
|
||||
points:
|
||||
- {team: radiant, type: eagle, index: -1, direction: right, x: 0, y: 28}
|
||||
@@ -52,40 +51,30 @@ bullet: &bullet
|
||||
piercing: 1
|
||||
|
||||
tanks:
|
||||
any:
|
||||
- type: 0
|
||||
width: 36
|
||||
- type: slow
|
||||
width: 38
|
||||
height: 36
|
||||
speed: 2.5
|
||||
speed: 2.3
|
||||
bullet:
|
||||
<<: *bullet
|
||||
speed: 12.0
|
||||
bullets: 1
|
||||
skin: bc
|
||||
|
||||
- type: fast
|
||||
width: 40
|
||||
height: 36
|
||||
speed: 4.0
|
||||
bullet:
|
||||
<<: *bullet
|
||||
speed: 8.0
|
||||
bullets: 1
|
||||
skin: bb
|
||||
|
||||
- type: 1
|
||||
width: 40
|
||||
height: 36
|
||||
speed: 3.0
|
||||
bullet:
|
||||
<<: *bullet
|
||||
speed: 8.5
|
||||
bullets: 1
|
||||
|
||||
- type: 2
|
||||
width: 40
|
||||
height: 36
|
||||
speed: 3.0
|
||||
bullet:
|
||||
<<: *bullet
|
||||
speed: 9.0
|
||||
bullets: 2
|
||||
|
||||
- type: 3
|
||||
width: 42
|
||||
height: 38
|
||||
speed: 2.9
|
||||
bullet:
|
||||
<<: *bullet
|
||||
speed: 9.0
|
||||
piercing: 3
|
||||
bullets: 2
|
||||
bonuses:
|
||||
- {type: clock}
|
||||
- {type: grenade}
|
||||
- {type: helmet}
|
||||
- {type: life}
|
||||
- {type: shovel}
|
||||
- {type: star}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
000044000000000000000000005500004400550000004400000000000000000000550000440055000000440000004400003333000055000044005555000044000000440000333300005500004400555500004422442244000000000000550000440000000000442244224400000000000055000044000000000000000000444444555544444400442200330000000000000044444455554444440044220033005555333333554422220000222244000022003300555533333355442222000022224400002200330000000000000044220000000022440000440033000000000000004422000000002244000044003300000000000000550000555500005500002200000000000000000055000055550000550000220000004444444400005500445555440055000044444444444444440000550044555544005500004444444400000022000055000055550000550000000000000000002200005500005555000055000000000000003300440000442200000000224400000000000000330044000044220000000022440000000000000033002200004422220000222244553333335555003300220000442222000022224455333333555500330022440044444455554444440000000000000033002244004444445555444444000000000000000000440000550000000000004422442244000000000044000055000000000000442244224400005555004400005500003333000044000000440000555500440000550000333300004400000044000000550044000055000000000000000000004400000055004400005500000000000000000000440000
|
||||
points: [{index: -1, team: radiant, x: 0, direction: right, type: eagle, y: 28}, {index: 0, team: radiant, x: 0, direction: right, type: tank, y: 0}, {index: 1, team: radiant, x: 6, direction: right, type: tank, y: 10}, {index: 2, team: radiant, x: 6, direction: right, type: tank, y: 16}, {index: 3, team: radiant, x: 6, direction: right, type: tank, y: 22}, {index: 4, team: radiant, x: 10, direction: right, type: tank, y: 28}, {index: -1, team: dire, x: 38, direction: right, type: eagle, y: 0}, {index: 0, team: dire, x: 38, direction: left, type: tank, y: 28}, {index: 1, team: dire, x: 32, direction: left, type: tank, y: 18}, {index: 2, team: dire, x: 32, direction: left, type: tank, y: 12}, {index: 3, team: dire, x: 32, direction: left, type: tank, y: 6}, {index: 4, team: dire, x: 28, direction: left, type: tank, y: 0}]
|
||||
data: "000044000000000000000000005500004400550000004400000000000000000000550000440055000000440000004400003333000055000044005555000044000000440000333300005500004400555500004422442244000000000000550000440000000000442244224400000000000055000044000000000000000000444444555544444400442200330000000000000044444455554444440044220033005555333333554422220000222244000022003300555533333355442222000022224400002200330000000000000044220000000022440000440033000000000000004422000000002244000044003300000000000000550000555500005500002200000000000000000055000055550000550000220000004444444400005500445555440055000044444444444444440000550044555544005500004444444400000022000055000055550000550000000000000000002200005500005555000055000000000000003300440000442200000000224400000000000000330044000044220000000022440000000000000033002200004422220000222244553333335555003300220000442222000022224455333333555500330022440044444455554444440000000000000033002244004444445555444444000000000000000000440000550000000000004422442244000000000044000055000000000000442244224400005555004400005500003333000044000000440000555500440000550000333300004400000044000000550044000055000000000000000000004400000055004400005500000000000000000000440000"
|
||||
|
||||
2
src/client/resources/dota/levels/level003.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
points: [{index: -1, direction: right, team: radiant, x: 24, type: eagle, y: 26}, {index: 0, direction: right, team: radiant, x: 14, type: tank, y: 26}, {index: 1, direction: right, team: radiant, x: 20, type: tank, y: 20}, {index: 2, direction: right, team: radiant, x: 26, type: tank, y: 20}, {index: 3, direction: right, team: radiant, x: 34, type: tank, y: 24}, {index: 4, direction: right, team: radiant, x: 38, type: tank, y: 22}, {index: -1, direction: right, team: dire, x: 22, type: eagle, y: 2}, {index: 0, direction: left, team: dire, x: 8, type: tank, y: 2}, {index: 1, direction: left, team: dire, x: 12, type: tank, y: 6}, {index: 2, direction: left, team: dire, x: 20, type: tank, y: 6}, {index: 3, direction: left, team: dire, x: 21, type: tank, y: 10}, {index: 4, direction: left, team: dire, x: 28, type: tank, y: 4}]
|
||||
data: "444444444400000000440000004444000000000044444444440000000044000000444400000000004444440000004444004400000044440033444400444444000000444400440000004444003344440000000000440000440044000000000000000000000000000044000044004400000000000000000000003344004400000000000044004444440000444400334400440000000000004400444444000044440000000000004400444444440033440000005544000000000000440044444444003344000000554444004433440044444400000000004400440000004400443344004444440000000000440044000000440000000000004444004444440044004444440044000000000000444400444444004400444444000000440055440044440044440000000055444400000044005544004444004444000000005544440000444400444400000000000000443300000000000044440044440000000000000044330000000000000044004444003300444444004444004433004400004400444400330044444400444400443300444400000000000033000000000000000044000000440000000000003300000000000000004400000044440044004444444400444444440000440044004444004400444444440044444444000044004400000000000000440000000000000000000000440000000000000044000000000000000000000044004455003344000000440044000000440033444400445500334400000044004400000044003344440044440000000044000000440000004400000000004444000000004400000044000000440000000000"
|
||||
2
src/client/resources/dota/levels/level004.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
points: [{index: -1, direction: right, team: radiant, x: 12, type: eagle, y: 2}, {index: 0, direction: right, team: radiant, x: 6, type: tank, y: 6}, {index: 1, direction: right, team: radiant, x: 10, type: tank, y: 10}, {index: 2, direction: right, team: radiant, x: 14, type: tank, y: 10}, {index: 3, direction: right, team: radiant, x: 18, type: tank, y: 6}, {index: 4, direction: right, team: radiant, x: 20, type: tank, y: 2}, {index: -1, direction: right, team: dire, x: 22, type: eagle, y: 26}, {index: 0, direction: left, team: dire, x: 12, type: tank, y: 26}, {index: 1, direction: left, team: dire, x: 18, type: tank, y: 22}, {index: 2, direction: left, team: dire, x: 24, type: tank, y: 22}, {index: 3, direction: left, team: dire, x: 28, type: tank, y: 18}, {index: 4, direction: left, team: dire, x: 30, type: tank, y: 10}]
|
||||
data: "000000000033333300000000000000000000000000000000003333330000000000000000000000000000004400330033004400000000003300000044000000440033003300440000000000330000004400000000003333330000000044440000000000000000000000333333000000004444000000000000000000000000000000003300000000004444000000000000000000000000330000000000444400000044000000004400000000004400000044000000004400000000440000000000440000004400000000000033000000000000004444000000000000000000003300000000000000444400000000000000000000000000330000440000000033000000000000000000000033000044000000003300000000000000000000000000444400004400000000000000000000000000000044440000440000000000000000000000334444004444000000000044000000000000000033444400444400000000004400000000004400000044000000000000330000440000000000440000004400000000000033000044000000000000440000000000330000440000000000000033000044000000000033000044000000000000003300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044000000003333330000000033000000000000004400000000333333000000003300000000000000000000440033003300440000000000000000000000000044003300330044000000000000000000000000000000333333000000000000000000000000000000000033333300000000000000"
|
||||
2
src/client/resources/dota/levels/level005.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
points: [{index: -1, direction: right, team: radiant, x: 19, type: eagle, y: 28}, {index: 0, direction: right, team: radiant, x: 0, type: tank, y: 28}, {index: 1, direction: right, team: radiant, x: 10, type: tank, y: 22}, {index: 2, direction: right, team: radiant, x: 19, type: tank, y: 18}, {index: 3, direction: right, team: radiant, x: 28, type: tank, y: 22}, {index: 4, direction: right, team: radiant, x: 38, type: tank, y: 28}, {index: -1, direction: right, team: dire, x: 19, type: eagle, y: 0}, {index: 0, direction: left, team: dire, x: 0, type: tank, y: 0}, {index: 1, direction: left, team: dire, x: 10, type: tank, y: 6}, {index: 2, direction: left, team: dire, x: 19, type: tank, y: 10}, {index: 3, direction: left, team: dire, x: 28, type: tank, y: 6}, {index: 4, direction: left, team: dire, x: 38, type: tank, y: 0}]
|
||||
data: "000000000000440000000000004400000000000000000000000044000000000000440000000000004400000000000000000440000000000000000044440000000000000000044000000000000000004400000000005555555555555555555500000000000000000000555555555555555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000550000000000000000000000000000000000000055000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004400000000000000000000440000000000000000440000000000000000000044000000005555555544333333333553333333334455555555555555554433333333355333333333445555555500000000440000000000000000000044000000000000000044000000000000000000004400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000550000000000000000000000000000000000000055000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000055555555555555555555000000000000000000005555555555555555555500000000004400000000000000000440000000000000000044440000000000000000044000000000000000004400000000000044000000000000440000000000000000000000004400000000000044000000000000"
|
||||
2
src/client/resources/dota/levels/level006.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
points: [{index: -1, direction: right, team: radiant, x: 19, type: eagle, y: 28}, {index: 0, direction: right, team: radiant, x: 2, type: tank, y: 22}, {index: 1, direction: right, team: radiant, x: 9, type: tank, y: 20}, {index: 2, direction: right, team: radiant, x: 19, type: tank, y: 24}, {index: 3, direction: right, team: radiant, x: 29, type: tank, y: 20}, {index: 4, direction: right, team: radiant, x: 36, type: tank, y: 22}, {index: -1, direction: right, team: dire, x: 19, type: eagle, y: 0}, {index: 0, direction: left, team: dire, x: 2, type: tank, y: 6}, {index: 1, direction: left, team: dire, x: 9, type: tank, y: 8}, {index: 2, direction: left, team: dire, x: 19, type: tank, y: 4}, {index: 3, direction: left, team: dire, x: 29, type: tank, y: 8}, {index: 4, direction: left, team: dire, x: 36, type: tank, y: 6}]
|
||||
data: "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005555555544444455555555000000000000000000555555554444445555555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005500000000000000550000000000000000000000550000000000000055000000000000000000000055000000000000005500000000000000000000005500000000000000550000000000000000000000000044000000440000000000000000000000000000004400000044000000000000000333333333333333445500004433333333333333333333333333333344550000443333333333333333333333333333334400440044333333333333333333333333333333440044004433333333333333333333333333333344000055443333333333333333333333333333334400005544333333333333333000000000000000440000004400000000000000000000000000000044000000440000000000000000000000000055000000000000005500000000000000000000005500000000000000550000000000000000000000550000000000000055000000000000000000000055000000000000005500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005555555544444455555555000000000000000000555555554444445555555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
|
Before Width: | Height: | Size: 450 B After Width: | Height: | Size: 450 B |
|
Before Width: | Height: | Size: 566 B After Width: | Height: | Size: 566 B |
|
Before Width: | Height: | Size: 354 B After Width: | Height: | Size: 354 B |
|
Before Width: | Height: | Size: 541 B After Width: | Height: | Size: 541 B |
|
Before Width: | Height: | Size: 455 B After Width: | Height: | Size: 455 B |
|
Before Width: | Height: | Size: 532 B After Width: | Height: | Size: 532 B |
BIN
src/client/resources/image/tank/ba-0.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
src/client/resources/image/tank/ba-1.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
src/client/resources/image/tank/bb-0.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
src/client/resources/image/tank/bb-1.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src/client/resources/image/tank/bc-0.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
src/client/resources/image/tank/bc-1.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
src/client/resources/image/tank/bd-0.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/client/resources/image/tank/bd-1.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/client/resources/image/tank/pa-0.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/client/resources/image/tank/pa-1.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
src/client/resources/image/tank/pb-0.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/client/resources/image/tank/pb-1.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/client/resources/image/tank/pc-0.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src/client/resources/image/tank/pc-1.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
src/client/resources/image/tank/pd-0.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/client/resources/image/tank/pd-1.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 590 B |
@@ -1,20 +1,22 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import ru.m.tankz.proto.pack.LeaveGameRequest;
|
||||
import ru.m.tankz.proto.pack.LeaveGameResponse;
|
||||
import ru.m.tankz.proto.pack.GameUpdateResponse;
|
||||
import ru.m.tankz.proto.pack.GameActionRequest;
|
||||
import ru.m.connect.IConnection;
|
||||
import protohx.Message;
|
||||
import ru.m.tankz.proto.pack.ErrorResponse;
|
||||
import ru.m.tankz.proto.pack.GameListRequest;
|
||||
import ru.m.tankz.proto.pack.GameListResponse;
|
||||
import ru.m.connect.IConnection;
|
||||
import ru.m.tankz.proto.pack.CreateGameRequest;
|
||||
import ru.m.tankz.proto.pack.CreateGameResponse;
|
||||
import ru.m.tankz.proto.pack.ErrorResponse;
|
||||
import ru.m.tankz.proto.pack.GameActionRequest;
|
||||
import ru.m.tankz.proto.pack.GameListRequest;
|
||||
import ru.m.tankz.proto.pack.GameListResponse;
|
||||
import ru.m.tankz.proto.pack.GameUpdateResponse;
|
||||
import ru.m.tankz.proto.pack.JoinGameRequest;
|
||||
import ru.m.tankz.proto.pack.JoinGameResponse;
|
||||
import ru.m.tankz.proto.pack.LeaveGameRequest;
|
||||
import ru.m.tankz.proto.pack.LeaveGameResponse;
|
||||
import ru.m.tankz.proto.pack.StartGameRequest;
|
||||
import ru.m.tankz.proto.pack.StartGameResponse;
|
||||
import Type;
|
||||
|
||||
|
||||
class PacketBuilder implements IPacketBuilder {
|
||||
|
||||
|
||||
26
src/common/haxe/ru/m/tankz/Type.hx
Normal file
@@ -0,0 +1,26 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import ru.m.draw.Color;
|
||||
|
||||
typedef Type = Dynamic;
|
||||
|
||||
typedef GameType = String;
|
||||
|
||||
typedef TeamId = String;
|
||||
|
||||
typedef ControlType = String;
|
||||
|
||||
typedef BrickType = Int;
|
||||
|
||||
typedef TankType = String;
|
||||
|
||||
typedef BonusType = String;
|
||||
|
||||
typedef PlayerId = {
|
||||
var team:TeamId;
|
||||
var type:ControlType;
|
||||
var index:Int;
|
||||
@:optional var color:Color;
|
||||
}
|
||||
|
||||
typedef GameMode = Array<PlayerId>;
|
||||
@@ -1,17 +1,56 @@
|
||||
package ru.m.tankz.bot;
|
||||
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.core.EntityType;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.geom.Direction;
|
||||
import haxe.Timer;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.core.Eagle;
|
||||
import ru.m.tankz.core.Entity;
|
||||
import ru.m.tankz.core.EntityType;
|
||||
import ru.m.tankz.core.Tank;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
class BotHelper {
|
||||
|
||||
public static function findEagle(team:TeamId, handler:ControlHandler):Null<Eagle> {
|
||||
for (entity in handler.entities) {
|
||||
switch (EntityTypeResolver.of(entity)) {
|
||||
case EntityType.EAGLE(eagle):
|
||||
if (eagle.team != team) {
|
||||
return eagle;
|
||||
}
|
||||
case x:
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getDirectionTo(entity:Entity, target:Entity):Direction {
|
||||
var x:Float = target.rect.x - entity.rect.x;
|
||||
var y:Float = target.rect.y - entity.rect.y;
|
||||
var xD:Direction = Direction.from(Std.int(x / Math.abs(x)), 0);
|
||||
var yD:Direction = Direction.from(0, Std.int(y / Math.abs(y)));
|
||||
if (entity.rect.direction == xD) return yD;
|
||||
if (entity.rect.direction == yD) return xD;
|
||||
return Math.abs(x) > Math.abs(y) ? xD : yD;
|
||||
}
|
||||
|
||||
public static function randomDirection():Direction {
|
||||
return [
|
||||
Direction.TOP,
|
||||
Direction.BOTTOM,
|
||||
Direction.LEFT,
|
||||
Direction.RIGHT,
|
||||
][Math.floor(Math.random() * 4)];
|
||||
}
|
||||
}
|
||||
|
||||
class BotControl extends Control {
|
||||
|
||||
private var shotTimer:Timer;
|
||||
private var turnRandomTimer:Timer;
|
||||
private var turnTimer:Timer;
|
||||
private var tank(get, null):Tank;
|
||||
|
||||
public function new(playerId:PlayerId) {
|
||||
super(playerId);
|
||||
@@ -27,7 +66,6 @@ class BotControl extends Control {
|
||||
|
||||
override public function start():Void {
|
||||
if (handler == null) return;
|
||||
var tank = handler.entities.get(tankId);
|
||||
action(TankAction.MOVE(tank.rect.direction));
|
||||
if (shotTimer == null) {
|
||||
shotTimer = new Timer(1000);
|
||||
@@ -65,15 +103,17 @@ class BotControl extends Control {
|
||||
turnTimer.stop();
|
||||
turnTimer = null;
|
||||
}
|
||||
action(TankAction.MOVE(randomDirection()));
|
||||
// ToDo:
|
||||
if (handler == null || tank == null) return;
|
||||
var eagle:Eagle = BotHelper.findEagle(playerId.team, handler);
|
||||
if (eagle != null && Math.random() > 0.25) {
|
||||
action(TankAction.MOVE(BotHelper.getDirectionTo(tank, eagle)));
|
||||
} else {
|
||||
action(TankAction.MOVE(BotHelper.randomDirection()));
|
||||
}
|
||||
}
|
||||
|
||||
private function randomDirection():Direction {
|
||||
return [
|
||||
Direction.TOP,
|
||||
Direction.BOTTOM,
|
||||
Direction.LEFT,
|
||||
Direction.RIGHT,
|
||||
][Math.floor(Math.random() * 4)];
|
||||
private function get_tank():Tank {
|
||||
return cast handler.entities[tankId];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package ru.m.tankz.config;
|
||||
|
||||
import ru.m.draw.Color;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
typedef GameConfig = {
|
||||
var levels: Int;
|
||||
@@ -7,7 +10,7 @@ typedef GameConfig = {
|
||||
}
|
||||
|
||||
typedef SpawnPoint = {
|
||||
var team:String;
|
||||
var team:TeamId;
|
||||
var type:String;
|
||||
var index:Int;
|
||||
var x:Int;
|
||||
@@ -23,7 +26,7 @@ typedef MapConfig = {
|
||||
}
|
||||
|
||||
typedef BrickConfig = {
|
||||
var type:Int;
|
||||
var type:BrickType;
|
||||
var layer:Int;
|
||||
var armor:Int;
|
||||
}
|
||||
@@ -35,31 +38,35 @@ typedef BulletConfig = {
|
||||
var piercing:Int;
|
||||
}
|
||||
|
||||
|
||||
typedef TankType = {
|
||||
var group:String;
|
||||
var type:String;
|
||||
}
|
||||
|
||||
typedef TankConfig = { > TankType,
|
||||
typedef TankConfig = {
|
||||
var type:TankType;
|
||||
var width:Float;
|
||||
var height:Float;
|
||||
var speed:Float;
|
||||
var bullet:BulletConfig;
|
||||
var bullets:Int;
|
||||
var hits:Int;
|
||||
var skin:String;
|
||||
@:optinal var upgrade:TankType;
|
||||
}
|
||||
|
||||
typedef TankSpawn = { > TankType,
|
||||
var rate: Float;
|
||||
typedef BonusConfig = {
|
||||
var type:BonusType;
|
||||
}
|
||||
|
||||
typedef TankSpawn = {
|
||||
var type:TankType;
|
||||
var rate:Float;
|
||||
@:optional var bonus:Float;
|
||||
}
|
||||
|
||||
|
||||
typedef TeamConfig = {
|
||||
var id:String;
|
||||
var id:TeamId;
|
||||
var size:Int;
|
||||
var spawnInterval:Int;
|
||||
var tanks:Array<TankSpawn>;
|
||||
@:optional var spawnInterval:Int;
|
||||
@:optional var color:Color;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,10 +84,12 @@ class Config {
|
||||
public var tanks(default, null):Array<TankConfig>;
|
||||
public var teams(default, null):Array<TeamConfig>;
|
||||
public var points(default, null):Array<SpawnPoint>;
|
||||
public var bonuses(default, null):Array<BonusConfig>;
|
||||
|
||||
private var brickMap:Map<Int, BrickConfig>;
|
||||
private var tankMap:Map<String, Map<String, TankConfig>>;
|
||||
private var teamMap:Map<String, TeamConfig>;
|
||||
private var tankMap:Map<TankType, TankConfig>;
|
||||
private var teamMap:Map<TeamId, TeamConfig>;
|
||||
private var bonusMap:Map<BonusType, BonusConfig>;
|
||||
|
||||
public function new(
|
||||
type:String,
|
||||
@@ -89,7 +98,8 @@ class Config {
|
||||
bricks:Array<BrickConfig>,
|
||||
teams:Array<TeamConfig>,
|
||||
points:Array<SpawnPoint>,
|
||||
tanks:Array<TankConfig>
|
||||
tanks:Array<TankConfig>,
|
||||
bonuses:Array<BonusConfig>
|
||||
) {
|
||||
this.type = type;
|
||||
this.game = game;
|
||||
@@ -98,6 +108,7 @@ class Config {
|
||||
this.teams = teams;
|
||||
this.points = points;
|
||||
this.tanks = tanks;
|
||||
this.bonuses = bonuses;
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -112,8 +123,11 @@ class Config {
|
||||
}
|
||||
tankMap = new Map();
|
||||
for (item in tanks) {
|
||||
if (!tankMap.exists(item.group)) tankMap.set(item.group, new Map<String, TankConfig>());
|
||||
tankMap.get(item.group).set(item.type, item);
|
||||
tankMap.set(item.type, item);
|
||||
}
|
||||
bonusMap = new Map();
|
||||
for (item in bonuses) {
|
||||
bonusMap.set(item.type, item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +139,11 @@ class Config {
|
||||
return teamMap.get(id);
|
||||
}
|
||||
|
||||
public function getTank(group:String, type:String):TankConfig {
|
||||
return tankMap.get(group).get(type);
|
||||
public function getTank(type:TankType):TankConfig {
|
||||
return tankMap.get(type);
|
||||
}
|
||||
|
||||
public function getBonus(type:BonusType):BonusConfig {
|
||||
return bonusMap.get(type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ typedef ConfigSource = {
|
||||
var bricks: Array<BrickConfig>;
|
||||
var teams: Array<TeamConfig>;
|
||||
var points: Array<SpawnPoint>;
|
||||
var tanks: Dynamic<Array<TankConfig>>;
|
||||
var tanks: Array<TankConfig>;
|
||||
var bonuses: Array<BonusConfig>;
|
||||
}
|
||||
|
||||
class ConfigBundle {
|
||||
@@ -22,15 +23,7 @@ class ConfigBundle {
|
||||
}
|
||||
|
||||
public static function get(type:String):Config {
|
||||
var source:ConfigSource = convert(Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()));
|
||||
var tanks:Array<TankConfig> = [];
|
||||
for (group in Reflect.fields(source.tanks)) {
|
||||
var data:Array<TankConfig> = Reflect.field(source.tanks, group);
|
||||
for (item in data) {
|
||||
item.group = group;
|
||||
tanks.push(item);
|
||||
}
|
||||
}
|
||||
return new Config(type, source.game, source.map, source.bricks, source.teams, source.points, tanks);
|
||||
var source = convert(Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()));
|
||||
return new Config(type, source.game, source.map, source.bricks, source.teams, source.points, source.tanks, source.bonuses);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package ru.m.tankz.config;
|
||||
|
||||
import yaml.Renderer;
|
||||
import yaml.Parser;
|
||||
import yaml.Yaml;
|
||||
import openfl.Assets;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.Type;
|
||||
import yaml.Parser;
|
||||
import yaml.Renderer;
|
||||
import yaml.Yaml;
|
||||
|
||||
|
||||
typedef LevelSource = {
|
||||
@@ -13,7 +13,6 @@ typedef LevelSource = {
|
||||
@:optional var points:Array<SpawnPoint>;
|
||||
}
|
||||
|
||||
|
||||
class LevelBundle {
|
||||
|
||||
private static function formatLevel(level:Int):String {
|
||||
@@ -37,20 +36,19 @@ class LevelBundle {
|
||||
}
|
||||
|
||||
public static function loads(config:Config, data:String):LevelConfig {
|
||||
try {
|
||||
if (config.type == 'classic') {
|
||||
return loadsOld(config, data);
|
||||
} else {
|
||||
var obj:LevelSource = Yaml.parse(data, Parser.options().useObjects());
|
||||
return {
|
||||
data: obj.data.split('').map(function(c) return config.getBrick(Std.parseInt(c))),
|
||||
points: obj.points,
|
||||
}
|
||||
} catch (error:Dynamic) {
|
||||
L.w('LevelBundle', '${error}');
|
||||
return loadsOld(config, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static function dumps(config:Config, level:LevelConfig):String {
|
||||
var bricksStr = level.data.map(function(brick:BrickConfig) return brick.type).join('');
|
||||
var bricksStr = level.data.map(function(brick:BrickConfig) return Std.string(brick.type)).join('');
|
||||
return Yaml.render({
|
||||
data: bricksStr,
|
||||
points: level.points,
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
package ru.m.tankz.control;
|
||||
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.core.Entity;
|
||||
import ru.m.tankz.core.EntityType;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
enum TankAction {
|
||||
MOVE(direction:Direction);
|
||||
LEVEL_UP(level:Int);
|
||||
UPGRADE;
|
||||
STOP;
|
||||
SHOT;
|
||||
}
|
||||
|
||||
|
||||
typedef ControlType = String;
|
||||
|
||||
|
||||
class Control {
|
||||
public static var NONE(default, never):ControlType = 'none';
|
||||
public static var HUMAN(default, never):ControlType = 'human';
|
||||
|
||||
15
src/common/haxe/ru/m/tankz/core/Bonus.hx
Normal file
@@ -0,0 +1,15 @@
|
||||
package ru.m.tankz.core;
|
||||
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
class Bonus extends Entity {
|
||||
|
||||
public var bonusType(default, null):BonusType;
|
||||
|
||||
public function new(bonusType:BonusType) {
|
||||
super(new Rectangle(0, 0, 44, 44));
|
||||
this.bonusType = bonusType;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package ru.m.tankz.core;
|
||||
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
class Bullet extends MobileEntity {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package ru.m.tankz.core;
|
||||
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
class Eagle extends Entity {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ru.m.tankz.core;
|
||||
|
||||
import ru.m.geom.Rectangle;
|
||||
import Type;
|
||||
|
||||
|
||||
class Entity implements IKey {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package ru.m.tankz.core;
|
||||
|
||||
import Type.ValueType;
|
||||
import ru.m.tankz.map.Grid.GridCell;
|
||||
import Type;
|
||||
import ru.m.tankz.map.Grid;
|
||||
|
||||
|
||||
enum EntityType {
|
||||
@@ -9,6 +9,7 @@ enum EntityType {
|
||||
TANK(tank:Tank);
|
||||
BULLET(bullet:Bullet);
|
||||
CELL(cell:GridCell);
|
||||
BONUS(bonus:Bonus);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +21,7 @@ class EntityTypeResolver {
|
||||
case ValueType.TClass(Tank): EntityType.TANK(cast entity);
|
||||
case ValueType.TClass(Bullet): EntityType.BULLET(cast entity);
|
||||
case ValueType.TClass(GridCell): EntityType.CELL(cast entity);
|
||||
case ValueType.TClass(Bonus): EntityType.BONUS(cast entity);
|
||||
case x: null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
package ru.m.tankz.core;
|
||||
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.draw.Color;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
class Tank extends MobileEntity {
|
||||
public var playerId(default, null):PlayerId;
|
||||
public var config(default, set):TankConfig;
|
||||
public var color(default, default):Color;
|
||||
public var hits(default, default):Int;
|
||||
public var bonus(default, default):Bool;
|
||||
|
||||
private var bulletsCounter:Int = 0;
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ class CollisionProcessor implements EngineListener {
|
||||
tank1.rect.lean(eagle.rect);
|
||||
case EntityType.CELL(cell):
|
||||
tank1.rect.lean(cell.rect);
|
||||
case EntityType.BONUS(bonus):
|
||||
engine.destroy(bonus);
|
||||
}
|
||||
case EntityType.BULLET(bullet1):
|
||||
switch (with) {
|
||||
@@ -74,6 +76,7 @@ class CollisionProcessor implements EngineListener {
|
||||
engine.destroy(eagle);
|
||||
case EntityType.CELL(cell):
|
||||
engine.destroy(bullet1);
|
||||
case EntityType.BONUS(bonus):
|
||||
}
|
||||
case _:
|
||||
}
|
||||
@@ -131,9 +134,10 @@ class Engine implements ControlHandler {
|
||||
switch (action) {
|
||||
case TankAction.MOVE(direction):
|
||||
tank.move(direction);
|
||||
case TankAction.LEVEL_UP(level):
|
||||
// ToDo:
|
||||
tank.config = config.getTank('human', Std.string(Std.int(Math.min(Std.parseInt(tank.config.type) + level, 3))));
|
||||
case TankAction.UPGRADE:
|
||||
if (tank.config.upgrade != null) {
|
||||
tank.config = config.getTank(tank.config.upgrade);
|
||||
}
|
||||
case TankAction.STOP:
|
||||
tank.stop();
|
||||
case TankAction.SHOT:
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.control.Control;
|
||||
import haxe.ds.Option;
|
||||
import ru.m.tankz.game.GameState.PlayerState;
|
||||
import ru.m.draw.Color;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.game.GameState.PlayerState;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
class ClassicGame extends Game {
|
||||
@@ -13,8 +15,16 @@ class ClassicGame extends Game {
|
||||
public static var HUMAN(default, never):TeamId = 'human';
|
||||
public static var BOT(default, never):TeamId = 'bot';
|
||||
|
||||
public static var PLAYER1(default, never):GameMode = [{team:HUMAN, type:Control.HUMAN, index:0}];
|
||||
public static var PLAYER2(default, never):GameMode = [{team:HUMAN, type:Control.HUMAN, index:0}, {team:HUMAN, type:Control.HUMAN, index:1}];
|
||||
private static var PLAYER1_COLOR:Color = 0xFC9838;
|
||||
private static var PLAYER2_COLOR:Color = 0x159D49;
|
||||
|
||||
public static var PLAYER1(default, never):GameMode = [
|
||||
{team:HUMAN, type:Control.HUMAN, color: PLAYER1_COLOR, index:0}
|
||||
];
|
||||
public static var PLAYER2(default, never):GameMode = [
|
||||
{team:HUMAN, type:Control.HUMAN, color: PLAYER1_COLOR, index:0},
|
||||
{team:HUMAN, type:Control.HUMAN, color: PLAYER2_COLOR, index:1}
|
||||
];
|
||||
|
||||
private static var HUMAN_LIFE(default, never):Int = 3;
|
||||
private static var BOT_LIFE(default, never):Int = 20;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.control.Control;
|
||||
import haxe.ds.Option;
|
||||
import ru.m.draw.Color;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
class DotaGame extends Game {
|
||||
@@ -17,14 +19,17 @@ class DotaGame extends Game {
|
||||
{team:RADIANT, type:Control.HUMAN, index:0}
|
||||
];
|
||||
|
||||
private static var PLAYER1_COLOR:Color = 0xff7777;
|
||||
private static var PLAYER2_COLOR:Color = 0x7777ff;
|
||||
|
||||
public static var PLAYER2_COOP(default, never):GameMode = [
|
||||
{team:RADIANT, type:Control.HUMAN, index:0},
|
||||
{team:RADIANT, type:Control.HUMAN, index:1}
|
||||
{team:RADIANT, type:Control.HUMAN, color: PLAYER1_COLOR, index:0},
|
||||
{team:RADIANT, type:Control.HUMAN, color: PLAYER1_COLOR, index:1}
|
||||
];
|
||||
|
||||
public static var PLAYER2_VS(default, never):GameMode = [
|
||||
{team:RADIANT, type:Control.HUMAN, index:0},
|
||||
{team:DIRE, type:Control.HUMAN, index:0}
|
||||
{team:RADIANT, type:Control.HUMAN, color: PLAYER1_COLOR, index:0},
|
||||
{team:DIRE, type:Control.HUMAN, color: PLAYER2_COLOR, index:0}
|
||||
];
|
||||
|
||||
private static var TEAM_SIZE(default, never):Int = 5;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.core.Bonus;
|
||||
import haxe.ds.Option;
|
||||
import haxe.Timer;
|
||||
import promhx.Deferred;
|
||||
@@ -19,24 +20,12 @@ import ru.m.tankz.core.Tank;
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.game.Spawner;
|
||||
|
||||
|
||||
typedef GameType = String;
|
||||
|
||||
typedef GameMode = Array<PlayerId>;
|
||||
|
||||
typedef TeamId = String;
|
||||
|
||||
typedef PlayerId = {
|
||||
var team:TeamId;
|
||||
var type:ControlType;
|
||||
var index:Int;
|
||||
}
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
class Game implements EngineListener {
|
||||
|
||||
private static var TAG(default, never):String = Type.getClassName(Game).split('.').pop();
|
||||
private static var TAG(default, never):String = 'Game';
|
||||
|
||||
public var type(default, null):GameType;
|
||||
public var state(default, null):GameState;
|
||||
@@ -61,10 +50,12 @@ class Game implements EngineListener {
|
||||
}
|
||||
|
||||
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 spawns:Array<TankSpawn> = teams[playerId.team].config.tanks;
|
||||
var spawn:TankSpawn = spawns[Math.floor(Math.random() * spawns.length)];
|
||||
var tankConfig:TankConfig = config.getTank(spawn.type);
|
||||
var tank = new Tank(playerId, tankConfig);
|
||||
tank.color = playerId.color.zero ? teams[playerId.team].config.color : playerId.color;
|
||||
tank.bonus = Math.random() < spawn.bonus;
|
||||
applyPoint(tank, point);
|
||||
return tank;
|
||||
}
|
||||
@@ -165,6 +156,11 @@ class Game implements EngineListener {
|
||||
case EntityType.TANK(tank):
|
||||
var control = getPlayer(tank.playerId).control;
|
||||
if (control != null) control.onCollision(with);
|
||||
switch (with) {
|
||||
case EntityType.BONUS(bonus):
|
||||
applyBonus(tank, bonus);
|
||||
case x:
|
||||
}
|
||||
case x:
|
||||
}
|
||||
}
|
||||
@@ -218,6 +214,7 @@ class Game implements EngineListener {
|
||||
state.teams[tank.playerId.team].lose = true;
|
||||
complete();
|
||||
}
|
||||
if (tank.bonus) spawnBonus();
|
||||
deferred.resolve(state);
|
||||
case EntityType.EAGLE(eagle):
|
||||
state.teams[eagle.team].lose = true;
|
||||
@@ -227,18 +224,53 @@ class Game implements EngineListener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onAction(tankId:Int, action:TankAction):Void {
|
||||
engine.action(tankId, action);
|
||||
}
|
||||
|
||||
|
||||
public function next():Option<GameState> {
|
||||
return Option.None;
|
||||
}
|
||||
|
||||
|
||||
public function dispose():Void {
|
||||
engine.dispose();
|
||||
}
|
||||
|
||||
|
||||
private function spawnBonus():Void {
|
||||
var bonusConfig = config.bonuses[Math.floor(Math.random() * config.bonuses.length)];
|
||||
L.d(TAG, 'Spawn Bonus(${bonusConfig}');
|
||||
var bonus = new Bonus(bonusConfig.type);
|
||||
bonus.rect.x = Math.random() * engine.map.width;
|
||||
bonus.rect.y = Math.random() * engine.map.height;
|
||||
engine.spawn(bonus);
|
||||
}
|
||||
|
||||
private function applyBonus(tank:Tank, bonus:Bonus):Void {
|
||||
switch (bonus.bonusType) {
|
||||
case 'life':
|
||||
state.teams[tank.playerId.team].players[tank.playerId.index].life++;
|
||||
case 'star':
|
||||
if (tank.config.upgrade != null) {
|
||||
tank.config = config.getTank(tank.config.upgrade);
|
||||
} else {
|
||||
tank.hits++;
|
||||
}
|
||||
case 'grenade':
|
||||
for (entity in engine.entities.iterator()) {
|
||||
switch (EntityTypeResolver.of(entity)) {
|
||||
case EntityType.TANK(t):
|
||||
if (t.playerId.team != tank.playerId.team) {
|
||||
engine.destroy(t);
|
||||
}
|
||||
case x:
|
||||
}
|
||||
}
|
||||
case 'helmet':
|
||||
case 'clock':
|
||||
case 'shovel':
|
||||
case x:
|
||||
engine.destroy(tank); // :-D
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.game.Game;
|
||||
|
||||
|
||||
typedef ControlType = String;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
typedef PlayerState = {
|
||||
@@ -11,14 +8,12 @@ typedef PlayerState = {
|
||||
var life:Int;
|
||||
}
|
||||
|
||||
|
||||
typedef TeamState = {
|
||||
var players:Map<Int, PlayerState>;
|
||||
var life:Int;
|
||||
var lose:Bool;
|
||||
}
|
||||
|
||||
|
||||
class GameState {
|
||||
public var type:GameType;
|
||||
public var mode:GameMode;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
class Player {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
|
||||
import haxe.Timer;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
typedef SpawnTask = {
|
||||
@@ -11,7 +10,6 @@ typedef SpawnTask = {
|
||||
var playerId:PlayerId;
|
||||
}
|
||||
|
||||
|
||||
class Spawner {
|
||||
|
||||
public var active(get, never):Bool;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.config.Config.TeamConfig;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.game.Player;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
class Team {
|
||||
|
||||
@@ -15,6 +15,9 @@ class LevelMap {
|
||||
public var gridWidth(default, null):Int;
|
||||
public var gridHeight(default, null):Int;
|
||||
|
||||
public var width(get, null):Float;
|
||||
public var height(get, null):Float;
|
||||
|
||||
public var bricks(default, null):Array<Brick>;
|
||||
|
||||
public var grid(default, null):Grid;
|
||||
@@ -68,4 +71,12 @@ class LevelMap {
|
||||
var cellY:Int = Math.floor(point.y / config.cellHeight);
|
||||
return bricks[cellX + cellY * config.gridWidth];
|
||||
}
|
||||
|
||||
private inline function get_width():Float {
|
||||
return config.cellWidth * config.gridWidth;
|
||||
}
|
||||
|
||||
private inline function get_height():Float {
|
||||
return config.cellHeight * config.gridHeight;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package ru.m.tankz.editor;
|
||||
|
||||
|
||||
import ru.m.tankz.editor.MapEditView.Brush;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.editor.MapEditView;
|
||||
import ru.m.tankz.game.DotaGame;
|
||||
import haxework.gui.list.ListView;
|
||||
import haxework.gui.list.VListView;
|
||||
@@ -25,6 +26,8 @@ import haxework.log.SocketLogger;
|
||||
|
||||
|
||||
interface EditorViewLayout {
|
||||
var gameClassicButton(default, null):ButtonView;
|
||||
var gameDotaButton(default, null):ButtonView;
|
||||
var openButton(default, null):ButtonView;
|
||||
var saveButton(default, null):ButtonView;
|
||||
var fileNameLabel(default, null):LabelView;
|
||||
@@ -70,16 +73,11 @@ class Editor {
|
||||
Root.bind(view);
|
||||
view.content.stage.stageFocusRect = false;
|
||||
|
||||
view.gameClassicButton.onPress = this;
|
||||
view.gameDotaButton.onPress = this;
|
||||
view.openButton.onPress = this;
|
||||
view.saveButton.onPress = this;
|
||||
|
||||
config = ConfigBundle.get(DotaGame.TYPE);
|
||||
view.mapView.config = config;
|
||||
view.mapView.data = LevelBundle.empty(config);
|
||||
|
||||
view.brickList.data = config.bricks.filter(function(brick) return brick.type > -1);
|
||||
view.spawnPointList.data = config.points;
|
||||
|
||||
var resetSelected = function() {
|
||||
for (v in view.brickList.items) {
|
||||
cast(v, BrickView).selected = false;
|
||||
@@ -104,12 +102,29 @@ class Editor {
|
||||
}
|
||||
});
|
||||
|
||||
setGameType(ClassicGame.TYPE);
|
||||
}
|
||||
|
||||
private function setGameType(type:GameType):Void {
|
||||
config = ConfigBundle.get(type);
|
||||
Provider.set(Config, config);
|
||||
|
||||
view.mapView.config = config;
|
||||
view.mapView.data = LevelBundle.empty(config);
|
||||
|
||||
view.brickList.data = config.bricks.filter(function(brick) return brick.type > -1);
|
||||
view.spawnPointList.data = config.points;
|
||||
|
||||
view.mapView.brush = Brush.BRICK(view.brickList.data[0]);
|
||||
cast(view.brickList.items[0], BrickView).selected = true;
|
||||
}
|
||||
|
||||
public function onPress(v:ButtonView):Void {
|
||||
switch (v.id) {
|
||||
case 'gameClassicButton':
|
||||
setGameType(ClassicGame.TYPE);
|
||||
case 'gameDotaButton':
|
||||
setGameType(DotaGame.TYPE);
|
||||
case 'openButton':
|
||||
L.d(TAG, 'OPEN');
|
||||
FileUtil.browse().then(function(content:FileContent) {
|
||||
|
||||
@@ -6,6 +6,24 @@ views:
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
views:
|
||||
- $type: haxework.gui.HGroupView
|
||||
pWidth: 100
|
||||
height: 20
|
||||
views:
|
||||
- id: gameClassicButton
|
||||
$type: haxework.gui.ButtonView
|
||||
text: Classic
|
||||
contentSize: true
|
||||
skin:
|
||||
$type: haxework.gui.skin.ButtonColorSkin
|
||||
color: 0xaaff00
|
||||
- id: gameDotaButton
|
||||
$type: haxework.gui.ButtonView
|
||||
text: DotA
|
||||
contentSize: true
|
||||
skin:
|
||||
$type: haxework.gui.skin.ButtonColorSkin
|
||||
color: 0xaaff00
|
||||
- $type: haxework.gui.HGroupView
|
||||
pWidth: 100
|
||||
height: 20
|
||||
|
||||
@@ -28,16 +28,27 @@ class SpawnPointItem extends BitmapItem<SpawnPointEntity> {
|
||||
|
||||
private var cellX:Int;
|
||||
private var cellY:Int;
|
||||
private var src:String;
|
||||
|
||||
public function new(value:SpawnPoint, config:MapConfig) {
|
||||
public function new(value:SpawnPoint, config:Config) {
|
||||
src = getSrc(value, config);
|
||||
super(new SpawnPointEntity(value, new Rectangle(
|
||||
value.x * config.cellWidth,
|
||||
value.y * config.cellHeight,
|
||||
config.cellWidth * 2,
|
||||
config.cellHeight * 2
|
||||
value.x * config.map.cellWidth,
|
||||
value.y * config.map.cellHeight,
|
||||
config.map.cellWidth * 2,
|
||||
config.map.cellHeight * 2
|
||||
)));
|
||||
}
|
||||
|
||||
public static function getSrc(value:SpawnPoint, config:Config):String {
|
||||
var tankType = config.getTeam(value.team).tanks[0];
|
||||
return switch(value.type) {
|
||||
case 'eagle': 'resources/images/eagle/eagle-0.png';
|
||||
case 'tank': TankItem.getTankFrames(value.team, value.index, tankType)[0];
|
||||
case x: 'resources/images/eagle/eagle-1.png';
|
||||
}
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (cellX != value.point.x || cellY != value.point.y) {
|
||||
@@ -50,11 +61,7 @@ class SpawnPointItem extends BitmapItem<SpawnPointEntity> {
|
||||
}
|
||||
|
||||
override private function getImage():String {
|
||||
return switch(value.point.type) {
|
||||
case 'eagle': 'resources/images/eagle/eagle-0.png';
|
||||
case 'tank': 'resources/images/tank/bot/tank_b0_0-0.png';
|
||||
case x: 'resources/images/eagle/eagle-1.png';
|
||||
}
|
||||
return src;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +193,7 @@ class MapEditView extends SpriteView {
|
||||
for (point in config.points) {
|
||||
var key = '${point.team}:${point.type}:${point.index}';
|
||||
if (!items.exists(key)) {
|
||||
items[key] = new SpawnPointItem(point, config.map);
|
||||
items[key] = new SpawnPointItem(point, config);
|
||||
spawnLayer.addChild(items[key].view);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package ru.m.tankz.editor;
|
||||
|
||||
import haxework.provider.Provider;
|
||||
import ru.m.tankz.editor.MapEditView.SpawnPointItem;
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.Shape;
|
||||
import haxework.gui.list.ListView;
|
||||
@@ -38,11 +40,7 @@ class SpawnPointView extends SpriteView implements IListItemView<SpawnPoint> {
|
||||
|
||||
private function set_data(value:SpawnPoint):SpawnPoint {
|
||||
data = value;
|
||||
var src = switch(value.type) {
|
||||
case 'eagle': 'resources/images/eagle/eagle-0.png';
|
||||
case 'tank': 'resources/images/tank/bot/tank_b0_0-0.png';
|
||||
case x: 'resources/images/eagle/eagle-1.png';
|
||||
}
|
||||
var src = SpawnPointItem.getSrc(value, Provider.get(Config));
|
||||
imageView.bitmapData = Assets.getBitmapData(src);
|
||||
imageView.x = (width - imageView.width) / 2;
|
||||
imageView.y = (height - imageView.height) / 2;
|
||||
|
||||