[common] tanks spawn types
This commit is contained in:
@@ -26,17 +26,28 @@ class Animate extends Bitmap {
|
||||
}
|
||||
}
|
||||
|
||||
private static var a = new BitmapData(1, 1);
|
||||
|
||||
public var playing(default, set):Bool;
|
||||
private var frames:Array<BitmapData>;
|
||||
public var frames(default, set):Array<BitmapData>;
|
||||
private var index:Int;
|
||||
|
||||
public function new(frames:Array<BitmapData>) {
|
||||
super(frames[0], PixelSnapping.AUTO, true);
|
||||
this.frames = frames;
|
||||
public function new(?frames:Array<BitmapData>) {
|
||||
super(null, PixelSnapping.AUTO, true);
|
||||
this.frames = frames == null ? [] : frames;
|
||||
init();
|
||||
instances.push(this);
|
||||
}
|
||||
|
||||
public function set_frames(value:Array<BitmapData>):Array<BitmapData> {
|
||||
if (value != null) {
|
||||
frames = value;
|
||||
bitmapData = frames[0];
|
||||
index = 0;
|
||||
}
|
||||
return frames;
|
||||
}
|
||||
|
||||
public function set_playing(value:Bool):Bool {
|
||||
if (playing != value) {
|
||||
playing = value;
|
||||
|
||||
@@ -117,25 +117,34 @@ class BrickItem extends RenderItem<Brick, Shape> {
|
||||
class TankItem extends RenderItem<Tank, Animate> {
|
||||
|
||||
private var type:String;
|
||||
private var hits:Int;
|
||||
|
||||
public function new(value:Tank) {
|
||||
super(value);
|
||||
this.view = new Animate(getFrames().map(function(s) return Assets.getBitmapData(s)));
|
||||
view = new Animate();
|
||||
redraw();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
view.frames = getFrames().map(function(s) return Assets.getBitmapData(s));
|
||||
}
|
||||
|
||||
private function getFrames():Array<String> {
|
||||
var team = value.playerId.team;
|
||||
var group = value.config.group;
|
||||
var index = value.playerId.index;
|
||||
if (group == 'human') group = 'player';
|
||||
if (group == 'radiant') {
|
||||
group = 'player';
|
||||
if (team == 'radiant') {
|
||||
index = 0;
|
||||
}
|
||||
if (group == 'dire') {
|
||||
group = 'player';
|
||||
if (team == 'dire') {
|
||||
index = 1;
|
||||
}
|
||||
if (group == 'bot') index = 0;
|
||||
if (team == 'human' || team == 'radiant' || team == 'dire') {
|
||||
group = 'player';
|
||||
}
|
||||
if (team == 'bot') {
|
||||
index = value.hits;
|
||||
}
|
||||
return [
|
||||
'resources/images/tank/${group}/tank_${group.charAt(0)}${value.config.type}_${index}-0.png',
|
||||
'resources/images/tank/${group}/tank_${group.charAt(0)}${value.config.type}_${index}-1.png',
|
||||
@@ -145,8 +154,10 @@ class TankItem extends RenderItem<Tank, Animate> {
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
var t = value.config.type;
|
||||
if (t != this.type) {
|
||||
var h = value.hits;
|
||||
if (t != this.type || h != this.hits) {
|
||||
this.type = t;
|
||||
this.hits = h;
|
||||
redraw();
|
||||
}
|
||||
view.playing = (value.mx !=0 || value.my != 0);
|
||||
|
||||
@@ -24,7 +24,7 @@ class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrame
|
||||
|
||||
public function onShow():Void {
|
||||
var state = Provider.get(GameState);
|
||||
var c = ConfigBundle.get(state.type).levels;
|
||||
var c = ConfigBundle.get(state.type).game.levels;
|
||||
levels.data = [for (i in 0...c) i];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user