[render] spawn eagle from GameEvent
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.render;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
import flash.display.DisplayObjectContainer;
|
import flash.display.DisplayObjectContainer;
|
||||||
import flash.display.Graphics;
|
import flash.display.Graphics;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
@@ -102,11 +103,11 @@ class Render extends SpriteView implements IRender implements GameListener {
|
|||||||
|
|
||||||
public function onSpawn(entity:EntityType):Void {
|
public function onSpawn(entity:EntityType):Void {
|
||||||
switch entity {
|
switch entity {
|
||||||
case EAGLE(eagle):
|
/*case EAGLE(eagle):
|
||||||
var item = new EagleRenderItem(eagle);
|
var item = new EagleRenderItem(eagle);
|
||||||
items.set(eagle.id, item);
|
items.set(eagle.id, item);
|
||||||
entryLayer.addChild(item.view);
|
entryLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();*/
|
||||||
case TANK(tank):
|
case TANK(tank):
|
||||||
var item = new TankRenderItem(tank);
|
var item = new TankRenderItem(tank);
|
||||||
items.set(tank.id, item);
|
items.set(tank.id, item);
|
||||||
@@ -142,6 +143,11 @@ class Render extends SpriteView implements IRender implements GameListener {
|
|||||||
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
case COMPLETE(_, _):
|
case COMPLETE(_, _):
|
||||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
|
case SPAWN(EAGLE(id, rect, teamId)):
|
||||||
|
var item = new EagleRenderItem(rect);
|
||||||
|
items.set(id, item);
|
||||||
|
entryLayer.addChild(item.view);
|
||||||
|
item.update();
|
||||||
case MOVE(BULLET(id, position)):
|
case MOVE(BULLET(id, position)):
|
||||||
if (items.exists(id)) {
|
if (items.exists(id)) {
|
||||||
var item = items[id];
|
var item = items[id];
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package ru.m.tankz.render.item;
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
import ru.m.tankz.core.Eagle;
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
class EagleRenderItem extends BitmapRenderItem {
|
class EagleRenderItem extends BitmapRenderItem {
|
||||||
public var death(default, set):Bool = true;
|
public var death(default, set):Bool = true;
|
||||||
|
|
||||||
public function new(eagle:Eagle) {
|
public function new(rect:Rectangle) {
|
||||||
super(eagle.rect);
|
super(rect);
|
||||||
death = false;
|
death = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,58 @@
|
|||||||
package ru.m.geom;
|
package ru.m.geom;
|
||||||
|
|
||||||
class Rectangle {
|
abstract Rectangle(Array<Float>) {
|
||||||
public var x(default, default):Float;
|
public var x(get, set):Float;
|
||||||
public var y(default, default):Float;
|
public var y(get, set):Float;
|
||||||
public var width(default, default):Float;
|
public var width(get, set):Float;
|
||||||
public var height(default, default):Float;
|
public var height(get, set):Float;
|
||||||
public var center(get, set):Point;
|
public var center(get, set):Point;
|
||||||
public var direction(default, set):Direction;
|
public var direction(get, set):Direction;
|
||||||
public var left(get, null):Float;
|
public var left(get, never):Float;
|
||||||
public var right(get, null):Float;
|
public var right(get, never):Float;
|
||||||
public var top(get, null):Float;
|
public var top(get, never):Float;
|
||||||
public var bottom(get, null):Float;
|
public var bottom(get, never):Float;
|
||||||
public var position(get, null):Position;
|
public var position(get, set):Position;
|
||||||
|
|
||||||
public function new(x:Float, y:Float, width:Float, height:Float) {
|
public function new(x:Float = 0, y:Float = 0, width:Float = 0, height:Float = 0, direction:Direction = null) {
|
||||||
this.x = x;
|
if (direction == null) {
|
||||||
this.y = y;
|
direction = Direction.RIGHT;
|
||||||
this.width = width;
|
}
|
||||||
this.height = height;
|
this = [
|
||||||
this.direction = Direction.RIGHT;
|
x, y, width, height,
|
||||||
|
direction.x, direction.y,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function get_x():Float {
|
||||||
|
return this[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function set_x(value:Float):Float {
|
||||||
|
return this[0] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function get_y():Float {
|
||||||
|
return this[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function set_y(value:Float):Float {
|
||||||
|
return this[1] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function get_width():Float {
|
||||||
|
return this[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function set_width(value:Float):Float {
|
||||||
|
return this[2] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function get_height():Float {
|
||||||
|
return this[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function set_height(value:Float):Float {
|
||||||
|
return this[3] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_center():Point {
|
private function get_center():Point {
|
||||||
@@ -26,8 +60,8 @@ class Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function set_center(value:Point):Point {
|
private function set_center(value:Point):Point {
|
||||||
this.x = value.x - width / 2;
|
x = value.x - width / 2;
|
||||||
this.y = value.y - height / 2;
|
y = value.y - height / 2;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +83,10 @@ class Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_direction():Direction {
|
||||||
|
return [Std.int(this[4]), Std.int(this[5])];
|
||||||
|
}
|
||||||
|
|
||||||
public function set_direction(value:Direction):Direction {
|
public function set_direction(value:Direction):Direction {
|
||||||
if (direction != value) {
|
if (direction != value) {
|
||||||
if (direction != null && direction.x * value.x == 0 && direction.y * value.y == 0) {
|
if (direction != null && direction.x * value.x == 0 && direction.y * value.y == 0) {
|
||||||
@@ -57,7 +95,8 @@ class Rectangle {
|
|||||||
width = h;
|
width = h;
|
||||||
height = w;
|
height = w;
|
||||||
}
|
}
|
||||||
direction = value;
|
this[4] = value.x;
|
||||||
|
this[5] = value.y;
|
||||||
}
|
}
|
||||||
return direction;
|
return direction;
|
||||||
}
|
}
|
||||||
@@ -96,23 +135,30 @@ class Rectangle {
|
|||||||
return 'Rectangle{x=$x,y=$y,width=$width,height=$height}';
|
return 'Rectangle{x=$x,y=$y,width=$width,height=$height}';
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_left():Float {
|
private function get_left():Float {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_right():Float {
|
private function get_right():Float {
|
||||||
return x + width;
|
return x + width;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_top():Float {
|
private function get_top():Float {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_bottom():Float {
|
private function get_bottom():Float {
|
||||||
return y + height;
|
return y + height;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_position():Position {
|
private function get_position():Position {
|
||||||
return {x:x, y:y, direction:direction};
|
return {x:x, y:y, direction:direction};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function set_position(position:Position):Position {
|
||||||
|
x = position.x;
|
||||||
|
y = position.y;
|
||||||
|
direction = position.direction;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ class Eagle extends Entity {
|
|||||||
|
|
||||||
public var score(get, null):Int;
|
public var score(get, null):Int;
|
||||||
|
|
||||||
public function new(id:Int, team:TeamId, config:EagleConfig) {
|
public function new(id:Int, rect:Rectangle, team:TeamId, config:EagleConfig) {
|
||||||
super(id, new Rectangle(0, 0, 44, 44)); // ToDo: hardcode size
|
super(id, rect);
|
||||||
this.team = team;
|
this.team = team;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.death = false;
|
this.death = false;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.core.Bonus;
|
import ru.m.tankz.core.Bonus;
|
||||||
import ru.m.tankz.core.Bullet;
|
import ru.m.tankz.core.Bullet;
|
||||||
@@ -15,10 +16,9 @@ class EntityBuilder {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildEagle(id:Int, teamId:TeamId):Eagle {
|
public function buildEagle(id:Int, rect:Rectangle, teamId:TeamId):Eagle {
|
||||||
var eageleConfig = config.getTeam(teamId).eagle;
|
var eageleConfig = config.getTeam(teamId).eagle;
|
||||||
var eaglePoint = config.getPoint(teamId, "eagle");
|
var eagle = new Eagle(id, rect, teamId, eageleConfig);
|
||||||
var eagle = new Eagle(id, teamId, eageleConfig);
|
|
||||||
eagle.color = config.getColor(new PlayerId(teamId, -1));
|
eagle.color = config.getColor(new PlayerId(teamId, -1));
|
||||||
return eagle;
|
return eagle;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,9 +74,8 @@ import ru.m.tankz.Type;
|
|||||||
case GameEvent.COMPLETE(state, winnerId):
|
case GameEvent.COMPLETE(state, winnerId):
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.winner = winnerId;
|
this.winner = winnerId;
|
||||||
case GameEvent.SPAWN(EAGLE(id, position, teamId)):
|
case GameEvent.SPAWN(EAGLE(id, rect, teamId)):
|
||||||
var eagle = builder.buildEagle(id, teamId);
|
var eagle = builder.buildEagle(id, rect, teamId);
|
||||||
applyPosition(eagle, position);
|
|
||||||
var team = getTeam(teamId);
|
var team = getTeam(teamId);
|
||||||
team.eagleId = eagle.id;
|
team.eagleId = eagle.id;
|
||||||
engine.spawn(eagle);
|
engine.spawn(eagle);
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
import ru.m.geom.Position;
|
import ru.m.geom.Position;
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
enum SpawnEvent {
|
enum SpawnEvent {
|
||||||
EAGLE(id:Int, position:Position, teamId:TeamId);
|
EAGLE(id:Int, rect:Rectangle, teamId:TeamId);
|
||||||
TANK(id:Int, position:Position, playerId:PlayerId, type:TankType);
|
TANK(id:Int, position:Position, playerId:PlayerId, type:TankType);
|
||||||
BULLET(id:Int, position:Position, playerId:PlayerId);
|
BULLET(id:Int, position:Position, playerId:PlayerId);
|
||||||
BONUS(id:Int, position:Position, type:BonusType);
|
BONUS(id:Int, position:Position, type:BonusType);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
import ru.m.geom.Direction;
|
import ru.m.geom.Direction;
|
||||||
import haxe.ds.Option;
|
import haxe.ds.Option;
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
@@ -78,7 +79,10 @@ class GameRunner implements EngineListener implements GameListener {
|
|||||||
}
|
}
|
||||||
if (team.config.eagle != null) {
|
if (team.config.eagle != null) {
|
||||||
var point = game.config.getPoint(team.id, "eagle");
|
var point = game.config.getPoint(team.id, "eagle");
|
||||||
gameEventSignal.emit(GameEvent.SPAWN(EAGLE(++entityId, pointToPosition(point), team.id)));
|
var position = pointToPosition(point);
|
||||||
|
var rect = new Rectangle(0, 0, 44, 44);
|
||||||
|
rect.center = new Point(position.x, position.y);
|
||||||
|
gameEventSignal.emit(GameEvent.SPAWN(EAGLE(++entityId, rect, team.id)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gameEventSignal.emit(GameEvent.START(state));
|
gameEventSignal.emit(GameEvent.START(state));
|
||||||
|
|||||||
Reference in New Issue
Block a user