[common] added Bonus entity
This commit is contained in:
@@ -43,7 +43,7 @@ class HumanControl extends Control {
|
||||
case _:
|
||||
}
|
||||
if (event.keyCode == Keyboard.U) {
|
||||
action(TankAction.LEVEL_UP(1));
|
||||
action(TankAction.UPGRADE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,11 @@ class Render extends SpriteView implements EngineListener {
|
||||
items.set(eagle.key, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
case EntityType.BONUS(bonus):
|
||||
var item = new BonusItem(bonus);
|
||||
items.set(bonus.key, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
case _:
|
||||
}
|
||||
}
|
||||
@@ -136,6 +141,11 @@ class Render extends SpriteView implements EngineListener {
|
||||
items.get(eagle.key).redraw();
|
||||
playTankBoom(eagle.rect.center);
|
||||
}
|
||||
case EntityType.BONUS(bonus):
|
||||
if (items.exists(bonus.key)) {
|
||||
entryLayer.removeChild(items.get(bonus.key).view);
|
||||
items.remove(bonus.key);
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
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;
|
||||
@@ -9,7 +12,6 @@ import ru.m.animate.Animate;
|
||||
import ru.m.draw.BitmapUtil;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import ru.m.tankz.core.Eagle;
|
||||
import ru.m.tankz.core.Tank;
|
||||
@@ -121,6 +123,19 @@ class BrickItem extends RenderItem<Brick, Shape> {
|
||||
}
|
||||
|
||||
|
||||
class AnimateItem<T:TRectangle> extends RenderItem<T, Animate> {
|
||||
|
||||
public function new(value:T) {
|
||||
super(value);
|
||||
view = new Animate();
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
view.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TankItem extends RenderItem<Tank, Sprite> {
|
||||
|
||||
private var type:String;
|
||||
@@ -131,28 +146,14 @@ class TankItem extends RenderItem<Tank, Sprite> {
|
||||
public function new(value:Tank) {
|
||||
super(value);
|
||||
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 {
|
||||
tankView.frames = getFrames().map(function(src) return BitmapUtil.colorize(Assets.getBitmapData(src), value.color));
|
||||
var colors:Array<Color> = [value.color, value.bonus ? 0xff00aa : value.color];
|
||||
tankView.frames = getFrames().map(function(src) return BitmapUtil.colorize(Assets.getBitmapData(src), colors.shift()));
|
||||
}
|
||||
|
||||
private function getFrames():Array<String> {
|
||||
@@ -199,3 +200,21 @@ class EagleItem extends BitmapItem<Eagle> {
|
||||
return 'resources/images/eagle/eagle-${destoyed ? 1 : 0}.png';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class BonusItem extends AnimateItem<Bonus> {
|
||||
|
||||
public function new(value:Bonus) {
|
||||
super(value);
|
||||
redraw();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
// ToDo: 15/15 frames
|
||||
view.frames = [
|
||||
Assets.getBitmapData('resources/image/bonus/${value.bonusType}.png'),
|
||||
new BitmapData(1, 1),
|
||||
];
|
||||
view.playing = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user