16 Commits
0.6.0 ... 0.7.0

Author SHA1 Message Date
5b04242aab [version] up to 0.7.0 2018-02-20 00:02:44 +03:00
a127777e49 [common] added GameSave 2018-02-20 00:01:35 +03:00
11aea59cf8 [client] resource images rename 2018-02-18 21:22:46 +03:00
5456a01551 [common] bonus config duration 2018-02-16 22:19:14 +03:00
a93a67161d Merge branch 'develop' of bitbucket.org:infernalgames/tankz into develop 2018-02-16 17:59:22 +03:00
52a4e44e47 [client] added AniamteBundle 2018-02-16 17:57:43 +03:00
79039ae79e [version] up 2018-02-16 00:09:13 +03:00
1ae84cf5a8 [common] bonuses implemented 2018-02-15 17:11:41 +03:00
032fa0c0ad [client] yaml layouts 2018-02-14 17:15:15 +03:00
1f8b43ba5d [editor] tank color view 2018-02-13 22:32:21 +03:00
4fc0ae103e [editor] added frame switcher 2018-02-13 17:57:07 +03:00
bd86412d83 [editor] fixes 2018-02-13 17:12:24 +03:00
592e59e01f [common] added Eagle death flag 2018-02-13 16:59:01 +03:00
05b6fe4a56 [client] added any map item renders 2018-02-13 14:44:04 +03:00
f68e5d160f [common] game state refactored 2018-02-12 22:26:30 +03:00
d279d52b09 [editor] fix 2018-02-11 14:37:02 +03:00
100 changed files with 1559 additions and 952 deletions

29
WORK.md
View File

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

View File

