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