udpate
This commit is contained in:
@@ -4,21 +4,21 @@ import haxe.Timer;
|
||||
import ru.m.geom.Direction;
|
||||
import flash.events.FocusEvent;
|
||||
import flash.ui.Keyboard;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import ru.m.tankz.core.Tank.TankAction;
|
||||
import flash.events.KeyboardEvent;
|
||||
import flash.Lib;
|
||||
|
||||
class PlayerControl {
|
||||
|
||||
private var engine:IEngine;
|
||||
private var engine:Engine;
|
||||
private var id:Int;
|
||||
|
||||
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>) {
|
||||
public function new(id:Int, engine:Engine, keyBinding:Map<Int, TankAction>) {
|
||||
this.id = id;
|
||||
this.engine = engine;
|
||||
this.keyBinding = keyBinding;
|
||||
@@ -83,7 +83,7 @@ class PlayerControl {
|
||||
engine.action(id, TankAction.SHOT);
|
||||
}
|
||||
|
||||
public static function forPlayer(index:Int, tankId:Int, engine:IEngine):PlayerControl {
|
||||
public static function forPlayer(index:Int, tankId:Int, engine:Engine):PlayerControl {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return new PlayerControl(tankId, engine, [
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import haxework.gui.IView;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
|
||||
|
||||
interface IRender extends IView {
|
||||
public function draw(game:IEngine):Void;
|
||||
public function draw(game:Engine):Void;
|
||||
public function reset():Void;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import ru.m.tankz.core.IMobileEntity;
|
||||
import ru.m.tankz.core.MobileEntity;
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import ru.m.tankz.core.Entity;
|
||||
import ru.m.tankz.map.Brick;
|
||||
import ru.m.geom.Direction;
|
||||
@@ -11,7 +12,6 @@ import ru.m.tankz.core.Tank;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.Graphics;
|
||||
import haxework.gui.SpriteView;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
|
||||
|
||||
interface IState<T> {
|
||||
@@ -81,7 +81,7 @@ class Render extends SpriteView implements IRender {
|
||||
reset();
|
||||
}
|
||||
|
||||
private function invalidateLayers(game:IEngine):Void {
|
||||
private function invalidateLayers(game:Engine):Void {
|
||||
for (brick in game.map.bricks) {
|
||||
if (!states.exists(brick.key)) {
|
||||
states[brick.key] = new BrickState();
|
||||
@@ -108,7 +108,7 @@ class Render extends SpriteView implements IRender {
|
||||
}
|
||||
}
|
||||
|
||||
private function drawBackground(game:IEngine):Void {
|
||||
private function drawBackground(game:Engine):Void {
|
||||
var mapWidth = game.map.gridWidth * game.map.cellWidth;
|
||||
var mapHeight = game.map.gridHeight * game.map.cellHeight;
|
||||
|
||||
@@ -126,7 +126,7 @@ class Render extends SpriteView implements IRender {
|
||||
}
|
||||
}
|
||||
|
||||
private function drawMap(game:IEngine):Void {
|
||||
private function drawMap(game:Engine):Void {
|
||||
if (layersForUpdate[groundLayer] || layersForUpdate[upLayer]) {
|
||||
groundLayer.graphics.clear();
|
||||
upLayer.graphics.clear();
|
||||
@@ -145,28 +145,36 @@ class Render extends SpriteView implements IRender {
|
||||
game.map.cellWidth,
|
||||
game.map.cellHeight
|
||||
);
|
||||
if (brick.config.breakable) {
|
||||
for (point in brick.breaked.keys()) {
|
||||
if (brick.breaked.get(point)) {
|
||||
g.beginFill(0x000000);
|
||||
g.drawRect(
|
||||
brick.cellX * game.map.cellWidth + point.x * game.map.cellWidth / 2,
|
||||
brick.cellY * game.map.cellHeight + point.y * game.map.cellHeight / 2,
|
||||
game.map.cellWidth / 2,
|
||||
game.map.cellHeight / 2
|
||||
);
|
||||
}
|
||||
for (point in brick.cells.keys()) {
|
||||
if (brick.cells.get(point).destroyed) {
|
||||
g.beginFill(0x000000);
|
||||
g.drawRect(
|
||||
brick.cellX * game.map.cellWidth + point.x * game.map.cellWidth / 2,
|
||||
brick.cellY * game.map.cellHeight + point.y * game.map.cellHeight / 2,
|
||||
game.map.cellWidth / 2,
|
||||
game.map.cellHeight / 2
|
||||
);
|
||||
}
|
||||
}
|
||||
g.endFill();
|
||||
}
|
||||
}
|
||||
/*var g = groundLayer.graphics;
|
||||
for (c in game.map.grid.cells.iterator()) {
|
||||
var color:Int = 0x000000;
|
||||
if (c.armor > 0) {
|
||||
color = 0x00ff00;
|
||||
}
|
||||
g.beginFill(color);
|
||||
g.drawRect(c.rect.x, c.rect.y, c.rect.width, c.rect.height);
|
||||
g.endFill();
|
||||
}*/
|
||||
layersForUpdate[groundLayer] = false;
|
||||
layersForUpdate[upLayer] = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function drawEntities(game:IEngine):Void {
|
||||
public function drawEntities(game:Engine):Void {
|
||||
if (layersForUpdate[entryLayer]) {
|
||||
var g:Graphics = entryLayer.graphics;
|
||||
g.clear();
|
||||
@@ -177,13 +185,13 @@ class Render extends SpriteView implements IRender {
|
||||
image = 'resources/images/tank/player/tank_p${tank.config.level}_${tank.index}-0.png';
|
||||
} else if (Std.is(ent, Bullet)) {
|
||||
var bullet:Bullet = cast ent;
|
||||
image = 'resources/images/bullet/bullet_${bullet.config.piercing-1}.png';
|
||||
image = 'resources/images/bullet/bullet_${bullet.config.piercing > 1 ? 1 : 0}.png';
|
||||
} else {
|
||||
image = 'ERROR'; // ToDo:
|
||||
}
|
||||
var m = new Matrix();
|
||||
if (Std.is(ent, IMobileEntity)) {
|
||||
m.rotate(calcRotate(cast(ent, IMobileEntity).direction));
|
||||
if (Std.is(ent, MobileEntity)) {
|
||||
m.rotate(calcRotate(cast(ent, MobileEntity).direction));
|
||||
}
|
||||
m.translate(ent.rect.x, ent.rect.y);
|
||||
g.beginBitmapFill(Assets.getBitmapData(image), m, true, true);
|
||||
@@ -194,7 +202,7 @@ class Render extends SpriteView implements IRender {
|
||||
}
|
||||
}
|
||||
|
||||
public function draw(game:IEngine):Void {
|
||||
public function draw(game:Engine):Void {
|
||||
invalidateLayers(game);
|
||||
drawBackground(game);
|
||||
drawMap(game);
|
||||
|
||||
@@ -4,7 +4,6 @@ import ru.m.tankz.proto.core.GameType;
|
||||
import ru.m.tankz.proto.core.Game;
|
||||
import ru.m.tankz.core.PlayerControl;
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
import protohx.Message;
|
||||
import ru.m.tankz.proto.pack.GameUpdateResponse;
|
||||
import ru.m.connect.IConnection;
|
||||
@@ -21,7 +20,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
||||
|
||||
public static inline var ID = "game";
|
||||
|
||||
private var engine:IEngine;
|
||||
private var engine:Engine;
|
||||
private var controls:Map<Int, PlayerControl>;
|
||||
|
||||
public function init():Void {
|
||||
|
||||
@@ -20,7 +20,7 @@ bricks:
|
||||
-1: &brick-boder
|
||||
type: -1
|
||||
layer: 2
|
||||
armor: 3
|
||||
armor: -1
|
||||
0: &brick-none
|
||||
type: 0
|
||||
layer: 0
|
||||
@@ -45,7 +45,6 @@ bricks:
|
||||
type: 5
|
||||
layer: 2
|
||||
armor: 1
|
||||
breakable: yes
|
||||
|
||||
bullet: &bullet
|
||||
width: 12
|
||||
@@ -81,7 +80,7 @@ tanks:
|
||||
bullet:
|
||||
<<: *bullet
|
||||
speed: 9.0
|
||||
bullets: 2
|
||||
bullets: 3
|
||||
3:
|
||||
level: 3
|
||||
width: 42
|
||||
@@ -90,5 +89,5 @@ tanks:
|
||||
bullet:
|
||||
<<: *bullet
|
||||
speed: 9.0
|
||||
piercing: 2
|
||||
piercing: 3
|
||||
bullets: 2
|
||||
|
||||
Reference in New Issue
Block a user