[render] update

This commit is contained in:
2018-01-17 21:58:30 +03:00
parent 35404d5732
commit 507320414f
8 changed files with 219 additions and 226 deletions

View File

@@ -10,24 +10,21 @@ class MobileEntity extends Entity {
public var layer(default, null):Int;
public var speed(default, null):Float;
public var direction(default, default):Direction;
public function new(rect:Rectangle, speed:Float, direction:Direction) {
super(rect);
this.speed = speed;
this.direction = direction;
this.layer = 0;
this.mx = 0;
this.my = 0;
}
public function move(direction:Direction):Void {
if (this.direction != direction) {
if (this.rect.direction != direction) {
this.rect.direction = direction;
this.direction = direction;
}
mx = direction.x * speed;
my = direction.y * speed;
mx = rect.direction.x * speed;
my = rect.direction.y * speed;
}
public function stop():Void {

View File

@@ -28,8 +28,9 @@ class Tank extends MobileEntity {
}
private function set_config(value:TankConfig):TankConfig {
var d = rect.direction;
rect = new Rectangle(rect.x, rect.y, value.width, value.height);
rect.direction = direction;
rect.direction = d;
speed = value.speed;
config = value;
return value;
@@ -38,8 +39,8 @@ class Tank extends MobileEntity {
public function shot():Null<Bullet> {
if (bulletsCounter >= config.bullets) return null;
var bullet = new Bullet(id, config, config.bullet);
bullet.rect.center = rect.center.add(new Point(rect.width / 4 * direction.x, rect.height / 4 * direction.y));
bullet.move(direction);
bullet.rect.center = rect.center.add(new Point(rect.width / 4 * rect.direction.x, rect.height / 4 * rect.direction.y));
bullet.move(rect.direction);
bulletsCounter++;
return bullet;
}

View File

@@ -39,7 +39,7 @@ class Engine {
private function buildTank(index:Int, config:TankConfig, point:SpawnPoint):Tank {
var tank = new Tank(index, config);
tank.rect.center = new Point((point.x + 1) * map.cellWidth, (point.y + 1) * map.cellHeight);
tank.direction = Direction.fromString(point.direction);
tank.rect.direction = Direction.fromString(point.direction);
return tank;
}
@@ -66,8 +66,8 @@ class Engine {
.setObjectId(tank.id)
.setX(tank.rect.x)
.setY(tank.rect.y)
.setDirectionX(tank.direction.x)
.setDirectionY(tank.direction.y)
.setDirectionX(tank.rect.direction.x)
.setDirectionY(tank.rect.direction.y)
);
}
@@ -214,7 +214,7 @@ class Engine {
}
for (other in entities.iterator()) {
if (other != ent) {
if (other != ent && other != null) {
if (other.rect.intersection2(side)) {
//if (ent.rect.intersection(other.rect)) {
var funName = 'collision${ent.type}${other.type}';

View File

@@ -24,6 +24,7 @@ class Brick implements IKey {
public var rect(default, null):Rectangle;
public var cells(default, null):HashMap<Point, GridCell>;
public var broken(get, null):Int;
public var destroyed(get, set):Bool;
public function new(mapConfig:MapConfig, config:BrickConfig, cellX:Int, cellY:Int, cells:HashMap<Point, GridCell>) {
@@ -40,6 +41,16 @@ class Brick implements IKey {
);
}
public function get_broken():Int {
var i:Int = 0;
for (c in cells.iterator()) {
if (c.destroyed) {
i++;
}
}
return i;
}
public function get_destroyed():Bool {
var i = 0;
var result:Bool = false;