10 Commits
0.6.0 ... 0.6.2

Author SHA1 Message Date
79039ae79e [version] up 2018-02-16 00:09:13 +03:00
1ae84cf5a8 [common] bonuses implemented 2018-02-15 17:11:41 +03:00
032fa0c0ad [client] yaml layouts 2018-02-14 17:15:15 +03:00
1f8b43ba5d [editor] tank color view 2018-02-13 22:32:21 +03:00
4fc0ae103e [editor] added frame switcher 2018-02-13 17:57:07 +03:00
bd86412d83 [editor] fixes 2018-02-13 17:12:24 +03:00
592e59e01f [common] added Eagle death flag 2018-02-13 16:59:01 +03:00
05b6fe4a56 [client] added any map item renders 2018-02-13 14:44:04 +03:00
f68e5d160f [common] game state refactored 2018-02-12 22:26:30 +03:00
d279d52b09 [editor] fix 2018-02-11 14:37:02 +03:00
64 changed files with 1166 additions and 820 deletions

29
WORK.md
View File

@@ -10,7 +10,7 @@
* ui
* auth frame 0%
* select game frame 30% (classic 1/2 player, dota singe/coop/vs)
* select game frame 100% (classic 1/2 player, dota singe/coop/vs)
* select level frame 10%
* game frame 50%
@@ -21,21 +21,29 @@
* bullets 100%
* boxes 100%
* map changes 100%
* bonuses 0%
* bonuses 100%
* eagle 100%
* game
* classic
* state 50%
* bot 50%
* player: 50%
* human 100%
* dota
* state 50%
* bot 10%
* player 0%
* human 100%
* bonus
* star 50%
* grenade 0%
* helm 0%
* clock 0%
* shovel 0%
* state
* score 0%
* human tank 0%
* save/load 0%
* export/import 0%
@@ -47,16 +55,19 @@
* animations
* tank spawn 0%
* tank move 100%
* map water 0%
* map water 100%
* bullet boom 90%
* tank boom 90%
* bonuses 0%
* bonuses 100%
* html5 50%
* proto
...
* editor
* open 0%
* edit 0%
* save 0%
* level
* open 100%
* edit 50%
* save 100%
* tank
* color 10%

View File

@@ -1,6 +1,6 @@
{
"name": "tankz",
"version": "0.6.0",
"version": "0.6.2",
"private": true,
"devDependencies": {
"ansi-colors": "^1.0.1",
@@ -37,6 +37,7 @@
"protohx": "0.4.6",
"yaml": "1.3.0",
"haxework": "git@bitbucket.org:shmyga/haxework.git",
"orm": "2.1.0"
"orm": "2.1.0",
"yield": "1.1.2"
}
}

View File

@@ -12,6 +12,7 @@
<haxelib name="protohx" version="0.4.6"/>
<haxelib name="haxework" version="git"/>
<haxelib name="yaml" version="1.3.0"/>
<haxelib name="yield" version="1.1.2"/>
<window fps="30"/>
<window width="1024" height="768" unless="html5"/>
<haxeflag name="-D" value="swf-gpu"/>

View File

@@ -1,13 +0,0 @@
{
"pWidth": 100, "pHeight": 100,
"views": [
{
"id": "state", "@type": "haxework.gui.LabelView", "@style": "label",
"pWidth": 100, "height": 20
},
{
"id": "render", "@type": "ru.m.tankz.render.Render",
"contentSize": true
}
]
}

View File

@@ -1,21 +0,0 @@
{
"pWidth": 100, "pHeight": 100,
"views": [
{
"id":"levels", "@type":"haxework.gui.list.VListView<Int>",
"factory": "@class:ru.m.tankz.view.frames.list.LevelView",
"pWidth":100,
"pHeight":100,
"paddings":10,
"scroll":{
"@type":"haxework.gui.list.VScrollView",
"width":10, "pHeight":100,
"skin":{"@type":"haxework.gui.list.VScrollSkin"}
},
"skin": {
"@type": "haxework.gui.skin.ColorSkin",
"color": "0x000000", "alpha": 0.0
}
}
]
}

View File

@@ -1,52 +0,0 @@
{
"pWidth": 100, "pHeight": 100,
"views": [
{
"@type": "haxework.gui.ImageView",
"image": "@asset:image:resources/images/logo/logo.png",
"contentSize": true, "bottomMargin": 15
},
{
"@type": "haxework.gui.LabelView", "@style": "label",
"fontSize": 20, "topMargin": 15,
"contentSize": true,
"text": "Classic"
},
{
"id": "classic_1p",
"@type": "haxework.gui.ButtonView",
"text": "1 Player",
"@style": "button"
},
{
"id": "classic_2p",
"@type": "haxework.gui.ButtonView",
"text": "2 Player",
"@style": "button"
},
{
"@type": "haxework.gui.LabelView", "@style": "label",
"fontSize": 20, "topMargin": 15,
"contentSize": true,
"text": "DotA"
},
{
"id": "dota_1p",
"@type": "haxework.gui.ButtonView",
"text": "1 Player",
"@style": "button"
},
{
"id": "dota_2p_coop",
"@type": "haxework.gui.ButtonView",
"text": "2 COOP",
"@style": "button"
},
{
"id": "dota_2p_vs",
"@type": "haxework.gui.ButtonView",
"text": "2 VS",
"@style": "button"
}
]
}

View File

@@ -1,38 +0,0 @@
{
"@type": "haxework.gui.VGroupView",
"pWidth": 100, "pHeight": 100,
"views": [
{
"id": "switcher", "@type": "haxework.gui.frame.FrameSwitcher",
"pWidth": 100, "pHeight": 100,
"skin": {
"@type": "haxework.gui.skin.BitmapSkin",
"image": "@asset:image:resources/images/background.png",
"fillType": "REPEAT"
},
"views": [
{
"id": "start",
"@type": "ru.m.tankz.view.frames.StartFrame"
},
{
"id": "level",
"@type": "ru.m.tankz.view.frames.LevelFrame"
},
{
"id": "game",
"@type": "ru.m.tankz.view.frames.GameFrame"
}
]
},
{
"@type": "haxework.gui.LabelView",
"inLayout": false,
"contentSize": true,
"vAlign": "BOTTOM",
"hAlign": "RIGHT",
"text": "@res:text:version",
"@style": "label"
}
]
}

View File

@@ -1,18 +0,0 @@
{
"level": {
"width": 440, "height": 44,
"margins": 5,
"views": [
{
"id": "label",
"@type": "haxework.gui.LabelView",
"pWidth": 100, "pHeight": 100, "text": "",
"@style": "label"
}
],
"skin": {
"@type": "haxework.gui.skin.ColorSkin",
"color": "0x000000", "alpha": 0.2
}
}
}

View File

@@ -1,33 +0,0 @@
{
"button": {
"width":250, "height":60,
"skin": {
"@type": "haxework.gui.skin.ButtonBitmapSkin",
"upImage": "@asset:image:resources/images/control/button_normal.png",
"downImage": "@asset:image:resources/images/control/button_down.png",
"overImage": "@asset:image:resources/images/control/button_over.png",
"fillType": "NINEPATH"
},
"fontFamily":"@res:text:font", "fontEmbed":true, "fontColor":"0xE7E0BB", "fontSize":20
},
"label": {
"fontColor": "0xffffff",
"fontEmbed": false,
"fontFamily": "@res:text:fontName",
"fontSize": 16,
"shadowColor": "0x000000"
},
"input": {
"fontColor": "0xffffff",
"fontEmbed": false,
"fontFamily": "@res:text:fontName",
"fontSize": 16,
"shadowColor": "0x000000",
"skin": {
"@type": "haxework.gui.skin.ColorSkin",
"color": "0x000000"
}
}
}

View File

@@ -26,8 +26,6 @@ class Animate extends Bitmap {
}
}
private static var a = new BitmapData(1, 1);
public var playing(default, set):Bool;
public var frames(default, set):Array<BitmapData>;
private var index:Int;

View File

