[common] humans in DotaGame
This commit is contained in:
@@ -7,21 +7,45 @@
|
||||
"contentSize": true, "bottomMargin": 15
|
||||
},
|
||||
{
|
||||
"id": "start_1p",
|
||||
"@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": "start_2p",
|
||||
"id": "classic_2p",
|
||||
"@type": "haxework.gui.ButtonView",
|
||||
"text": "2 Player",
|
||||
"@style": "button"
|
||||
},
|
||||
{
|
||||
"id": "dota",
|
||||
"@type": "haxework.gui.LabelView", "@style": "label",
|
||||
"fontSize": 20, "topMargin": 15,
|
||||
"contentSize": true,
|
||||
"text": "DotA"
|
||||
},
|
||||
{
|
||||
"id": "dota_1p",
|
||||
"@type": "haxework.gui.ButtonView",
|
||||
"text": "DotA",
|
||||
"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"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -13,14 +13,13 @@ typedef KeyBinding = Map<Int, TankAction>;
|
||||
|
||||
|
||||
class HumanControl extends Control {
|
||||
public static var TYPE(default, never):ControlType = 'human';
|
||||
|
||||
private var keyBinding:KeyBinding;
|
||||
private var moveQueue:Array<Int>;
|
||||
private var shotTimer:Timer;
|
||||
|
||||
public function new(index:Int) {
|
||||
super({type:TYPE, index:index});
|
||||
super({type:Control.HUMAN, index:index});
|
||||
this.keyBinding = resolve(index);
|
||||
moveQueue = new Array<Int>();
|
||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
|
||||
@@ -5,12 +5,8 @@ import openfl.Assets;
|
||||
import ru.m.animate.OnceAnimate;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import ru.m.tankz.core.EntityType;
|
||||
import flash.display.DisplayObject;
|
||||
import Type.ValueType;
|
||||
import ru.m.tankz.render.RenderItem;
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import ru.m.tankz.core.Tank;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.Graphics;
|
||||
import haxework.gui.SpriteView;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import ru.m.tankz.control.Control;
|
||||
import flash.display.Sprite;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.tankz.core.Eagle;
|
||||
import flash.display.DisplayObject;
|
||||
@@ -114,19 +116,38 @@ class BrickItem extends RenderItem<Brick, Shape> {
|
||||
}
|
||||
|
||||
|
||||
class TankItem extends RenderItem<Tank, Animate> {
|
||||
class TankItem extends RenderItem<Tank, Sprite> {
|
||||
|
||||
private var type:String;
|
||||
private var hits:Int;
|
||||
|
||||
private var tankView:Animate;
|
||||
|
||||
public function new(value:Tank) {
|
||||
super(value);
|
||||
view = new Animate();
|
||||
view = new Sprite();
|
||||
if (value.playerId.type == Control.HUMAN) {
|
||||
view.addChild(buildHumanMarkView(value));
|
||||
}
|
||||
tankView = new Animate();
|
||||
view.addChild(tankView);
|
||||
redraw();
|
||||
}
|
||||
|
||||
private static function buildHumanMarkView(tank:Tank):DisplayObject {
|
||||
var view = new Shape();
|
||||
view.graphics.beginFill(0x00aa00);
|
||||
view.graphics.lineStyle(2, 0x00ff00);
|
||||
view.graphics.drawCircle(0, 0, 23);
|
||||
view.graphics.endFill();
|
||||
view.x = tank.rect.width / 2;
|
||||
view.y = tank.rect.height / 2;
|
||||
view.alpha = 0.2;
|
||||
return view;
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
view.frames = getFrames().map(function(s) return Assets.getBitmapData(s));
|
||||
tankView.frames = getFrames().map(function(s) return Assets.getBitmapData(s));
|
||||
}
|
||||
|
||||
private function getFrames():Array<String> {
|
||||
@@ -160,13 +181,13 @@ class TankItem extends RenderItem<Tank, Animate> {
|
||||
this.hits = h;
|
||||
redraw();
|
||||
}
|
||||
view.playing = (value.mx !=0 || value.my != 0);
|
||||
tankView.playing = (value.mx !=0 || value.my != 0);
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
if (view != null) {
|
||||
view.dispose();
|
||||
view = null;
|
||||
if (tankView != null) {
|
||||
tankView.dispose();
|
||||
tankView = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,11 @@ import haxework.gui.VGroupView;
|
||||
|
||||
|
||||
interface StartFrameLayout {
|
||||
var start_1p(default, null):ButtonView;
|
||||
var start_2p(default, null):ButtonView;
|
||||
var dota(default, null):ButtonView;
|
||||
var classic_1p(default, null):ButtonView;
|
||||
var classic_2p(default, null):ButtonView;
|
||||
var dota_1p(default, null):ButtonView;
|
||||
var dota_2p_coop(default, null):ButtonView;
|
||||
var dota_2p_vs(default, null):ButtonView;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,29 +26,35 @@ class StartFrame extends VGroupView implements ViewBuilder implements StartFrame
|
||||
public static inline var ID = "start";
|
||||
|
||||
public function init() {
|
||||
start_1p.onPress = this;
|
||||
start_2p.onPress = this;
|
||||
dota.onPress = this;
|
||||
classic_1p.onPress = this;
|
||||
classic_2p.onPress = this;
|
||||
dota_1p.onPress = this;
|
||||
dota_2p_coop.onPress = this;
|
||||
dota_2p_vs.onPress = this;
|
||||
}
|
||||
|
||||
public function onPress(view:ButtonView):Void {
|
||||
switch (view.id) {
|
||||
case 'start_1p':
|
||||
startGame(ClassicGame.TYPE, 1);
|
||||
case 'start_2p':
|
||||
startGame(ClassicGame.TYPE, 2);
|
||||
case 'dota':
|
||||
startGame(DotaGame.TYPE, 2);
|
||||
case 'classic_1p':
|
||||
startGame(ClassicGame.TYPE, ClassicGame.PLAYER1);
|
||||
case 'classic_2p':
|
||||
startGame(ClassicGame.TYPE, ClassicGame.PLAYER2);
|
||||
case 'dota_1p':
|
||||
startGame(DotaGame.TYPE, DotaGame.PLAYER1);
|
||||
case 'dota_2p_coop':
|
||||
startGame(DotaGame.TYPE, DotaGame.PLAYER2_COOP);
|
||||
case 'dota_2p_vs':
|
||||
startGame(DotaGame.TYPE, DotaGame.PLAYER2_VS);
|
||||
}
|
||||
}
|
||||
|
||||
private function startGame(type:GameType, humans:Int):Void {
|
||||
private function startGame(type:GameType, mode:GameMode):Void {
|
||||
switch (type) {
|
||||
case ClassicGame.TYPE:
|
||||
Provider.set(GameState, ClassicGame.buildState(0, humans));
|
||||
Provider.set(GameState, ClassicGame.buildState(0, mode));
|
||||
Provider.get(IFrameSwitcher).change(LevelFrame.ID);
|
||||
case DotaGame.TYPE:
|
||||
Provider.set(GameState, DotaGame.buildState(0, humans));
|
||||
Provider.set(GameState, DotaGame.buildState(0, mode));
|
||||
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user