[common] player tank levels

This commit is contained in:
2018-01-08 22:28:35 +03:00
parent 3061a4088c
commit d3294a04f5
8 changed files with 125 additions and 30 deletions

View File

@@ -1,5 +1,6 @@
package ru.m.tankz.core;
import haxe.Timer;
import ru.m.geom.Direction;
import flash.events.FocusEvent;
import flash.ui.Keyboard;
@@ -15,6 +16,7 @@ class PlayerControl {
private var keyBinding:Map<Int, TankAction>;
private var moveQueue:Array<Int>;
private var shotTimer:Timer;
public function new(id:Int, engine:IEngine, keyBinding:Map<Int, TankAction>) {
this.id = id;
@@ -34,9 +36,16 @@ class PlayerControl {
updateMove();
}
case TankAction.SHOT:
engine.action(id, TankAction.SHOT);
if (shotTimer == null) {
shotTimer = new Timer(300);
shotTimer.run = shot;
shot();
}
case _:
}
if (event.keyCode == Keyboard.U) {
engine.action(id, TankAction.LEVEL_UP(1));
}
}
private function onKeyUp(event:KeyboardEvent):Void {
@@ -44,6 +53,11 @@ class PlayerControl {
case TankAction.MOVE(direction):
moveQueue.remove(event.keyCode);
updateMove();
case TankAction.SHOT:
if (shotTimer != null) {
shotTimer.stop();
shotTimer = null;
}
case _:
}
}
@@ -65,6 +79,10 @@ class PlayerControl {
}
}
private function shot():Void {
engine.action(id, TankAction.SHOT);
}
public static function forPlayer(index:Int, tankId:Int, engine:IEngine):PlayerControl {
switch (index) {
case 0:

View File

@@ -35,6 +35,7 @@ class BrickState implements IState<Brick> {
class EntityState implements IState<Entity> {
private var x:Float;
private var y:Float;
private var level:Int;
public function new() {}
@@ -44,6 +45,13 @@ class EntityState implements IState<Entity> {
y = object.rect.y;
return true;
}
if (Std.is(object, Tank)) {
var tank:Tank = cast object;
if (tank.config.level != level) {
level = tank.config.level;
return true;
}
}
return false;
}
}
@@ -153,17 +161,18 @@ class Render extends SpriteView implements IRender {
}
}
public function drawEntries(game:IEngine):Void {
public function drawEntities(game:IEngine):Void {
if (layersForUpdate[entryLayer]) {
var g:Graphics = entryLayer.graphics;
g.clear();
for (ent in game.entities) {
var image:String = null;
if (Std.is(ent, Tank)) {
image = 'resources/images/tank/player/tank_p0_${cast(ent, Tank).index}-0.png';
var tank:Tank = cast ent;
image = 'resources/images/tank/player/tank_p${tank.config.level}_${tank.index}-0.png';
} else if (Std.is(ent, Bullet)) {
var m = new Matrix();
image = 'resources/images/bullet/bullet_0.png';
var bullet:Bullet = cast ent;
image = 'resources/images/bullet/bullet_${bullet.config.type}.png';
} else {
image = 'ERROR'; // ToDo:
}
@@ -172,7 +181,7 @@ class Render extends SpriteView implements IRender {
m.rotate(calcRotate(cast(ent, IMobileEntity).direction));
}
m.translate(ent.rect.x, ent.rect.y);
g.beginBitmapFill(Assets.getBitmapData(image), m);
g.beginBitmapFill(Assets.getBitmapData(image), m, true, true);
g.drawRect(ent.rect.x, ent.rect.y, ent.rect.width, ent.rect.height);
g.endFill();
}
@@ -184,7 +193,7 @@ class Render extends SpriteView implements IRender {
invalidateLayers(game);
drawBackground(game);
drawMap(game);
drawEntries(game);
drawEntities(game);
}
public function reset():Void {