From 556cd2f1a9193bded4c307eca193c46440ff1277 Mon Sep 17 00:00:00 2001 From: shmyga Date: Mon, 25 Mar 2019 17:42:20 +0300 Subject: [PATCH] [common] add deathmatch mode --- .../haxe/ru/m/tankz/view/ClientView.yaml | 5 ++ src/client/haxe/ru/m/tankz/view/StartFrame.hx | 3 + .../haxe/ru/m/tankz/view/StartFrame.yaml | 5 ++ .../haxe/ru/m/tankz/view/common/GameFrame.hx | 14 +-- .../ru/m/tankz/view/common/PlayerView.yaml | 3 +- .../ru/m/tankz/view/death/DeathGameFrame.hx | 21 +++++ .../ru/m/tankz/view/death/DeathGameFrame.yaml | 8 ++ .../ru/m/tankz/view/death/DeathLevelFrame.hx | 37 ++++++++ .../m/tankz/view/death/DeathLevelFrame.yaml | 24 +++++ .../haxe/ru/m/tankz/preset/DeathGame.hx | 7 ++ src/common/resources/death/config.yaml | 89 +++++++++++++++++++ .../resources/death/levels/level000.txt | 2 + .../ru/m/tankz/editor/frame/LevelFrame.hx | 6 +- .../ru/m/tankz/editor/frame/LevelFrame.yaml | 14 +-- 14 files changed, 223 insertions(+), 15 deletions(-) create mode 100755 src/client/haxe/ru/m/tankz/view/death/DeathGameFrame.hx create mode 100644 src/client/haxe/ru/m/tankz/view/death/DeathGameFrame.yaml create mode 100644 src/client/haxe/ru/m/tankz/view/death/DeathLevelFrame.hx create mode 100644 src/client/haxe/ru/m/tankz/view/death/DeathLevelFrame.yaml create mode 100644 src/common/haxe/ru/m/tankz/preset/DeathGame.hx create mode 100644 src/common/resources/death/config.yaml create mode 100644 src/common/resources/death/levels/level000.txt diff --git a/src/client/haxe/ru/m/tankz/view/ClientView.yaml b/src/client/haxe/ru/m/tankz/view/ClientView.yaml index 75f568e..065c3ba 100755 --- a/src/client/haxe/ru/m/tankz/view/ClientView.yaml +++ b/src/client/haxe/ru/m/tankz/view/ClientView.yaml @@ -15,6 +15,11 @@ views: $type: ru.m.tankz.view.dota.DotaLevelFrame - id: dota.game $type: ru.m.tankz.view.dota.DotaGameFrame + # death + - id: death.level + $type: ru.m.tankz.view.death.DeathLevelFrame + - id: death.game + $type: ru.m.tankz.view.death.DeathGameFrame # result - id: result $type: ru.m.tankz.view.ResultFrame diff --git a/src/client/haxe/ru/m/tankz/view/StartFrame.hx b/src/client/haxe/ru/m/tankz/view/StartFrame.hx index 644bece..ce0ea6b 100644 --- a/src/client/haxe/ru/m/tankz/view/StartFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/StartFrame.hx @@ -4,6 +4,7 @@ import haxework.view.ButtonView; import haxework.view.frame.FrameSwitcher; import haxework.view.VGroupView; import ru.m.tankz.view.classic.ClassicLevelFrame; +import ru.m.tankz.view.death.DeathLevelFrame; import ru.m.tankz.view.dota.DotaLevelFrame; import ru.m.tankz.view.popup.FontPopup; @@ -21,6 +22,8 @@ import ru.m.tankz.view.popup.FontPopup; frameSwitcher.change(ClassicLevelFrame.ID); case 'dota': frameSwitcher.change(DotaLevelFrame.ID); + case 'death': + frameSwitcher.change(DeathLevelFrame.ID); case 'network': //frameSwitcher.change(NetworkFrame.ID); case 'settings': diff --git a/src/client/haxe/ru/m/tankz/view/StartFrame.yaml b/src/client/haxe/ru/m/tankz/view/StartFrame.yaml index fe828d0..ddef1e4 100644 --- a/src/client/haxe/ru/m/tankz/view/StartFrame.yaml +++ b/src/client/haxe/ru/m/tankz/view/StartFrame.yaml @@ -17,6 +17,11 @@ views: skinId: button +onPress: $this:onPress text: DotA + - id: death + $type: haxework.view.ButtonView + skinId: button + +onPress: $this:onPress + text: DeathMatch # - id: font # $type: haxework.view.ButtonView # skinId: button diff --git a/src/client/haxe/ru/m/tankz/view/common/GameFrame.hx b/src/client/haxe/ru/m/tankz/view/common/GameFrame.hx index fad8934..31faa17 100644 --- a/src/client/haxe/ru/m/tankz/view/common/GameFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/common/GameFrame.hx @@ -1,16 +1,16 @@ package ru.m.tankz.view.common; -import ru.m.tankz.game.GameState; import flash.events.Event; import haxe.ds.Option; import haxe.Timer; import haxework.view.frame.FrameSwitcher; import haxework.view.GroupView; -import ru.m.tankz.view.common.IGamePanel; import ru.m.tankz.game.Game; +import ru.m.tankz.game.GameState; import ru.m.tankz.network.NetworkManager; import ru.m.tankz.render.Render; import ru.m.tankz.sound.SoundManager; +import ru.m.tankz.view.common.IGamePanel; class GameFrame extends GroupView { @@ -33,7 +33,7 @@ class GameFrame extends GroupView { } private function get_panel():IGamePanel { - throw "Not implemented"; + return null; } public function onShow():Void { @@ -47,7 +47,9 @@ class GameFrame extends GroupView { game.start(state).then(onGameStateChange).endThen(onGameComplete); timer = new Timer(10); timer.run = updateEngine; - panel.game = game; + if (panel != null) { + panel.game = game; + } content.addEventListener(Event.ENTER_FRAME, _redraw); render.draw(game.engine); sound.play('start'); @@ -67,7 +69,9 @@ class GameFrame extends GroupView { } private function onGameStateChange(_):Void { - panel.toUpdate(); + if (panel != null) { + panel.toUpdate(); + } } private function onGameComplete(_):Void { diff --git a/src/client/haxe/ru/m/tankz/view/common/PlayerView.yaml b/src/client/haxe/ru/m/tankz/view/common/PlayerView.yaml index cd01d7b..e4bb79c 100644 --- a/src/client/haxe/ru/m/tankz/view/common/PlayerView.yaml +++ b/src/client/haxe/ru/m/tankz/view/common/PlayerView.yaml @@ -10,6 +10,7 @@ views: $type: haxework.view.DataView factory: $this:teamViewFactory layout: - $type: haxework.view.layout.HorizontalLayout + $type: haxework.view.layout.TailLayout + rowSize: 5 margin: 3 +onDataSelect: $this:onTeamSelect diff --git a/src/client/haxe/ru/m/tankz/view/death/DeathGameFrame.hx b/src/client/haxe/ru/m/tankz/view/death/DeathGameFrame.hx new file mode 100755 index 0000000..290341e --- /dev/null +++ b/src/client/haxe/ru/m/tankz/view/death/DeathGameFrame.hx @@ -0,0 +1,21 @@ +package ru.m.tankz.view.death; + +import ru.m.tankz.render.Render; +import ru.m.tankz.view.common.GameFrame; +import ru.m.tankz.view.common.IGamePanel; + +@:template class DeathGameFrame extends GameFrame { + + public static inline var ID = "death.game"; + + @:view("render") private var renderView(default, null):Render; + //@:view("panel") private var panelView(default, null):IGamePanel; + + override private function get_render():Render { + return renderView; + } + + /*override private function get_panel():IGamePanel { + return panelView; + }*/ +} diff --git a/src/client/haxe/ru/m/tankz/view/death/DeathGameFrame.yaml b/src/client/haxe/ru/m/tankz/view/death/DeathGameFrame.yaml new file mode 100644 index 0000000..1e4149b --- /dev/null +++ b/src/client/haxe/ru/m/tankz/view/death/DeathGameFrame.yaml @@ -0,0 +1,8 @@ +--- +skinId: container +views: + - $type: haxework.view.VGroupView + layout.margin: 5 + views: + - id: render + $type: ru.m.tankz.render.Render diff --git a/src/client/haxe/ru/m/tankz/view/death/DeathLevelFrame.hx b/src/client/haxe/ru/m/tankz/view/death/DeathLevelFrame.hx new file mode 100644 index 0000000..5c949c3 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/view/death/DeathLevelFrame.hx @@ -0,0 +1,37 @@ +package ru.m.tankz.view.death; + +import haxework.view.ButtonView; +import haxework.view.DataView; +import haxework.view.frame.FrameSwitcher; +import ru.m.tankz.game.GameState; +import ru.m.tankz.preset.DeathGame; +import ru.m.tankz.view.common.LevelFrame; +import ru.m.tankz.view.common.PlayerView; + +@:template class DeathLevelFrame extends LevelFrame { + public static inline var ID = "death.level"; + + @:view var levels(default, null):DataView; + @:view var players(default, null):DataView, PlayerView>; + + @:provide var frames:FrameSwitcher; + + private function onShow():Void { + gameType = DeathGame.TYPE; + levels.data = [for (i in 0...config.game.levels) i]; + players.data = [for (i in 0...2) state.players]; + } + + private function playerViewFactory(index:Int, data:Array):PlayerView { + var view = new PlayerView(); + view.item_index = index; + view.data = data; + return view; + } + + override private function set_level(value:Int):Int { + var result = super.set_level(value); + frames.change(DeathGameFrame.ID); + return result; + } +} diff --git a/src/client/haxe/ru/m/tankz/view/death/DeathLevelFrame.yaml b/src/client/haxe/ru/m/tankz/view/death/DeathLevelFrame.yaml new file mode 100644 index 0000000..1b9887d --- /dev/null +++ b/src/client/haxe/ru/m/tankz/view/death/DeathLevelFrame.yaml @@ -0,0 +1,24 @@ +--- +skinId: container +layout: + $type: haxework.view.layout.VerticalLayout +views: + - $type: haxework.view.LabelView + skinId: text.header + text: DeathMatch + - id: players + $type: haxework.view.DataView + layout: + $type: haxework.view.layout.VerticalLayout + hAlign: right + factory: $this:playerViewFactory + geometry.padding: 10 + - id: levels + $type: haxework.view.DataView + layout: + $type: haxework.view.layout.TailLayout + rowSize: 5 + margin: 5 + factory: $this:levelViewFactory + +onDataSelect: $code:function(value) level = value + geometry.padding: 10 diff --git a/src/common/haxe/ru/m/tankz/preset/DeathGame.hx b/src/common/haxe/ru/m/tankz/preset/DeathGame.hx new file mode 100644 index 0000000..2332802 --- /dev/null +++ b/src/common/haxe/ru/m/tankz/preset/DeathGame.hx @@ -0,0 +1,7 @@ +package ru.m.tankz.preset; + +import ru.m.tankz.Type; + +class DeathGame { + public static var TYPE(default, never):GameType = 'death'; +} diff --git a/src/common/resources/death/config.yaml b/src/common/resources/death/config.yaml new file mode 100644 index 0000000..930ce92 --- /dev/null +++ b/src/common/resources/death/config.yaml @@ -0,0 +1,89 @@ +game: + levels: 1 + friendlyFire: true + complete: [] + +map: + cellWidth: 22 + cellHeight: 22 + gridWidth: 20 + gridHeight: 20 + +bricks: + - {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} + +player: + default: &player + protect: 3 + tanks: + - {type: default, rate: 1} + +team: + base: &team + life: 10 + players: + - {<<: *player, index: 0} + +presets: + - id: default + teams: + - id: alpha + color: 0xFF4422 + <<: *team + - id: beta + color: 0xFFD000 + <<: *team + - id: gamma + color: 0x3EFE00 + <<: *team + - id: delta + color: 0x00FFF8 + <<: *team + - id: epsilon + color: 0x00B37F + <<: *team + - id: zeta + color: 0xFC00FF + <<: *team + - id: eta + color: 0x8F00FD + <<: *team + - id: theta + color: 0xB66F00 + <<: *team + +points: + - {team: alpha, type: tank, index: 0, direction: right, x: 0, y: 0} + - {team: beta, type: tank, index: 0, direction: right, x: 2, y: 0} + - {team: gamma, type: tank, index: 0, direction: right, x: 4, y: 0} + - {team: delta, type: tank, index: 0, direction: right, x: 6, y: 0} + - {team: epsilon, type: tank, index: 0, direction: right, x: 0, y: 2} + - {team: zeta, type: tank, index: 0, direction: right, x: 2, y: 2} + - {team: eta, type: tank, index: 0, direction: right, x: 4, y: 2} + - {team: theta, type: tank, index: 0, direction: right, x: 6, y: 2} + +bullet: &bullet + width: 12 + height: 12 + speed: 0 + piercing: 1 + +tanks: + - type: default + width: 38 + height: 36 + speed: 2.3 + bullet: + <<: *bullet + speed: 12.0 + bullets: 2 + score: 100 + skin: pc + +bonuses: [] diff --git a/src/common/resources/death/levels/level000.txt b/src/common/resources/death/levels/level000.txt new file mode 100644 index 0000000..6af02f4 --- /dev/null +++ b/src/common/resources/death/levels/level000.txt @@ -0,0 +1,2 @@ +points: [{y: 0, team: alpha, x: 0, direction: right, type: tank, index: 0}, {y: 0, team: beta, x: 6, direction: right, type: tank, index: 0}, {y: 0, team: gamma, x: 12, direction: right, type: tank, index: 0}, {y: 0, team: delta, x: 18, direction: right, type: tank, index: 0}, {y: 18, team: epsilon, x: 0, direction: right, type: tank, index: 0}, {y: 18, team: zeta, x: 6, direction: right, type: tank, index: 0}, {y: 18, team: eta, x: 12, direction: right, type: tank, index: 0}, {y: 18, team: theta, x: 18, direction: right, type: tank, index: 0}] +data: "0004400004400004400000044000044000044000555555555555555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000555555555555555555550004400004400004400000044000044000044000" diff --git a/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx index 7410e91..aa6b9dc 100644 --- a/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx +++ b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.hx @@ -29,7 +29,8 @@ import ru.m.tankz.util.LevelUtil; @:view var spawnPointList:DataView; @:view var brickList:DataView; - private var config:Config; + @:provide var configBundle:IConfigBundle; + @:provide var config:Config; public function init():Void { var resetSelected = function() { @@ -59,8 +60,7 @@ import ru.m.tankz.util.LevelUtil; } private function setGameType(type:GameType):Void { - config = Provider.get(IConfigBundle).get(type); - Provider.set(Config, config); + config = configBundle.get(type); mapView.config = config; mapView.data = LevelUtil.empty(config); diff --git a/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml index e12fbaa..b851559 100644 --- a/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml +++ b/src/editor/haxe/ru/m/tankz/editor/frame/LevelFrame.yaml @@ -7,16 +7,18 @@ layout.hAlign: center views: - $type: haxework.view.HGroupView views: - - id: gameClassicButton - $type: haxework.view.ButtonView + - $type: haxework.view.ButtonView skinId: button.simple text: Classic - +onPress: $this:onPress - - id: gameDotaButton - $type: haxework.view.ButtonView + +onPress: $code:setGameType('classic') + - $type: haxework.view.ButtonView skinId: button.simple text: DotA - +onPress: $this:onPress + +onPress: $code:setGameType('dota') + - $type: haxework.view.ButtonView + skinId: button.simple + text: DeathMatch + +onPress: $code:setGameType('death') - id: fileNameLabel $type: haxework.view.LabelView # map