@@ -1,34 +1,37 @@
package ru.m.tankz;
import flash.events.KeyboardEvent;
import flash.text.Font;
import flash.ui.Keyboard;
import haxework.gui.ButtonView;
import haxework.gui.frame.IFrameSwitcher;
import haxework.gui.Root;
import haxework.gui.VGroupView;
import haxework.gui.ViewBuilder;
import haxework.log.TraceLogger;
import haxework.provider.Provider;
import haxework.resources.IResources;
import haxework.resources.Resources;
import ru.m.connect.IConnection;
import ru.m.tankz.frame.StartFrame;
import ru.m.tankz.game.ClassicGame;
import ru.m.tankz.game.DotaGame;
import ru.m.tankz.game.Game;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.text.Font;
import ru.m.tankz.view.frames.StartFrame;
import haxework.log.SocketLogger;
import haxework.resources.Resources;
import haxework.resources.IResources;
import haxework.gui.VGroupView;
import haxework.gui.ViewBuilder;
import haxework.gui.ButtonView;
import ru.m.tankz.PacketBuilder;
import haxework.log.JSLogger;
import haxework.gui.frame.IFrameSwitcher;
import haxework.provider.Provider;
import haxework.gui.frame.FrameSwitcher;
import haxework.gui.Root;
import openfl.Assets;
import ru.m.connect.IConnection;
import haxework.log.TraceLogger;
#if flash import haxework.log.JSLogger; #end
#if debug import haxework.log.SocketLogger; #end
@:template("layout/main.json", "layout/styles.json")
class MainView extends VGroupView implements ViewBuilder {}
interface ClientViewLayout {
var switcher(default, null):IFrameSwitcher;
}
@:template('ru/m/tankz/Client.yaml', 'ru/m/tankz/Style.yaml')
class ClientView extends VGroupView implements ClientViewLayout implements ViewBuilder {}
class Client implements IConnectionHandler {
private static inline var TAG = "Tankz";
private static inline var TAG = 'Tankz';
public static function main() {
L.push(new TraceLogger());
@@ -39,31 +42,31 @@ class Client implements IConnectionHandler {
L.push(new SocketLogger());
#end
Const.init();
L.d(TAG, "Debug: " + Const.DEBUG);
L.i(TAG, "Version: " + Const.VERSION);
L.i(TAG, "Build: " + Const.BUILD);
L.d(TAG, 'Debug: ${Const.DEBUG}');
L.i(TAG, 'Version: ${Const.VERSION}');
L.i(TAG, 'Build: ${Const.BUILD}');
new Client();
}
private var view:MainView;
private var view:ClientView;
public function new() {
Provider.setFactory(IResources, Resources);
var font:Font = Font.enumerateFonts()[0];
Provider.get(IResources).text.put("font", "Bookman Old Style");
Provider.get(IResources).text.put("version", 'v${Const.VERSION} b${Const.BUILD}');
Provider.get(IResources).text.put('font', 'Bookman Old Style');
Provider.get(IResources).text.put('version', 'v${Const.VERSION} b${Const.BUILD}');
Provider.set(IPacketBuilder, new PacketBuilder());
#if flash
Provider.set(IConnection, new ru.m.connect.flash.FlashConnection("localhost", 5001));
Provider.set(IConnection, new ru.m.connect.flash.FlashConnection('localhost', 5001));
#elseif html5
Provider.set(IConnection, new ru.m.connect.js.JsConnection("localhost", 5001));
Provider.set(IConnection, new ru.m.connect.js.JsConnection('localhost', 5001));
#end
//Provider.get(IConnection).handler.addListener(this);
view = new MainView();
view = new ClientView();
Provider.set(IFrameSwitcher, view.switcher);
Root.bind(view);
view.content.stage.stageFocusRect = false;
@@ -82,7 +85,7 @@ class Client implements IConnectionHandler {
public function onPress(view:ButtonView):Void {
switch (view.id) {
case "logout":
case 'logout':
Provider.get(IConnection).disconnect();
}
}
@@ -94,7 +97,7 @@ class Client implements IConnectionHandler {
}
public function onError(error:Dynamic):Void {
L.e(TAG, "", error);
L.e(TAG, '', error);
//view.switcher.change(AuthFrame.ID);
}
}

View File

@@ -0,0 +1,27 @@
---
$type: haxework.gui.VGroupView
pWidth: 100
pHeight: 100
views:
- id: switcher
$type: haxework.gui.frame.FrameSwitcher
pWidth: 100
pHeight: 100
skin:
$type: haxework.gui.skin.BitmapSkin
image: "@asset:image:resources/images/background.png"
fillType: REPEAT
views:
- id: start
$type: ru.m.tankz.frame.StartFrame
- id: level
$type: ru.m.tankz.frame.LevelFrame
- id: game
$type: ru.m.tankz.frame.GameFrame
- $type: haxework.gui.LabelView
$style: label
inLayout: false
contentSize: true
vAlign: BOTTOM
hAlign: RIGHT
text: "@res:text:version"

View File

@@ -0,0 +1,21 @@
---
button:
width: 250
height: 60
skin:
$type: haxework.gui.skin.ButtonBitmapSkin
upImage: "@asset:image:resources/images/control/button_normal.png"
downImage: "@asset:image:resources/images/control/button_down.png"
overImage: "@asset:image:resources/images/control/button_over.png"
fillType: NINEPATH
fontFamily: "@res:text:font"
fontEmbed: true
fontColor: "#E7E0BB"
fontSize: 20
label:
fontColor: "#ffffff"
fontEmbed: false
fontFamily: Courirer New
fontSize: 16
shadowColor: 0x000000

View File

@@ -1,8 +1,7 @@
package ru.m.tankz.view.frames;
package ru.m.tankz.frame;
import haxe.ds.Option;
import haxe.ds.Option;
import flash.events.Event;
import haxe.ds.Option;
import haxe.Timer;
import haxework.gui.frame.IFrameSwitcher;
import haxework.gui.LabelView;
@@ -22,8 +21,7 @@ interface GameFrameLayout {
var render(default, null):Render;
}
@:template("layout/frames/game.json", "layout/styles.json")
@:template("ru/m/tankz/frame/GameFrame.yaml", "ru/m/tankz/Style.yaml")
class GameFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements GameFrameLayout {
private static inline var TAG = "GameFrame";
@@ -51,7 +49,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
render.draw(game.engine);
timer = new Timer(10);
timer.run = updateEngine;
state.text = stateString(s);
state.text = stateString(game);
}
private function stop():Void {
@@ -68,20 +66,18 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
render.reset();
}
private function stateString(state:GameState):String {
private function stateString(game:Game):String {
var result:Array<String> = [];
result.push('Level: ${state.level}');
for (teamId in state.teams.keys()) {
var ts:TeamState = state.teams[teamId];
if (ts.lose) {
result.push('${teamId}: LOSE');
} else if (ts.life > -1) {
result.push('${teamId}: ${ts.life}');
result.push('Level: ${game.state.level}');
for (team in game.teams) {
if (game.state.loser == team.id) {
result.push('${team.id}: LOSE');
} else if (team.life > -1) {
result.push('${team.id}: ${team.life}');
} else {
for (index in ts.players.keys()) {
var ps:PlayerState = ts.players[index];
if (ps.life > -1) {
result.push('${teamId}${index}: ${ps.life}');
for (player in team.players) {
if (player.life > -1) {
result.push('${player.id.team}${player.id.index}: ${player.life}');
}
}
}
@@ -90,14 +86,14 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
}
private function onGameStateChange(s:GameState):GameState {
state.text = stateString(s);
state.text = stateString(game);
return s;
}
private function onGameComplete(result:Option<GameState>):Void {
switch (result) {
case Option.Some(s):
state.text = stateString(s);
state.text = stateString(game);
case Option.None:
}
switch (game.next()) {

View File

@@ -0,0 +1,12 @@
---
pWidth: 100
pHeight: 100
views:
- id: state
$type: haxework.gui.LabelView
$style: label
pWidth: 100
height: 20
- id: render
$type: ru.m.tankz.render.Render
contentSize: true

View File

@@ -1,4 +1,4 @@
package ru.m.tankz.view.frames;
package ru.m.tankz.frame;
import ru.m.tankz.config.ConfigBundle;
import haxework.gui.frame.IFrameSwitcher;
@@ -14,7 +14,7 @@ interface LevelFrameLayout {
}
@:template("layout/frames/level.json", "layout/styles.json")
@:template("ru/m/tankz/frame/LevelFrame.yaml", "ru/m/tankz/Style.yaml")
class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrameLayout {
public static inline var ID = "level";

View File

@@ -0,0 +1,20 @@
---
pWidth: 100
pHeight: 100
views:
- id: levels
$type: haxework.gui.list.VListView<Int>
factory: "@class:ru.m.tankz.frame.level.LevelView"
pWidth: 100
pHeight: 100
paddings: 10
scroll:
$type: haxework.gui.list.VScrollView
width: 10
pHeight: 100
skin:
$type: haxework.gui.list.VScrollSkin
skin:
$type: haxework.gui.skin.ColorSkin
color: "#000000"
alpha: 0

View File

@@ -1,4 +1,4 @@
package ru.m.tankz.view.frames;
package ru.m.tankz.frame;
import haxework.gui.ButtonView;
import haxework.gui.frame.IFrameSwitcher;
@@ -19,7 +19,7 @@ interface StartFrameLayout {
var dota_2p_vs(default, null):ButtonView;
}
@:template("layout/frames/start.json", "layout/styles.json")
@:template("ru/m/tankz/frame/StartFrame.yaml", "ru/m/tankz/Style.yaml")
class StartFrame extends VGroupView implements ViewBuilder implements StartFrameLayout {
public static inline var ID = "start";
@@ -47,14 +47,8 @@ class StartFrame extends VGroupView implements ViewBuilder implements StartFrame
}
}
private function startGame(type:GameType, mode:GameMode):Void {
switch (type) {
case ClassicGame.TYPE:
Provider.set(GameState, ClassicGame.buildState(0, mode));
Provider.get(IFrameSwitcher).change(LevelFrame.ID);
case DotaGame.TYPE:
Provider.set(GameState, DotaGame.buildState(0, mode));
Provider.get(IFrameSwitcher).change(LevelFrame.ID);
}
private function startGame(type:GameType, presetId:PresetId):Void {
Provider.set(GameState, new GameState(type, presetId));
Provider.get(IFrameSwitcher).change(LevelFrame.ID);
}
}

View File

@@ -0,0 +1,40 @@
---
pWidth: 100
pHeight: 100
views:
- $type: haxework.gui.ImageView
image: "@asset:image:resources/images/logo/logo.png"
contentSize: true
bottomMargin: 15
- $type: haxework.gui.LabelView
$style: label
fontSize: 20
topMargin: 15
contentSize: true
text: Classic
- id: classic_1p
$type: haxework.gui.ButtonView
text: 1 Player
$style: button
- id: classic_2p
$type: haxework.gui.ButtonView
text: 2 Player
$style: button
- $type: haxework.gui.LabelView
$style: label
fontSize: 20
topMargin: 15
contentSize: true
text: DotA
- id: dota_1p
$type: haxework.gui.ButtonView
text: 1 Player
$style: button
- id: dota_2p_coop
$type: haxework.gui.ButtonView
text: 2 COOP
$style: button
- id: dota_2p_vs
$type: haxework.gui.ButtonView
text: 2 VS
$style: button

View File

@@ -1,4 +1,4 @@
package ru.m.tankz.view.frames.list;
package ru.m.tankz.frame.level;
import haxework.gui.ViewBuilder;
import haxework.gui.HGroupView;
@@ -10,7 +10,7 @@ interface LevelViewLayout {
var label(default, null):LabelView;
}
@:template("layout/other.json@level", "layout/styles.json")
@:template("ru/m/tankz/frame/level/LevelView.yaml", "ru/m/tankz/Style.yaml")
class LevelView extends HGroupView implements ViewBuilder implements IListItemView<Int> implements LevelViewLayout {
public var item_index(default, default):Int;

View File

@@ -0,0 +1,15 @@
---
width: 440
height: 44
margins: 5
views:
- id: label
$type: haxework.gui.LabelView
$style: label
pWidth: 100
pHeight: 100
text: ""
skin:
$type: haxework.gui.skin.ColorSkin
color: "#000000"
alpha: 0.2

View File

@@ -54,13 +54,21 @@ class Render extends SpriteView implements EngineListener {
}
public function draw(game:Engine):Void {
for (brick in game.map.bricks) if (brick.config.type > 0) {
for (brick in game.map.bricks) if (brick.config.index > 0) {
if (!items.exists(brick.key)) {
items[brick.key] = new BrickItem(brick);
if (brick.config.layer > 2) {
upLayer.addChild(items[brick.key].view);
} else {
groundLayer.addChild(items[brick.key].view);
var item:RenderItem<Dynamic, Dynamic> = switch(brick.config.type) {
case 'ace' | 'bush': new BrickItem(brick);
case 'water': new BrickAnimateItem(brick);
case 'armor' | 'brick': new BrickBreakingItem(brick);
case x: null;
};
if (item != null) {
items[brick.key] = item;
if (brick.config.layer > 2) {
upLayer.addChild(item.view);
} else {
groundLayer.addChild(item.view);
}
}
}
}
@@ -118,11 +126,15 @@ class Render extends SpriteView implements EngineListener {
}
public function onCollision(entity:EntityType, with:EntityType):Void {
switch [entity, with] {
case [EntityType.BULLET(_), EntityType.EAGLE(eagle)]:
playTankBoom(eagle.rect.center);
case _:
}
}
public function onDestroy(entity:EntityType):Void {
switch(entity) {
switch entity {
case EntityType.TANK(tank):
if (items.exists(tank.key)) {
entryLayer.removeChild(items.get(tank.key).view);
@@ -135,12 +147,6 @@ class Render extends SpriteView implements EngineListener {
items.remove(bullet.key);
playBulletBoom(bullet.rect.center.add(new Point(bullet.rect.width * bullet.rect.direction.x, bullet.rect.height * bullet.rect.direction.y)));
}
case EntityType.EAGLE(eagle):
if (items.exists(eagle.key)) {
cast(items.get(eagle.key), EagleItem).destoyed = true;
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);

View File

@@ -1,5 +1,6 @@
package ru.m.tankz.render;
import ru.m.tankz.Type.BrickType;
import openfl.display.BitmapData;
import ru.m.draw.Color;
import ru.m.tankz.core.Bonus;
@@ -77,10 +78,51 @@ class BitmapItem<T:TRectangle> extends RenderItem<T, Bitmap> {
}
class BrickItem extends RenderItem<Brick, Shape> {
class BrickItem extends BitmapItem<Brick> {
private var type:BrickType;
public function new(value:Brick) {
super(value);
redraw();
}
override public function update():Void {
super.update();
var t = value.config.type;
if (t != type) {
type = t;
view.visible = t != 'none';
redraw();
}
}
override private function getImage():String {
return 'resources/image/map/${value.config.type}.png';
}
}
class BrickAnimateItem extends AnimateItem<Brick> {
public function new(value:Brick) {
super(value);
redraw();
}
override public function redraw():Void {
var frame0 = Assets.getBitmapData('resources/image/map/${value.config.type}-0.png');
var frame1 = Assets.getBitmapData('resources/image/map/${value.config.type}-1.png');
view.frames = [for (i in 0...15) frame0].concat([for (i in 0...15) frame1]);
view.playing = true;
}
}
class BrickBreakingItem extends RenderItem<Brick, Shape> {
private var broken:Int;
private var type:Int;
private var type:BrickType;
public function new(value:Brick) {
super(value);
@@ -93,7 +135,7 @@ class BrickItem extends RenderItem<Brick, Shape> {
var g = view.graphics;
g.clear();
if (value.destroyed) return;
if (value.config.type > 0) {
if (value.config.index > 0) {
g.beginBitmapFill(image);
g.drawRect(0, 0, value.rect.width, value.rect.height);
for (c in value.cells) {
@@ -118,7 +160,7 @@ class BrickItem extends RenderItem<Brick, Shape> {
}
private function getImage():String {
return 'resources/images/map/map_${value.config.type}.png';
return 'resources/image/map/${value.config.type}.png';
}
}
@@ -140,14 +182,23 @@ class TankItem extends RenderItem<Tank, Sprite> {
private var type:String;
private var hits:Int;
private var protected:Bool;
private var frozen:Bool;
private var tankView:Animate;
private var protectView:Animate;
public function new(value:Tank) {
super(value);
view = new Sprite();
tankView = new Animate();
view.addChild(tankView);
protectView = new Animate(
[for (i in 0...5) Assets.getBitmapData('resources/images/tank/protect/protect-0.png')].concat(
[for (i in 0...5) Assets.getBitmapData('resources/images/tank/protect/protect-1.png')])
);
protectView.visible = false;
view.addChild(protectView);
redraw();
}
@@ -158,6 +209,15 @@ class TankItem extends RenderItem<Tank, Sprite> {
frames[0], frames[0], frames[0],
frames[1], frames[1], frames[1],
];
if (value.protect.active) {
protectView.x = (tankView.frames[0].width - protectView.frames[0].width) / 2;
protectView.y = (tankView.frames[0].height - protectView.frames[0].height) / 2;
protectView.playing = true;
protectView.visible = true;
} else {
protectView.playing = false;
protectView.visible = false;
}
}
private function getFrames():Array<String> {
@@ -170,12 +230,16 @@ class TankItem extends RenderItem<Tank, Sprite> {
super.update();
var t = value.config.type;
var h = value.hits;
if (t != this.type || h != this.hits) {
var p = value.protect.active;
var f = value.freezing.active;
if (t != type || h != hits || p != protected || f != frozen) {
this.type = t;
this.hits = h;
this.protected = p;
this.frozen = f;
redraw();
}
tankView.playing = (value.mx !=0 || value.my != 0);
tankView.playing = !value.freezing.active && (value.mx !=0 || value.my != 0);
}
override public function dispose():Void {
@@ -197,10 +261,19 @@ class BulletItem extends BitmapItem<Bullet> {
class EagleItem extends BitmapItem<Eagle> {
public var destoyed(default, default):Bool;
private var death:Bool;
override public function update():Void {
super.update();
var d = value.death;
if (d != death) {
death = d;
redraw();
}
}
override private function getImage():String {
return 'resources/images/eagle/eagle-${destoyed ? 1 : 0}.png';
return 'resources/image/eagle/eagle${value.death ? '-death' : ''}.png';
}
}

View File

@@ -9,26 +9,63 @@ map:
gridHeight: 26
bricks:
- {type: -1, layer: 2, armor: -1} # border
- {type: 0, layer: 0, armor: 0} # none
- {type: 1, layer: 0, armor: 0} # ace
- {type: 2, layer: 3, armor: 0} # bush
- {type: 3, layer: 1, armor: 0} # water
- {type: 4, layer: 2, armor: 2} # armor
- {type: 5, layer: 2, armor: 1} # brick
- {type: border, index: -1, layer: 2, 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}
- {type: water, index: 3, layer: 1, armor: 0}
- {type: armor, index: 4, layer: 2, armor: 2}
- {type: brick, index: 5, layer: 2, armor: 1}
teams:
- id: human
player:
human: &human
control: human
life: 3
tanks:
- {type: human0, rate: 1}
- id: bot
spawnInterval: 3000
- {type: human0, rate: 1, protect: 5}
bot: &bot
control: bot
life: -1
tanks:
- {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}
presets:
- id: player1
teams:
- id: human
life: -1
players:
- {<<: *human, index: 0, color: 0xF5C040, life: 3}
- id: bot
spawnInterval: 3000
life: 20
players:
- {<<: *bot, index: 0}
- {<<: *bot, index: 1}
- {<<: *bot, index: 2}
- {<<: *bot, index: 3}
- id: player2
teams:
- id: human
life: -1
players:
- {<<: *human, index: 0, color: 0xF5C040, life: 3}
- {<<: *human, index: 1, color: 0x15C040, life: 3}
- id: bot
spawnInterval: 3000
life: 20
players:
- {<<: *bot, index: 0}
- {<<: *bot, index: 1}
- {<<: *bot, index: 2}
- {<<: *bot, index: 3}
- {<<: *bot, index: 4}
- {<<: *bot, index: 5}
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}

View File

@@ -1,5 +1,5 @@
game:
levels: 7
levels: 8
friendlyFire: true
map:
@@ -9,26 +9,90 @@ map:
gridHeight: 30
bricks:
- {type: -1, layer: 2, armor: -1} # border
- {type: 0, layer: 0, armor: 0} # none
- {type: 1, layer: 0, armor: 0} # ace
- {type: 2, layer: 3, armor: 0} # bush
- {type: 3, layer: 1, armor: 0} # water
- {type: 4, layer: 2, armor: 2} # armor
- {type: 5, layer: 2, armor: 1} # brick
- {type: border, index: -1, layer: 2, 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}
- {type: water, index: 3, layer: 1, armor: 0}
- {type: armor, index: 4, layer: 2, armor: 2}
- {type: brick, index: 5, layer: 2, armor: 1}
team_tanks: &team_tanks
tanks:
- {type: slow, rate: 0.5}
- {type: fast, rate: 0.5}
teams:
- <<: *team_tanks
team:
radiant: &radiant
id: radiant
color: 0xff5555
- <<: *team_tanks
color: 0xff4422
life: 20
dire: &dire
id: dire
color: 0x5555ff
color: 0x2244ff
life: 20
player: &player
life: -1
control: bot
tanks:
- {type: slow, rate: 0.5, protect: 3, bonus: 0}
- {type: fast, rate: 0.5, protect: 3, bonus: 0}
human1: &human1
<<: *player
control: human
color: 0xf055a0
human2: &human2
<<: *player
control: human
color: 0xa055f0
presets:
- id: player1
teams:
- <<: *radiant
players:
- {<<: *human1, index: 0}
- {<<: *player, index: 1}
- {<<: *player, index: 2}
- {<<: *player, index: 3}
- {<<: *player, index: 4}
- <<: *dire
players:
- {<<: *player, index: 0}
- {<<: *player, index: 1}
- {<<: *player, index: 2}
- {<<: *player, index: 3}
- {<<: *player, index: 4}
- id: player2_coop
teams:
- <<: *radiant
players:
- {<<: *human1, index: 0}
- {<<: *human1, index: 1}
- {<<: *player, index: 2}
- {<<: *player, index: 3}
- {<<: *player, index: 4}
- <<: *dire
players:
- {<<: *player, index: 0}
- {<<: *player, index: 1}
- {<<: *player, index: 2}
- {<<: *player, index: 3}
- {<<: *player, index: 4}
- id: player2_vs
teams:
- <<: *radiant
players:
- {<<: *human1, index: 0}
- {<<: *player, index: 1}
- {<<: *player, index: 2}
- {<<: *player, index: 3}
- {<<: *player, index: 4}
- <<: *dire
players:
- {<<: *human2, index: 0}
- {<<: *player, index: 1}
- {<<: *player, index: 2}
- {<<: *player, index: 3}
- {<<: *player, index: 4}
points:
- {team: radiant, type: eagle, index: -1, direction: right, x: 0, y: 28}

View File

@@ -0,0 +1,2 @@
data: "444455555555555555555555555555555555444444445555555555555555555555555555555544440044004444444400444444440044444444004400004400444444440044444444004444444400440000220000000000000000000000000000000022000022000000000000000000000000000000002200004400444444442244444444224444444400440000440044444444224444444422444444440044000011000033550000000000000000553300001100001100003355000000000000000055330000110000110000444444004444444400444444440011000011000044444400444444440044444444001100004400000000000055333355000000000000440000440000000000005533335500000000000044000000442244444400443333440044444422440000000044224444440044333344004444442244000000440000000000005533335500000000000044000044000000000000553333550000000000004400001100444444440044444444004444444400110000110044444444004444444400444444440011000011000033550000000000000000553300001100001100003355000000000000000055330000110000440044444444224444444422444444440044000044004444444422444444442244444444004400002200000000000000000000000000000000220000220000000000000000000000000000000022000044004444444400444444440044444440004400004400444444440044444444004444444000440044445555555555555555555555555555555544444444555555555555555555555555555555554444"
points: [{team: radiant, direction: right, x: 2, type: eagle, y: 14, index: -1}, {team: radiant, direction: right, x: 14, type: tank, y: 2, index: 0}, {team: radiant, direction: right, x: 6, type: tank, y: 8, index: 1}, {team: radiant, direction: right, x: 14, type: tank, y: 14, index: 2}, {team: radiant, direction: right, x: 6, type: tank, y: 20, index: 3}, {team: radiant, direction: right, x: 14, type: tank, y: 26, index: 4}, {team: dire, direction: right, x: 36, type: eagle, y: 14, index: -1}, {team: dire, direction: left, x: 24, type: tank, y: 2, index: 0}, {team: dire, direction: left, x: 32, type: tank, y: 8, index: 1}, {team: dire, direction: left, x: 24, type: tank, y: 14, index: 2}, {team: dire, direction: left, x: 32, type: tank, y: 20, index: 3}, {team: dire, direction: left, x: 24, type: tank, y: 26, index: 4}]

View File

Before

Width:  |  Height:  |  Size: 374 B

After

Width:  |  Height:  |  Size: 374 B

View File

Before

Width:  |  Height:  |  Size: 737 B

After

Width:  |  Height:  |  Size: 737 B

View File

Before

Width:  |  Height:  |  Size: 307 B

After

Width:  |  Height:  |  Size: 307 B

View File

Before

Width:  |  Height:  |  Size: 304 B

After

Width:  |  Height:  |  Size: 304 B

View File

Before

Width:  |  Height:  |  Size: 279 B

After

Width:  |  Height:  |  Size: 279 B

View File

Before

Width:  |  Height:  |  Size: 969 B

After

Width:  |  Height:  |  Size: 969 B

View File

Before

Width:  |  Height:  |  Size: 93 B

After

Width:  |  Height:  |  Size: 93 B

View File

Before

Width:  |  Height:  |  Size: 598 B

After

Width:  |  Height:  |  Size: 598 B

View File

Before

Width:  |  Height:  |  Size: 531 B

After

Width:  |  Height:  |  Size: 531 B

View File

Before

Width:  |  Height:  |  Size: 598 B

After

Width:  |  Height:  |  Size: 598 B

View File

@@ -1,6 +1,5 @@
package ru.m.tankz;
import ru.m.draw.Color;
typedef Type = Dynamic;
@@ -10,7 +9,7 @@ typedef TeamId = String;
typedef ControlType = String;
typedef BrickType = Int;
typedef BrickType = String;
typedef TankType = String;
@@ -18,9 +17,7 @@ typedef BonusType = String;
typedef PlayerId = {
var team:TeamId;
var type:ControlType;
var index:Int;
@:optional var color:Color;
}
typedef GameMode = Array<PlayerId>;
typedef PresetId = String;

View File

@@ -27,6 +27,7 @@ typedef MapConfig = {
typedef BrickConfig = {
var type:BrickType;
var index:Int;
var layer:Int;
var armor:Int;
}
@@ -58,17 +59,29 @@ typedef TankSpawn = {
var type:TankType;
var rate:Float;
@:optional var bonus:Float;
@:optional var protect:Float;
}
typedef PlayerConfig = {
var index:Int;
var control:ControlType;
var tanks:Array<TankSpawn>;
@:optional var life:Int;
@:optional var color:Color;
}
typedef TeamConfig = {
var id:TeamId;
var size:Int;
var tanks:Array<TankSpawn>;
var players:Array<PlayerConfig>;
@:optional var life:Int;
@:optional var spawnInterval:Int;
@:optional var color:Color;
}
typedef GamePreset = {
var id:PresetId;
var teams:Array<TeamConfig>;
}
typedef LevelConfig = {
var data:Array<BrickConfig>;
@@ -82,13 +95,14 @@ class Config {
public var map(default, null):MapConfig;
public var bricks(default, null):Array<BrickConfig>;
public var tanks(default, null):Array<TankConfig>;
public var teams(default, null):Array<TeamConfig>;
public var presets(default, null):Array<GamePreset>;
public var points(default, null):Array<SpawnPoint>;
public var bonuses(default, null):Array<BonusConfig>;
private var brickMap:Map<Int, BrickConfig>;
private var brickMap:Map<BrickType, BrickConfig>;
private var brickMapByIndex:Map<Int, BrickConfig>;
private var tankMap:Map<TankType, TankConfig>;
private var teamMap:Map<TeamId, TeamConfig>;
private var presetsMap:Map<PresetId, GamePreset>;
private var bonusMap:Map<BonusType, BonusConfig>;
public function new(
@@ -96,7 +110,7 @@ class Config {
game:GameConfig,
map:MapConfig,
bricks:Array<BrickConfig>,
teams:Array<TeamConfig>,
presets:Array<GamePreset>,
points:Array<SpawnPoint>,
tanks:Array<TankConfig>,
bonuses:Array<BonusConfig>
@@ -105,7 +119,7 @@ class Config {
this.game = game;
this.map = map;
this.bricks = bricks;
this.teams = teams;
this.presets = presets;
this.points = points;
this.tanks = tanks;
this.bonuses = bonuses;
@@ -114,12 +128,14 @@ class Config {
private function init() {
brickMap = new Map();
brickMapByIndex = new Map();
for (item in bricks) {
brickMap.set(item.type, item);
brickMapByIndex.set(item.index, item);
}
teamMap = new Map();
for (team in teams) {
teamMap.set(team.id, team);
presetsMap = new Map();
for (preset in presets) {
presetsMap.set(preset.id, preset);
}
tankMap = new Map();
for (item in tanks) {
@@ -131,12 +147,16 @@ class Config {
}
}
public function getBrick(type:Int):BrickConfig {
public function getBrick(type:BrickType):BrickConfig {
return brickMap.get(type);
}
public function getTeam(id:String):TeamConfig {
return teamMap.get(id);
public function getBrickByIndex(index:Int):BrickConfig {
return brickMapByIndex.get(index);
}
public function getPreset(id:PresetId):GamePreset {
return presetsMap.get(id);
}
public function getTank(type:TankType):TankConfig {

View File

@@ -10,7 +10,7 @@ typedef ConfigSource = {
var game:GameConfig;
var map: MapConfig;
var bricks: Array<BrickConfig>;
var teams: Array<TeamConfig>;
var presets: Array<GamePreset>;
var points: Array<SpawnPoint>;
var tanks: Array<TankConfig>;
var bonuses: Array<BonusConfig>;
@@ -24,6 +24,6 @@ class ConfigBundle {
public static function get(type:String):Config {
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);
return new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses);
}
}

View File

@@ -26,7 +26,7 @@ class LevelBundle {
for (line in ~/\s+/g.split(data)) {
for (c in line.split('')) {
if (c.length > 0) {
bricks.push(config.getBrick(Std.parseInt(c)));
bricks.push(config.getBrickByIndex(Std.parseInt(c)));
}
}
}
@@ -41,14 +41,14 @@ class LevelBundle {
} else {
var obj:LevelSource = Yaml.parse(data, Parser.options().useObjects());
return {
data: obj.data.split('').map(function(c) return config.getBrick(Std.parseInt(c))),
data: obj.data.split('').map(function(c) return config.getBrickByIndex(Std.parseInt(c))),
points: obj.points,
}
}
}
public static function dumps(config:Config, level:LevelConfig):String {
var bricksStr = level.data.map(function(brick:BrickConfig) return Std.string(brick.type)).join('');
var bricksStr = level.data.map(function(brick:BrickConfig) return Std.string(brick.index)).join('');
return Yaml.render({
data: bricksStr,
points: level.points,

View File

@@ -7,9 +7,11 @@ import ru.m.tankz.Type;
class Eagle extends Entity {
public var team(default, null):TeamId;
public var death(default, default):Bool;
public function new(team:TeamId) {
super(new Rectangle(0, 0, 44, 44));
this.team = team;
this.death = false;
}
}

View File

@@ -25,4 +25,19 @@ class EntityTypeResolver {
case x: null;
}
}
public static function as<T>(entity:Entity, type:Class<T>):Null<T> {
if (Std.is(entity, type)) {
return cast entity;
}
return null;
}
public static function asCall<T, R>(entity:Entity, type:Class<T>, fun:T->R, ?defaultResult:R):R {
var e:T = as(entity, type);
if (e != null) {
return fun(e);
}
return defaultResult;
}
}

View File

@@ -0,0 +1,27 @@
package ru.m.tankz.core;
import haxe.Timer;
class Modificator {
public var active(default, default):Bool;
private var timer:Timer;
public function new() {
active = false;
}
public function on(seconds:Float):Void {
off();
active = true;
timer = Timer.delay(off, Std.int(seconds * 1000));
}
public function off():Void {
if (timer != null) {
timer.stop();
timer = null;
}
active = false;
}
}

View File

@@ -15,11 +15,15 @@ class Tank extends MobileEntity {
public var color(default, default):Color;
public var hits(default, default):Int;
public var bonus(default, default):Bool;
public var protect(default, null):Modificator;
public var freezing(default, null):Modificator;
private var bulletsCounter:Int = 0;
public function new(playerId:PlayerId, config:TankConfig) {
super(new Rectangle(0, 0, config.width, config.height), config.speed, Direction.RIGHT);
this.protect = new Modificator();
this.freezing = new Modificator();
this.playerId = playerId;
this.config = config;
this.hits = config.hits;
@@ -35,7 +39,14 @@ class Tank extends MobileEntity {
return value;
}
override public function move(direction:Direction):Void {
if (!freezing.active) {
super.move(direction);
}
}
public function shot():Null<Bullet> {
if (freezing.active) return null;
if (bulletsCounter >= config.bullets) return null;
var bullet = new Bullet(this);
bullet.rect.center = rect.center.add(new Point(rect.width / 4 * rect.direction.x, rect.height / 4 * rect.direction.y));

View File

@@ -12,14 +12,12 @@ import ru.m.tankz.core.Tank;
import ru.m.tankz.map.LevelMap;
interface EngineListener {
public function onSpawn(entity:EntityType):Void;
public function onCollision(entity:EntityType, with:EntityType):Void;
public function onDestroy(entity:EntityType):Void;
}
class CollisionProcessor implements EngineListener {
private var engine:Engine;
@@ -30,54 +28,36 @@ class CollisionProcessor implements EngineListener {
public function onSpawn(entity:EntityType):Void {}
private function checkTankBullet(tank:Tank, bullet:Bullet):Bool {
if (bullet.tankId == tank.id) return false;
return engine.config.game.friendlyFire || tank.playerId.team != bullet.playerId.team;
}
private function hitTank(tank:Tank):Void {
if (tank.hits > 0) {
tank.hits--;
} else {
engine.destroy(tank);
}
}
public function onCollision(entity:EntityType, with:EntityType):Void {
switch (entity) {
case EntityType.TANK(tank1):
switch (with) {
case EntityType.TANK(tank2):
tank1.rect.lean(tank2.rect);
case EntityType.BULLET(bullet2):
if (checkTankBullet(tank1, bullet2)) {
hitTank(tank1);
engine.destroy(bullet2);
switch [entity, with] {
case [EntityType.TANK(tank), EntityType.TANK(other_tank)]:
tank.rect.lean(other_tank.rect);
case [EntityType.TANK(tank), EntityType.EAGLE(eagle)]:
tank.rect.lean(eagle.rect);
case [EntityType.TANK(tank), EntityType.BONUS(bonus)]:
engine.destroy(bonus);
case [EntityType.TANK(tank), EntityType.BULLET(bullet)] |
[EntityType.BULLET(bullet), EntityType.TANK(tank)]:
if (bullet.tankId == tank.id || (!engine.config.game.friendlyFire && tank.playerId.team == bullet.playerId.team)) {
// Nothing
} else {
if (!tank.protect.active) {
if (tank.hits > 0) {
tank.hits--;
} else {
engine.destroy(tank);
}
case EntityType.EAGLE(eagle):
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) {
case EntityType.TANK(tank2):
if (checkTankBullet(tank2, bullet1)) {
engine.destroy(bullet1);
hitTank(tank2);
}
case EntityType.BULLET(bullet2):
engine.destroy(bullet1);
engine.destroy(bullet2);
case EntityType.EAGLE(eagle):
engine.destroy(bullet1);
engine.destroy(eagle);
case EntityType.CELL(cell):
engine.destroy(bullet1);
case EntityType.BONUS(bonus):
}
engine.destroy(bullet);
}
case [EntityType.BULLET(bullet), EntityType.BULLET(other_bullet)]:
engine.destroy(bullet);
engine.destroy(other_bullet);
case [EntityType.BULLET(bullet), EntityType.CELL(cell)]:
engine.destroy(bullet);
case [EntityType.BULLET(bullet), EntityType.EAGLE(eagle)]:
engine.destroy(bullet);
eagle.death = true;
case _:
}
}
@@ -85,7 +65,8 @@ class CollisionProcessor implements EngineListener {
public function onDestroy(entity:EntityType):Void { }
}
@:build(yield.parser.Parser.run())
//@:yield //ToDo: not working
class Engine implements ControlHandler {
public var config(default, default):Config;
@@ -148,8 +129,6 @@ class Engine implements ControlHandler {
}
}
public function update():Void {
var newTime:Float = Date.now().getTime();
var d:Float = newTime - time;
@@ -169,6 +148,15 @@ class Engine implements ControlHandler {
}*/
if (entity.mx != 0 || entity.my != 0) {
var asTank:Tank = EntityTypeResolver.as(entity, Tank);
var asBullet:Bullet = EntityTypeResolver.as(entity, Bullet);
if (asTank != null) {
if (asTank.freezing.active) {
continue;
}
}
var side:Line = entity.rect.getSide(entity.rect.direction.reverse());
var step:Point = new Point(entity.rect.direction.x * map.cellWidth / 4, entity.rect.direction.y * map.cellHeight / 4);
var end:Point = side.center.add(new Point(entity.mx * (d / 30), entity.my * (d / 30)));
@@ -202,15 +190,14 @@ class Engine implements ControlHandler {
}
}
if (Std.is(entity, Bullet)) {
var bullet:Bullet = cast ent;
if (asBullet != null) {
if (collision) {
cells = map.grid.getCells(side.setLength(map.grid.cellWidth * 3));
for (cell in cells) {
if (cell.armor > 0) {
if (cell.armor == bullet.config.piercing) {
if (cell.armor == asBullet.config.piercing) {
cell.destroyed = true;
} else if (cell.armor < bullet.config.piercing) {
} else if (cell.armor < asBullet.config.piercing) {
var brick = map.getBrick(cell);
brick.destroyed = true;
}
@@ -234,4 +221,13 @@ class Engine implements ControlHandler {
listeners = [];
entities = new Map();
}
public function iterTanks(filter:Tank->Bool):Iterator<Tank> {
for (entity in entities) {
var tank:Tank = EntityTypeResolver.as(entity, Tank);
if (tank != null && filter(tank)) {
@yield return tank;
}
}
}
}

View File

@@ -1,10 +1,8 @@
package ru.m.tankz.game;
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.PlayerState;
import ru.m.tankz.game.GameState;
import ru.m.tankz.Type;
@@ -15,57 +13,17 @@ class ClassicGame extends Game {
public static var HUMAN(default, never):TeamId = 'human';
public static var BOT(default, never):TeamId = 'bot';
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;
public static var PLAYER1(default, never):PresetId = 'player1';
public static var PLAYER2(default, never):PresetId = 'player2';
public function new() {
super(TYPE);
}
public static function buildState(level:Int, mode:GameMode):GameState {
var state = new GameState();
state.type = TYPE;
state.mode = mode;
state.level = level;
state.teams[HUMAN] = {life: -1, players: new Map(), lose: false};
state.teams[BOT] = {life: BOT_LIFE, players: new Map(), lose: false};
for (human in mode) {
state.teams[HUMAN].players[human.index] = {
id:human,
life:HUMAN_LIFE,
};
}
for (i in 0...mode.length * 2 + 2) {
state.teams[BOT].players[i] = {
id:{team:BOT, index:i, type:Control.BOT},
life:-1,
};
}
return state;
}
override public function next():Option<GameState> {
if (!state.teams[HUMAN].lose) {
state.level++;
if (state.level >= config.game.levels) state.level = 0;
state.teams[BOT].lose = false;
state.teams[BOT].life = BOT_LIFE;
for (ps in state.teams[HUMAN].players) {
if (ps.life > 0) ps.life++;
}
return Option.Some(state);
if (state.loser == HUMAN) {
return Option.None;
}
return Option.None;
return super.next();
}
}

View File

@@ -1,10 +1,6 @@
package ru.m.tankz.game;
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;
@@ -15,57 +11,11 @@ class DotaGame extends Game {
public static var RADIANT(default, never):TeamId = 'radiant';
public static var DIRE(default, never):TeamId = 'dire';
public static var PLAYER1(default, never):GameMode = [
{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, 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, color: PLAYER1_COLOR, index:0},
{team:DIRE, type:Control.HUMAN, color: PLAYER2_COLOR, index:0}
];
private static var TEAM_SIZE(default, never):Int = 5;
public static var PLAYER1(default, never):PresetId = 'player1';
public static var PLAYER2_COOP(default, never):PresetId = 'player2_coop';
public static var PLAYER2_VS(default, never):PresetId = 'player2_vs';
public function new() {
super(TYPE);
}
public static function buildState(level:Int, mode:GameMode):GameState {
var state = new GameState();
state.type = TYPE;
state.mode = mode;
state.level = level;
state.teams[RADIANT] = {life: 20, players: new Map(), lose: false};
state.teams[DIRE] = {life: 20, players: new Map(), lose: false};
for (i in 0...TEAM_SIZE) {
state.teams[RADIANT].players[i] = {
id: {team:RADIANT, index:i, type:Control.BOT},
life: -1,
};
}
for (i in 0...TEAM_SIZE) {
state.teams[DIRE].players[i] = {
id: {team:DIRE, index:i, type:Control.BOT},
life: -1,
};
}
for (human in mode) {
state.teams[human.team].players[human.index].id = human;
}
return state;
}
override public function next():Option<GameState> {
state.level++;
if (state.level >= config.game.levels) state.level = 0;
return Option.Some(buildState(state.level, state.mode));
}
}

View File

@@ -1,6 +1,5 @@
package ru.m.tankz.game;
import ru.m.tankz.core.Bonus;
import haxe.ds.Option;
import haxe.Timer;
import promhx.Deferred;
@@ -13,6 +12,7 @@ import ru.m.tankz.config.ConfigBundle;
import ru.m.tankz.config.LevelBundle;
import ru.m.tankz.control.Control;
import ru.m.tankz.control.HumanControl;
import ru.m.tankz.core.Bonus;
import ru.m.tankz.core.Eagle;
import ru.m.tankz.core.Entity;
import ru.m.tankz.core.EntityType;
@@ -29,12 +29,12 @@ class Game implements EngineListener {
public var type(default, null):GameType;
public var state(default, null):GameState;
public var preset(default, null):GamePreset;
public var teams(default, null):Map<TeamId, Team>;
public var config(default, null):Config;
public var engine(default, null):Engine;
private var points:Array<SpawnPoint>;
private var spawners:Map<TeamId, Spawner>;
private var deferred:Deferred<GameState>;
private var stream:Stream<GameState>;
@@ -45,18 +45,26 @@ class Game implements EngineListener {
engine.listeners.push(this);
}
public function getTeam(teamId:TeamId):Team {
return teams[teamId];
}
public function getPlayer(playerId:PlayerId):Player {
return teams[playerId.team].players[playerId.index];
}
private function buildTank(playerId:PlayerId, point:SpawnPoint):Tank {
var spawns:Array<TankSpawn> = teams[playerId.team].config.tanks;
var player = getPlayer(playerId);
var spawns:Array<TankSpawn> = player.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.color = player.config.color.zero ? teams[playerId.team].config.color : player.config.color;
tank.bonus = Math.random() < spawn.bonus;
applyPoint(tank, point);
if (spawn.protect > 0) {
tank.protect.on(spawn.protect);
}
return tank;
}
@@ -66,26 +74,25 @@ class Game implements EngineListener {
}
public function start(state:GameState):Stream<GameState> {
this.deferred = new Deferred();
this.state = state;
this.preset = config.getPreset(state.presetId);
this.deferred = new Deferred();
var level = LevelBundle.get(type, config, state.level);
points = level.points != null ? level.points : config.points;
engine.map.setData(level.data);
teams = new Map<TeamId, Team>();
spawners = new Map<TeamId, Spawner>();
var humanControlIndex = 0;
for (teamConfig in config.teams) {
var team = new Team(teamConfig);
for (playerState in state.teams[team.id].players) {
var player = new Player(playerState.id);
team.players[player.id.index] = player;
teams[team.id] = team;
if (player.id.type != null) {
var control = switch (player.id.type) {
for (teamConfig in preset.teams) {
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == teamConfig.id);
var team:Team = new Team(teamConfig, teamPoints);
teams[team.id] = team;
for (player in team.players.iterator()) {
if (player.config.control != null) {
var control = switch (player.config.control) {
case Control.HUMAN: new HumanControl(player.id, humanControlIndex++);
case Control.BOT: new BotControl(player.id);
case Control.NONE: null;
case _: throw 'Unsupported control type: "${player.id.type}"';
case _: throw 'Unsupported control type: "${player.config.control}"';
}
L.d(TAG, 'control(${player.id} - ${control})');
if (control != null) {
@@ -94,17 +101,16 @@ class Game implements EngineListener {
}
}
}
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == team.id);
spawners[team.id] = new Spawner(team.config, teamPoints, spawn);
team.spawner.runner = spawn;
}
for (team in teams) {
for (player in team.players) {
if (trySpawn(player.id)) {
spawners[team.id].push(player.id);
for (team in teams.iterator()) {
for (player in team.players.iterator()) {
if (team.trySpawn(player.id)) {
team.spawner.push(player.id);
}
}
var eaglePoint = spawners[team.id].getPoint('eagle');
var eaglePoint = team.spawner.getPoint('eagle');
if (eaglePoint != null) {
var eagle = new Eagle(team.id);
applyPoint(eagle, eaglePoint);
@@ -117,15 +123,15 @@ class Game implements EngineListener {
private function spawn(task:SpawnTask):Void {
L.d(TAG, 'spawn(${task}');
getPlayer(task.playerId).tankId = 0;
if (trySpawn(task.playerId, true)) {
var team = getTeam(task.playerId.team);
var player = getPlayer(task.playerId);
player.tankId = 0;
if (getTeam(task.playerId.team).trySpawn(task.playerId, true)) {
var tank = buildTank(task.playerId, task.point);
var player:Player = getPlayer(task.playerId);
player.tankId = tank.id;
Timer.delay(function() engine.spawn(tank), 1500);
} else if (!isTeamAlive(task.playerId.team)) {
state.teams[task.playerId.team].lose = true;
complete();
engine.spawn(tank);
} else if (!team.isAlive) {
lose(team.id);
}
deferred.resolve(state);
}
@@ -147,109 +153,84 @@ class Game implements EngineListener {
switch (entity) {
case EntityType.TANK(tank):
getPlayer(tank.playerId).control.start();
case x:
case _:
}
}
public function onCollision(entity:EntityType, with:EntityType):Void {
switch (entity) {
switch entity {
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:
case _:
}
}
private function isTeamAlive(team:TeamId):Bool {
var ts:TeamState = state.teams[team];
var life:Int = Lambda.fold(ts.players, function(ps, t) return t + ps.life, ts.life);
if (life > 0) {
return true;
} else {
for (player in teams[team].players) {
if (player.tankId > 0) {
return true;
}
}
if (spawners[team].active) {
return true;
}
switch [entity, with] {
case [EntityType.TANK(tank), EntityType.BONUS(bonus)]:
applyBonus(tank, bonus);
case [EntityType.BULLET(_), EntityType.EAGLE(eagle)]:
lose(eagle.team);
deferred.resolve(state);
case _:
}
return false;
}
private function trySpawn(player:PlayerId, spawn:Bool = false):Bool {
var ts:TeamState = state.teams[player.team];
var ps:PlayerState = ts.players[player.index];
var result = false;
if (ps.life > -1) {
if (ps.life > 0) {
if (spawn) ps.life--;
result = true;
}
} else if (ts.life > -1) {
if (ts.life > 0) {
if (spawn) ts.life--;
result = true;
}
}
return result;
}
public function onDestroy(entity:EntityType):Void {
switch (entity) {
case EntityType.TANK(tank):
getPlayer(tank.playerId).control.stop();
getPlayer(tank.playerId).tankId = 0; //ToDo: ?
var respawn:Bool = trySpawn(tank.playerId);
var team = getTeam(tank.playerId.team);
var player = getPlayer(tank.playerId);
player.control.stop();
player.tankId = 0; //ToDo: ?
var respawn:Bool = team.trySpawn(player.id);
if (respawn) {
spawners[tank.playerId.team].push(tank.playerId);
team.spawner.push(player.id);
}
if (!isTeamAlive(tank.playerId.team)) {
state.teams[tank.playerId.team].lose = true;
complete();
if (!team.isAlive) {
lose(team.id);
}
if (tank.bonus) spawnBonus();
deferred.resolve(state);
case EntityType.EAGLE(eagle):
state.teams[eagle.team].lose = true;
complete();
deferred.resolve(state);
case x:
case _:
}
}
private function lose(teamId:TeamId):Void {
state.loser = teamId;
complete();
}
public function onAction(tankId:Int, action:TankAction):Void {
engine.action(tankId, action);
}
public function next():Option<GameState> {
return Option.None;
var level = state.level + 1;
state.level++;
if (level >= config.game.levels) level = 0;
return Option.Some(new GameState(state.type, preset.id, level));
}
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}');
private function spawnBonus(?type:BonusType):Void {
var bonusConfig:BonusConfig = type != null ? config.getBonus(type) : config.bonuses[Math.floor(Math.random() * config.bonuses.length)];
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);
}
inline private function alienTank(team:TeamId):Tank->Bool {
return function(tank:Tank):Bool return team != tank.playerId.team;
}
private function applyBonus(tank:Tank, bonus:Bonus):Void {
L.e('XXX', 'applyBonus: ${bonus.bonusType}');
switch (bonus.bonusType) {
case 'life':
state.teams[tank.playerId.team].players[tank.playerId.index].life++;
getPlayer(tank.playerId).life++;
case 'star':
if (tank.config.upgrade != null) {
tank.config = config.getTank(tank.config.upgrade);
@@ -257,19 +238,18 @@ class Game implements EngineListener {
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:
}
for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
engine.destroy(t);
}
case 'helmet':
tank.protect.on(20);
case 'clock':
for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
t.freezing.on(10);
}
case 'shovel':
case x:
// ToDo: protect eagle/area
case _:
engine.destroy(tank); // :-D
}
}

View File

@@ -3,26 +3,16 @@ package ru.m.tankz.game;
import ru.m.tankz.Type;
typedef PlayerState = {
var id:PlayerId;
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;
public var level:Int;
public var teams:Map<TeamId, TeamState>;
public var presetId:PresetId;
public var loser:TeamId;
public function new() {
type = null;
level = -1;
teams = new Map();
public function new(type:GameType, presetId:PresetId, level:Int = 0) {
this.type = type;
this.presetId = presetId;
this.level = level;
this.loser = null;
}
}

View File

@@ -1,21 +1,27 @@
package ru.m.tankz.game;
import ru.m.tankz.config.Config;
import ru.m.tankz.control.Control;
import ru.m.tankz.Type;
class Player {
public var config(default, null):PlayerConfig;
public var id(default, null):PlayerId;
public var tankId(default, set):Int;
public var control(default, set):Control;
public var life(default, default):Int;
public var isAlive(get, null):Bool;
public function new(id:PlayerId, control:Control=null) {
this.id = id;
this.control = control;
public function new(teamId:TeamId, config:PlayerConfig) {
this.config = config;
this.id = {team:teamId, index:config.index};
this.control = null;
this.life = config.life;
}
public function set_tankId(value:Int):Int {
private function set_tankId(value:Int):Int {
tankId = value;
if (control != null) {
control.tankId = tankId;
@@ -23,7 +29,7 @@ class Player {
return tankId;
}
public function set_control(value:Control):Control {
private function set_control(value:Control):Control {
if (control != null) control.dispose();
control = value;
if (control != null) {
@@ -31,4 +37,8 @@ class Player {
}
return control;
}
private function get_isAlive():Bool {
return tankId > 0 || life > 0;
}
}

View File

@@ -13,10 +13,10 @@ typedef SpawnTask = {
class Spawner {
public var active(get, never):Bool;
public var runner(default, default):SpawnTask -> Void;
private var config:TeamConfig;
private var points:Array<SpawnPoint>;
private var runner:SpawnTask -> Void;
private var queue:Array<SpawnTask>;
private var timer:Timer;
@@ -24,10 +24,10 @@ class Spawner {
private var anyPoints:Array<SpawnPoint>;
private var index:Int;
public function new(config:TeamConfig, points:Array<SpawnPoint>, runner:SpawnTask -> Void) {
public function new(config:TeamConfig, points:Array<SpawnPoint>) {
this.config = config;
this.points = points;
this.runner = runner;
this.runner = null;
queue = [];
indexedPoints = new Map();
anyPoints = [];

View File

@@ -1,21 +1,59 @@
package ru.m.tankz.game;
import ru.m.tankz.config.Config;
import ru.m.tankz.game.Player;
import ru.m.tankz.Type;
import ru.m.tankz.config.Config;
class Team {
public var id(default, null):TeamId;
public var config(default, null):TeamConfig;
public var spawner(default, null):Spawner;
public var players(default, null):Map<Int, Player>;
public var life(default, default):Int;
public var isAlive(get, null):Bool;
private static var i:Int = 0;
public function new(config:TeamConfig) {
public function new(config:TeamConfig, points:Array<SpawnPoint>) {
this.id = config.id;
this.config = config;
this.players = new Map();
for (playerConfig in config.players) {
this.players[playerConfig.index] = new Player(id, playerConfig);
}
this.life = config.life;
this.spawner = new Spawner(config, points);
}
public function trySpawn(playerId:PlayerId, spawn:Bool = false):Bool {
var player:Player = players[playerId.index];
var result = false;
if (player.life > -1) {
if (player.life > 0) {
if (spawn) player.life--;
result = true;
}
} else if (life > -1) {
if (life > 0) {
if (spawn) life--;
result = true;
}
}
return result;
}
// ToDo: eagle state?
private function get_isAlive():Bool {
if (life > 0) {
return true;
}
if (spawner.active) {
return true;
}
for (player in players) {
if (player.isAlive) {
return true;
}
}
return false;
}
}

View File

@@ -9,12 +9,6 @@ import ru.m.tankz.core.IKey;
class Brick implements IKey {
public static var BORDER:BrickConfig = {
type: -1,
layer: 2,
armor: -1,
}
public var cellX(default, null):Int;
public var cellY(default, null):Int;
public var key(get, null):String;

View File

@@ -1,47 +1,30 @@
package ru.m.tankz.editor;
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;
import ru.m.tankz.editor.FileUtil;
import haxework.gui.LabelView;
import ru.m.tankz.config.Config;
import ru.m.tankz.config.LevelBundle;
import ru.m.tankz.game.ClassicGame;
import ru.m.tankz.config.ConfigBundle;
import haxework.gui.ButtonView;
import haxework.gui.Root;
import flash.text.Font;
import haxework.resources.Resources;
import haxework.resources.IResources;
import haxework.provider.Provider;
import haxework.log.TraceLogger;
import haxework.gui.ButtonView;
import haxework.gui.frame.FrameSwitcher;
import haxework.gui.VGroupView;
import haxework.gui.Root;
import haxework.gui.ViewBuilder;
import haxework.gui.GroupView;
import haxework.log.JSLogger;
import haxework.log.SocketLogger;
import haxework.log.TraceLogger;
import haxework.provider.Provider;
import haxework.resources.IResources;
import haxework.resources.Resources;
import ru.m.tankz.frame.LevelFrame;
#if flash import haxework.log.JSLogger; #end
#if debug import haxework.log.SocketLogger; #end
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;
var mapView(default, null):MapEditView;
var spawnPointList(default, null):VListView<SpawnPoint>;
var brickList(default, null):VListView<BrickConfig>;
var switcher(default, null):FrameSwitcher;
}
@:template("ru/m/tankz/editor/Editor.yaml")
class EditorView extends GroupView implements ViewBuilder implements EditorViewLayout {}
@:template('ru/m/tankz/editor/Editor.yaml', 'ru/m/tankz/editor/Style.yaml')
class EditorView extends VGroupView implements ViewBuilder implements EditorViewLayout {}
class Editor {
private static inline var TAG = "Tankz.Editor";
private static inline var TAG = 'Editor';
public static function main() {
L.push(new TraceLogger());
@@ -52,92 +35,29 @@ class Editor {
L.push(new SocketLogger());
#end
Const.init();
L.d(TAG, "Debug: " + Const.DEBUG);
L.i(TAG, "Version: " + Const.VERSION);
L.i(TAG, "Build: " + Const.BUILD);
L.d(TAG, 'Debug: ${Const.DEBUG}');
L.i(TAG, 'Version: ${Const.VERSION}');
L.i(TAG, 'Build: ${Const.BUILD}');
new Editor();
}
private var view:EditorView;
private var config:Config;
public function new() {
Provider.setFactory(IResources, Resources);
var font:Font = Font.enumerateFonts()[0];
Provider.get(IResources).text.put("font", "Bookman Old Style");
Provider.get(IResources).text.put("version", 'v${Const.VERSION} b${Const.BUILD}');
Provider.get(IResources).text.put('font', 'Bookman Old Style');
Provider.get(IResources).text.put('version', 'v${Const.VERSION} b${Const.BUILD}');
view = new EditorView();
view = new EditorView({handler: this});
Root.bind(view);
view.content.stage.stageFocusRect = false;
view.gameClassicButton.onPress = this;
view.gameDotaButton.onPress = this;
view.openButton.onPress = this;
view.saveButton.onPress = this;
var resetSelected = function() {
for (v in view.brickList.items) {
cast(v, BrickView).selected = false;
}
for (v in view.spawnPointList.items) {
cast(v, SpawnPointView).selected = false;
}
};
view.brickList.dispatcher.addListener({
onListItemClick: function(item:IListItemView<BrickConfig>) {
view.mapView.brush = Brush.BRICK(item.data);
resetSelected();
cast(item, BrickView).selected = true; }
});
view.spawnPointList.dispatcher.addListener({
onListItemClick: function(item:IListItemView<SpawnPoint>) {
view.mapView.brush = Brush.POINT(item.data);
resetSelected();
cast(item, SpawnPointView).selected = true;
}
});
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;
view.switcher.change(LevelFrame.ID);
}
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) {
view.fileNameLabel.text = content.name;
view.mapView.data = LevelBundle.loads(config, content.content);
});
case 'saveButton':
L.d(TAG, 'SAVE');
FileUtil.save({
name: view.fileNameLabel.text,
content: LevelBundle.dumps(config, view.mapView.data),
});
case _:
}
view.switcher.change(v.id.split('btn_').pop());
}
}

View File

@@ -1,89 +1,48 @@
$type: haxework.gui.GroupView
---
$type: haxework.gui.VGroupView
pWidth: 100
pHeight: 100
skin:
$type: haxework.gui.skin.BitmapSkin
image: "@asset:image:resources/images/background.png"
fillType: REPEAT
views:
- $type: haxework.gui.VGroupView
# Tabs
- $type: haxework.gui.HGroupView
contentSize: true
views:
- id: btn_level
$type: haxework.gui.ButtonView
$style: button
text: Level
onPress: "@link:handler"
- id: btn_tank
$type: haxework.gui.ButtonView
$style: button
text: Tank
onPress: "@link:handler"
- $type: haxework.gui.SpriteView
height: 3
pWidth: 100
skin:
$type: haxework.gui.skin.ColorSkin
color: "#aaaaaa"
# Switcher
- id: switcher
$type: haxework.gui.frame.FrameSwitcher
pWidth: 100
pHeight: 100
paddings: 5
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
views:
- id: openButton
$type: haxework.gui.ButtonView
text: Open
contentSize: true
skin:
$type: haxework.gui.skin.ButtonColorSkin
color: 0xaaff00
- id: saveButton
$type: haxework.gui.ButtonView
text: Save
contentSize: true
skin:
$type: haxework.gui.skin.ButtonColorSkin
color: 0xaaff00
- id: fileNameLabel
$type: haxework.gui.LabelView
contentSize: true
- $type: haxework.gui.HGroupView
contentSize: true
views:
- id: spawnPointList
$type: haxework.gui.list.VListView<SpawnPoint>
factory: '@class:ru.m.tankz.editor.SpawnPointView'
width: 56
pHeight: 100
scroll:
$type: haxework.gui.list.VScrollView
width: 0
pHeight: 100
skin:
$type: haxework.gui.list.VScrollSkin
skin:
$type: haxework.gui.skin.ColorSkin
color: 0x000000
alpha: 0.0
- id: mapView
$type: ru.m.tankz.editor.MapEditView
contentSize: true
- id: brickList
$type: haxework.gui.list.VListView<BrickConfig>
factory: '@class:ru.m.tankz.editor.BrickView'
width: 30
pHeight: 100
scroll:
$type: haxework.gui.list.VScrollView
width: 0
pHeight: 100
skin:
$type: haxework.gui.list.VScrollSkin
skin:
$type: haxework.gui.skin.ColorSkin
color: 0x000000
alpha: 0.0
- id: level
$type: ru.m.tankz.editor.frame.LevelFrame
- id: tank
$type: ru.m.tankz.editor.frame.TankFrame
# Version
- $type: haxework.gui.LabelView
$style: label
inLayout: false
contentSize: true
vAlign: BOTTOM
hAlign: RIGHT
text: '@res:text:version'
text: "@res:text:version"

View File

@@ -0,0 +1,15 @@
---
button:
height: 20
width: 150
margins: 2
skin:
$type: haxework.gui.skin.ButtonColorSkin
color: 0xaaff00
label:
fontColor: 0xffffff
fontEmbed: false
fontFamily: '@res:text:fontName'
fontSize: 16
shadowColor: 0x000000

View File

@@ -0,0 +1,110 @@
package ru.m.tankz.editor.frame;
import haxework.gui.ButtonView;
import haxework.gui.LabelView;
import haxework.gui.list.ListView;
import haxework.gui.list.VListView;
import haxework.gui.VGroupView;
import haxework.gui.ViewBuilder;
import haxework.provider.Provider;
import ru.m.tankz.config.Config;
import ru.m.tankz.config.ConfigBundle;
import ru.m.tankz.config.LevelBundle;
import ru.m.tankz.editor.FileUtil;
import ru.m.tankz.editor.level.BrickView;
import ru.m.tankz.editor.level.MapEditView;
import ru.m.tankz.editor.level.SpawnPointView;
import ru.m.tankz.game.ClassicGame;
import ru.m.tankz.game.DotaGame;
import ru.m.tankz.Type;
interface LevelFrameLayout {
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;
var mapView(default, null):MapEditView;
var spawnPointList(default, null):VListView<SpawnPoint>;
var brickList(default, null):VListView<BrickConfig>;
}
@:template('ru/m/tankz/editor/frame/LevelFrame.yaml', 'ru/m/tankz/editor/Style.yaml')
class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrameLayout {
public static inline var ID = 'level';
public static inline var TAG = 'level';
private var config:Config;
public function init():Void {
gameClassicButton.onPress = this;
gameDotaButton.onPress = this;
openButton.onPress = this;
saveButton.onPress = this;
var resetSelected = function() {
for (v in brickList.items) {
cast(v, BrickView).selected = false;
}
for (v in spawnPointList.items) {
cast(v, SpawnPointView).selected = false;
}
};
brickList.dispatcher.addListener({
onListItemClick: function(item:IListItemView<BrickConfig>) {
mapView.brush = Brush.BRICK(item.data);
resetSelected();
cast(item, BrickView).selected = true; }
});
spawnPointList.dispatcher.addListener({
onListItemClick: function(item:IListItemView<SpawnPoint>) {
mapView.brush = Brush.POINT(item.data);
resetSelected();
cast(item, SpawnPointView).selected = true;
}
});
}
public function onShow():Void {
setGameType(ClassicGame.TYPE);
}
private function setGameType(type:GameType):Void {
config = ConfigBundle.get(type);
Provider.set(Config, config);
mapView.config = config;
mapView.data = LevelBundle.empty(config);
brickList.data = config.bricks.filter(function(brick) return brick.index > -1);
spawnPointList.data = config.points;
mapView.brush = Brush.BRICK(brickList.data[0]);
cast(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) {
fileNameLabel.text = content.name;
mapView.data = LevelBundle.loads(config, content.content);
});
case 'saveButton':
L.d(TAG, 'SAVE');
FileUtil.save({
name: fileNameLabel.text,
content: LevelBundle.dumps(config, mapView.data),
});
case _:
}
}
}

View File

@@ -0,0 +1,68 @@
---
$type: haxework.gui.VGroupView
pWidth: 100
pHeight: 100
layoutMargin: 2
layoutVAlign: TOP
views:
- $type: haxework.gui.HGroupView
contentSize: true
views:
- id: gameClassicButton
$type: haxework.gui.ButtonView
$style: button
text: Classic
- id: gameDotaButton
$type: haxework.gui.ButtonView
$style: button
text: DotA
- $type: haxework.gui.HGroupView
contentSize: true
views:
- id: openButton
$type: haxework.gui.ButtonView
$style: button
text: Open
- id: saveButton
$type: haxework.gui.ButtonView
$style: button
text: Save
- id: fileNameLabel
$type: haxework.gui.LabelView
contentSize: true
- $type: haxework.gui.HGroupView
contentSize: true
views:
- id: spawnPointList
$type: haxework.gui.list.VListView<SpawnPoint>
factory: "@class:ru.m.tankz.editor.level.SpawnPointView"
width: 56
pHeight: 100
scroll:
$type: haxework.gui.list.VScrollView
width: 0
pHeight: 100
skin:
$type: haxework.gui.list.VScrollSkin
skin:
$type: haxework.gui.skin.ColorSkin
color: 0x000000
alpha: 0.0
- id: mapView
$type: ru.m.tankz.editor.level.MapEditView
contentSize: true
- id: brickList
$type: haxework.gui.list.VListView<BrickConfig>
factory: "@class:ru.m.tankz.editor.level.BrickView"
width: 30
pHeight: 100
scroll:
$type: haxework.gui.list.VScrollView
width: 0
pHeight: 100
skin:
$type: haxework.gui.list.VScrollSkin
skin:
$type: haxework.gui.skin.ColorSkin
color: 0x000000
alpha: 0.0

View File

@@ -0,0 +1,34 @@
package ru.m.tankz.editor.frame;
import ru.m.draw.Color;
import ru.m.tankz.editor.tank.TankView;
import haxework.gui.InputView;
import haxework.gui.HGroupView;
import haxework.gui.ViewBuilder;
interface TankFrameLayout {
var tank(default, null):TankView;
var colorR(default, null):InputView;
var colorG(default, null):InputView;
var colorB(default, null):InputView;
}
@:template('ru/m/tankz/editor/frame/TankFrame.yaml', 'ru/m/tankz/editor/Style.yaml')
class TankFrame extends HGroupView implements ViewBuilder implements TankFrameLayout {
public static inline var ID = 'tank';
public function init():Void {
colorR.onKeyUp = this;
colorG.onKeyUp = this;
colorB.onKeyUp = this;
}
public function onShow():Void {
onKeyUp(null);
}
public function onKeyUp(text:String):Void {
tank.color = Color.fromString('#${colorR.text}${colorG.text}${colorB.text}');
}
}

View File

@@ -0,0 +1,49 @@
---
$type: haxework.gui.HGroupView
pWidth: 100
pHeight: 100
views:
- $type: ru.m.tankz.editor.tank.TankView
contentSize: true
rightMargin: 20
image: "@asset:image:resources/image/tank/bc-0.png"
color: "#ff4422"
- $type: ru.m.tankz.editor.tank.TankView
contentSize: true
rightMargin: 20
image: "@asset:image:resources/image/tank/bc-0.png"
color: "#f055a0"
- $type: ru.m.tankz.editor.tank.TankView
contentSize: true
rightMargin: 20
image: "@asset:image:resources/image/tank/bc-0.png"
color: "#2244ff"
- id: tank
$type: ru.m.tankz.editor.tank.TankView
contentSize: true
rightMargin: 20
image: "@asset:image:resources/image/tank/bc-0.png"
- id: colorR
$type: haxework.gui.InputView
width: 30
height: 20
text: "a0"
skin:
$type: haxework.gui.skin.ColorSkin
color: 0xffffff
- id: colorG
$type: haxework.gui.InputView
width: 30
height: 20
text: "55"
skin:
$type: haxework.gui.skin.ColorSkin
color: 0xffffff
- id: colorB
$type: haxework.gui.InputView
width: 30
height: 20
text: "f0"
skin:
$type: haxework.gui.skin.ColorSkin
color: 0xffffff

View File

@@ -1,4 +1,4 @@
package ru.m.tankz.editor;
package ru.m.tankz.editor.level;
import flash.display.Bitmap;
import flash.display.Shape;
@@ -38,7 +38,7 @@ class BrickView extends SpriteView implements IListItemView<BrickConfig> {
private function set_data(value:BrickConfig):BrickConfig {
data = value;
var src = 'resources/images/map/map_${value.type}.png';
var src = 'resources/image/map/${value.type}.png';
imageView.bitmapData = Assets.getBitmapData(src);
imageView.x = (width - imageView.width) / 2;
imageView.y = (height - imageView.height) / 2;

View File

@@ -1,17 +1,17 @@
package ru.m.tankz.editor;
package ru.m.tankz.editor.level;
import ru.m.geom.Rectangle;
import ru.m.tankz.core.Entity;
import ru.m.geom.Point;
import flash.events.MouseEvent;
import ru.m.tankz.map.Brick;
import flash.display.DisplayObjectContainer;
import flash.display.Graphics;
import flash.display.Sprite;
import ru.m.tankz.render.RenderItem;
import ru.m.tankz.config.Config;
import ru.m.tankz.map.LevelMap;
import flash.events.MouseEvent;
import haxework.gui.SpriteView;
import ru.m.geom.Point;
import ru.m.geom.Rectangle;
import ru.m.tankz.config.Config;
import ru.m.tankz.core.Entity;
import ru.m.tankz.map.Brick;
import ru.m.tankz.map.LevelMap;
import ru.m.tankz.render.RenderItem;
class SpawnPointEntity extends Entity {
@@ -41,11 +41,23 @@ class SpawnPointItem extends BitmapItem<SpawnPointEntity> {
}
public static function getSrc(value:SpawnPoint, config:Config):String {
var tankType = config.getTeam(value.team).tanks[0];
var preset:GamePreset = config.presets[config.presets.length - 1];
var tankConfig:TankConfig = null;
if (value.type == 'tank') {
var team:TeamConfig = Lambda.find(preset.teams, function(t) return t.id == value.team);
var player:PlayerConfig = null;
if (value.index > 0) {
player = Lambda.find(team.players, function(p) return p.index == value.index);
} else {
player = team.players[0];
}
var tankType = player.tanks[0];
tankConfig = config.getTank(tankType.type);
}
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';
case 'eagle': 'resources/image/eagle/eagle.png';
case 'tank': 'resources/image/tank/${tankConfig.skin}-0.png';
case x: 'resources/image/eagle/eagle-death.png';
}
}
@@ -180,7 +192,7 @@ class MapEditView extends SpriteView {
}
private function drawMap() {
for (brick in map.bricks) if (brick.config.type > 0) {
for (brick in map.bricks) if (brick.config.index > 0) {
if (!items.exists(brick.key)) {
items[brick.key] = new BrickItem(brick);
if (brick.config.layer > 2) {

View File

@@ -1,13 +1,13 @@
package ru.m.tankz.editor;
package ru.m.tankz.editor.level;
import haxework.provider.Provider;
import ru.m.tankz.editor.MapEditView.SpawnPointItem;
import flash.display.Bitmap;
import flash.display.Shape;
import haxework.gui.list.ListView;
import haxework.gui.SpriteView;
import haxework.provider.Provider;
import openfl.utils.Assets;
import ru.m.tankz.config.Config;
import ru.m.tankz.editor.level.MapEditView;
class SpawnPointView extends SpriteView implements IListItemView<SpawnPoint> {

View File

@@ -0,0 +1,45 @@
package ru.m.tankz.editor.tank;
import ru.m.draw.BitmapUtil;
import ru.m.draw.Color;
import flash.display.BitmapData;
import flash.display.Bitmap;
import haxework.gui.View;
class TankView extends View {
public var contentAsBitmap(get, null):Bitmap;
public var image(default, set):BitmapData;
public var color(default, set):Color;
public function new() {
super(new Bitmap());
}
inline private function get_contentAsBitmap():Bitmap {
return cast content;
}
inline private function get_image():BitmapData {
return contentAsBitmap.bitmapData;
}
inline private function set_image(value:BitmapData):BitmapData {
image = value;
contentAsBitmap.bitmapData = BitmapUtil.colorize(image, color);
if (contentSize) {
width = image.width;
height = image.height;
}
return image;
}
inline private function set_color(value:Color):Color {
color = value;
if (image != null) {
contentAsBitmap.bitmapData = BitmapUtil.colorize(image, color);
}
return color;
}
}