@@ -21,7 +21,7 @@ const generate = () => function generate() {
]);
};
const build = (platform) => function build() {
const build = (platform, values) => function build() {
const argv = yargs.argv;
return gulp.src('.')
.pipe(new Haxe().openfl({
@@ -29,6 +29,7 @@ const build = (platform) => function build() {
platform: platform,
version: version,
debug: argv.dev,
values: values
}))
.pipe(gulp.dest(`target/${platform}`));
};
@@ -87,6 +88,7 @@ const buildDeb = gulp.series(
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: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:webapp'] = webapp;
exports['client:deb'] = buildDeb;
@@ -108,9 +110,9 @@ const testFlash = function() {
.pipe(debug());
};
const testHtml5 = function() {
const testHtml5 = (dom) => function() {
return gulp.series(
build('html5'),
build('html5', {dom:dom}),
() => gulp.src('target/html5').pipe(webserver({
host: 'localhost', port: 3000,
open: true,
@@ -130,7 +132,8 @@ const testLinux = gulp.series(
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:test'] = exports['client:flash:test'];

View File

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

View File

@@ -12,13 +12,15 @@
<haxelib name="protohx" version="0.4.6"/>
<haxelib name="haxework" version="git"/>
<haxelib name="yaml" version="1.3.0"/>
<haxelib name="yield" version="1.1.2"/>
<window fps="30"/>
<window width="1024" height="768" unless="html5"/>
<haxeflag name="-D" value="swf-gpu"/>
<haxeflag name="-D" value="native-trace"/>
<!--<haxeflag name="-D" value="proto_debug"/>-->
<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"/>-->
<section if="build_editor">

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -6,6 +6,11 @@ import flash.display.Bitmap;
import flash.display.BitmapData;
typedef Frame = {
var image:BitmapData;
var length:Int;
}
class Animate extends Bitmap {
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 frames(default, set):Array<BitmapData>;
public var frames(default, set):Array<Frame>;
private var sequence:Array<BitmapData>;
private var index:Int;
public function new(?frames:Array<BitmapData>) {
public function new(?frames:Array<Frame>) {
super(null, PixelSnapping.AUTO, true);
this.frames = frames == null ? [] : frames;
init();
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) {
frames = value;
bitmapData = frames[0];
index = 0;
for (frame in frames) {
sequence = sequence.concat([for (i in 0...frame.length) frame.image]);
}
bitmapData = sequence[0];
} else {
bitmapData = null;
}
return frames;
}
@@ -56,10 +67,10 @@ class Animate extends Bitmap {
}
private function update():Void {
if (++index >= frames.length) {
if (++index >= sequence.length) {
index = 0;
}
var nextBitmapData = frames[index];
var nextBitmapData = sequence[index];
x -= (nextBitmapData.width - bitmapData.width) / 2;
y -= (nextBitmapData.height - bitmapData.height) / 2;
bitmapData = nextBitmapData;

View File

@@ -1,7 +1,6 @@
package ru.m.animate;
import promhx.Deferred;
import flash.display.BitmapData;
import promhx.Promise;
@@ -9,10 +8,6 @@ class OnceAnimate extends Animate {
private var deferred:Deferred<Animate>;
public function new(frames:Array<BitmapData>) {
super(frames);
}
public function play():Promise<Animate> {
deferred = new Deferred();
playing = true;

View File

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

View File

@@ -0,0 +1,27 @@
---
$type: haxework.gui.VGroupView
pWidth: 100
pHeight: 100
views:
- id: switcher
$type: haxework.gui.frame.FrameSwitcher
pWidth: 100
pHeight: 100
skin:
$type: haxework.gui.skin.BitmapSkin
image: "@asset:image:resources/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"

View 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

View File

@@ -1,29 +1,30 @@
package ru.m.tankz.config;
package ru.m.tankz.bundle;
import yaml.Parser;
import openfl.Assets;
import yaml.Yaml;
import ru.m.tankz.config.Config;
import ru.m.tankz.Type;
import yaml.Parser;
import yaml.Yaml;
typedef ConfigSource = {
var game:GameConfig;
var map: MapConfig;
var bricks: Array<BrickConfig>;
var teams: Array<TeamConfig>;
var presets: Array<GamePreset>;
var points: Array<SpawnPoint>;
var tanks: Array<TankConfig>;
var bonuses: Array<BonusConfig>;
}
class ConfigBundle {
class ConfigBundle implements IConfigBundle {
private static function convert(raw:Dynamic):ConfigSource {
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()));
return new Config(type, source.game, source.map, source.bricks, source.teams, source.points, source.tanks, source.bonuses);
return new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses);
}
}

View File

@@ -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);
}
}

View File

@@ -1,8 +1,7 @@
package ru.m.tankz.view.frames;
package ru.m.tankz.frame;
import haxe.ds.Option;
import haxe.ds.Option;
import flash.events.Event;
import haxe.ds.Option;
import haxe.Timer;
import haxework.gui.frame.IFrameSwitcher;
import haxework.gui.LabelView;
@@ -12,9 +11,11 @@ import haxework.provider.Provider;
import protohx.Message;
import ru.m.connect.IConnection;
import ru.m.tankz.game.Game;
import ru.m.tankz.game.GameSave;
import ru.m.tankz.game.GameState;
import ru.m.tankz.proto.pack.GameUpdateResponse;
import ru.m.tankz.render.Render;
import ru.m.tankz.storage.SaveStorage;
interface GameFrameLayout {
@@ -22,8 +23,7 @@ interface GameFrameLayout {
var render(default, null):Render;
}
@:template("layout/frames/game.json", "layout/styles.json")
@:template("ru/m/tankz/frame/GameFrame.yaml", "ru/m/tankz/Style.yaml")
class GameFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements GameFrameLayout {
private static inline var TAG = "GameFrame";
@@ -36,22 +36,22 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
public function init():Void {}
public function onShow():Void {
start(Provider.get(GameState));
start(Provider.get(GameSave));
}
private function start(s:GameState):Void {
game = Provider.build(Game, s.type);
private function start(save:GameSave):Void {
game = Provider.build(Game, save.state.type);
if (game == null) {
throw 'Unsupported game type "${s.type}"';
throw 'Unsupported game type "${save.state.type}"';
}
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);
//Provider.get(IConnection).packetHandler.addListener(this);
render.draw(game.engine);
timer = new Timer(10);
timer.run = updateEngine;
state.text = stateString(s);
state.text = stateString(game);
}
private function stop():Void {
@@ -68,20 +68,21 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
render.reset();
}
private function stateString(state:GameState):String {
private function stateString(game:Game):String {
if (game.state == null) {
return '';
}
var result:Array<String> = [];
result.push('Level: ${state.level}');
for (teamId in state.teams.keys()) {
var ts:TeamState = state.teams[teamId];
if (ts.lose) {
result.push('${teamId}: LOSE');
} else if (ts.life > -1) {
result.push('${teamId}: ${ts.life}');
result.push('Level: ${game.state.level}');
for (team in game.teams) {
if (game.state.loser == team.id) {
result.push('${team.id}: LOSE');
} else if (team.life > -1) {
result.push('${team.id}: ${team.life}');
} else {
for (index in ts.players.keys()) {
var ps:PlayerState = ts.players[index];
if (ps.life > -1) {
result.push('${teamId}${index}: ${ps.life}');
for (player in team.players) {
if (player.life > -1) {
result.push('${player.id.team}${player.id.index}: ${player.life}');
}
}
}
@@ -90,20 +91,22 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
}
private function onGameStateChange(s:GameState):GameState {
state.text = stateString(s);
state.text = stateString(game);
return s;
}
private function onGameComplete(result:Option<GameState>):Void {
switch (result) {
case Option.Some(s):
state.text = stateString(s);
state.text = stateString(game);
case Option.None:
}
switch (game.next()) {
case Option.Some(s):
var save = game.save();
Provider.get(SaveStorage).write(save);
stop();
start(s);
start(save);
case Option.None:
Provider.get(IFrameSwitcher).change(StartFrame.ID);
}

View File

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

View File

@@ -1,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 ru.m.tankz.game.GameState;
import haxework.provider.Provider;
import haxework.gui.list.ListView;
import haxework.gui.ViewBuilder;
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 {
@@ -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 {
public static inline var ID = "level";
@@ -23,13 +24,13 @@ class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrame
}
public function onShow():Void {
var state = Provider.get(GameState);
var c = ConfigBundle.get(state.type).game.levels;
var state:GameState = Provider.get(GameSave).state;
var c = Provider.get(IConfigBundle).get(state.type).game.levels;
levels.data = [for (i in 0...c) i];
}
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);
}
}

View File

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

View File

@@ -1,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.frame.IFrameSwitcher;
import haxework.gui.VGroupView;
@@ -14,30 +16,38 @@ import ru.m.tankz.Type;
interface StartFrameLayout {
var classic_1p(default, null):ButtonView;
var classic_2p(default, null):ButtonView;
var classic_load(default, null):ButtonView;
var dota_1p(default, null):ButtonView;
var dota_2p_coop(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 {
public static inline var ID = "start";
public function init() {
public function init():Void {
classic_1p.onPress = this;
classic_2p.onPress = this;
classic_load.onPress = this;
dota_1p.onPress = this;
dota_2p_coop.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 {
switch (view.id) {
case 'classic_1p':
startGame(ClassicGame.TYPE, ClassicGame.PLAYER1);
case 'classic_2p':
startGame(ClassicGame.TYPE, ClassicGame.PLAYER2);
case 'classic_load':
loadGame(ClassicGame.TYPE);
case 'dota_1p':
startGame(DotaGame.TYPE, DotaGame.PLAYER1);
case 'dota_2p_coop':
@@ -47,14 +57,14 @@ class StartFrame extends VGroupView implements ViewBuilder implements StartFrame
}
}
private function startGame(type:GameType, mode:GameMode):Void {
switch (type) {
case ClassicGame.TYPE:
Provider.set(GameState, ClassicGame.buildState(0, mode));
Provider.get(IFrameSwitcher).change(LevelFrame.ID);
case DotaGame.TYPE:
Provider.set(GameState, DotaGame.buildState(0, mode));
private function startGame(type:GameType, presetId:PresetId):Void {
Provider.set(GameSave, new GameSave({type: type, presetId: presetId}));
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);
}
}

View 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

View File

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

View File

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

View File

@@ -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}];
}
}

View File

@@ -1,15 +1,15 @@
package ru.m.tankz.render;
import ru.m.geom.Point;
import openfl.Assets;
import ru.m.animate.OnceAnimate;
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.Sprite;
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 {
@@ -54,13 +54,21 @@ class Render extends SpriteView implements EngineListener {
}
public function draw(game:Engine):Void {
for (brick in game.map.bricks) if (brick.config.type > 0) {
for (brick in game.map.bricks) if (brick.config.index > 0) {
if (!items.exists(brick.key)) {
items[brick.key] = new BrickItem(brick);
var item:RenderItem<Dynamic, Dynamic> = switch(brick.config.type) {
case 'ace' | 'bush': new BrickItem(brick);
case 'water': new BrickAnimateItem(brick);
case 'armor' | 'brick': new BrickBreakingItem(brick);
case x: null;
};
if (item != null) {
items[brick.key] = item;
if (brick.config.layer > 2) {
upLayer.addChild(items[brick.key].view);
upLayer.addChild(item.view);
} 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);
entryLayer.addChild(item.view);
item.update();
playTankSpawn(tank.rect.center);
playAnimate(tank.rect.center, AnimateBundle.tankSpawn());
case EntityType.BULLET(bullet):
var item = new BulletItem(bullet);
items.set(bullet.key, item);
@@ -111,85 +119,53 @@ class Render extends SpriteView implements EngineListener {
case EntityType.BONUS(bonus):
var item = new BonusItem(bonus);
items.set(bonus.key, item);
entryLayer.addChild(item.view);
upperLayer.addChild(item.view);
item.update();
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 {
switch(entity) {
switch entity {
case EntityType.TANK(tank):
if (items.exists(tank.key)) {
entryLayer.removeChild(items.get(tank.key).view);
items.remove(tank.key);
playTankBoom(tank.rect.center);
playAnimate(tank.rect.center, AnimateBundle.tankBoom());
}
case EntityType.BULLET(bullet):
if (items.exists(bullet.key)) {
entryLayer.removeChild(items.get(bullet.key).view);
items.remove(bullet.key);
playBulletBoom(bullet.rect.center.add(new Point(bullet.rect.width * bullet.rect.direction.x, bullet.rect.height * bullet.rect.direction.y)));
}
case EntityType.EAGLE(eagle):
if (items.exists(eagle.key)) {
cast(items.get(eagle.key), EagleItem).destoyed = true;
items.get(eagle.key).redraw();
playTankBoom(eagle.rect.center);
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.BONUS(bonus):
if (items.exists(bonus.key)) {
entryLayer.removeChild(items.get(bonus.key).view);
upperLayer.removeChild(items.get(bonus.key).view);
items.remove(bonus.key);
}
case _:
}
}
private function playTankSpawn(point:Point):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);
private function playAnimate(point:Point, animate:OnceAnimate):Void {
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 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) {
animate.play().then(function(animate:Animate):Void {
upperLayer.removeChild(animate);
animate.dispose();
});

View File

@@ -1,21 +1,19 @@
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.DisplayObject;
import flash.display.Shape;
import flash.display.Sprite;
import openfl.Assets;
import ru.m.animate.Animate;
import ru.m.draw.BitmapUtil;
import ru.m.geom.Direction;
import ru.m.geom.Rectangle;
import ru.m.tankz.core.Bonus;
import ru.m.tankz.core.Bullet;
import ru.m.tankz.core.Eagle;
import ru.m.tankz.core.Tank;
import ru.m.tankz.map.Brick;
import ru.m.tankz.Type.BrickType;
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 type:Int;
private var type:BrickType;
public function new(value:Brick) {
super(value);
@@ -93,7 +131,7 @@ class BrickItem extends RenderItem<Brick, Shape> {
var g = view.graphics;
g.clear();
if (value.destroyed) return;
if (value.config.type > 0) {
if (value.config.index > 0) {
g.beginBitmapFill(image);
g.drawRect(0, 0, value.rect.width, value.rect.height);
for (c in value.cells) {
@@ -118,7 +156,7 @@ class BrickItem extends RenderItem<Brick, Shape> {
}
private function getImage():String {
return 'resources/images/map/map_${value.config.type}.png';
return 'resources/image/map/${value.config.type}.png';
}
}
@@ -140,24 +178,34 @@ class TankItem extends RenderItem<Tank, Sprite> {
private var type:String;
private var hits:Int;
private var protected:Bool;
private var frozen:Bool;
private var tankView:Animate;
private var protectView:Animate;
public function new(value:Tank) {
super(value);
view = new Sprite();
tankView = new Animate();
view.addChild(tankView);
protectView = AnimateBundle.tankProtect();
protectView.visible = false;
view.addChild(protectView);
redraw();
}
override public function redraw():Void {
var colors:Array<Color> = [value.color, value.bonus ? 0xff00aa : value.color];
var frames = [for (frame in getFrames()) BitmapUtil.colorize(Assets.getBitmapData(frame), colors.shift())];
tankView.frames = [
frames[0], frames[0], frames[0],
frames[1], frames[1], frames[1],
];
tankView.frames = AnimateBundle.tankFrames(value);
if (value.protect.active) {
protectView.x = (tankView.frames[0].image.width - protectView.frames[0].image.width) / 2;
protectView.y = (tankView.frames[0].image.height - protectView.frames[0].image.height) / 2;
protectView.playing = true;
protectView.visible = true;
} else {
protectView.playing = false;
protectView.visible = false;
}
}
private function getFrames():Array<String> {
@@ -170,12 +218,16 @@ class TankItem extends RenderItem<Tank, Sprite> {
super.update();
var t = value.config.type;
var h = value.hits;
if (t != this.type || h != this.hits) {
var p = value.protect.active;
var f = value.freezing.active;
if (t != type || h != hits || p != protected || f != frozen) {
this.type = t;
this.hits = h;
this.protected = p;
this.frozen = f;
redraw();
}
tankView.playing = (value.mx !=0 || value.my != 0);
tankView.playing = !value.freezing.active && (value.mx !=0 || value.my != 0);
}
override public function dispose():Void {
@@ -190,17 +242,32 @@ class TankItem extends RenderItem<Tank, Sprite> {
class BulletItem extends BitmapItem<Bullet> {
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> {
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 {
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 {
var image = Assets.getBitmapData('resources/image/bonus/${value.bonusType}.png');
var empty = new BitmapData(image.width, image.height, true, 0x00000000);
view.frames = [for (i in 0...15) image].concat([for (i in 0...15) empty]);
var image = Assets.getBitmapData('resources/image/bonus/${value.config.type}.png');
view.frames = AnimateBundle.bonusFrames(value.config.type);
view.playing = true;
}
}

View 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();
}
}

View File

@@ -9,26 +9,64 @@ map:
gridHeight: 26
bricks:
- {type: -1, layer: 2, armor: -1} # border
- {type: 0, layer: 0, armor: 0} # none
- {type: 1, layer: 0, armor: 0} # ace
- {type: 2, layer: 3, armor: 0} # bush
- {type: 3, layer: 1, armor: 0} # water
- {type: 4, layer: 2, armor: 2} # armor
- {type: 5, layer: 2, armor: 1} # brick
- {type: border, index: -1, layer: 2, armor: -1}
- {type: none, index: 0, layer: 0, armor: 0}
- {type: ace, index: 1, layer: 0, armor: 0}
- {type: bush, index: 2, layer: 3, armor: 0}
- {type: water, index: 3, layer: 1, armor: 0}
- {type: armor, index: 4, layer: 2, armor: 2}
- {type: brick, index: 5, layer: 2, armor: 1}
teams:
- id: human
player:
human: &human
control: human
life: 3
tanks:
- {type: human0, rate: 1}
- id: bot
spawnInterval: 3000
- {type: human0, rate: 1, protect: 5}
bot: &bot
control: bot
color: 0xFFFFFF
life: -1
tanks:
- {type: bot0, rate: 0.25, bonus: 0.25}
- {type: bot1, rate: 0.25, bonus: 0.25}
- {type: bot2, rate: 0.25, bonus: 0.25}
- {type: bot3, rate: 0.25, bonus: 0.25}
presets:
- id: player1
teams:
- id: human
life: -1
players:
- {<<: *human, index: 0, color: 0xF5C040, life: 3}
- id: bot
spawnInterval: 3000
life: 20
players:
- {<<: *bot, index: 0}
- {<<: *bot, index: 1}
- {<<: *bot, index: 2}
- {<<: *bot, index: 3}
- id: player2
teams:
- id: human
life: -1
players:
- {<<: *human, index: 0, color: 0xF5C040, life: 3}
- {<<: *human, index: 1, color: 0x15C040, life: 3}
- id: bot
spawnInterval: 3000
life: 20
players:
- {<<: *bot, index: 0}
- {<<: *bot, index: 1}
- {<<: *bot, index: 2}
- {<<: *bot, index: 3}
- {<<: *bot, index: 4}
- {<<: *bot, index: 5}
points:
- {team: human, type: eagle, index: -1, direction: right, x: 12, y: 24}
- {team: human, type: tank, index: 0, direction: top, x: 8, y: 24}
@@ -136,9 +174,9 @@ tanks:
skin: bd
bonuses:
- {type: clock}
- {type: clock, duration: 10}
- {type: grenade}
- {type: helmet}
- {type: helmet, duration: 20}
- {type: life}
- {type: shovel}
- {type: shovel, duration: 10}
- {type: star}

View File

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

View File

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

View File

Before

Width:  |  Height:  |  Size: 110 B

After

Width:  |  Height:  |  Size: 110 B

View File

Before

Width:  |  Height:  |  Size: 141 B

After

Width:  |  Height:  |  Size: 141 B

View File

Before

Width:  |  Height:  |  Size: 144 B

After

Width:  |  Height:  |  Size: 144 B

View File

Before

Width:  |  Height:  |  Size: 186 B

After

Width:  |  Height:  |  Size: 186 B

View File

Before

Width:  |  Height:  |  Size: 144 B

After

Width:  |  Height:  |  Size: 144 B

View File

Before

Width:  |  Height:  |  Size: 186 B

After

Width:  |  Height:  |  Size: 186 B

View File

Before

Width:  |  Height:  |  Size: 144 B

After

Width:  |  Height:  |  Size: 144 B

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

Before

Width:  |  Height:  |  Size: 292 B

After

Width:  |  Height:  |  Size: 292 B

View File

Before

Width:  |  Height:  |  Size: 386 B

After

Width:  |  Height:  |  Size: 386 B

View File

Before

Width:  |  Height:  |  Size: 389 B

After

Width:  |  Height:  |  Size: 389 B

View File

Before

Width:  |  Height:  |  Size: 375 B

After

Width:  |  Height:  |  Size: 375 B

View File

Before

Width:  |  Height:  |  Size: 374 B

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 737 B

After

Width:  |  Height:  |  Size: 737 B

View File

Before

Width:  |  Height:  |  Size: 307 B

After

Width:  |  Height:  |  Size: 307 B

View File

Before

Width:  |  Height:  |  Size: 304 B

After

Width:  |  Height:  |  Size: 304 B

View File

Before

Width:  |  Height:  |  Size: 279 B

After

Width:  |  Height:  |  Size: 279 B

View File

Before

Width:  |  Height:  |  Size: 969 B

After

Width:  |  Height:  |  Size: 969 B

View File

Before

Width:  |  Height:  |  Size: 93 B

After

Width:  |  Height:  |  Size: 93 B

View File

Before

Width:  |  Height:  |  Size: 598 B

After

Width:  |  Height:  |  Size: 598 B

View File

Before

Width:  |  Height:  |  Size: 531 B

After

Width:  |  Height:  |  Size: 531 B

View File

Before

Width:  |  Height:  |  Size: 598 B

After

Width:  |  Height:  |  Size: 598 B

View File

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

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

View File

@@ -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;
}

View 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;
}

View File

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

View File

@@ -1,15 +1,15 @@
package ru.m.tankz.core;
import ru.m.tankz.config.Config;
import ru.m.geom.Rectangle;
import ru.m.tankz.Type;
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));
this.bonusType = bonusType;
this.config = config;
}
}

View File

@@ -7,9 +7,13 @@ import ru.m.tankz.Type;
class Eagle extends Entity {
public var team(default, null):TeamId;
public var death(default, default):Bool;
public var protect(default, null):Modificator;
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.death = false;
this.protect = new Modificator();
}
}

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
package ru.m.tankz.engine;
import ru.m.geom.Point;
import ru.m.geom.Line;
import ru.m.geom.Point;
import ru.m.tankz.config.Config;
import ru.m.tankz.control.Control;
import ru.m.tankz.core.Bullet;
@@ -12,14 +12,19 @@ import ru.m.tankz.core.Tank;
import ru.m.tankz.map.LevelMap;
enum EntityChange {
DEATH;
HIT;
}
interface EngineListener {
public function onSpawn(entity:EntityType):Void;
public function onChange(entity:EntityType, ?change:EntityChange):Void;
public function onCollision(entity:EntityType, with:EntityType):Void;
public function onDestroy(entity:EntityType):Void;
}
class CollisionProcessor implements EngineListener {
private var engine:Engine;
@@ -30,53 +35,41 @@ class CollisionProcessor implements EngineListener {
public function onSpawn(entity:EntityType):Void {}
private function checkTankBullet(tank:Tank, bullet:Bullet):Bool {
if (bullet.tankId == tank.id) return false;
return engine.config.game.friendlyFire || tank.playerId.team != bullet.playerId.team;
}
public function onChange(entity:EntityType, ?change:EntityChange):Void {}
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) {
tank.hits--;
engine.change(tank, EntityChange.HIT);
} else {
engine.destroy(tank);
}
}
public function onCollision(entity:EntityType, with:EntityType):Void {
switch (entity) {
case EntityType.TANK(tank1):
switch (with) {
case EntityType.TANK(tank2):
tank1.rect.lean(tank2.rect);
case EntityType.BULLET(bullet2):
if (checkTankBullet(tank1, bullet2)) {
hitTank(tank1);
engine.destroy(bullet2);
engine.destroy(bullet);
}
case EntityType.EAGLE(eagle):
tank1.rect.lean(eagle.rect);
case EntityType.CELL(cell):
tank1.rect.lean(cell.rect);
case EntityType.BONUS(bonus):
engine.destroy(bonus);
}
case EntityType.BULLET(bullet1):
switch (with) {
case EntityType.TANK(tank2):
if (checkTankBullet(tank2, bullet1)) {
engine.destroy(bullet1);
hitTank(tank2);
}
case EntityType.BULLET(bullet2):
engine.destroy(bullet1);
engine.destroy(bullet2);
case EntityType.EAGLE(eagle):
engine.destroy(bullet1);
engine.destroy(eagle);
case EntityType.CELL(cell):
engine.destroy(bullet1);
case EntityType.BONUS(bonus):
case [EntityType.BULLET(bullet), EntityType.BULLET(other_bullet)]:
engine.destroy(bullet);
engine.destroy(other_bullet);
case [EntityType.BULLET(bullet), EntityType.CELL(cell)]:
engine.destroy(bullet);
case [EntityType.BULLET(bullet), EntityType.EAGLE(eagle)]:
engine.destroy(bullet);
if (!eagle.protect.active) {
eagle.death = true;
engine.change(eagle, EntityChange.DEATH);
}
case _:
}
@@ -85,7 +78,7 @@ class CollisionProcessor implements EngineListener {
public function onDestroy(entity:EntityType):Void { }
}
@:yield
class Engine implements ControlHandler {
public var config(default, default):Config;
@@ -114,6 +107,11 @@ class Engine implements ControlHandler {
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 {
if (entities.exists(entity.id)) {
var type = EntityTypeResolver.of(entity);
@@ -148,8 +146,6 @@ class Engine implements ControlHandler {
}
}
public function update():Void {
var newTime:Float = Date.now().getTime();
var d:Float = newTime - time;
@@ -169,6 +165,15 @@ class Engine implements ControlHandler {
}*/
if (entity.mx != 0 || entity.my != 0) {
var asTank:Tank = EntityTypeResolver.as(entity, Tank);
var asBullet:Bullet = EntityTypeResolver.as(entity, Bullet);
if (asTank != null) {
if (asTank.freezing.active) {
continue;
}
}
var side:Line = entity.rect.getSide(entity.rect.direction.reverse());
var step:Point = new Point(entity.rect.direction.x * map.cellWidth / 4, entity.rect.direction.y * map.cellHeight / 4);
var end:Point = side.center.add(new Point(entity.mx * (d / 30), entity.my * (d / 30)));
@@ -202,15 +207,14 @@ class Engine implements ControlHandler {
}
}
if (Std.is(entity, Bullet)) {
var bullet:Bullet = cast ent;
if (asBullet != null) {
if (collision) {
cells = map.grid.getCells(side.setLength(map.grid.cellWidth * 3));
for (cell in cells) {
if (cell.armor > 0) {
if (cell.armor == bullet.config.piercing) {
if (cell.armor == asBullet.config.piercing) {
cell.destroyed = true;
} else if (cell.armor < bullet.config.piercing) {
} else if (cell.armor < asBullet.config.piercing) {
var brick = map.getBrick(cell);
brick.destroyed = true;
}
@@ -234,4 +238,13 @@ class Engine implements ControlHandler {
listeners = [];
entities = new Map();
}
public function iterTanks(filter:Tank->Bool):Iterator<Tank> {
for (entity in entities) {
var tank:Tank = EntityTypeResolver.as(entity, Tank);
if (tank != null && filter(tank)) {
@yield return tank;
}
}
}
}

View File

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

View File

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

View File

@@ -1,18 +1,20 @@
package ru.m.tankz.game;
import ru.m.tankz.core.Bonus;
import ru.m.tankz.game.GameSave.PlayerSave;
import haxe.ds.Option;
import haxe.Timer;
import haxework.provider.Provider;
import promhx.Deferred;
import promhx.Stream;
import ru.m.geom.Direction;
import ru.m.geom.Point;
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.ConfigBundle;
import ru.m.tankz.config.LevelBundle;
import ru.m.tankz.control.Control;
import ru.m.tankz.control.HumanControl;
import ru.m.tankz.core.Bonus;
import ru.m.tankz.core.Eagle;
import ru.m.tankz.core.Entity;
import ru.m.tankz.core.EntityType;
@@ -29,34 +31,42 @@ class Game implements EngineListener {
public var type(default, null):GameType;
public var state(default, null):GameState;
public var preset(default, null):GamePreset;
public var teams(default, null):Map<TeamId, Team>;
public var config(default, null):Config;
public var engine(default, null):Engine;
private var points:Array<SpawnPoint>;
private var spawners:Map<TeamId, Spawner>;
private var deferred:Deferred<GameState>;
private var stream:Stream<GameState>;
public function new(type:GameType) {
this.type = type;
this.config = ConfigBundle.get(type);
this.config = Provider.get(IConfigBundle).get(type);
this.engine = new Engine(config);
engine.listeners.push(this);
}
public function getTeam(teamId:TeamId):Team {
return teams[teamId];
}
public function getPlayer(playerId:PlayerId):Player {
return teams[playerId.team].players[playerId.index];
}
private function buildTank(playerId:PlayerId, point:SpawnPoint):Tank {
var spawns:Array<TankSpawn> = teams[playerId.team].config.tanks;
var player = getPlayer(playerId);
var spawns:Array<TankSpawn> = player.config.tanks;
var spawn:TankSpawn = spawns[Math.floor(Math.random() * spawns.length)];
var tankConfig:TankConfig = config.getTank(spawn.type);
var tank = new Tank(playerId, tankConfig);
tank.color = playerId.color.zero ? teams[playerId.team].config.color : playerId.color;
tank.color = player.config.color.zero ? teams[playerId.team].config.color : player.config.color;
tank.bonus = Math.random() < spawn.bonus;
applyPoint(tank, point);
if (spawn.protect > 0) {
tank.protect.on(spawn.protect);
}
return tank;
}
@@ -65,27 +75,36 @@ class Game implements EngineListener {
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.state = state;
var level = LevelBundle.get(type, config, state.level);
var level:LevelConfig = Provider.get(ILevelBundle).get(type, config, state.level);
points = level.points != null ? level.points : config.points;
engine.map.setData(level.data);
teams = new Map<TeamId, Team>();
spawners = new Map<TeamId, Spawner>();
var humanControlIndex = 0;
for (teamConfig in config.teams) {
var team = new Team(teamConfig);
for (playerState in state.teams[team.id].players) {
var player = new Player(playerState.id);
team.players[player.id.index] = player;
for (teamConfig in preset.teams) {
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == teamConfig.id);
var team:Team = new Team(teamConfig, teamPoints);
teams[team.id] = team;
if (player.id.type != null) {
var control = switch (player.id.type) {
for (player in team.players.iterator()) {
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.BOT: new BotControl(player.id);
case Control.NONE: null;
case _: throw 'Unsupported control type: "${player.id.type}"';
case _: throw 'Unsupported control type: "${player.config.control}"';
}
L.d(TAG, 'control(${player.id} - ${control})');
if (control != null) {
@@ -94,19 +113,19 @@ class Game implements EngineListener {
}
}
}
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == team.id);
spawners[team.id] = new Spawner(team.config, teamPoints, spawn);
team.spawner.runner = spawn;
}
for (team in teams) {
for (player in team.players) {
if (trySpawn(player.id)) {
spawners[team.id].push(player.id);
for (team in teams.iterator()) {
for (player in team.players.iterator()) {
if (team.trySpawn(player.id)) {
team.spawner.push(player.id);
}
}
var eaglePoint = spawners[team.id].getPoint('eagle');
var eaglePoint = team.spawner.getPoint('eagle');
if (eaglePoint != null) {
var eagle = new Eagle(team.id);
team.eagleId = eagle.id;
applyPoint(eagle, eaglePoint);
engine.spawn(eagle);
}
@@ -117,15 +136,15 @@ class Game implements EngineListener {
private function spawn(task:SpawnTask):Void {
L.d(TAG, 'spawn(${task}');
getPlayer(task.playerId).tankId = 0;
if (trySpawn(task.playerId, true)) {
var team = getTeam(task.playerId.team);
var player = getPlayer(task.playerId);
player.tankId = 0;
if (getTeam(task.playerId.team).trySpawn(task.playerId, true)) {
var tank = buildTank(task.playerId, task.point);
var player:Player = getPlayer(task.playerId);
player.tankId = tank.id;
Timer.delay(function() engine.spawn(tank), 1500);
} else if (!isTeamAlive(task.playerId.team)) {
state.teams[task.playerId.team].lose = true;
complete();
engine.spawn(tank);
} else if (!team.isAlive) {
lose(team.id);
}
deferred.resolve(state);
}
@@ -147,130 +166,148 @@ class Game implements EngineListener {
switch (entity) {
case EntityType.TANK(tank):
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 {
switch (entity) {
switch entity {
case EntityType.TANK(tank):
var control = getPlayer(tank.playerId).control;
if (control != null) control.onCollision(with);
switch (with) {
case EntityType.BONUS(bonus):
case _:
}
switch [entity, with] {
case [EntityType.TANK(tank), EntityType.BONUS(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 {
switch (entity) {
case EntityType.TANK(tank):
getPlayer(tank.playerId).control.stop();
getPlayer(tank.playerId).tankId = 0; //ToDo: ?
var respawn:Bool = trySpawn(tank.playerId);
var team = getTeam(tank.playerId.team);
var player = getPlayer(tank.playerId);
player.control.stop();
player.tankId = 0; //ToDo: ?
var respawn:Bool = team.trySpawn(player.id);
if (respawn) {
spawners[tank.playerId.team].push(tank.playerId);
team.spawner.push(player.id);
}
if (!isTeamAlive(tank.playerId.team)) {
state.teams[tank.playerId.team].lose = true;
complete();
if (!team.isAlive) {
lose(team.id);
}
if (tank.bonus) {
spawnBonus();
}
if (tank.bonus) spawnBonus();
deferred.resolve(state);
case EntityType.EAGLE(eagle):
state.teams[eagle.team].lose = true;
complete();
deferred.resolve(state);
case x:
case _:
}
}
private function lose(teamId:TeamId):Void {
state.loser = teamId;
complete();
}
public function onAction(tankId:Int, action:TankAction):Void {
engine.action(tankId, action);
}
public function next():Option<GameState> {
return Option.None;
var level = state.level + 1;
state.level++;
if (level >= config.game.levels) level = 0;
return Option.Some({type: state.type, presetId: preset.id, level: level});
}
public function dispose():Void {
engine.dispose();
}
private function spawnBonus():Void {
var bonusConfig = config.bonuses[Math.floor(Math.random() * config.bonuses.length)];
L.d(TAG, 'Spawn Bonus(${bonusConfig}');
var bonus = new Bonus(bonusConfig.type);
private function spawnBonus(?type:BonusType):Void {
var bonusConfig:BonusConfig = type != null ? config.getBonus(type) : config.bonuses[Math.floor(Math.random() * config.bonuses.length)];
var bonus = new Bonus(bonusConfig);
bonus.rect.x = Math.random() * engine.map.width;
bonus.rect.y = Math.random() * engine.map.height;
engine.spawn(bonus);
}
inline private function alienTank(team:TeamId):Tank->Bool {
return function(tank:Tank):Bool return team != tank.playerId.team;
}
private function applyBonus(tank:Tank, bonus:Bonus):Void {
switch (bonus.bonusType) {
switch (bonus.config.type) {
case 'life':
state.teams[tank.playerId.team].players[tank.playerId.index].life++;
getPlayer(tank.playerId).life++;
case 'star':
if (tank.config.upgrade != null) {
tank.config = config.getTank(tank.config.upgrade);
} else {
tank.hits++;
}
engine.change(tank);
case 'grenade':
for (entity in engine.entities.iterator()) {
switch (EntityTypeResolver.of(entity)) {
case EntityType.TANK(t):
if (t.playerId.team != tank.playerId.team) {
for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
engine.destroy(t);
}
case x:
}
}
case 'helmet':
tank.protect.on(bonus.config.duration);
engine.change(tank);
case 'clock':
for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
t.freezing.on(bonus.config.duration);
engine.change(t);
}
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
}
}
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);
}
}

View 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);
}
}

View File

@@ -3,26 +3,9 @@ package ru.m.tankz.game;
import ru.m.tankz.Type;
typedef PlayerState = {
var id:PlayerId;
var life:Int;
}
typedef TeamState = {
var players:Map<Int, PlayerState>;
var life:Int;
var lose:Bool;
}
class GameState {
public var type:GameType;
public var mode:GameMode;
public var level:Int;
public var teams:Map<TeamId, TeamState>;
public function new() {
type = null;
level = -1;
teams = new Map();
}
typedef GameState = {
var type:GameType;
var presetId:PresetId;
@:optional var level:Int;
@:optional var loser:TeamId;
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,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.Type;
import yaml.Parser;
import yaml.Renderer;
import yaml.Yaml;
@@ -13,9 +11,9 @@ typedef LevelSource = {
@: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);
while (result.length < 3) result = '0${result}';
return result;
@@ -26,7 +24,7 @@ class LevelBundle {
for (line in ~/\s+/g.split(data)) {
for (c in line.split('')) {
if (c.length > 0) {
bricks.push(config.getBrick(Std.parseInt(c)));
bricks.push(config.getBrickByIndex(Std.parseInt(c)));
}
}
}
@@ -41,14 +39,14 @@ class LevelBundle {
} else {
var obj:LevelSource = Yaml.parse(data, Parser.options().useObjects());
return {
data: obj.data.split('').map(function(c) return config.getBrick(Std.parseInt(c))),
data: obj.data.split('').map(function(c) return config.getBrickByIndex(Std.parseInt(c))),
points: obj.points,
}
}
}
public static function dumps(config:Config, level:LevelConfig):String {
var bricksStr = level.data.map(function(brick:BrickConfig) return Std.string(brick.type)).join('');
var bricksStr = level.data.map(function(brick:BrickConfig) return Std.string(brick.index)).join('');
return Yaml.render({
data: bricksStr,
points: level.points,
@@ -60,9 +58,4 @@ class LevelBundle {
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);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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