[common] tanks and bullets config
This commit is contained in:
@@ -157,23 +157,24 @@ class Render extends SpriteView implements IRender {
|
||||
if (layersForUpdate[entryLayer]) {
|
||||
var g:Graphics = entryLayer.graphics;
|
||||
g.clear();
|
||||
for (ent in game.entities) if (Std.is(ent, IMobileEntity)) {
|
||||
var e:IMobileEntity = cast ent;
|
||||
if (Std.is(e, Tank)) {
|
||||
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';
|
||||
} else if (Std.is(ent, Bullet)) {
|
||||
var m = new Matrix();
|
||||
m.rotate(calcRotate(e.direction));
|
||||
m.translate(e.rect.x, e.rect.y);
|
||||
g.beginBitmapFill(Assets.getBitmapData("resources/images/tank/player/tank_p0_0-0.png"), m);
|
||||
g.drawRect(e.rect.x, e.rect.y, e.rect.width, e.rect.height);
|
||||
g.endFill();
|
||||
} else if (Std.is(e, Bullet)) {
|
||||
var m = new Matrix();
|
||||
m.rotate(calcRotate(e.direction));
|
||||
m.translate(e.rect.x, e.rect.y);
|
||||
g.beginBitmapFill(Assets.getBitmapData("resources/images/bullet/bullet_0.png"), m);
|
||||
g.drawRect(e.rect.x, e.rect.y, e.rect.width, e.rect.height);
|
||||
g.endFill();
|
||||
image = 'resources/images/bullet/bullet_0.png';
|
||||
} else {
|
||||
image = 'ERROR'; // ToDo:
|
||||
}
|
||||
var m = new Matrix();
|
||||
if (Std.is(ent, IMobileEntity)) {
|
||||
m.rotate(calcRotate(cast(ent, IMobileEntity).direction));
|
||||
}
|
||||
m.translate(ent.rect.x, ent.rect.y);
|
||||
g.beginBitmapFill(Assets.getBitmapData(image), m);
|
||||
g.drawRect(ent.rect.x, ent.rect.y, ent.rect.width, ent.rect.height);
|
||||
g.endFill();
|
||||
}
|
||||
layersForUpdate[entryLayer] = false;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package ru.m.tankz.config;
|
||||
|
||||
import ru.m.tankz.core.Bullet.BulletType;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import openfl.utils.Assets;
|
||||
import ru.m.tankz.map.Brick.BrickType;
|
||||
import ru.m.tankz.map.Brick;
|
||||
import ru.m.tankz.proto.core.GameType;
|
||||
import ru.m.geom.Direction;
|
||||
|
||||
@@ -14,6 +16,21 @@ typedef MapConfig = {
|
||||
var bricks:Array<BrickType>;
|
||||
}
|
||||
|
||||
typedef BulletConfig = {
|
||||
var width:Float;
|
||||
var height:Float;
|
||||
var speed:Float;
|
||||
var type:BulletType;
|
||||
}
|
||||
|
||||
typedef TankConfig = {
|
||||
var width:Float;
|
||||
var height:Float;
|
||||
var speed:Float;
|
||||
var bullet:BulletConfig;
|
||||
var bullets:Int;
|
||||
}
|
||||
|
||||
enum SpawnPointType {
|
||||
PLAYER;
|
||||
BOT;
|
||||
@@ -51,7 +68,6 @@ class Config {
|
||||
|
||||
class ConfigBundle {
|
||||
|
||||
|
||||
public static var CLASSIC:Config = new Config(
|
||||
{
|
||||
cellWidth: 22,
|
||||
@@ -78,6 +94,21 @@ class ConfigBundle {
|
||||
]
|
||||
);
|
||||
|
||||
public static var BULLET_A:BulletConfig = {
|
||||
width: 12,
|
||||
height: 12,
|
||||
speed: 5,
|
||||
type: BulletType.NORMAL
|
||||
}
|
||||
|
||||
public static var PLAYER_TANK_A:TankConfig = {
|
||||
width: 36,
|
||||
height: 36,
|
||||
speed: 3,
|
||||
bullet: BULLET_A,
|
||||
bullets: 1
|
||||
}
|
||||
|
||||
public static function get(type:Int, level:Int):Config {
|
||||
switch (type) {
|
||||
case GameType.CLASSIC:
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
package ru.m.tankz.core;
|
||||
|
||||
import ru.m.tankz.config.Config.BulletConfig;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.geom.Direction;
|
||||
|
||||
|
||||
class Bullet extends MobileEntity {
|
||||
@:enum abstract BulletType(Int) from Int to Int {
|
||||
var NORMAL = 1;
|
||||
var PIERCING = 2;
|
||||
}
|
||||
|
||||
|
||||
class Bullet extends MobileEntity {
|
||||
public var tankId(default, null):Int;
|
||||
|
||||
public function new(tankId:Int, x:Float, y:Float, speed:Float, direction:Direction) {
|
||||
super(new Rectangle(x, y, 12, 12), speed, direction);
|
||||
private var config:BulletConfig;
|
||||
|
||||
public function new(tankId:Int, config:BulletConfig) {
|
||||
super(new Rectangle(0, 0, config.width, config.height), config.speed, Direction.TOP);
|
||||
this.tankId = tankId;
|
||||
this.config = config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package ru.m.tankz.core;
|
||||
|
||||
import ru.m.tankz.config.Config.TankConfig;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.geom.Direction;
|
||||
|
||||
@@ -11,22 +13,27 @@ enum TankAction {
|
||||
}
|
||||
|
||||
class Tank extends MobileEntity {
|
||||
public var index(default, null):Int;
|
||||
|
||||
public var bulletsCount:Int = 0;
|
||||
private var bulletsCounter:Int = 0;
|
||||
private var config:TankConfig;
|
||||
|
||||
public function new(x:Float, y:Float, direction:Direction) {
|
||||
super(new Rectangle(x, y, 36, 36), 4, direction);
|
||||
public function new(index:Int, config: TankConfig) {
|
||||
super(new Rectangle(0, 0, config.width, config.height), config.speed, Direction.TOP);
|
||||
this.index = index;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public function shot():Null<Bullet> {
|
||||
if (bulletsCount >= 5) return null;
|
||||
var bullet = new Bullet(id, rect.x + rect.width / 2 - 5, rect.y + rect.height / 2 - 5, 6, direction);
|
||||
if (bulletsCounter >= config.bullets) return null;
|
||||
var bullet = new Bullet(id, config.bullet);
|
||||
bullet.rect.center = rect.center;
|
||||
bullet.move(direction);
|
||||
bulletsCount++;
|
||||
bulletsCounter++;
|
||||
return bullet;
|
||||
}
|
||||
|
||||
public function onDestroyBullet():Void {
|
||||
bulletsCount--;
|
||||
bulletsCounter--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.m.tankz.engine;
|
||||
|
||||
import ru.m.tankz.config.Config.TankConfig;
|
||||
import ru.m.tankz.core.IEntity;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.tankz.map.Brick;
|
||||
@@ -32,9 +33,6 @@ class Engine implements IEngine {
|
||||
public var entities(default, null):Map<Int, IEntity>;
|
||||
public var removedEntities(default, null):Array<String>;
|
||||
|
||||
private var x_limit:Float;
|
||||
private var y_limit:Float;
|
||||
|
||||
private var playerTanks(default, null):Map<Int, Tank>;
|
||||
private var time:Float;
|
||||
|
||||
@@ -44,8 +42,11 @@ class Engine implements IEngine {
|
||||
playerTanks = new Map<Int, Tank>();
|
||||
}
|
||||
|
||||
private function buildTank(cellX:Float, cellY:Float, direction:Direction):Tank {
|
||||
return new Tank(cellX * map.cellWidth, cellY * map.cellHeight, direction);
|
||||
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 = point.direction;
|
||||
return tank;
|
||||
}
|
||||
|
||||
public function init(config:Config):Void {
|
||||
@@ -54,8 +55,6 @@ class Engine implements IEngine {
|
||||
playerTanks = new Map<Int, Tank>();
|
||||
entities = new Map<Int, IEntity>();
|
||||
removedEntities = new Array<String>();
|
||||
x_limit = map.gridWidth * map.cellWidth;
|
||||
y_limit = map.gridHeight * map.cellHeight;
|
||||
time = Date.now().getTime();
|
||||
}
|
||||
|
||||
@@ -64,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(point.x, point.y, point.direction);
|
||||
var tank = buildTank(index, ConfigBundle.PLAYER_TANK_A, point);
|
||||
playerTanks.set(player.id, tank);
|
||||
entities.set(tank.id, tank);
|
||||
changes.push(new GameChange()
|
||||
|
||||
Reference in New Issue
Block a user