[common] added Bonus entity

This commit is contained in:
2018-02-09 16:57:33 +03:00
parent 5c57454998
commit 41c5610f9a
22 changed files with 182 additions and 40 deletions

View File

@@ -43,7 +43,7 @@ class HumanControl extends Control {
case _:
}
if (event.keyCode == Keyboard.U) {
action(TankAction.LEVEL_UP(1));
action(TankAction.UPGRADE);
}
}

View File

@@ -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 _:
}
}

View File

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

View File

@@ -24,10 +24,10 @@ teams:
- id: bot
spawnInterval: 3000
tanks:
- {type: bot0, rate: 0.5}
- {type: bot1, rate: 0.5}
- {type: bot2, rate: 0.5}
- {type: bot3, rate: 0.5}
- {type: bot0, rate: 0.25, bonus: 1}
- {type: bot1, rate: 0.25, bonus: 1}
- {type: bot2, rate: 0.25, bonus: 1}
- {type: bot3, rate: 0.25, bonus: 1}
points:
- {team: human, type: eagle, index: -1, direction: right, x: 12, y: 24}
@@ -45,6 +45,7 @@ bullet: &bullet
tanks:
- type: human0
upgrade: human1
width: 36
height: 36
speed: 2.5
@@ -55,6 +56,7 @@ tanks:
skin: pa
- type: human1
upgrade: human2
width: 40
height: 36
speed: 3.0
@@ -65,6 +67,7 @@ tanks:
skin: pb
- type: human2
upgrade: human3
width: 40
height: 36
speed: 3.0
@@ -75,6 +78,7 @@ tanks:
skin: pc
- type: human3
upgrade: human3
width: 42
height: 38
speed: 2.9
@@ -130,3 +134,11 @@ tanks:
score: 400
hits: 3
skin: bd
bonuses:
- {type: clock}
- {type: grenade}
- {type: helmet}
- {type: life}
- {type: shovel}
- {type: star}

View File

@@ -70,3 +70,11 @@ tanks:
speed: 7.0
bullets: 1
skin: bb
bonuses:
- {type: clock}
- {type: grenade}
- {type: helmet}
- {type: life}
- {type: shovel}
- {type: star}

View File

Before

Width:  |  Height:  |  Size: 450 B

After

Width:  |  Height:  |  Size: 450 B

View File

Before

Width:  |  Height:  |  Size: 566 B

After

Width:  |  Height:  |  Size: 566 B

View File

Before

Width:  |  Height:  |  Size: 354 B

After

Width:  |  Height:  |  Size: 354 B

View File

Before

Width:  |  Height:  |  Size: 541 B

After

Width:  |  Height:  |  Size: 541 B

View File

Before

Width:  |  Height:  |  Size: 455 B

After

Width:  |  Height:  |  Size: 455 B

View File

Before

Width:  |  Height:  |  Size: 532 B

After

Width:  |  Height:  |  Size: 532 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 590 B