Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b04242aab | |||
| a127777e49 | |||
| 11aea59cf8 | |||
| 5456a01551 | |||
| a93a67161d | |||
| 52a4e44e47 | |||
| 79039ae79e | |||
| 1ae84cf5a8 | |||
| 032fa0c0ad | |||
| 1f8b43ba5d | |||
| 4fc0ae103e | |||
| bd86412d83 | |||
| 592e59e01f | |||
| 05b6fe4a56 | |||
| f68e5d160f | |||
| d279d52b09 |
29
WORK.md
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
* ui
|
* ui
|
||||||
* auth frame 0%
|
* 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%
|
* select level frame 10%
|
||||||
* game frame 50%
|
* game frame 50%
|
||||||
|
|
||||||
@@ -21,21 +21,29 @@
|
|||||||
* bullets 100%
|
* bullets 100%
|
||||||
* boxes 100%
|
* boxes 100%
|
||||||
* map changes 100%
|
* map changes 100%
|
||||||
* bonuses 0%
|
* bonuses 100%
|
||||||
* eagle 100%
|
* eagle 100%
|
||||||
|
|
||||||
* game
|
* game
|
||||||
* classic
|
* classic
|
||||||
* state 50%
|
* state 50%
|
||||||
* bot 50%
|
* bot 50%
|
||||||
* player: 50%
|
* human 100%
|
||||||
* dota
|
* dota
|
||||||
* state 50%
|
* state 50%
|
||||||
* bot 10%
|
* bot 10%
|
||||||
* player 0%
|
* human 100%
|
||||||
|
|
||||||
|
* bonus
|
||||||
|
* star 50%
|
||||||
|
* grenade 0%
|
||||||
|
* helm 0%
|
||||||
|
* clock 0%
|
||||||
|
* shovel 0%
|
||||||
|
|
||||||
* state
|
* state
|
||||||
* score 0%
|
* score 0%
|
||||||
|
* human tank 0%
|
||||||
* save/load 0%
|
* save/load 0%
|
||||||
* export/import 0%
|
* export/import 0%
|
||||||
|
|
||||||
@@ -47,16 +55,19 @@
|
|||||||
* animations
|
* animations
|
||||||
* tank spawn 0%
|
* tank spawn 0%
|
||||||
* tank move 100%
|
* tank move 100%
|
||||||
* map water 0%
|
* map water 100%
|
||||||
* bullet boom 90%
|
* bullet boom 90%
|
||||||
* tank boom 90%
|
* tank boom 90%
|
||||||
* bonuses 0%
|
* bonuses 100%
|
||||||
* html5 50%
|
* html5 50%
|
||||||
|
|
||||||
* proto
|
* proto
|
||||||
...
|
...
|
||||||
|
|
||||||
* editor
|
* editor
|
||||||
* open 0%
|
* level
|
||||||
* edit 0%
|
* open 100%
|
||||||
* save 0%
|
* edit 50%
|
||||||
|
* save 100%
|
||||||
|
* tank
|
||||||
|
* color 10%
|
||||||
@@ -21,7 +21,7 @@ const generate = () => function generate() {
|
|||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const build = (platform) => function build() {
|
const build = (platform, values) => function build() {
|
||||||
const argv = yargs.argv;
|
const argv = yargs.argv;
|
||||||
return gulp.src('.')
|
return gulp.src('.')
|
||||||
.pipe(new Haxe().openfl({
|
.pipe(new Haxe().openfl({
|
||||||
@@ -29,6 +29,7 @@ const build = (platform) => function build() {
|
|||||||
platform: platform,
|
platform: platform,
|
||||||
version: version,
|
version: version,
|
||||||
debug: argv.dev,
|
debug: argv.dev,
|
||||||
|
values: values
|
||||||
}))
|
}))
|
||||||
.pipe(gulp.dest(`target/${platform}`));
|
.pipe(gulp.dest(`target/${platform}`));
|
||||||
};
|
};
|
||||||
@@ -87,6 +88,7 @@ const buildDeb = gulp.series(
|
|||||||
exports['client:flash:html'] = gulp.parallel(flashIndex, flashJs);
|
exports['client:flash:html'] = gulp.parallel(flashIndex, flashJs);
|
||||||
exports['client:flash'] = gulp.series(prepare(Haxe.ID), generate(), build('flash'), exports['client:flash:html']);
|
exports['client:flash'] = gulp.series(prepare(Haxe.ID), generate(), build('flash'), exports['client:flash:html']);
|
||||||
exports['client:html5'] = gulp.series(prepare(Haxe.ID), generate(), build('html5'));
|
exports['client:html5'] = gulp.series(prepare(Haxe.ID), generate(), build('html5'));
|
||||||
|
exports['client:html5-dom'] = gulp.series(prepare(Haxe.ID), generate(), build('html5', {dom:true}));
|
||||||
exports['client:linux'] = gulp.series(prepare(Haxe.ID), generate(), build('linux'));
|
exports['client:linux'] = gulp.series(prepare(Haxe.ID), generate(), build('linux'));
|
||||||
exports['client:webapp'] = webapp;
|
exports['client:webapp'] = webapp;
|
||||||
exports['client:deb'] = buildDeb;
|
exports['client:deb'] = buildDeb;
|
||||||
@@ -108,9 +110,9 @@ const testFlash = function() {
|
|||||||
.pipe(debug());
|
.pipe(debug());
|
||||||
};
|
};
|
||||||
|
|
||||||
const testHtml5 = function() {
|
const testHtml5 = (dom) => function() {
|
||||||
return gulp.series(
|
return gulp.series(
|
||||||
build('html5'),
|
build('html5', {dom:dom}),
|
||||||
() => gulp.src('target/html5').pipe(webserver({
|
() => gulp.src('target/html5').pipe(webserver({
|
||||||
host: 'localhost', port: 3000,
|
host: 'localhost', port: 3000,
|
||||||
open: true,
|
open: true,
|
||||||
@@ -130,7 +132,8 @@ const testLinux = gulp.series(
|
|||||||
|
|
||||||
|
|
||||||
exports['client:flash:test'] = gulp.series(prepare(Haxe.ID, FlashPlayer.ID), testFlash);
|
exports['client:flash:test'] = gulp.series(prepare(Haxe.ID, FlashPlayer.ID), testFlash);
|
||||||
exports['client:html5:test'] = gulp.series(prepare(Haxe.ID), testHtml5);
|
exports['client:html5:test'] = gulp.series(prepare(Haxe.ID), testHtml5());
|
||||||
|
exports['client:html5-dom:test'] = gulp.series(prepare(Haxe.ID), testHtml5(true));
|
||||||
exports['client:linux:test'] = gulp.series(prepare(Haxe.ID), testLinux);
|
exports['client:linux:test'] = gulp.series(prepare(Haxe.ID), testLinux);
|
||||||
exports['client:test'] = exports['client:flash:test'];
|
exports['client:test'] = exports['client:flash:test'];
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tankz",
|
"name": "tankz",
|
||||||
"version": "0.6.0",
|
"version": "0.7.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ansi-colors": "^1.0.1",
|
"ansi-colors": "^1.0.1",
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
"protohx": "0.4.6",
|
"protohx": "0.4.6",
|
||||||
"yaml": "1.3.0",
|
"yaml": "1.3.0",
|
||||||
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
||||||
"orm": "2.1.0"
|
"orm": "2.1.0",
|
||||||
|
"yield": "1.1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,15 @@
|
|||||||
<haxelib name="protohx" version="0.4.6"/>
|
<haxelib name="protohx" version="0.4.6"/>
|
||||||
<haxelib name="haxework" version="git"/>
|
<haxelib name="haxework" version="git"/>
|
||||||
<haxelib name="yaml" version="1.3.0"/>
|
<haxelib name="yaml" version="1.3.0"/>
|
||||||
|
<haxelib name="yield" version="1.1.2"/>
|
||||||
<window fps="30"/>
|
<window fps="30"/>
|
||||||
<window width="1024" height="768" unless="html5"/>
|
<window width="1024" height="768" unless="html5"/>
|
||||||
<haxeflag name="-D" value="swf-gpu"/>
|
<haxeflag name="-D" value="swf-gpu"/>
|
||||||
<haxeflag name="-D" value="native-trace"/>
|
<haxeflag name="-D" value="native-trace"/>
|
||||||
<!--<haxeflag name="-D" value="proto_debug"/>-->
|
<!--<haxeflag name="-D" value="proto_debug"/>-->
|
||||||
<haxeflag name="-dce" value="no"/>
|
<haxeflag name="-dce" value="no"/>
|
||||||
<haxeflag name="-D" value="dom"/>
|
<!--<haxeflag name="-D" value="dom"/>-->
|
||||||
|
<haxeflag name="--macro" value="yield.parser.Parser.auto()"/>
|
||||||
<!--<template path="src/client/webapp/index_template.html" rename="index.html"/>-->
|
<!--<template path="src/client/webapp/index_template.html" rename="index.html"/>-->
|
||||||
|
|
||||||
<section if="build_editor">
|
<section if="build_editor">
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,11 @@ import flash.display.Bitmap;
|
|||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
|
|
||||||
|
|
||||||
|
typedef Frame = {
|
||||||
|
var image:BitmapData;
|
||||||
|
var length:Int;
|
||||||
|
}
|
||||||
|
|
||||||
class Animate extends Bitmap {
|
class Animate extends Bitmap {
|
||||||
|
|
||||||
private static var timer:Timer;
|
private static var timer:Timer;
|
||||||
@@ -26,24 +31,30 @@ class Animate extends Bitmap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static var a = new BitmapData(1, 1);
|
|
||||||
|
|
||||||
public var playing(default, set):Bool;
|
public var playing(default, set):Bool;
|
||||||
public var frames(default, set):Array<BitmapData>;
|
public var frames(default, set):Array<Frame>;
|
||||||
|
|
||||||
|
private var sequence:Array<BitmapData>;
|
||||||
private var index:Int;
|
private var index:Int;
|
||||||
|
|
||||||
public function new(?frames:Array<BitmapData>) {
|
public function new(?frames:Array<Frame>) {
|
||||||
super(null, PixelSnapping.AUTO, true);
|
super(null, PixelSnapping.AUTO, true);
|
||||||
this.frames = frames == null ? [] : frames;
|
this.frames = frames == null ? [] : frames;
|
||||||
init();
|
init();
|
||||||
instances.push(this);
|
instances.push(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_frames(value:Array<BitmapData>):Array<BitmapData> {
|
public function set_frames(value:Array<Frame>):Array<Frame> {
|
||||||
|
sequence = [];
|
||||||
|
index = 0;
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
frames = value;
|
frames = value;
|
||||||
bitmapData = frames[0];
|
for (frame in frames) {
|
||||||
index = 0;
|
sequence = sequence.concat([for (i in 0...frame.length) frame.image]);
|
||||||
|
}
|
||||||
|
bitmapData = sequence[0];
|
||||||
|
} else {
|
||||||
|
bitmapData = null;
|
||||||
}
|
}
|
||||||
return frames;
|
return frames;
|
||||||
}
|
}
|
||||||
@@ -56,10 +67,10 @@ class Animate extends Bitmap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function update():Void {
|
private function update():Void {
|
||||||
if (++index >= frames.length) {
|
if (++index >= sequence.length) {
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
var nextBitmapData = frames[index];
|
var nextBitmapData = sequence[index];
|
||||||
x -= (nextBitmapData.width - bitmapData.width) / 2;
|
x -= (nextBitmapData.width - bitmapData.width) / 2;
|
||||||
y -= (nextBitmapData.height - bitmapData.height) / 2;
|
y -= (nextBitmapData.height - bitmapData.height) / 2;
|
||||||
bitmapData = nextBitmapData;
|
bitmapData = nextBitmapData;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package ru.m.animate;
|
package ru.m.animate;
|
||||||
|
|
||||||
import promhx.Deferred;
|
import promhx.Deferred;
|
||||||
import flash.display.BitmapData;
|
|
||||||
import promhx.Promise;
|
import promhx.Promise;
|
||||||
|
|
||||||
|
|
||||||
@@ -9,10 +8,6 @@ class OnceAnimate extends Animate {
|
|||||||
|
|
||||||
private var deferred:Deferred<Animate>;
|
private var deferred:Deferred<Animate>;
|
||||||
|
|
||||||
public function new(frames:Array<BitmapData>) {
|
|
||||||
super(frames);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function play():Promise<Animate> {
|
public function play():Promise<Animate> {
|
||||||
deferred = new Deferred();
|
deferred = new Deferred();
|
||||||
playing = true;
|
playing = true;
|
||||||
|
|||||||
@@ -1,34 +1,42 @@
|
|||||||
package ru.m.tankz;
|
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.bundle.ConfigBundle;
|
||||||
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
|
import ru.m.tankz.bundle.LevelBundle;
|
||||||
|
import ru.m.tankz.frame.StartFrame;
|
||||||
import ru.m.tankz.game.ClassicGame;
|
import ru.m.tankz.game.ClassicGame;
|
||||||
import ru.m.tankz.game.DotaGame;
|
import ru.m.tankz.game.DotaGame;
|
||||||
import ru.m.tankz.game.Game;
|
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 ru.m.tankz.PacketBuilder;
|
||||||
import haxework.log.JSLogger;
|
import ru.m.tankz.storage.SaveStorage;
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
#if flash import haxework.log.JSLogger; #end
|
||||||
import haxework.provider.Provider;
|
#if debug import haxework.log.SocketLogger; #end
|
||||||
import haxework.gui.frame.FrameSwitcher;
|
|
||||||
import haxework.gui.Root;
|
|
||||||
import openfl.Assets;
|
|
||||||
import ru.m.connect.IConnection;
|
|
||||||
import haxework.log.TraceLogger;
|
|
||||||
|
|
||||||
@: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 {
|
class Client implements IConnectionHandler {
|
||||||
|
|
||||||
private static inline var TAG = "Tankz";
|
private static inline var TAG = 'Tankz';
|
||||||
|
|
||||||
public static function main() {
|
public static function main() {
|
||||||
L.push(new TraceLogger());
|
L.push(new TraceLogger());
|
||||||
@@ -39,36 +47,35 @@ class Client implements IConnectionHandler {
|
|||||||
L.push(new SocketLogger());
|
L.push(new SocketLogger());
|
||||||
#end
|
#end
|
||||||
Const.init();
|
Const.init();
|
||||||
L.d(TAG, "Debug: " + Const.DEBUG);
|
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
||||||
L.i(TAG, "Version: " + Const.VERSION);
|
L.i(TAG, 'Version: ${Const.VERSION}');
|
||||||
L.i(TAG, "Build: " + Const.BUILD);
|
L.i(TAG, 'Build: ${Const.BUILD}');
|
||||||
new Client();
|
new Client();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private var view:MainView;
|
private var view:ClientView;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
Provider.setFactory(IResources, Resources);
|
Provider.setFactory(IResources, Resources);
|
||||||
|
|
||||||
var font:Font = Font.enumerateFonts()[0];
|
var font:Font = Font.enumerateFonts()[0];
|
||||||
Provider.get(IResources).text.put("font", "Bookman Old Style");
|
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('version', 'v${Const.VERSION} b${Const.BUILD}');
|
||||||
|
|
||||||
Provider.set(IPacketBuilder, new PacketBuilder());
|
Provider.set(IPacketBuilder, new PacketBuilder());
|
||||||
#if flash
|
#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
|
#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
|
#end
|
||||||
|
|
||||||
//Provider.get(IConnection).handler.addListener(this);
|
//Provider.get(IConnection).handler.addListener(this);
|
||||||
view = new MainView();
|
view = new ClientView();
|
||||||
Provider.set(IFrameSwitcher, view.switcher);
|
Provider.set(IFrameSwitcher, view.switcher);
|
||||||
Root.bind(view);
|
Root.bind(view);
|
||||||
view.content.stage.stageFocusRect = false;
|
view.content.stage.stageFocusRect = false;
|
||||||
//view.logout.onPress = this;
|
//view.logout.onPress = this;
|
||||||
view.switcher.change(StartFrame.ID);
|
|
||||||
|
|
||||||
view.content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
view.content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
||||||
if (event.keyCode == Keyboard.ESCAPE) {
|
if (event.keyCode == Keyboard.ESCAPE) {
|
||||||
@@ -76,13 +83,18 @@ class Client implements IConnectionHandler {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Provider.setFactory(IConfigBundle, ConfigBundle);
|
||||||
|
Provider.setFactory(ILevelBundle, LevelBundle);
|
||||||
|
Provider.setFactory(SaveStorage, SaveStorage);
|
||||||
Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE);
|
Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE);
|
||||||
Provider.setFactory(Game, DotaGame, DotaGame.TYPE);
|
Provider.setFactory(Game, DotaGame, DotaGame.TYPE);
|
||||||
|
|
||||||
|
view.switcher.change(StartFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPress(view:ButtonView):Void {
|
public function onPress(view:ButtonView):Void {
|
||||||
switch (view.id) {
|
switch (view.id) {
|
||||||
case "logout":
|
case 'logout':
|
||||||
Provider.get(IConnection).disconnect();
|
Provider.get(IConnection).disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +106,7 @@ class Client implements IConnectionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onError(error:Dynamic):Void {
|
public function onError(error:Dynamic):Void {
|
||||||
L.e(TAG, "", error);
|
L.e(TAG, '', error);
|
||||||
//view.switcher.change(AuthFrame.ID);
|
//view.switcher.change(AuthFrame.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/client/haxe/ru/m/tankz/Client.yaml
Executable 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/image/ui/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"
|
||||||
21
src/client/haxe/ru/m/tankz/Style.yaml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
button:
|
||||||
|
width: 250
|
||||||
|
height: 60
|
||||||
|
skin:
|
||||||
|
$type: haxework.gui.skin.ButtonBitmapSkin
|
||||||
|
upImage: "@asset:image:resources/image/ui/button/normal.png"
|
||||||
|
downImage: "@asset:image:resources/image/ui/button/down.png"
|
||||||
|
overImage: "@asset:image:resources/image/ui/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
|
||||||
@@ -1,29 +1,30 @@
|
|||||||
package ru.m.tankz.config;
|
package ru.m.tankz.bundle;
|
||||||
|
|
||||||
import yaml.Parser;
|
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import yaml.Yaml;
|
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import yaml.Parser;
|
||||||
|
import yaml.Yaml;
|
||||||
|
|
||||||
|
|
||||||
typedef ConfigSource = {
|
typedef ConfigSource = {
|
||||||
var game:GameConfig;
|
var game:GameConfig;
|
||||||
var map: MapConfig;
|
var map: MapConfig;
|
||||||
var bricks: Array<BrickConfig>;
|
var bricks: Array<BrickConfig>;
|
||||||
var teams: Array<TeamConfig>;
|
var presets: Array<GamePreset>;
|
||||||
var points: Array<SpawnPoint>;
|
var points: Array<SpawnPoint>;
|
||||||
var tanks: Array<TankConfig>;
|
var tanks: Array<TankConfig>;
|
||||||
var bonuses: Array<BonusConfig>;
|
var bonuses: Array<BonusConfig>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConfigBundle {
|
class ConfigBundle implements IConfigBundle {
|
||||||
|
|
||||||
private static function convert(raw:Dynamic):ConfigSource {
|
private static function convert(raw:Dynamic):ConfigSource {
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get(type:String):Config {
|
public function get(type:GameType):Config {
|
||||||
var source = convert(Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()));
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
15
src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package ru.m.tankz.bundle;
|
||||||
|
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import ru.m.tankz.util.LevelUtil;
|
||||||
|
|
||||||
|
|
||||||
|
class LevelBundle implements ILevelBundle {
|
||||||
|
|
||||||
|
public function get(type:GameType, config:Config, level:Int):LevelConfig {
|
||||||
|
var data:String = Assets.getText('resources/${type}/levels/level${LevelUtil.formatLevel(level)}.txt');
|
||||||
|
return LevelUtil.loads(config, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 flash.events.Event;
|
||||||
|
import haxe.ds.Option;
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
import haxework.gui.LabelView;
|
import haxework.gui.LabelView;
|
||||||
@@ -12,9 +11,11 @@ import haxework.provider.Provider;
|
|||||||
import protohx.Message;
|
import protohx.Message;
|
||||||
import ru.m.connect.IConnection;
|
import ru.m.connect.IConnection;
|
||||||
import ru.m.tankz.game.Game;
|
import ru.m.tankz.game.Game;
|
||||||
|
import ru.m.tankz.game.GameSave;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.proto.pack.GameUpdateResponse;
|
import ru.m.tankz.proto.pack.GameUpdateResponse;
|
||||||
import ru.m.tankz.render.Render;
|
import ru.m.tankz.render.Render;
|
||||||
|
import ru.m.tankz.storage.SaveStorage;
|
||||||
|
|
||||||
|
|
||||||
interface GameFrameLayout {
|
interface GameFrameLayout {
|
||||||
@@ -22,8 +23,7 @@ interface GameFrameLayout {
|
|||||||
var render(default, null):Render;
|
var render(default, null):Render;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@:template("ru/m/tankz/frame/GameFrame.yaml", "ru/m/tankz/Style.yaml")
|
||||||
@:template("layout/frames/game.json", "layout/styles.json")
|
|
||||||
class GameFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements GameFrameLayout {
|
class GameFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements GameFrameLayout {
|
||||||
|
|
||||||
private static inline var TAG = "GameFrame";
|
private static inline var TAG = "GameFrame";
|
||||||
@@ -36,22 +36,22 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
|||||||
public function init():Void {}
|
public function init():Void {}
|
||||||
|
|
||||||
public function onShow():Void {
|
public function onShow():Void {
|
||||||
start(Provider.get(GameState));
|
start(Provider.get(GameSave));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function start(s:GameState):Void {
|
private function start(save:GameSave):Void {
|
||||||
game = Provider.build(Game, s.type);
|
game = Provider.build(Game, save.state.type);
|
||||||
if (game == null) {
|
if (game == null) {
|
||||||
throw 'Unsupported game type "${s.type}"';
|
throw 'Unsupported game type "${save.state.type}"';
|
||||||
}
|
}
|
||||||
game.engine.listeners.push(render);
|
game.engine.listeners.push(render);
|
||||||
game.start(s).then(onGameStateChange).endThen(onGameComplete);
|
game.start(save).then(onGameStateChange).endThen(onGameComplete);
|
||||||
content.addEventListener(Event.ENTER_FRAME, redraw);
|
content.addEventListener(Event.ENTER_FRAME, redraw);
|
||||||
//Provider.get(IConnection).packetHandler.addListener(this);
|
//Provider.get(IConnection).packetHandler.addListener(this);
|
||||||
render.draw(game.engine);
|
render.draw(game.engine);
|
||||||
timer = new Timer(10);
|
timer = new Timer(10);
|
||||||
timer.run = updateEngine;
|
timer.run = updateEngine;
|
||||||
state.text = stateString(s);
|
state.text = stateString(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function stop():Void {
|
private function stop():Void {
|
||||||
@@ -68,20 +68,21 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
|||||||
render.reset();
|
render.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function stateString(state:GameState):String {
|
private function stateString(game:Game):String {
|
||||||
|
if (game.state == null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
var result:Array<String> = [];
|
var result:Array<String> = [];
|
||||||
result.push('Level: ${state.level}');
|
result.push('Level: ${game.state.level}');
|
||||||
for (teamId in state.teams.keys()) {
|
for (team in game.teams) {
|
||||||
var ts:TeamState = state.teams[teamId];
|
if (game.state.loser == team.id) {
|
||||||
if (ts.lose) {
|
result.push('${team.id}: LOSE');
|
||||||
result.push('${teamId}: LOSE');
|
} else if (team.life > -1) {
|
||||||
} else if (ts.life > -1) {
|
result.push('${team.id}: ${team.life}');
|
||||||
result.push('${teamId}: ${ts.life}');
|
|
||||||
} else {
|
} else {
|
||||||
for (index in ts.players.keys()) {
|
for (player in team.players) {
|
||||||
var ps:PlayerState = ts.players[index];
|
if (player.life > -1) {
|
||||||
if (ps.life > -1) {
|
result.push('${player.id.team}${player.id.index}: ${player.life}');
|
||||||
result.push('${teamId}${index}: ${ps.life}');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,20 +91,22 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function onGameStateChange(s:GameState):GameState {
|
private function onGameStateChange(s:GameState):GameState {
|
||||||
state.text = stateString(s);
|
state.text = stateString(game);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onGameComplete(result:Option<GameState>):Void {
|
private function onGameComplete(result:Option<GameState>):Void {
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case Option.Some(s):
|
case Option.Some(s):
|
||||||
state.text = stateString(s);
|
state.text = stateString(game);
|
||||||
case Option.None:
|
case Option.None:
|
||||||
}
|
}
|
||||||
switch (game.next()) {
|
switch (game.next()) {
|
||||||
case Option.Some(s):
|
case Option.Some(s):
|
||||||
|
var save = game.save();
|
||||||
|
Provider.get(SaveStorage).write(save);
|
||||||
stop();
|
stop();
|
||||||
start(s);
|
start(save);
|
||||||
case Option.None:
|
case Option.None:
|
||||||
Provider.get(IFrameSwitcher).change(StartFrame.ID);
|
Provider.get(IFrameSwitcher).change(StartFrame.ID);
|
||||||
}
|
}
|
||||||
12
src/client/haxe/ru/m/tankz/frame/GameFrame.yaml
Normal 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
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
package ru.m.tankz.view.frames;
|
package ru.m.tankz.frame;
|
||||||
|
|
||||||
import ru.m.tankz.config.ConfigBundle;
|
import ru.m.tankz.game.GameSave;
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
import ru.m.tankz.game.GameState;
|
|
||||||
import haxework.provider.Provider;
|
|
||||||
import haxework.gui.list.ListView;
|
import haxework.gui.list.ListView;
|
||||||
import haxework.gui.ViewBuilder;
|
|
||||||
import haxework.gui.VGroupView;
|
import haxework.gui.VGroupView;
|
||||||
|
import haxework.gui.ViewBuilder;
|
||||||
|
import haxework.provider.Provider;
|
||||||
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
|
||||||
|
|
||||||
interface LevelFrameLayout {
|
interface LevelFrameLayout {
|
||||||
@@ -14,7 +15,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 {
|
class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrameLayout {
|
||||||
public static inline var ID = "level";
|
public static inline var ID = "level";
|
||||||
|
|
||||||
@@ -23,13 +24,13 @@ class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrame
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onShow():Void {
|
public function onShow():Void {
|
||||||
var state = Provider.get(GameState);
|
var state:GameState = Provider.get(GameSave).state;
|
||||||
var c = ConfigBundle.get(state.type).game.levels;
|
var c = Provider.get(IConfigBundle).get(state.type).game.levels;
|
||||||
levels.data = [for (i in 0...c) i];
|
levels.data = [for (i in 0...c) i];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onListItemClick(item:IListItemView<Int>):Void {
|
public function onListItemClick(item:IListItemView<Int>):Void {
|
||||||
Provider.get(GameState).level = item.data;
|
Provider.get(GameSave).state.level = item.data;
|
||||||
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
20
src/client/haxe/ru/m/tankz/frame/LevelFrame.yaml
Normal 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
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package ru.m.tankz.view.frames;
|
package ru.m.tankz.frame;
|
||||||
|
|
||||||
|
import ru.m.tankz.storage.SaveStorage;
|
||||||
|
import ru.m.tankz.game.GameSave;
|
||||||
import haxework.gui.ButtonView;
|
import haxework.gui.ButtonView;
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
import haxework.gui.VGroupView;
|
import haxework.gui.VGroupView;
|
||||||
@@ -14,30 +16,38 @@ import ru.m.tankz.Type;
|
|||||||
interface StartFrameLayout {
|
interface StartFrameLayout {
|
||||||
var classic_1p(default, null):ButtonView;
|
var classic_1p(default, null):ButtonView;
|
||||||
var classic_2p(default, null):ButtonView;
|
var classic_2p(default, null):ButtonView;
|
||||||
|
var classic_load(default, null):ButtonView;
|
||||||
var dota_1p(default, null):ButtonView;
|
var dota_1p(default, null):ButtonView;
|
||||||
var dota_2p_coop(default, null):ButtonView;
|
var dota_2p_coop(default, null):ButtonView;
|
||||||
var dota_2p_vs(default, null):ButtonView;
|
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 {
|
class StartFrame extends VGroupView implements ViewBuilder implements StartFrameLayout {
|
||||||
|
|
||||||
public static inline var ID = "start";
|
public static inline var ID = "start";
|
||||||
|
|
||||||
public function init() {
|
public function init():Void {
|
||||||
classic_1p.onPress = this;
|
classic_1p.onPress = this;
|
||||||
classic_2p.onPress = this;
|
classic_2p.onPress = this;
|
||||||
|
classic_load.onPress = this;
|
||||||
dota_1p.onPress = this;
|
dota_1p.onPress = this;
|
||||||
dota_2p_coop.onPress = this;
|
dota_2p_coop.onPress = this;
|
||||||
dota_2p_vs.onPress = this;
|
dota_2p_vs.onPress = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onShow():Void {
|
||||||
|
classic_load.visible = Provider.get(SaveStorage).read(ClassicGame.TYPE) != null;
|
||||||
|
}
|
||||||
|
|
||||||
public function onPress(view:ButtonView):Void {
|
public function onPress(view:ButtonView):Void {
|
||||||
switch (view.id) {
|
switch (view.id) {
|
||||||
case 'classic_1p':
|
case 'classic_1p':
|
||||||
startGame(ClassicGame.TYPE, ClassicGame.PLAYER1);
|
startGame(ClassicGame.TYPE, ClassicGame.PLAYER1);
|
||||||
case 'classic_2p':
|
case 'classic_2p':
|
||||||
startGame(ClassicGame.TYPE, ClassicGame.PLAYER2);
|
startGame(ClassicGame.TYPE, ClassicGame.PLAYER2);
|
||||||
|
case 'classic_load':
|
||||||
|
loadGame(ClassicGame.TYPE);
|
||||||
case 'dota_1p':
|
case 'dota_1p':
|
||||||
startGame(DotaGame.TYPE, DotaGame.PLAYER1);
|
startGame(DotaGame.TYPE, DotaGame.PLAYER1);
|
||||||
case 'dota_2p_coop':
|
case 'dota_2p_coop':
|
||||||
@@ -47,14 +57,14 @@ class StartFrame extends VGroupView implements ViewBuilder implements StartFrame
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function startGame(type:GameType, mode:GameMode):Void {
|
private function startGame(type:GameType, presetId:PresetId):Void {
|
||||||
switch (type) {
|
Provider.set(GameSave, new GameSave({type: type, presetId: presetId}));
|
||||||
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);
|
Provider.get(IFrameSwitcher).change(LevelFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function loadGame(type:GameType):Void {
|
||||||
|
var save:GameSave = Provider.get(SaveStorage).read(type);
|
||||||
|
Provider.set(GameSave, save);
|
||||||
|
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
44
src/client/haxe/ru/m/tankz/frame/StartFrame.yaml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
---
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
views:
|
||||||
|
- $type: haxework.gui.ImageView
|
||||||
|
image: "@asset:image:resources/image/ui/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
|
||||||
|
- id: classic_load
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
text: Load
|
||||||
|
$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
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ru.m.tankz.view.frames.list;
|
package ru.m.tankz.frame.level;
|
||||||
|
|
||||||
import haxework.gui.ViewBuilder;
|
import haxework.gui.ViewBuilder;
|
||||||
import haxework.gui.HGroupView;
|
import haxework.gui.HGroupView;
|
||||||
@@ -10,7 +10,7 @@ interface LevelViewLayout {
|
|||||||
var label(default, null):LabelView;
|
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 {
|
class LevelView extends HGroupView implements ViewBuilder implements IListItemView<Int> implements LevelViewLayout {
|
||||||
|
|
||||||
public var item_index(default, default):Int;
|
public var item_index(default, default):Int;
|
||||||
15
src/client/haxe/ru/m/tankz/frame/level/LevelView.yaml
Normal 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
|
||||||
71
src/client/haxe/ru/m/tankz/render/AnimateBundle.hx
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
|
import ru.m.draw.BitmapUtil;
|
||||||
|
import ru.m.draw.Color;
|
||||||
|
import flash.display.BitmapData;
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.animate.Animate;
|
||||||
|
import ru.m.animate.OnceAnimate;
|
||||||
|
import ru.m.tankz.core.Tank;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
|
class AnimateBundle {
|
||||||
|
|
||||||
|
private static function buildAnimate(name:String, sequence:Array<Int>):OnceAnimate {
|
||||||
|
var template:String = 'resources/image/animate/${name}/%index%.png';
|
||||||
|
var frames = [for (i in sequence) ({
|
||||||
|
image: Assets.getBitmapData(StringTools.replace(template, '%index%', Std.string(i))),
|
||||||
|
length: 1
|
||||||
|
})];
|
||||||
|
return new OnceAnimate(frames);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tankSpawn():OnceAnimate {
|
||||||
|
return buildAnimate('appear', [
|
||||||
|
0, 1, 2, 3, 3, 4, 5, 5, 6
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tankBoom():OnceAnimate {
|
||||||
|
return buildAnimate('boom', [
|
||||||
|
0, 1, 2, 3, 4, 4, 4, 1, 4, 4, 7, 7, 8, 9, 9
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function bulletBoom():OnceAnimate {
|
||||||
|
return buildAnimate('boom-sm', [
|
||||||
|
0, 1, 1, 0, 0, 1
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tankProtect():Animate {
|
||||||
|
return new Animate([for (i in 0...2) ({
|
||||||
|
image: Assets.getBitmapData('resources/image/animate/protect/${i}.png'),
|
||||||
|
length: 5
|
||||||
|
})]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tankFrames(tank:Tank):Array<Frame> {
|
||||||
|
var color:Color = switch (tank.hits) {
|
||||||
|
case 1: 0x869C43;
|
||||||
|
case 2: 0xDEAF80;
|
||||||
|
case 3: 0x5EA67A;
|
||||||
|
case _: tank.color;
|
||||||
|
}
|
||||||
|
var colors:Array<Color> = [color, color];
|
||||||
|
if (tank.bonus) {
|
||||||
|
colors[1] = 0xff00aa;
|
||||||
|
}
|
||||||
|
return [for (i in 0...2) ({
|
||||||
|
image: BitmapUtil.colorize(Assets.getBitmapData('resources/image/tank/${tank.config.skin}-${i}.png'), colors[i]),
|
||||||
|
length: 3
|
||||||
|
})];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function bonusFrames(type:BonusType):Array<Frame> {
|
||||||
|
var image = Assets.getBitmapData('resources/image/bonus/${type}.png');
|
||||||
|
var empty = new BitmapData(image.width, image.height, true, 0x00000000);
|
||||||
|
return [{image: image, length: 15}, {image: empty, length: 15}];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
package ru.m.tankz.render;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
import ru.m.geom.Point;
|
|
||||||
import openfl.Assets;
|
|
||||||
import ru.m.animate.OnceAnimate;
|
|
||||||
import flash.display.DisplayObjectContainer;
|
import flash.display.DisplayObjectContainer;
|
||||||
import ru.m.tankz.core.EntityType;
|
|
||||||
import ru.m.tankz.render.RenderItem;
|
|
||||||
import ru.m.tankz.engine.Engine;
|
|
||||||
import flash.display.Sprite;
|
|
||||||
import flash.display.Graphics;
|
import flash.display.Graphics;
|
||||||
|
import flash.display.Sprite;
|
||||||
import haxework.gui.SpriteView;
|
import haxework.gui.SpriteView;
|
||||||
|
import ru.m.animate.Animate;
|
||||||
|
import ru.m.animate.OnceAnimate;
|
||||||
|
import ru.m.geom.Point;
|
||||||
|
import ru.m.tankz.core.EntityType;
|
||||||
|
import ru.m.tankz.engine.Engine;
|
||||||
|
import ru.m.tankz.render.RenderItem;
|
||||||
|
|
||||||
|
|
||||||
class Render extends SpriteView implements EngineListener {
|
class Render extends SpriteView implements EngineListener {
|
||||||
@@ -54,13 +54,21 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function draw(game:Engine):Void {
|
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)) {
|
if (!items.exists(brick.key)) {
|
||||||
items[brick.key] = new BrickItem(brick);
|
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) {
|
if (brick.config.layer > 2) {
|
||||||
upLayer.addChild(items[brick.key].view);
|
upLayer.addChild(item.view);
|
||||||
} else {
|
} else {
|
||||||
groundLayer.addChild(items[brick.key].view);
|
groundLayer.addChild(item.view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,7 +105,7 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
items.set(tank.key, item);
|
items.set(tank.key, item);
|
||||||
entryLayer.addChild(item.view);
|
entryLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();
|
||||||
playTankSpawn(tank.rect.center);
|
playAnimate(tank.rect.center, AnimateBundle.tankSpawn());
|
||||||
case EntityType.BULLET(bullet):
|
case EntityType.BULLET(bullet):
|
||||||
var item = new BulletItem(bullet);
|
var item = new BulletItem(bullet);
|
||||||
items.set(bullet.key, item);
|
items.set(bullet.key, item);
|
||||||
@@ -111,85 +119,53 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
case EntityType.BONUS(bonus):
|
case EntityType.BONUS(bonus):
|
||||||
var item = new BonusItem(bonus);
|
var item = new BonusItem(bonus);
|
||||||
items.set(bonus.key, item);
|
items.set(bonus.key, item);
|
||||||
entryLayer.addChild(item.view);
|
upperLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onCollision(entity:EntityType, with:EntityType):Void {
|
public function onChange(entity:EntityType, ?change:EntityChange):Void {}
|
||||||
|
|
||||||
|
public function onCollision(entity:EntityType, with:EntityType):Void {
|
||||||
|
switch [entity, with] {
|
||||||
|
case [EntityType.BULLET(_), EntityType.EAGLE(eagle)]:
|
||||||
|
if (eagle.death) {
|
||||||
|
playAnimate(eagle.rect.center, AnimateBundle.tankBoom());
|
||||||
|
}
|
||||||
|
case _:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onDestroy(entity:EntityType):Void {
|
public function onDestroy(entity:EntityType):Void {
|
||||||
switch(entity) {
|
switch entity {
|
||||||
case EntityType.TANK(tank):
|
case EntityType.TANK(tank):
|
||||||
if (items.exists(tank.key)) {
|
if (items.exists(tank.key)) {
|
||||||
entryLayer.removeChild(items.get(tank.key).view);
|
entryLayer.removeChild(items.get(tank.key).view);
|
||||||
items.remove(tank.key);
|
items.remove(tank.key);
|
||||||
playTankBoom(tank.rect.center);
|
playAnimate(tank.rect.center, AnimateBundle.tankBoom());
|
||||||
}
|
}
|
||||||
case EntityType.BULLET(bullet):
|
case EntityType.BULLET(bullet):
|
||||||
if (items.exists(bullet.key)) {
|
if (items.exists(bullet.key)) {
|
||||||
entryLayer.removeChild(items.get(bullet.key).view);
|
entryLayer.removeChild(items.get(bullet.key).view);
|
||||||
items.remove(bullet.key);
|
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)));
|
var point = bullet.rect.center.add(new Point(bullet.rect.width * bullet.rect.direction.x, bullet.rect.height * bullet.rect.direction.y));
|
||||||
}
|
playAnimate(point, AnimateBundle.bulletBoom());
|
||||||
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):
|
case EntityType.BONUS(bonus):
|
||||||
if (items.exists(bonus.key)) {
|
if (items.exists(bonus.key)) {
|
||||||
entryLayer.removeChild(items.get(bonus.key).view);
|
upperLayer.removeChild(items.get(bonus.key).view);
|
||||||
items.remove(bonus.key);
|
items.remove(bonus.key);
|
||||||
}
|
}
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function playTankSpawn(point:Point):Void {
|
private function playAnimate(point:Point, animate:OnceAnimate):Void {
|
||||||
var arr = [
|
|
||||||
0, 1, 2, 3, 3, 4, 5, 5, 6
|
|
||||||
];
|
|
||||||
var frames = [for (i in arr) Assets.getBitmapData('resources/images/tank/appear/appear-${i}.png')];
|
|
||||||
var animate = new OnceAnimate(frames);
|
|
||||||
animate.x = point.x - animate.width / 2;
|
animate.x = point.x - animate.width / 2;
|
||||||
animate.y = point.y - animate.height / 2;
|
animate.y = point.y - animate.height / 2;
|
||||||
upperLayer.addChild(animate);
|
upperLayer.addChild(animate);
|
||||||
animate.play().then(function(animate) {
|
animate.play().then(function(animate:Animate):Void {
|
||||||
upperLayer.removeChild(animate);
|
|
||||||
animate.dispose();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function playBulletBoom(point:Point):Void {
|
|
||||||
var arr = [
|
|
||||||
0, 1, 1, 0, 0, 1
|
|
||||||
];
|
|
||||||
var frames = [for (i in arr) Assets.getBitmapData('resources/images/bullet/boom/boom-${i}.png')];
|
|
||||||
var animate = new OnceAnimate(frames);
|
|
||||||
animate.x = point.x - animate.width / 2;
|
|
||||||
animate.y = point.y - animate.height / 2;
|
|
||||||
upperLayer.addChild(animate);
|
|
||||||
animate.play().then(function(animate) {
|
|
||||||
upperLayer.removeChild(animate);
|
|
||||||
animate.dispose();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function playTankBoom(point:Point):Void {
|
|
||||||
var arr = [
|
|
||||||
0, 1, 2, 3, 4, 4, 4, 1, 4, 4, 7, 7, 8, 9, 9
|
|
||||||
];
|
|
||||||
var frames = [for (i in arr) Assets.getBitmapData('resources/images/tank/kaboom/kaboom-${i}.png')];
|
|
||||||
var animate = new OnceAnimate(frames);
|
|
||||||
animate.x = point.x - animate.width / 2;
|
|
||||||
animate.y = point.y - animate.height / 2;
|
|
||||||
upperLayer.addChild(animate);
|
|
||||||
animate.play().then(function(animate) {
|
|
||||||
upperLayer.removeChild(animate);
|
upperLayer.removeChild(animate);
|
||||||
animate.dispose();
|
animate.dispose();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
package ru.m.tankz.render;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
import openfl.display.BitmapData;
|
|
||||||
import ru.m.draw.Color;
|
|
||||||
import ru.m.tankz.core.Bonus;
|
|
||||||
import flash.display.Bitmap;
|
import flash.display.Bitmap;
|
||||||
import flash.display.DisplayObject;
|
import flash.display.DisplayObject;
|
||||||
import flash.display.Shape;
|
import flash.display.Shape;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import ru.m.animate.Animate;
|
import ru.m.animate.Animate;
|
||||||
import ru.m.draw.BitmapUtil;
|
|
||||||
import ru.m.geom.Direction;
|
import ru.m.geom.Direction;
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
|
import ru.m.tankz.core.Bonus;
|
||||||
import ru.m.tankz.core.Bullet;
|
import ru.m.tankz.core.Bullet;
|
||||||
import ru.m.tankz.core.Eagle;
|
import ru.m.tankz.core.Eagle;
|
||||||
import ru.m.tankz.core.Tank;
|
import ru.m.tankz.core.Tank;
|
||||||
import ru.m.tankz.map.Brick;
|
import ru.m.tankz.map.Brick;
|
||||||
|
import ru.m.tankz.Type.BrickType;
|
||||||
|
|
||||||
|
|
||||||
typedef TRectangle = {
|
typedef TRectangle = {
|
||||||
@@ -77,10 +75,50 @@ 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 {
|
||||||
|
view.frames = [for (i in 0...2) ({
|
||||||
|
image: Assets.getBitmapData('resources/image/map/${value.config.type}-${i}.png'),
|
||||||
|
length: 15
|
||||||
|
})];
|
||||||
|
view.playing = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class BrickBreakingItem extends RenderItem<Brick, Shape> {
|
||||||
private var broken:Int;
|
private var broken:Int;
|
||||||
private var type:Int;
|
private var type:BrickType;
|
||||||
|
|
||||||
public function new(value:Brick) {
|
public function new(value:Brick) {
|
||||||
super(value);
|
super(value);
|
||||||
@@ -93,7 +131,7 @@ class BrickItem extends RenderItem<Brick, Shape> {
|
|||||||
var g = view.graphics;
|
var g = view.graphics;
|
||||||
g.clear();
|
g.clear();
|
||||||
if (value.destroyed) return;
|
if (value.destroyed) return;
|
||||||
if (value.config.type > 0) {
|
if (value.config.index > 0) {
|
||||||
g.beginBitmapFill(image);
|
g.beginBitmapFill(image);
|
||||||
g.drawRect(0, 0, value.rect.width, value.rect.height);
|
g.drawRect(0, 0, value.rect.width, value.rect.height);
|
||||||
for (c in value.cells) {
|
for (c in value.cells) {
|
||||||
@@ -118,7 +156,7 @@ class BrickItem extends RenderItem<Brick, Shape> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getImage():String {
|
private function getImage():String {
|
||||||
return 'resources/images/map/map_${value.config.type}.png';
|
return 'resources/image/map/${value.config.type}.png';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,24 +178,34 @@ class TankItem extends RenderItem<Tank, Sprite> {
|
|||||||
|
|
||||||
private var type:String;
|
private var type:String;
|
||||||
private var hits:Int;
|
private var hits:Int;
|
||||||
|
private var protected:Bool;
|
||||||
|
private var frozen:Bool;
|
||||||
|
|
||||||
private var tankView:Animate;
|
private var tankView:Animate;
|
||||||
|
private var protectView:Animate;
|
||||||
|
|
||||||
public function new(value:Tank) {
|
public function new(value:Tank) {
|
||||||
super(value);
|
super(value);
|
||||||
view = new Sprite();
|
view = new Sprite();
|
||||||
tankView = new Animate();
|
tankView = new Animate();
|
||||||
view.addChild(tankView);
|
view.addChild(tankView);
|
||||||
|
protectView = AnimateBundle.tankProtect();
|
||||||
|
protectView.visible = false;
|
||||||
|
view.addChild(protectView);
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function redraw():Void {
|
override public function redraw():Void {
|
||||||
var colors:Array<Color> = [value.color, value.bonus ? 0xff00aa : value.color];
|
tankView.frames = AnimateBundle.tankFrames(value);
|
||||||
var frames = [for (frame in getFrames()) BitmapUtil.colorize(Assets.getBitmapData(frame), colors.shift())];
|
if (value.protect.active) {
|
||||||
tankView.frames = [
|
protectView.x = (tankView.frames[0].image.width - protectView.frames[0].image.width) / 2;
|
||||||
frames[0], frames[0], frames[0],
|
protectView.y = (tankView.frames[0].image.height - protectView.frames[0].image.height) / 2;
|
||||||
frames[1], frames[1], frames[1],
|
protectView.playing = true;
|
||||||
];
|
protectView.visible = true;
|
||||||
|
} else {
|
||||||
|
protectView.playing = false;
|
||||||
|
protectView.visible = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getFrames():Array<String> {
|
private function getFrames():Array<String> {
|
||||||
@@ -170,12 +218,16 @@ class TankItem extends RenderItem<Tank, Sprite> {
|
|||||||
super.update();
|
super.update();
|
||||||
var t = value.config.type;
|
var t = value.config.type;
|
||||||
var h = value.hits;
|
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.type = t;
|
||||||
this.hits = h;
|
this.hits = h;
|
||||||
|
this.protected = p;
|
||||||
|
this.frozen = f;
|
||||||
redraw();
|
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 {
|
override public function dispose():Void {
|
||||||
@@ -190,17 +242,32 @@ class TankItem extends RenderItem<Tank, Sprite> {
|
|||||||
class BulletItem extends BitmapItem<Bullet> {
|
class BulletItem extends BitmapItem<Bullet> {
|
||||||
|
|
||||||
override private function getImage():String {
|
override private function getImage():String {
|
||||||
return 'resources/images/bullet/bullet_${value.config.piercing > 1 ? 1 : 0}.png';
|
var type:String = 'normal';
|
||||||
|
if (value.config.piercing > 0) type = 'piercing';
|
||||||
|
return 'resources/image/bullet/${type}.png';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class EagleItem extends BitmapItem<Eagle> {
|
class EagleItem extends BitmapItem<Eagle> {
|
||||||
|
|
||||||
public var destoyed(default, default):Bool;
|
private var death:Bool;
|
||||||
|
private var protected:Bool;
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
super.update();
|
||||||
|
var d = value.death;
|
||||||
|
var p = value.protect.active;
|
||||||
|
if (d != death || p != protected) {
|
||||||
|
death = d;
|
||||||
|
protected = p;
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override private function getImage():String {
|
override private function getImage():String {
|
||||||
return 'resources/images/eagle/eagle-${destoyed ? 1 : 0}.png';
|
var suffix = value.death ? '-death' : value.protect.active ? '-protected' : '';
|
||||||
|
return 'resources/image/eagle/eagle${suffix}.png';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,9 +280,8 @@ class BonusItem extends AnimateItem<Bonus> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override public function redraw():Void {
|
override public function redraw():Void {
|
||||||
var image = Assets.getBitmapData('resources/image/bonus/${value.bonusType}.png');
|
var image = Assets.getBitmapData('resources/image/bonus/${value.config.type}.png');
|
||||||
var empty = new BitmapData(image.width, image.height, true, 0x00000000);
|
view.frames = AnimateBundle.bonusFrames(value.config.type);
|
||||||
view.frames = [for (i in 0...15) image].concat([for (i in 0...15) empty]);
|
|
||||||
view.playing = true;
|
view.playing = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/client/haxe/ru/m/tankz/storage/SaveStorage.hx
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
|
import flash.net.SharedObject;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import ru.m.tankz.game.GameSave;
|
||||||
|
|
||||||
|
|
||||||
|
class SaveStorage {
|
||||||
|
|
||||||
|
private static var TAG(default, never):String = 'SaveStorage';
|
||||||
|
|
||||||
|
private var so:SharedObject;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
so = SharedObject.getLocal('tankz');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function read(type:GameType):Null<GameSave> {
|
||||||
|
var data:String = Reflect.getProperty(so.data, type);
|
||||||
|
L.d(TAG, 'read: ${data}');
|
||||||
|
if (data != null) {
|
||||||
|
return GameSave.fromYaml(data);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function write(save:GameSave):Void {
|
||||||
|
var data:String = save.toYaml();
|
||||||
|
L.d(TAG, 'write: ${data}');
|
||||||
|
so.setProperty(save.state.type, data);
|
||||||
|
so.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,26 +9,64 @@ map:
|
|||||||
gridHeight: 26
|
gridHeight: 26
|
||||||
|
|
||||||
bricks:
|
bricks:
|
||||||
- {type: -1, layer: 2, armor: -1} # border
|
- {type: border, index: -1, layer: 2, armor: -1}
|
||||||
- {type: 0, layer: 0, armor: 0} # none
|
- {type: none, index: 0, layer: 0, armor: 0}
|
||||||
- {type: 1, layer: 0, armor: 0} # ace
|
- {type: ace, index: 1, layer: 0, armor: 0}
|
||||||
- {type: 2, layer: 3, armor: 0} # bush
|
- {type: bush, index: 2, layer: 3, armor: 0}
|
||||||
- {type: 3, layer: 1, armor: 0} # water
|
- {type: water, index: 3, layer: 1, armor: 0}
|
||||||
- {type: 4, layer: 2, armor: 2} # armor
|
- {type: armor, index: 4, layer: 2, armor: 2}
|
||||||
- {type: 5, layer: 2, armor: 1} # brick
|
- {type: brick, index: 5, layer: 2, armor: 1}
|
||||||
|
|
||||||
teams:
|
player:
|
||||||
- id: human
|
human: &human
|
||||||
|
control: human
|
||||||
|
life: 3
|
||||||
tanks:
|
tanks:
|
||||||
- {type: human0, rate: 1}
|
- {type: human0, rate: 1, protect: 5}
|
||||||
- id: bot
|
bot: &bot
|
||||||
spawnInterval: 3000
|
control: bot
|
||||||
|
color: 0xFFFFFF
|
||||||
|
life: -1
|
||||||
tanks:
|
tanks:
|
||||||
- {type: bot0, rate: 0.25, bonus: 0.25}
|
- {type: bot0, rate: 0.25, bonus: 0.25}
|
||||||
- {type: bot1, rate: 0.25, bonus: 0.25}
|
- {type: bot1, rate: 0.25, bonus: 0.25}
|
||||||
- {type: bot2, rate: 0.25, bonus: 0.25}
|
- {type: bot2, rate: 0.25, bonus: 0.25}
|
||||||
- {type: bot3, 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:
|
points:
|
||||||
- {team: human, type: eagle, index: -1, direction: right, x: 12, y: 24}
|
- {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: 0, direction: top, x: 8, y: 24}
|
||||||
@@ -136,9 +174,9 @@ tanks:
|
|||||||
skin: bd
|
skin: bd
|
||||||
|
|
||||||
bonuses:
|
bonuses:
|
||||||
- {type: clock}
|
- {type: clock, duration: 10}
|
||||||
- {type: grenade}
|
- {type: grenade}
|
||||||
- {type: helmet}
|
- {type: helmet, duration: 20}
|
||||||
- {type: life}
|
- {type: life}
|
||||||
- {type: shovel}
|
- {type: shovel, duration: 10}
|
||||||
- {type: star}
|
- {type: star}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
game:
|
game:
|
||||||
levels: 7
|
levels: 8
|
||||||
friendlyFire: true
|
friendlyFire: true
|
||||||
|
|
||||||
map:
|
map:
|
||||||
@@ -9,26 +9,90 @@ map:
|
|||||||
gridHeight: 30
|
gridHeight: 30
|
||||||
|
|
||||||
bricks:
|
bricks:
|
||||||
- {type: -1, layer: 2, armor: -1} # border
|
- {type: border, index: -1, layer: 2, armor: -1}
|
||||||
- {type: 0, layer: 0, armor: 0} # none
|
- {type: none, index: 0, layer: 0, armor: 0}
|
||||||
- {type: 1, layer: 0, armor: 0} # ace
|
- {type: ace, index: 1, layer: 0, armor: 0}
|
||||||
- {type: 2, layer: 3, armor: 0} # bush
|
- {type: bush, index: 2, layer: 3, armor: 0}
|
||||||
- {type: 3, layer: 1, armor: 0} # water
|
- {type: water, index: 3, layer: 1, armor: 0}
|
||||||
- {type: 4, layer: 2, armor: 2} # armor
|
- {type: armor, index: 4, layer: 2, armor: 2}
|
||||||
- {type: 5, layer: 2, armor: 1} # brick
|
- {type: brick, index: 5, layer: 2, armor: 1}
|
||||||
|
|
||||||
team_tanks: &team_tanks
|
team:
|
||||||
tanks:
|
radiant: &radiant
|
||||||
- {type: slow, rate: 0.5}
|
|
||||||
- {type: fast, rate: 0.5}
|
|
||||||
|
|
||||||
teams:
|
|
||||||
- <<: *team_tanks
|
|
||||||
id: radiant
|
id: radiant
|
||||||
color: 0xff5555
|
color: 0xff4422
|
||||||
- <<: *team_tanks
|
life: 20
|
||||||
|
dire: &dire
|
||||||
id: 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:
|
points:
|
||||||
- {team: radiant, type: eagle, index: -1, direction: right, x: 0, y: 28}
|
- {team: radiant, type: eagle, index: -1, direction: right, x: 0, y: 28}
|
||||||
@@ -72,9 +136,9 @@ tanks:
|
|||||||
skin: bb
|
skin: bb
|
||||||
|
|
||||||
bonuses:
|
bonuses:
|
||||||
- {type: clock}
|
- {type: clock, duration: 10}
|
||||||
- {type: grenade}
|
- {type: grenade}
|
||||||
- {type: helmet}
|
- {type: helmet, duration: 20}
|
||||||
- {type: life}
|
- {type: life}
|
||||||
- {type: shovel}
|
- {type: shovel, duration: 10}
|
||||||
- {type: star}
|
- {type: star}
|
||||||
|
|||||||
2
src/client/resources/dota/levels/level007.txt
Normal 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}]
|
||||||
|
Before Width: | Height: | Size: 110 B After Width: | Height: | Size: 110 B |
|
Before Width: | Height: | Size: 141 B After Width: | Height: | Size: 141 B |
|
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
|
Before Width: | Height: | Size: 186 B After Width: | Height: | Size: 186 B |
|
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
|
Before Width: | Height: | Size: 186 B After Width: | Height: | Size: 186 B |
|
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 292 B After Width: | Height: | Size: 292 B |
|
Before Width: | Height: | Size: 386 B After Width: | Height: | Size: 386 B |
|
Before Width: | Height: | Size: 389 B After Width: | Height: | Size: 389 B |
|
Before Width: | Height: | Size: 375 B After Width: | Height: | Size: 375 B |
|
Before Width: | Height: | Size: 374 B After Width: | Height: | Size: 374 B |
BIN
src/client/resources/image/eagle/eagle-protected.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 737 B After Width: | Height: | Size: 737 B |
|
Before Width: | Height: | Size: 307 B After Width: | Height: | Size: 307 B |
|
Before Width: | Height: | Size: 304 B After Width: | Height: | Size: 304 B |
|
Before Width: | Height: | Size: 279 B After Width: | Height: | Size: 279 B |
|
Before Width: | Height: | Size: 969 B After Width: | Height: | Size: 969 B |
|
Before Width: | Height: | Size: 93 B After Width: | Height: | Size: 93 B |
|
Before Width: | Height: | Size: 598 B After Width: | Height: | Size: 598 B |
|
Before Width: | Height: | Size: 531 B After Width: | Height: | Size: 531 B |
|
Before Width: | Height: | Size: 598 B After Width: | Height: | Size: 598 B |
|
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 9.8 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
@@ -1,6 +1,5 @@
|
|||||||
package ru.m.tankz;
|
package ru.m.tankz;
|
||||||
|
|
||||||
import ru.m.draw.Color;
|
|
||||||
|
|
||||||
typedef Type = Dynamic;
|
typedef Type = Dynamic;
|
||||||
|
|
||||||
@@ -10,7 +9,7 @@ typedef TeamId = String;
|
|||||||
|
|
||||||
typedef ControlType = String;
|
typedef ControlType = String;
|
||||||
|
|
||||||
typedef BrickType = Int;
|
typedef BrickType = String;
|
||||||
|
|
||||||
typedef TankType = String;
|
typedef TankType = String;
|
||||||
|
|
||||||
@@ -18,9 +17,7 @@ typedef BonusType = String;
|
|||||||
|
|
||||||
typedef PlayerId = {
|
typedef PlayerId = {
|
||||||
var team:TeamId;
|
var team:TeamId;
|
||||||
var type:ControlType;
|
|
||||||
var index:Int;
|
var index:Int;
|
||||||
@:optional var color:Color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef GameMode = Array<PlayerId>;
|
typedef PresetId = String;
|
||||||
|
|||||||
9
src/common/haxe/ru/m/tankz/bundle/IConfigBundle.hx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package ru.m.tankz.bundle;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
|
interface IConfigBundle {
|
||||||
|
public function get(type:GameType):Config;
|
||||||
|
}
|
||||||
9
src/common/haxe/ru/m/tankz/bundle/ILevelBundle.hx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package ru.m.tankz.bundle;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
|
interface ILevelBundle {
|
||||||
|
public function get(type:GameType, config:Config, level:Int):LevelConfig;
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ typedef MapConfig = {
|
|||||||
|
|
||||||
typedef BrickConfig = {
|
typedef BrickConfig = {
|
||||||
var type:BrickType;
|
var type:BrickType;
|
||||||
|
var index:Int;
|
||||||
var layer:Int;
|
var layer:Int;
|
||||||
var armor:Int;
|
var armor:Int;
|
||||||
}
|
}
|
||||||
@@ -52,23 +53,36 @@ typedef TankConfig = {
|
|||||||
|
|
||||||
typedef BonusConfig = {
|
typedef BonusConfig = {
|
||||||
var type:BonusType;
|
var type:BonusType;
|
||||||
|
@:optional var duration:Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef TankSpawn = {
|
typedef TankSpawn = {
|
||||||
var type:TankType;
|
var type:TankType;
|
||||||
var rate:Float;
|
var rate:Float;
|
||||||
@:optional var bonus: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 = {
|
typedef TeamConfig = {
|
||||||
var id:TeamId;
|
var id:TeamId;
|
||||||
var size:Int;
|
var players:Array<PlayerConfig>;
|
||||||
var tanks:Array<TankSpawn>;
|
@:optional var life:Int;
|
||||||
@:optional var spawnInterval:Int;
|
@:optional var spawnInterval:Int;
|
||||||
@:optional var color:Color;
|
@:optional var color:Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef GamePreset = {
|
||||||
|
var id:PresetId;
|
||||||
|
var teams:Array<TeamConfig>;
|
||||||
|
}
|
||||||
|
|
||||||
typedef LevelConfig = {
|
typedef LevelConfig = {
|
||||||
var data:Array<BrickConfig>;
|
var data:Array<BrickConfig>;
|
||||||
@@ -82,13 +96,14 @@ class Config {
|
|||||||
public var map(default, null):MapConfig;
|
public var map(default, null):MapConfig;
|
||||||
public var bricks(default, null):Array<BrickConfig>;
|
public var bricks(default, null):Array<BrickConfig>;
|
||||||
public var tanks(default, null):Array<TankConfig>;
|
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 points(default, null):Array<SpawnPoint>;
|
||||||
public var bonuses(default, null):Array<BonusConfig>;
|
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 tankMap:Map<TankType, TankConfig>;
|
||||||
private var teamMap:Map<TeamId, TeamConfig>;
|
private var presetsMap:Map<PresetId, GamePreset>;
|
||||||
private var bonusMap:Map<BonusType, BonusConfig>;
|
private var bonusMap:Map<BonusType, BonusConfig>;
|
||||||
|
|
||||||
public function new(
|
public function new(
|
||||||
@@ -96,7 +111,7 @@ class Config {
|
|||||||
game:GameConfig,
|
game:GameConfig,
|
||||||
map:MapConfig,
|
map:MapConfig,
|
||||||
bricks:Array<BrickConfig>,
|
bricks:Array<BrickConfig>,
|
||||||
teams:Array<TeamConfig>,
|
presets:Array<GamePreset>,
|
||||||
points:Array<SpawnPoint>,
|
points:Array<SpawnPoint>,
|
||||||
tanks:Array<TankConfig>,
|
tanks:Array<TankConfig>,
|
||||||
bonuses:Array<BonusConfig>
|
bonuses:Array<BonusConfig>
|
||||||
@@ -105,7 +120,7 @@ class Config {
|
|||||||
this.game = game;
|
this.game = game;
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.bricks = bricks;
|
this.bricks = bricks;
|
||||||
this.teams = teams;
|
this.presets = presets;
|
||||||
this.points = points;
|
this.points = points;
|
||||||
this.tanks = tanks;
|
this.tanks = tanks;
|
||||||
this.bonuses = bonuses;
|
this.bonuses = bonuses;
|
||||||
@@ -114,12 +129,14 @@ class Config {
|
|||||||
|
|
||||||
private function init() {
|
private function init() {
|
||||||
brickMap = new Map();
|
brickMap = new Map();
|
||||||
|
brickMapByIndex = new Map();
|
||||||
for (item in bricks) {
|
for (item in bricks) {
|
||||||
brickMap.set(item.type, item);
|
brickMap.set(item.type, item);
|
||||||
|
brickMapByIndex.set(item.index, item);
|
||||||
}
|
}
|
||||||
teamMap = new Map();
|
presetsMap = new Map();
|
||||||
for (team in teams) {
|
for (preset in presets) {
|
||||||
teamMap.set(team.id, team);
|
presetsMap.set(preset.id, preset);
|
||||||
}
|
}
|
||||||
tankMap = new Map();
|
tankMap = new Map();
|
||||||
for (item in tanks) {
|
for (item in tanks) {
|
||||||
@@ -131,12 +148,16 @@ class Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBrick(type:Int):BrickConfig {
|
public function getBrick(type:BrickType):BrickConfig {
|
||||||
return brickMap.get(type);
|
return brickMap.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTeam(id:String):TeamConfig {
|
public function getBrickByIndex(index:Int):BrickConfig {
|
||||||
return teamMap.get(id);
|
return brickMapByIndex.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPreset(id:PresetId):GamePreset {
|
||||||
|
return presetsMap.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTank(type:TankType):TankConfig {
|
public function getTank(type:TankType):TankConfig {
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package ru.m.tankz.core;
|
package ru.m.tankz.core;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
import ru.m.tankz.Type;
|
|
||||||
|
|
||||||
|
|
||||||
class Bonus extends Entity {
|
class Bonus extends Entity {
|
||||||
|
|
||||||
public var bonusType(default, null):BonusType;
|
public var config(default, null):BonusConfig;
|
||||||
|
|
||||||
public function new(bonusType:BonusType) {
|
public function new(config:BonusConfig) {
|
||||||
super(new Rectangle(0, 0, 44, 44));
|
super(new Rectangle(0, 0, 44, 44));
|
||||||
this.bonusType = bonusType;
|
this.config = config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,13 @@ import ru.m.tankz.Type;
|
|||||||
class Eagle extends Entity {
|
class Eagle extends Entity {
|
||||||
|
|
||||||
public var team(default, null):TeamId;
|
public var team(default, null):TeamId;
|
||||||
|
public var death(default, default):Bool;
|
||||||
|
public var protect(default, null):Modificator;
|
||||||
|
|
||||||
public function new(team:TeamId) {
|
public function new(team:TeamId) {
|
||||||
super(new Rectangle(0, 0, 44, 44));
|
super(new Rectangle(0, 0, 44, 44)); // ToDo: hardcode size
|
||||||
this.team = team;
|
this.team = team;
|
||||||
|
this.death = false;
|
||||||
|
this.protect = new Modificator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,19 @@ class EntityTypeResolver {
|
|||||||
case x: null;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
27
src/common/haxe/ru/m/tankz/core/Modificator.hx
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,11 +15,15 @@ class Tank extends MobileEntity {
|
|||||||
public var color(default, default):Color;
|
public var color(default, default):Color;
|
||||||
public var hits(default, default):Int;
|
public var hits(default, default):Int;
|
||||||
public var bonus(default, default):Bool;
|
public var bonus(default, default):Bool;
|
||||||
|
public var protect(default, null):Modificator;
|
||||||
|
public var freezing(default, null):Modificator;
|
||||||
|
|
||||||
private var bulletsCounter:Int = 0;
|
private var bulletsCounter:Int = 0;
|
||||||
|
|
||||||
public function new(playerId:PlayerId, config:TankConfig) {
|
public function new(playerId:PlayerId, config:TankConfig) {
|
||||||
super(new Rectangle(0, 0, config.width, config.height), config.speed, Direction.RIGHT);
|
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.playerId = playerId;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.hits = config.hits;
|
this.hits = config.hits;
|
||||||
@@ -35,7 +39,14 @@ class Tank extends MobileEntity {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override public function move(direction:Direction):Void {
|
||||||
|
if (!freezing.active) {
|
||||||
|
super.move(direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function shot():Null<Bullet> {
|
public function shot():Null<Bullet> {
|
||||||
|
if (freezing.active) return null;
|
||||||
if (bulletsCounter >= config.bullets) return null;
|
if (bulletsCounter >= config.bullets) return null;
|
||||||
var bullet = new Bullet(this);
|
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));
|
bullet.rect.center = rect.center.add(new Point(rect.width / 4 * rect.direction.x, rect.height / 4 * rect.direction.y));
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package ru.m.tankz.engine;
|
package ru.m.tankz.engine;
|
||||||
|
|
||||||
import ru.m.geom.Point;
|
|
||||||
import ru.m.geom.Line;
|
import ru.m.geom.Line;
|
||||||
|
import ru.m.geom.Point;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.core.Bullet;
|
import ru.m.tankz.core.Bullet;
|
||||||
@@ -12,14 +12,19 @@ import ru.m.tankz.core.Tank;
|
|||||||
import ru.m.tankz.map.LevelMap;
|
import ru.m.tankz.map.LevelMap;
|
||||||
|
|
||||||
|
|
||||||
|
enum EntityChange {
|
||||||
|
DEATH;
|
||||||
|
HIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
interface EngineListener {
|
interface EngineListener {
|
||||||
public function onSpawn(entity:EntityType):Void;
|
public function onSpawn(entity:EntityType):Void;
|
||||||
|
public function onChange(entity:EntityType, ?change:EntityChange):Void;
|
||||||
public function onCollision(entity:EntityType, with:EntityType):Void;
|
public function onCollision(entity:EntityType, with:EntityType):Void;
|
||||||
public function onDestroy(entity:EntityType):Void;
|
public function onDestroy(entity:EntityType):Void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CollisionProcessor implements EngineListener {
|
class CollisionProcessor implements EngineListener {
|
||||||
|
|
||||||
private var engine:Engine;
|
private var engine:Engine;
|
||||||
@@ -30,53 +35,41 @@ class CollisionProcessor implements EngineListener {
|
|||||||
|
|
||||||
public function onSpawn(entity:EntityType):Void {}
|
public function onSpawn(entity:EntityType):Void {}
|
||||||
|
|
||||||
private function checkTankBullet(tank:Tank, bullet:Bullet):Bool {
|
public function onChange(entity:EntityType, ?change:EntityChange):Void {}
|
||||||
if (bullet.tankId == tank.id) return false;
|
|
||||||
return engine.config.game.friendlyFire || tank.playerId.team != bullet.playerId.team;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function hitTank(tank:Tank):Void {
|
public function onCollision(entity:EntityType, with:EntityType):Void {
|
||||||
|
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) {
|
if (tank.hits > 0) {
|
||||||
tank.hits--;
|
tank.hits--;
|
||||||
|
engine.change(tank, EntityChange.HIT);
|
||||||
} else {
|
} else {
|
||||||
engine.destroy(tank);
|
engine.destroy(tank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
engine.destroy(bullet);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
case EntityType.EAGLE(eagle):
|
case [EntityType.BULLET(bullet), EntityType.BULLET(other_bullet)]:
|
||||||
tank1.rect.lean(eagle.rect);
|
engine.destroy(bullet);
|
||||||
case EntityType.CELL(cell):
|
engine.destroy(other_bullet);
|
||||||
tank1.rect.lean(cell.rect);
|
case [EntityType.BULLET(bullet), EntityType.CELL(cell)]:
|
||||||
case EntityType.BONUS(bonus):
|
engine.destroy(bullet);
|
||||||
engine.destroy(bonus);
|
case [EntityType.BULLET(bullet), EntityType.EAGLE(eagle)]:
|
||||||
}
|
engine.destroy(bullet);
|
||||||
case EntityType.BULLET(bullet1):
|
if (!eagle.protect.active) {
|
||||||
switch (with) {
|
eagle.death = true;
|
||||||
case EntityType.TANK(tank2):
|
engine.change(eagle, EntityChange.DEATH);
|
||||||
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):
|
|
||||||
}
|
}
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
@@ -85,7 +78,7 @@ class CollisionProcessor implements EngineListener {
|
|||||||
public function onDestroy(entity:EntityType):Void { }
|
public function onDestroy(entity:EntityType):Void { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@:yield
|
||||||
class Engine implements ControlHandler {
|
class Engine implements ControlHandler {
|
||||||
|
|
||||||
public var config(default, default):Config;
|
public var config(default, default):Config;
|
||||||
@@ -114,6 +107,11 @@ class Engine implements ControlHandler {
|
|||||||
for (l in listeners) l.onSpawn(type);
|
for (l in listeners) l.onSpawn(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function change(entity:Entity, ?change:EntityChange):Void {
|
||||||
|
var type = EntityTypeResolver.of(entity);
|
||||||
|
for (l in listeners) l.onChange(type, change);
|
||||||
|
}
|
||||||
|
|
||||||
public function destroy(entity:Entity):Void {
|
public function destroy(entity:Entity):Void {
|
||||||
if (entities.exists(entity.id)) {
|
if (entities.exists(entity.id)) {
|
||||||
var type = EntityTypeResolver.of(entity);
|
var type = EntityTypeResolver.of(entity);
|
||||||
@@ -148,8 +146,6 @@ class Engine implements ControlHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function update():Void {
|
public function update():Void {
|
||||||
var newTime:Float = Date.now().getTime();
|
var newTime:Float = Date.now().getTime();
|
||||||
var d:Float = newTime - time;
|
var d:Float = newTime - time;
|
||||||
@@ -169,6 +165,15 @@ class Engine implements ControlHandler {
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (entity.mx != 0 || entity.my != 0) {
|
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 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 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)));
|
var end:Point = side.center.add(new Point(entity.mx * (d / 30), entity.my * (d / 30)));
|
||||||
@@ -202,15 +207,14 @@ class Engine implements ControlHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Std.is(entity, Bullet)) {
|
if (asBullet != null) {
|
||||||
var bullet:Bullet = cast ent;
|
|
||||||
if (collision) {
|
if (collision) {
|
||||||
cells = map.grid.getCells(side.setLength(map.grid.cellWidth * 3));
|
cells = map.grid.getCells(side.setLength(map.grid.cellWidth * 3));
|
||||||
for (cell in cells) {
|
for (cell in cells) {
|
||||||
if (cell.armor > 0) {
|
if (cell.armor > 0) {
|
||||||
if (cell.armor == bullet.config.piercing) {
|
if (cell.armor == asBullet.config.piercing) {
|
||||||
cell.destroyed = true;
|
cell.destroyed = true;
|
||||||
} else if (cell.armor < bullet.config.piercing) {
|
} else if (cell.armor < asBullet.config.piercing) {
|
||||||
var brick = map.getBrick(cell);
|
var brick = map.getBrick(cell);
|
||||||
brick.destroyed = true;
|
brick.destroyed = true;
|
||||||
}
|
}
|
||||||
@@ -234,4 +238,13 @@ class Engine implements ControlHandler {
|
|||||||
listeners = [];
|
listeners = [];
|
||||||
entities = new Map();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
import haxe.ds.Option;
|
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.Game;
|
||||||
import ru.m.tankz.game.GameState.PlayerState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
@@ -15,57 +13,17 @@ class ClassicGame extends Game {
|
|||||||
public static var HUMAN(default, never):TeamId = 'human';
|
public static var HUMAN(default, never):TeamId = 'human';
|
||||||
public static var BOT(default, never):TeamId = 'bot';
|
public static var BOT(default, never):TeamId = 'bot';
|
||||||
|
|
||||||
private static var PLAYER1_COLOR:Color = 0xFC9838;
|
public static var PLAYER1(default, never):PresetId = 'player1';
|
||||||
private static var PLAYER2_COLOR:Color = 0x159D49;
|
public static var PLAYER2(default, never):PresetId = 'player2';
|
||||||
|
|
||||||
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 function new() {
|
public function new() {
|
||||||
super(TYPE);
|
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> {
|
override public function next():Option<GameState> {
|
||||||
if (!state.teams[HUMAN].lose) {
|
if (state.loser == HUMAN) {
|
||||||
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);
|
|
||||||
}
|
|
||||||
return Option.None;
|
return Option.None;
|
||||||
}
|
}
|
||||||
|
return super.next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
package ru.m.tankz.game;
|
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.Game;
|
||||||
import ru.m.tankz.game.GameState;
|
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
@@ -15,57 +11,11 @@ class DotaGame extends Game {
|
|||||||
public static var RADIANT(default, never):TeamId = 'radiant';
|
public static var RADIANT(default, never):TeamId = 'radiant';
|
||||||
public static var DIRE(default, never):TeamId = 'dire';
|
public static var DIRE(default, never):TeamId = 'dire';
|
||||||
|
|
||||||
public static var PLAYER1(default, never):GameMode = [
|
public static var PLAYER1(default, never):PresetId = 'player1';
|
||||||
{team:RADIANT, type:Control.HUMAN, index:0}
|
public static var PLAYER2_COOP(default, never):PresetId = 'player2_coop';
|
||||||
];
|
public static var PLAYER2_VS(default, never):PresetId = 'player2_vs';
|
||||||
|
|
||||||
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 function new() {
|
public function new() {
|
||||||
super(TYPE);
|
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
import ru.m.tankz.core.Bonus;
|
import ru.m.tankz.game.GameSave.PlayerSave;
|
||||||
import haxe.ds.Option;
|
import haxe.ds.Option;
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
|
import haxework.provider.Provider;
|
||||||
import promhx.Deferred;
|
import promhx.Deferred;
|
||||||
import promhx.Stream;
|
import promhx.Stream;
|
||||||
import ru.m.geom.Direction;
|
import ru.m.geom.Direction;
|
||||||
import ru.m.geom.Point;
|
import ru.m.geom.Point;
|
||||||
import ru.m.tankz.bot.BotControl;
|
import ru.m.tankz.bot.BotControl;
|
||||||
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.config.ConfigBundle;
|
|
||||||
import ru.m.tankz.config.LevelBundle;
|
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.control.HumanControl;
|
import ru.m.tankz.control.HumanControl;
|
||||||
|
import ru.m.tankz.core.Bonus;
|
||||||
import ru.m.tankz.core.Eagle;
|
import ru.m.tankz.core.Eagle;
|
||||||
import ru.m.tankz.core.Entity;
|
import ru.m.tankz.core.Entity;
|
||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.core.EntityType;
|
||||||
@@ -29,34 +31,42 @@ class Game implements EngineListener {
|
|||||||
|
|
||||||
public var type(default, null):GameType;
|
public var type(default, null):GameType;
|
||||||
public var state(default, null):GameState;
|
public var state(default, null):GameState;
|
||||||
|
public var preset(default, null):GamePreset;
|
||||||
public var teams(default, null):Map<TeamId, Team>;
|
public var teams(default, null):Map<TeamId, Team>;
|
||||||
public var config(default, null):Config;
|
public var config(default, null):Config;
|
||||||
public var engine(default, null):Engine;
|
public var engine(default, null):Engine;
|
||||||
|
|
||||||
private var points:Array<SpawnPoint>;
|
private var points:Array<SpawnPoint>;
|
||||||
private var spawners:Map<TeamId, Spawner>;
|
|
||||||
private var deferred:Deferred<GameState>;
|
private var deferred:Deferred<GameState>;
|
||||||
private var stream:Stream<GameState>;
|
private var stream:Stream<GameState>;
|
||||||
|
|
||||||
public function new(type:GameType) {
|
public function new(type:GameType) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.config = ConfigBundle.get(type);
|
this.config = Provider.get(IConfigBundle).get(type);
|
||||||
this.engine = new Engine(config);
|
this.engine = new Engine(config);
|
||||||
engine.listeners.push(this);
|
engine.listeners.push(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTeam(teamId:TeamId):Team {
|
||||||
|
return teams[teamId];
|
||||||
|
}
|
||||||
|
|
||||||
public function getPlayer(playerId:PlayerId):Player {
|
public function getPlayer(playerId:PlayerId):Player {
|
||||||
return teams[playerId.team].players[playerId.index];
|
return teams[playerId.team].players[playerId.index];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildTank(playerId:PlayerId, point:SpawnPoint):Tank {
|
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 spawn:TankSpawn = spawns[Math.floor(Math.random() * spawns.length)];
|
||||||
var tankConfig:TankConfig = config.getTank(spawn.type);
|
var tankConfig:TankConfig = config.getTank(spawn.type);
|
||||||
var tank = new Tank(playerId, tankConfig);
|
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;
|
tank.bonus = Math.random() < spawn.bonus;
|
||||||
applyPoint(tank, point);
|
applyPoint(tank, point);
|
||||||
|
if (spawn.protect > 0) {
|
||||||
|
tank.protect.on(spawn.protect);
|
||||||
|
}
|
||||||
return tank;
|
return tank;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,27 +75,36 @@ class Game implements EngineListener {
|
|||||||
entity.rect.direction = Direction.fromString(point.direction);
|
entity.rect.direction = Direction.fromString(point.direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start(state:GameState):Stream<GameState> {
|
public function start(save:GameSave):Stream<GameState> {
|
||||||
|
this.state = save.state;
|
||||||
|
this.preset = config.getPreset(state.presetId);
|
||||||
this.deferred = new Deferred();
|
this.deferred = new Deferred();
|
||||||
this.state = state;
|
var level:LevelConfig = Provider.get(ILevelBundle).get(type, config, state.level);
|
||||||
var level = LevelBundle.get(type, config, state.level);
|
|
||||||
points = level.points != null ? level.points : config.points;
|
points = level.points != null ? level.points : config.points;
|
||||||
engine.map.setData(level.data);
|
engine.map.setData(level.data);
|
||||||
teams = new Map<TeamId, Team>();
|
teams = new Map<TeamId, Team>();
|
||||||
spawners = new Map<TeamId, Spawner>();
|
|
||||||
var humanControlIndex = 0;
|
var humanControlIndex = 0;
|
||||||
for (teamConfig in config.teams) {
|
for (teamConfig in preset.teams) {
|
||||||
var team = new Team(teamConfig);
|
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == teamConfig.id);
|
||||||
for (playerState in state.teams[team.id].players) {
|
var team:Team = new Team(teamConfig, teamPoints);
|
||||||
var player = new Player(playerState.id);
|
|
||||||
team.players[player.id.index] = player;
|
|
||||||
teams[team.id] = team;
|
teams[team.id] = team;
|
||||||
if (player.id.type != null) {
|
for (player in team.players.iterator()) {
|
||||||
var control = switch (player.id.type) {
|
var playerSave:PlayerSave = save.getPlayer(player.id);
|
||||||
|
if (playerSave != null) {
|
||||||
|
player.life = playerSave.life;
|
||||||
|
if (playerSave.tank != null) {
|
||||||
|
player.config.tanks = [{
|
||||||
|
type: playerSave.tank,
|
||||||
|
rate: 1,
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (player.config.control != null) {
|
||||||
|
var control = switch (player.config.control) {
|
||||||
case Control.HUMAN: new HumanControl(player.id, humanControlIndex++);
|
case Control.HUMAN: new HumanControl(player.id, humanControlIndex++);
|
||||||
case Control.BOT: new BotControl(player.id);
|
case Control.BOT: new BotControl(player.id);
|
||||||
case Control.NONE: null;
|
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})');
|
L.d(TAG, 'control(${player.id} - ${control})');
|
||||||
if (control != null) {
|
if (control != null) {
|
||||||
@@ -94,19 +113,19 @@ class Game implements EngineListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == team.id);
|
team.spawner.runner = spawn;
|
||||||
spawners[team.id] = new Spawner(team.config, teamPoints, spawn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (team in teams) {
|
for (team in teams.iterator()) {
|
||||||
for (player in team.players) {
|
for (player in team.players.iterator()) {
|
||||||
if (trySpawn(player.id)) {
|
if (team.trySpawn(player.id)) {
|
||||||
spawners[team.id].push(player.id);
|
team.spawner.push(player.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var eaglePoint = spawners[team.id].getPoint('eagle');
|
var eaglePoint = team.spawner.getPoint('eagle');
|
||||||
if (eaglePoint != null) {
|
if (eaglePoint != null) {
|
||||||
var eagle = new Eagle(team.id);
|
var eagle = new Eagle(team.id);
|
||||||
|
team.eagleId = eagle.id;
|
||||||
applyPoint(eagle, eaglePoint);
|
applyPoint(eagle, eaglePoint);
|
||||||
engine.spawn(eagle);
|
engine.spawn(eagle);
|
||||||
}
|
}
|
||||||
@@ -117,15 +136,15 @@ class Game implements EngineListener {
|
|||||||
|
|
||||||
private function spawn(task:SpawnTask):Void {
|
private function spawn(task:SpawnTask):Void {
|
||||||
L.d(TAG, 'spawn(${task}');
|
L.d(TAG, 'spawn(${task}');
|
||||||
getPlayer(task.playerId).tankId = 0;
|
var team = getTeam(task.playerId.team);
|
||||||
if (trySpawn(task.playerId, true)) {
|
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 tank = buildTank(task.playerId, task.point);
|
||||||
var player:Player = getPlayer(task.playerId);
|
|
||||||
player.tankId = tank.id;
|
player.tankId = tank.id;
|
||||||
Timer.delay(function() engine.spawn(tank), 1500);
|
engine.spawn(tank);
|
||||||
} else if (!isTeamAlive(task.playerId.team)) {
|
} else if (!team.isAlive) {
|
||||||
state.teams[task.playerId.team].lose = true;
|
lose(team.id);
|
||||||
complete();
|
|
||||||
}
|
}
|
||||||
deferred.resolve(state);
|
deferred.resolve(state);
|
||||||
}
|
}
|
||||||
@@ -147,130 +166,148 @@ class Game implements EngineListener {
|
|||||||
switch (entity) {
|
switch (entity) {
|
||||||
case EntityType.TANK(tank):
|
case EntityType.TANK(tank):
|
||||||
getPlayer(tank.playerId).control.start();
|
getPlayer(tank.playerId).control.start();
|
||||||
case x:
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onChange(entity:EntityType, ?change:EntityChange):Void {
|
||||||
|
switch [entity, change] {
|
||||||
|
case [EntityType.EAGLE(eagle), EntityChange.DEATH]:
|
||||||
|
if (eagle.death) {
|
||||||
|
lose(eagle.team);
|
||||||
|
deferred.resolve(state);
|
||||||
|
}
|
||||||
|
case [EntityType.TANK(tank), EntityChange.HIT]:
|
||||||
|
if (tank.bonus) {
|
||||||
|
tank.bonus = false;
|
||||||
|
spawnBonus();
|
||||||
|
}
|
||||||
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onCollision(entity:EntityType, with:EntityType):Void {
|
public function onCollision(entity:EntityType, with:EntityType):Void {
|
||||||
switch (entity) {
|
switch entity {
|
||||||
case EntityType.TANK(tank):
|
case EntityType.TANK(tank):
|
||||||
var control = getPlayer(tank.playerId).control;
|
var control = getPlayer(tank.playerId).control;
|
||||||
if (control != null) control.onCollision(with);
|
if (control != null) control.onCollision(with);
|
||||||
switch (with) {
|
case _:
|
||||||
case EntityType.BONUS(bonus):
|
}
|
||||||
|
switch [entity, with] {
|
||||||
|
case [EntityType.TANK(tank), EntityType.BONUS(bonus)]:
|
||||||
applyBonus(tank, bonus);
|
applyBonus(tank, bonus);
|
||||||
case x:
|
case _:
|
||||||
}
|
}
|
||||||
case x:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 {
|
public function onDestroy(entity:EntityType):Void {
|
||||||
switch (entity) {
|
switch (entity) {
|
||||||
case EntityType.TANK(tank):
|
case EntityType.TANK(tank):
|
||||||
getPlayer(tank.playerId).control.stop();
|
var team = getTeam(tank.playerId.team);
|
||||||
getPlayer(tank.playerId).tankId = 0; //ToDo: ?
|
var player = getPlayer(tank.playerId);
|
||||||
var respawn:Bool = trySpawn(tank.playerId);
|
player.control.stop();
|
||||||
|
player.tankId = 0; //ToDo: ?
|
||||||
|
var respawn:Bool = team.trySpawn(player.id);
|
||||||
if (respawn) {
|
if (respawn) {
|
||||||
spawners[tank.playerId.team].push(tank.playerId);
|
team.spawner.push(player.id);
|
||||||
}
|
}
|
||||||
if (!isTeamAlive(tank.playerId.team)) {
|
if (!team.isAlive) {
|
||||||
state.teams[tank.playerId.team].lose = true;
|
lose(team.id);
|
||||||
complete();
|
}
|
||||||
|
if (tank.bonus) {
|
||||||
|
spawnBonus();
|
||||||
}
|
}
|
||||||
if (tank.bonus) spawnBonus();
|
|
||||||
deferred.resolve(state);
|
deferred.resolve(state);
|
||||||
case EntityType.EAGLE(eagle):
|
case _:
|
||||||
state.teams[eagle.team].lose = true;
|
|
||||||
complete();
|
|
||||||
deferred.resolve(state);
|
|
||||||
case x:
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function lose(teamId:TeamId):Void {
|
||||||
|
state.loser = teamId;
|
||||||
|
complete();
|
||||||
|
}
|
||||||
|
|
||||||
public function onAction(tankId:Int, action:TankAction):Void {
|
public function onAction(tankId:Int, action:TankAction):Void {
|
||||||
engine.action(tankId, action);
|
engine.action(tankId, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function next():Option<GameState> {
|
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({type: state.type, presetId: preset.id, level: level});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dispose():Void {
|
public function dispose():Void {
|
||||||
engine.dispose();
|
engine.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function spawnBonus(?type:BonusType):Void {
|
||||||
private function spawnBonus():Void {
|
var bonusConfig:BonusConfig = type != null ? config.getBonus(type) : config.bonuses[Math.floor(Math.random() * config.bonuses.length)];
|
||||||
var bonusConfig = config.bonuses[Math.floor(Math.random() * config.bonuses.length)];
|
var bonus = new Bonus(bonusConfig);
|
||||||
L.d(TAG, 'Spawn Bonus(${bonusConfig}');
|
|
||||||
var bonus = new Bonus(bonusConfig.type);
|
|
||||||
bonus.rect.x = Math.random() * engine.map.width;
|
bonus.rect.x = Math.random() * engine.map.width;
|
||||||
bonus.rect.y = Math.random() * engine.map.height;
|
bonus.rect.y = Math.random() * engine.map.height;
|
||||||
engine.spawn(bonus);
|
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 {
|
private function applyBonus(tank:Tank, bonus:Bonus):Void {
|
||||||
switch (bonus.bonusType) {
|
switch (bonus.config.type) {
|
||||||
case 'life':
|
case 'life':
|
||||||
state.teams[tank.playerId.team].players[tank.playerId.index].life++;
|
getPlayer(tank.playerId).life++;
|
||||||
case 'star':
|
case 'star':
|
||||||
if (tank.config.upgrade != null) {
|
if (tank.config.upgrade != null) {
|
||||||
tank.config = config.getTank(tank.config.upgrade);
|
tank.config = config.getTank(tank.config.upgrade);
|
||||||
} else {
|
} else {
|
||||||
tank.hits++;
|
tank.hits++;
|
||||||
}
|
}
|
||||||
|
engine.change(tank);
|
||||||
case 'grenade':
|
case 'grenade':
|
||||||
for (entity in engine.entities.iterator()) {
|
for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
|
||||||
switch (EntityTypeResolver.of(entity)) {
|
|
||||||
case EntityType.TANK(t):
|
|
||||||
if (t.playerId.team != tank.playerId.team) {
|
|
||||||
engine.destroy(t);
|
engine.destroy(t);
|
||||||
}
|
}
|
||||||
case x:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case 'helmet':
|
case 'helmet':
|
||||||
|
tank.protect.on(bonus.config.duration);
|
||||||
|
engine.change(tank);
|
||||||
case 'clock':
|
case 'clock':
|
||||||
|
for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
|
||||||
|
t.freezing.on(bonus.config.duration);
|
||||||
|
engine.change(t);
|
||||||
|
}
|
||||||
case 'shovel':
|
case 'shovel':
|
||||||
case x:
|
// ToDo: protect eagle/area
|
||||||
|
var team:Team = teams[tank.playerId.team];
|
||||||
|
if (team.eagleId > 0) {
|
||||||
|
var eagle:Eagle = cast(engine.entities[team.eagleId], Eagle);
|
||||||
|
eagle.protect.on(bonus.config.duration);
|
||||||
|
engine.change(eagle);
|
||||||
|
}
|
||||||
|
case _:
|
||||||
engine.destroy(tank); // :-D
|
engine.destroy(tank); // :-D
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function save():GameSave {
|
||||||
|
var players:Array<PlayerSave> = [];
|
||||||
|
for (team in teams) {
|
||||||
|
for (player in team.players) {
|
||||||
|
if (player.config.control == Control.HUMAN) {
|
||||||
|
var tank:Tank = EntityTypeResolver.as(engine.entities[player.tankId], Tank);
|
||||||
|
players.push({
|
||||||
|
id: player.id,
|
||||||
|
life: player.life + (player.tankId > 0 ? 1 : 0),
|
||||||
|
tank: tank != null ? tank.config.type : null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new GameSave({
|
||||||
|
type: state.type,
|
||||||
|
presetId: state.presetId,
|
||||||
|
level: state.level
|
||||||
|
}, players);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
46
src/common/haxe/ru/m/tankz/game/GameSave.hx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
|
import yaml.Parser;
|
||||||
|
import yaml.Renderer;
|
||||||
|
import yaml.Yaml;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
|
typedef PlayerSave = {
|
||||||
|
var id:PlayerId;
|
||||||
|
var tank:TankType;
|
||||||
|
var life:Int;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class GameSave {
|
||||||
|
|
||||||
|
public var state:GameState;
|
||||||
|
public var players:Array<PlayerSave>;
|
||||||
|
|
||||||
|
public function new(state:GameState, ?players:Array<PlayerSave>) {
|
||||||
|
this.state = state;
|
||||||
|
this.players = players != null ? players : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlayer(id:PlayerId):PlayerSave {
|
||||||
|
for (player in players) {
|
||||||
|
if (player.id.team == id.team && player.id.index == id.index) {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toYaml():String {
|
||||||
|
return Yaml.render({
|
||||||
|
state: state,
|
||||||
|
players: players,
|
||||||
|
}, Renderer.options().setFlowLevel(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function fromYaml(value:String):GameSave {
|
||||||
|
var data:Dynamic = Yaml.parse(value, Parser.options().useObjects());
|
||||||
|
return new GameSave(data.state, data.players);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,26 +3,9 @@ package ru.m.tankz.game;
|
|||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
typedef PlayerState = {
|
typedef GameState = {
|
||||||
var id:PlayerId;
|
var type:GameType;
|
||||||
var life:Int;
|
var presetId:PresetId;
|
||||||
}
|
@:optional var level:Int;
|
||||||
|
@:optional var loser:TeamId;
|
||||||
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 function new() {
|
|
||||||
type = null;
|
|
||||||
level = -1;
|
|
||||||
teams = new Map();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,27 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
class Player {
|
class Player {
|
||||||
|
|
||||||
|
public var config(default, null):PlayerConfig;
|
||||||
public var id(default, null):PlayerId;
|
public var id(default, null):PlayerId;
|
||||||
public var tankId(default, set):Int;
|
public var tankId(default, set):Int;
|
||||||
public var control(default, set):Control;
|
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) {
|
public function new(teamId:TeamId, config:PlayerConfig) {
|
||||||
this.id = id;
|
this.config = config;
|
||||||
this.control = control;
|
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;
|
tankId = value;
|
||||||
if (control != null) {
|
if (control != null) {
|
||||||
control.tankId = tankId;
|
control.tankId = tankId;
|
||||||
@@ -23,7 +29,7 @@ class Player {
|
|||||||
return tankId;
|
return tankId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_control(value:Control):Control {
|
private function set_control(value:Control):Control {
|
||||||
if (control != null) control.dispose();
|
if (control != null) control.dispose();
|
||||||
control = value;
|
control = value;
|
||||||
if (control != null) {
|
if (control != null) {
|
||||||
@@ -31,4 +37,8 @@ class Player {
|
|||||||
}
|
}
|
||||||
return control;
|
return control;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_isAlive():Bool {
|
||||||
|
return tankId > 0 || life > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ typedef SpawnTask = {
|
|||||||
class Spawner {
|
class Spawner {
|
||||||
|
|
||||||
public var active(get, never):Bool;
|
public var active(get, never):Bool;
|
||||||
|
public var runner(default, default):SpawnTask -> Void;
|
||||||
|
|
||||||
private var config:TeamConfig;
|
private var config:TeamConfig;
|
||||||
private var points:Array<SpawnPoint>;
|
private var points:Array<SpawnPoint>;
|
||||||
private var runner:SpawnTask -> Void;
|
|
||||||
private var queue:Array<SpawnTask>;
|
private var queue:Array<SpawnTask>;
|
||||||
private var timer:Timer;
|
private var timer:Timer;
|
||||||
|
|
||||||
@@ -24,10 +24,10 @@ class Spawner {
|
|||||||
private var anyPoints:Array<SpawnPoint>;
|
private var anyPoints:Array<SpawnPoint>;
|
||||||
private var index:Int;
|
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.config = config;
|
||||||
this.points = points;
|
this.points = points;
|
||||||
this.runner = runner;
|
this.runner = null;
|
||||||
queue = [];
|
queue = [];
|
||||||
indexedPoints = new Map();
|
indexedPoints = new Map();
|
||||||
anyPoints = [];
|
anyPoints = [];
|
||||||
|
|||||||
@@ -1,21 +1,60 @@
|
|||||||
package ru.m.tankz.game;
|
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.Type;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
|
||||||
|
|
||||||
class Team {
|
class Team {
|
||||||
|
|
||||||
public var id(default, null):TeamId;
|
public var id(default, null):TeamId;
|
||||||
public var config(default, null):TeamConfig;
|
public var config(default, null):TeamConfig;
|
||||||
|
public var spawner(default, null):Spawner;
|
||||||
public var players(default, null):Map<Int, Player>;
|
public var players(default, null):Map<Int, Player>;
|
||||||
|
public var life(default, default):Int;
|
||||||
|
public var isAlive(get, null):Bool;
|
||||||
|
public var eagleId(default, default):Int;
|
||||||
|
|
||||||
private static var i:Int = 0;
|
public function new(config:TeamConfig, points:Array<SpawnPoint>) {
|
||||||
|
|
||||||
public function new(config:TeamConfig) {
|
|
||||||
this.id = config.id;
|
this.id = config.id;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.players = new Map();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,6 @@ import ru.m.tankz.core.IKey;
|
|||||||
|
|
||||||
|
|
||||||
class Brick implements IKey {
|
class Brick implements IKey {
|
||||||
public static var BORDER:BrickConfig = {
|
|
||||||
type: -1,
|
|
||||||
layer: 2,
|
|
||||||
armor: -1,
|
|
||||||
}
|
|
||||||
|
|
||||||
public var cellX(default, null):Int;
|
public var cellX(default, null):Int;
|
||||||
public var cellY(default, null):Int;
|
public var cellY(default, null):Int;
|
||||||
public var key(get, null):String;
|
public var key(get, null):String;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package ru.m.tankz.config;
|
package ru.m.tankz.util;
|
||||||
|
|
||||||
import openfl.Assets;
|
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.Type;
|
|
||||||
import yaml.Parser;
|
import yaml.Parser;
|
||||||
import yaml.Renderer;
|
import yaml.Renderer;
|
||||||
import yaml.Yaml;
|
import yaml.Yaml;
|
||||||
@@ -13,9 +11,9 @@ typedef LevelSource = {
|
|||||||
@:optional var points:Array<SpawnPoint>;
|
@:optional var points:Array<SpawnPoint>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class LevelBundle {
|
class LevelUtil {
|
||||||
|
|
||||||
private static function formatLevel(level:Int):String {
|
public static function formatLevel(level:Int):String {
|
||||||
var result = Std.string(level);
|
var result = Std.string(level);
|
||||||
while (result.length < 3) result = '0${result}';
|
while (result.length < 3) result = '0${result}';
|
||||||
return result;
|
return result;
|
||||||
@@ -26,7 +24,7 @@ class LevelBundle {
|
|||||||
for (line in ~/\s+/g.split(data)) {
|
for (line in ~/\s+/g.split(data)) {
|
||||||
for (c in line.split('')) {
|
for (c in line.split('')) {
|
||||||
if (c.length > 0) {
|
if (c.length > 0) {
|
||||||
bricks.push(config.getBrick(Std.parseInt(c)));
|
bricks.push(config.getBrickByIndex(Std.parseInt(c)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,14 +39,14 @@ class LevelBundle {
|
|||||||
} else {
|
} else {
|
||||||
var obj:LevelSource = Yaml.parse(data, Parser.options().useObjects());
|
var obj:LevelSource = Yaml.parse(data, Parser.options().useObjects());
|
||||||
return {
|
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,
|
points: obj.points,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function dumps(config:Config, level:LevelConfig):String {
|
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({
|
return Yaml.render({
|
||||||
data: bricksStr,
|
data: bricksStr,
|
||||||
points: level.points,
|
points: level.points,
|
||||||
@@ -60,9 +58,4 @@ class LevelBundle {
|
|||||||
data: [for (i in 0...config.map.gridWidth * config.map.gridHeight) config.bricks[1]]
|
data: [for (i in 0...config.map.gridWidth * config.map.gridHeight) config.bricks[1]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get(type:GameType, config:Config, level:Int):LevelConfig {
|
|
||||||
var data:String = Assets.getText('resources/${type}/levels/level${formatLevel(level)}.txt');
|
|
||||||
return loads(config, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,47 +1,30 @@
|
|||||||
package ru.m.tankz.editor;
|
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 flash.text.Font;
|
||||||
import haxework.resources.Resources;
|
import haxework.gui.ButtonView;
|
||||||
import haxework.resources.IResources;
|
import haxework.gui.frame.FrameSwitcher;
|
||||||
import haxework.provider.Provider;
|
import haxework.gui.VGroupView;
|
||||||
import haxework.log.TraceLogger;
|
import haxework.gui.Root;
|
||||||
import haxework.gui.ViewBuilder;
|
import haxework.gui.ViewBuilder;
|
||||||
import haxework.gui.GroupView;
|
import haxework.log.TraceLogger;
|
||||||
import haxework.log.JSLogger;
|
import haxework.provider.Provider;
|
||||||
import haxework.log.SocketLogger;
|
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 {
|
interface EditorViewLayout {
|
||||||
var gameClassicButton(default, null):ButtonView;
|
var switcher(default, null):FrameSwitcher;
|
||||||
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/Editor.yaml")
|
@:template('ru/m/tankz/editor/Editor.yaml', 'ru/m/tankz/editor/Style.yaml')
|
||||||
class EditorView extends GroupView implements ViewBuilder implements EditorViewLayout {}
|
class EditorView extends VGroupView implements ViewBuilder implements EditorViewLayout {}
|
||||||
|
|
||||||
class Editor {
|
class Editor {
|
||||||
|
|
||||||
private static inline var TAG = "Tankz.Editor";
|
private static inline var TAG = 'Editor';
|
||||||
|
|
||||||
public static function main() {
|
public static function main() {
|
||||||
L.push(new TraceLogger());
|
L.push(new TraceLogger());
|
||||||
@@ -52,92 +35,29 @@ class Editor {
|
|||||||
L.push(new SocketLogger());
|
L.push(new SocketLogger());
|
||||||
#end
|
#end
|
||||||
Const.init();
|
Const.init();
|
||||||
L.d(TAG, "Debug: " + Const.DEBUG);
|
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
||||||
L.i(TAG, "Version: " + Const.VERSION);
|
L.i(TAG, 'Version: ${Const.VERSION}');
|
||||||
L.i(TAG, "Build: " + Const.BUILD);
|
L.i(TAG, 'Build: ${Const.BUILD}');
|
||||||
new Editor();
|
new Editor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private var view:EditorView;
|
private var view:EditorView;
|
||||||
private var config:Config;
|
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
Provider.setFactory(IResources, Resources);
|
Provider.setFactory(IResources, Resources);
|
||||||
|
|
||||||
var font:Font = Font.enumerateFonts()[0];
|
var font:Font = Font.enumerateFonts()[0];
|
||||||
Provider.get(IResources).text.put("font", "Bookman Old Style");
|
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('version', 'v${Const.VERSION} b${Const.BUILD}');
|
||||||
|
|
||||||
view = new EditorView();
|
view = new EditorView({handler: this});
|
||||||
Root.bind(view);
|
Root.bind(view);
|
||||||
view.content.stage.stageFocusRect = false;
|
view.content.stage.stageFocusRect = false;
|
||||||
|
|
||||||
view.gameClassicButton.onPress = this;
|
view.switcher.change(LevelFrame.ID);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPress(v:ButtonView):Void {
|
public function onPress(v:ButtonView):Void {
|
||||||
switch (v.id) {
|
view.switcher.change(v.id.split('btn_').pop());
|
||||||
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 _:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,89 +1,48 @@
|
|||||||
$type: haxework.gui.GroupView
|
---
|
||||||
|
$type: haxework.gui.VGroupView
|
||||||
pWidth: 100
|
pWidth: 100
|
||||||
pHeight: 100
|
pHeight: 100
|
||||||
views:
|
|
||||||
- $type: haxework.gui.VGroupView
|
|
||||||
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:
|
skin:
|
||||||
$type: haxework.gui.skin.ButtonColorSkin
|
$type: haxework.gui.skin.BitmapSkin
|
||||||
color: 0xaaff00
|
image: "@asset:image:resources/images/background.png"
|
||||||
- id: gameDotaButton
|
fillType: REPEAT
|
||||||
$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:
|
views:
|
||||||
- id: openButton
|
# Tabs
|
||||||
$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
|
- $type: haxework.gui.HGroupView
|
||||||
contentSize: true
|
contentSize: true
|
||||||
views:
|
views:
|
||||||
- id: spawnPointList
|
- id: btn_level
|
||||||
$type: haxework.gui.list.VListView<SpawnPoint>
|
$type: haxework.gui.ButtonView
|
||||||
factory: '@class:ru.m.tankz.editor.SpawnPointView'
|
$style: button
|
||||||
width: 56
|
text: Level
|
||||||
pHeight: 100
|
onPress: "@link:handler"
|
||||||
scroll:
|
- id: btn_tank
|
||||||
$type: haxework.gui.list.VScrollView
|
$type: haxework.gui.ButtonView
|
||||||
width: 0
|
$style: button
|
||||||
pHeight: 100
|
text: Tank
|
||||||
skin:
|
onPress: "@link:handler"
|
||||||
$type: haxework.gui.list.VScrollSkin
|
- $type: haxework.gui.SpriteView
|
||||||
|
height: 3
|
||||||
|
pWidth: 100
|
||||||
skin:
|
skin:
|
||||||
$type: haxework.gui.skin.ColorSkin
|
$type: haxework.gui.skin.ColorSkin
|
||||||
color: 0x000000
|
color: "#aaaaaa"
|
||||||
alpha: 0.0
|
# Switcher
|
||||||
- id: mapView
|
- id: switcher
|
||||||
$type: ru.m.tankz.editor.MapEditView
|
$type: haxework.gui.frame.FrameSwitcher
|
||||||
contentSize: true
|
pWidth: 100
|
||||||
- id: brickList
|
|
||||||
$type: haxework.gui.list.VListView<BrickConfig>
|
|
||||||
factory: '@class:ru.m.tankz.editor.BrickView'
|
|
||||||
width: 30
|
|
||||||
pHeight: 100
|
pHeight: 100
|
||||||
scroll:
|
paddings: 5
|
||||||
$type: haxework.gui.list.VScrollView
|
views:
|
||||||
width: 0
|
- id: level
|
||||||
pHeight: 100
|
$type: ru.m.tankz.editor.frame.LevelFrame
|
||||||
skin:
|
- id: tank
|
||||||
$type: haxework.gui.list.VScrollSkin
|
$type: ru.m.tankz.editor.frame.TankFrame
|
||||||
skin:
|
# Version
|
||||||
$type: haxework.gui.skin.ColorSkin
|
|
||||||
color: 0x000000
|
|
||||||
alpha: 0.0
|
|
||||||
- $type: haxework.gui.LabelView
|
- $type: haxework.gui.LabelView
|
||||||
|
$style: label
|
||||||
inLayout: false
|
inLayout: false
|
||||||
contentSize: true
|
contentSize: true
|
||||||
vAlign: BOTTOM
|
vAlign: BOTTOM
|
||||||
hAlign: RIGHT
|
hAlign: RIGHT
|
||||||
text: '@res:text:version'
|
text: "@res:text:version"
|
||||||
|
|||||||
15
src/editor/haxe/ru/m/tankz/editor/Style.yaml
Normal 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
|
||||||
110
src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx
Normal 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 _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
68
src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml
Normal 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
|
||||||
34
src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.hx
Normal 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}');
|
||||||
|
}
|
||||||
|
}
|
||||||
49
src/editor/haxe/ru/m/tankz/editor/frame/TankFrame.yaml
Normal 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
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ru.m.tankz.editor;
|
package ru.m.tankz.editor.level;
|
||||||
|
|
||||||
import flash.display.Bitmap;
|
import flash.display.Bitmap;
|
||||||
import flash.display.Shape;
|
import flash.display.Shape;
|
||||||
@@ -38,7 +38,7 @@ class BrickView extends SpriteView implements IListItemView<BrickConfig> {
|
|||||||
|
|
||||||
private function set_data(value:BrickConfig):BrickConfig {
|
private function set_data(value:BrickConfig):BrickConfig {
|
||||||
data = value;
|
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.bitmapData = Assets.getBitmapData(src);
|
||||||
imageView.x = (width - imageView.width) / 2;
|
imageView.x = (width - imageView.width) / 2;
|
||||||
imageView.y = (height - imageView.height) / 2;
|
imageView.y = (height - imageView.height) / 2;
|
||||||
@@ -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.DisplayObjectContainer;
|
||||||
import flash.display.Graphics;
|
import flash.display.Graphics;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import ru.m.tankz.render.RenderItem;
|
import flash.events.MouseEvent;
|
||||||
import ru.m.tankz.config.Config;
|
|
||||||
import ru.m.tankz.map.LevelMap;
|
|
||||||
import haxework.gui.SpriteView;
|
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 {
|
class SpawnPointEntity extends Entity {
|
||||||
@@ -41,11 +41,23 @@ class SpawnPointItem extends BitmapItem<SpawnPointEntity> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function getSrc(value:SpawnPoint, config:Config):String {
|
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) {
|
return switch(value.type) {
|
||||||
case 'eagle': 'resources/images/eagle/eagle-0.png';
|
case 'eagle': 'resources/image/eagle/eagle.png';
|
||||||
case 'tank': TankItem.getTankFrames(value.team, value.index, tankType)[0];
|
case 'tank': 'resources/image/tank/${tankConfig.skin}-0.png';
|
||||||
case x: 'resources/images/eagle/eagle-1.png';
|
case x: 'resources/image/eagle/eagle-death.png';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +192,7 @@ class MapEditView extends SpriteView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function drawMap() {
|
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)) {
|
if (!items.exists(brick.key)) {
|
||||||
items[brick.key] = new BrickItem(brick);
|
items[brick.key] = new BrickItem(brick);
|
||||||
if (brick.config.layer > 2) {
|
if (brick.config.layer > 2) {
|
||||||
@@ -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.Bitmap;
|
||||||
import flash.display.Shape;
|
import flash.display.Shape;
|
||||||
import haxework.gui.list.ListView;
|
import haxework.gui.list.ListView;
|
||||||
import haxework.gui.SpriteView;
|
import haxework.gui.SpriteView;
|
||||||
|
import haxework.provider.Provider;
|
||||||
import openfl.utils.Assets;
|
import openfl.utils.Assets;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.editor.level.MapEditView;
|
||||||
|
|
||||||
|
|
||||||
class SpawnPointView extends SpriteView implements IListItemView<SpawnPoint> {
|
class SpawnPointView extends SpriteView implements IListItemView<SpawnPoint> {
|
||||||
45
src/editor/haxe/ru/m/tankz/editor/tank/TankView.hx
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||