[common] player tank levels
This commit is contained in:
@@ -6,12 +6,14 @@ class Rectangle {
|
||||
public var width(default, default):Float;
|
||||
public var height(default, default):Float;
|
||||
public var center(get, set):Point;
|
||||
public var direction(default, set):Direction;
|
||||
|
||||
public function new(x:Float, y:Float, width:Float, height:Float) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.direction = Direction.RIGHT;
|
||||
}
|
||||
|
||||
private function get_center():Point {
|
||||
@@ -28,4 +30,17 @@ class Rectangle {
|
||||
return center.add(new Point(direction.x * width / 2, direction.y * height / 2));
|
||||
}
|
||||
|
||||
public function set_direction(value:Direction):Direction {
|
||||
if (direction != value) {
|
||||
if (direction != null && direction.x * value.x == 0 && direction.y * value.y == 0) {
|
||||
var w = width;
|
||||
var h = height;
|
||||
width = h;
|
||||
height = w;
|
||||
}
|
||||
direction = value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ typedef BulletConfig = {
|
||||
}
|
||||
|
||||
typedef TankConfig = {
|
||||
var level:Int;
|
||||
var width:Float;
|
||||
var height:Float;
|
||||
var speed:Float;
|
||||
@@ -94,19 +95,53 @@ class ConfigBundle {
|
||||
]
|
||||
);
|
||||
|
||||
public static var BULLET_A:BulletConfig = {
|
||||
width: 12,
|
||||
height: 12,
|
||||
speed: 5,
|
||||
type: BulletType.NORMAL
|
||||
private static function bulletConfig(speed:Float, type:BulletType):BulletConfig {
|
||||
return {
|
||||
width: 12,
|
||||
height: 12,
|
||||
speed: speed,
|
||||
type: type
|
||||
}
|
||||
}
|
||||
|
||||
public static var PLAYER_TANK_A:TankConfig = {
|
||||
width: 36,
|
||||
height: 36,
|
||||
speed: 3,
|
||||
bullet: BULLET_A,
|
||||
bullets: 1
|
||||
public static var PLAYER_TANKS:Array<TankConfig> = [
|
||||
{
|
||||
level: 0,
|
||||
width: 36,
|
||||
height: 36,
|
||||
speed: 3,
|
||||
bullet: bulletConfig(5, BulletType.NORMAL),
|
||||
bullets: 1
|
||||
},
|
||||
{
|
||||
level: 1,
|
||||
width: 40,
|
||||
height: 36,
|
||||
speed: 3.5,
|
||||
bullet: bulletConfig(5.5, BulletType.NORMAL),
|
||||
bullets: 1
|
||||
},
|
||||
{
|
||||
level: 2,
|
||||
width: 40,
|
||||
height: 36,
|
||||
speed: 3.5,
|
||||
bullet: bulletConfig(5.5, BulletType.NORMAL),
|
||||
bullets: 2
|
||||
},
|
||||
{
|
||||
level: 3,
|
||||
width: 42,
|
||||
height: 38,
|
||||
speed: 3.5,
|
||||
bullet: bulletConfig(6, BulletType.PIERCING),
|
||||
bullets: 2
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
public static function getPlayerTank(level:Int):TankConfig {
|
||||
return PLAYER_TANKS[level];
|
||||
}
|
||||
|
||||
public static function get(type:Int, level:Int):Config {
|
||||
|
||||
@@ -6,18 +6,17 @@ import ru.m.geom.Direction;
|
||||
|
||||
|
||||
@:enum abstract BulletType(Int) from Int to Int {
|
||||
var NORMAL = 1;
|
||||
var PIERCING = 2;
|
||||
var NORMAL = 0;
|
||||
var PIERCING = 1;
|
||||
}
|
||||
|
||||
|
||||
class Bullet extends MobileEntity {
|
||||
public var tankId(default, null):Int;
|
||||
|
||||
private var config:BulletConfig;
|
||||
public var config(default, null):BulletConfig;
|
||||
|
||||
public function new(tankId:Int, config:BulletConfig) {
|
||||
super(new Rectangle(0, 0, config.width, config.height), config.speed, Direction.TOP);
|
||||
super(new Rectangle(0, 0, config.width, config.height), config.speed, Direction.RIGHT);
|
||||
this.tankId = tankId;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,10 @@ class MobileEntity extends Entity implements IMobileEntity {
|
||||
}
|
||||
|
||||
public function move(direction:Direction):Void {
|
||||
this.direction = direction;
|
||||
if (this.direction != direction) {
|
||||
this.rect.direction = direction;
|
||||
this.direction = direction;
|
||||
}
|
||||
mx = direction.x * speed;
|
||||
my = direction.y * speed;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.m.tankz.core;
|
||||
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.tankz.config.Config.TankConfig;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import ru.m.geom.Rectangle;
|
||||
@@ -8,26 +9,35 @@ import ru.m.geom.Direction;
|
||||
|
||||
enum TankAction {
|
||||
MOVE(direction:Direction);
|
||||
LEVEL_UP(level:Int);
|
||||
STOP;
|
||||
SHOT;
|
||||
}
|
||||
|
||||
class Tank extends MobileEntity {
|
||||
public var index(default, null):Int;
|
||||
public var config(default, set):TankConfig;
|
||||
|
||||
private var bulletsCounter:Int = 0;
|
||||
private var config:TankConfig;
|
||||
|
||||
public function new(index:Int, config: TankConfig) {
|
||||
super(new Rectangle(0, 0, config.width, config.height), config.speed, Direction.TOP);
|
||||
super(new Rectangle(0, 0, config.width, config.height), config.speed, Direction.RIGHT);
|
||||
this.index = index;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
private function set_config(value:TankConfig):TankConfig {
|
||||
rect = new Rectangle(rect.x, rect.y, value.width, value.height);
|
||||
rect.direction = direction;
|
||||
speed = value.speed;
|
||||
config = value;
|
||||
return value;
|
||||
}
|
||||
|
||||
public function shot():Null<Bullet> {
|
||||
if (bulletsCounter >= config.bullets) return null;
|
||||
var bullet = new Bullet(id, config.bullet);
|
||||
bullet.rect.center = rect.center;
|
||||
bullet.rect.center = rect.center.add(new Point(rect.width / 2 * direction.x, rect.height / 2 * direction.y));
|
||||
bullet.move(direction);
|
||||
bulletsCounter++;
|
||||
return bullet;
|
||||
|
||||
@@ -63,7 +63,7 @@ class Engine implements IEngine {
|
||||
for (index in 0...players.length) {
|
||||
var player:Player = players[index];
|
||||
var point:SpawnPoint = config.getSpawnPoint(SpawnPointType.PLAYER, index);
|
||||
var tank = buildTank(index, ConfigBundle.PLAYER_TANK_A, point);
|
||||
var tank = buildTank(index, ConfigBundle.getPlayerTank(0), point);
|
||||
playerTanks.set(player.id, tank);
|
||||
entities.set(tank.id, tank);
|
||||
changes.push(new GameChange()
|
||||
@@ -90,6 +90,8 @@ class Engine implements IEngine {
|
||||
.setDirectionX(direction.x)
|
||||
.setDirectionY(direction.y)
|
||||
);*/
|
||||
case TankAction.LEVEL_UP(level):
|
||||
tank.config = ConfigBundle.getPlayerTank(Std.int(Math.min(tank.config.level + level, 3)));
|
||||
case TankAction.STOP:
|
||||
tank.stop();
|
||||
/*Provider.get(IConnection).send(
|
||||
@@ -196,10 +198,11 @@ class Engine implements IEngine {
|
||||
);
|
||||
|
||||
if (objectType == GameObjectType.BULLET) {
|
||||
var bullet:Bullet = cast ent;
|
||||
for (brick in bricks) {
|
||||
if (BULLET_BRICKS.indexOf(brick.type) > -1) {
|
||||
entities.remove(entity.id);
|
||||
var tank:Tank = cast entities.get(cast(entity, Bullet).tankId);
|
||||
var tank:Tank = cast entities.get(bullet.tankId);
|
||||
tank.onDestroyBullet();
|
||||
changes.push(new GameChange()
|
||||
.setType(GameChangeType.DESTROED)
|
||||
@@ -211,7 +214,10 @@ class Engine implements IEngine {
|
||||
}
|
||||
}
|
||||
for (brick in bricks) {
|
||||
if (brick.type == BrickType.BRICK || brick.type == BrickType.BUSH) {
|
||||
if (brick.type == BrickType.BRICK) {
|
||||
brick.type = BrickType.NONE;
|
||||
}
|
||||
if (bullet.config.type == BulletType.PIERCING && brick.type == BrickType.ARMOR) {
|
||||
brick.type = BrickType.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user