[common] breakable bricks
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tankz",
|
"name": "tankz",
|
||||||
"version": "0.0.2",
|
"version": "0.0.3",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ansi-colors": "^1.0.1",
|
"ansi-colors": "^1.0.1",
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ class Render extends SpriteView implements IRender {
|
|||||||
layersForUpdate[upLayer] = true;
|
layersForUpdate[upLayer] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
layersForUpdate[groundLayer] = true; //ToDo:
|
||||||
for (entry in game.entities) {
|
for (entry in game.entities) {
|
||||||
if (!states.exists(entry.key)) {
|
if (!states.exists(entry.key)) {
|
||||||
states[entry.key] = new EntityState();
|
states[entry.key] = new EntityState();
|
||||||
@@ -137,7 +138,6 @@ class Render extends SpriteView implements IRender {
|
|||||||
g = upLayer.graphics;
|
g = upLayer.graphics;
|
||||||
}
|
}
|
||||||
if (g != null) {
|
if (g != null) {
|
||||||
g.beginFill(0x00ff00);
|
|
||||||
g.beginBitmapFill(Assets.getBitmapData('resources/images/map/map_${brick.config.type}.png'));
|
g.beginBitmapFill(Assets.getBitmapData('resources/images/map/map_${brick.config.type}.png'));
|
||||||
g.drawRect(
|
g.drawRect(
|
||||||
brick.cellX * game.map.cellWidth,
|
brick.cellX * game.map.cellWidth,
|
||||||
@@ -145,6 +145,19 @@ class Render extends SpriteView implements IRender {
|
|||||||
game.map.cellWidth,
|
game.map.cellWidth,
|
||||||
game.map.cellHeight
|
game.map.cellHeight
|
||||||
);
|
);
|
||||||
|
if (brick.config.breakable) {
|
||||||
|
for (point in brick.breaked.keys()) {
|
||||||
|
if (brick.breaked.get(point)) {
|
||||||
|
g.beginFill(0x000000);
|
||||||
|
g.drawRect(
|
||||||
|
brick.cellX * game.map.cellWidth + point.x * game.map.cellWidth / 2,
|
||||||
|
brick.cellY * game.map.cellHeight + point.y * game.map.cellHeight / 2,
|
||||||
|
game.map.cellWidth / 2,
|
||||||
|
game.map.cellHeight / 2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
g.endFill();
|
g.endFill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ bricks:
|
|||||||
type: 5
|
type: 5
|
||||||
layer: 2
|
layer: 2
|
||||||
armor: 1
|
armor: 1
|
||||||
|
breakable: yes
|
||||||
|
|
||||||
bullet: &bullet
|
bullet: &bullet
|
||||||
width: 12
|
width: 12
|
||||||
|
|||||||
@@ -12,4 +12,12 @@ class Point {
|
|||||||
public function add(point:Point):Point {
|
public function add(point:Point):Point {
|
||||||
return new Point(x + point.x, y + point.y);
|
return new Point(x + point.x, y + point.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hashCode():Int {
|
||||||
|
return Std.int(x + 1000 * y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toString():String {
|
||||||
|
return 'Point{x=$x,y=$y}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ typedef BrickConfig = {
|
|||||||
var type:Int;
|
var type:Int;
|
||||||
var layer:Int;
|
var layer:Int;
|
||||||
var armor:Int;
|
var armor:Int;
|
||||||
|
var breakable:Bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef BulletConfig = {
|
typedef BulletConfig = {
|
||||||
|
|||||||
@@ -191,25 +191,78 @@ class Engine implements IEngine {
|
|||||||
|
|
||||||
if (objectType == GameObjectType.BULLET) {
|
if (objectType == GameObjectType.BULLET) {
|
||||||
var bullet:Bullet = cast ent;
|
var bullet:Bullet = cast ent;
|
||||||
|
var collision:Bool = false;
|
||||||
for (brick in bricks) {
|
for (brick in bricks) {
|
||||||
if (1 < brick.config.layer && brick.config.layer < 3) {
|
if (1 < brick.config.layer && brick.config.layer < 3) {
|
||||||
entities.remove(entity.id);
|
collision = true;
|
||||||
var tank:Tank = cast entities.get(bullet.tankId);
|
|
||||||
tank.onDestroyBullet();
|
|
||||||
changes.push(new GameChange()
|
|
||||||
.setType(GameChangeType.DESTROED)
|
|
||||||
.setObjectType(objectType)
|
|
||||||
.setObjectId(entity.id)
|
|
||||||
);
|
|
||||||
removedEntities.push(entity.key);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (brick in bricks) {
|
var d:Direction = ent.rect.direction;
|
||||||
|
for (i in 0...bricks.length) {
|
||||||
|
var brick = bricks[i];
|
||||||
if (brick.config.armor > 0 && brick.config.armor <= bullet.config.piercing) {
|
if (brick.config.armor > 0 && brick.config.armor <= bullet.config.piercing) {
|
||||||
brick.config = config.getBrick(0);
|
if (brick.config.breakable && brick.config.armor == bullet.config.piercing) {
|
||||||
|
//~~~~~~~~~~
|
||||||
|
var p1:Point = new Point(0, 0);
|
||||||
|
if (d.x > 0 || d.y > 0) {
|
||||||
|
if (i == 0) {
|
||||||
|
p1 = p1.add(new Point(0, 0));
|
||||||
|
} else {
|
||||||
|
p1 = p1.add(new Point(d.y, d.x));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (i == 0) {
|
||||||
|
p1 = p1.add(new Point(-d.x, -d.y));
|
||||||
|
} else {
|
||||||
|
p1 = p1.add(new Point(1, 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//~~~~~~~~~~
|
||||||
|
var p2:Point = p1.add(new Point(0, 0));
|
||||||
|
if (d.x > 0 || d.y > 0) {
|
||||||
|
if (i == 0) {
|
||||||
|
p2 = p2.add(new Point(d.y, d.x));
|
||||||
|
} else {
|
||||||
|
p2 = p2.add(new Point(-d.y, -d.x));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (i == 0) {
|
||||||
|
p2 = p2.add(new Point(-d.y, -d.x));
|
||||||
|
} else {
|
||||||
|
p2 = p2.add(new Point(d.y, d.x));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//~~~~~~~~~~
|
||||||
|
if (brick.breaked.get(p1)) {
|
||||||
|
p1 = p1.add(new Point(ent.rect.direction.x, ent.rect.direction.y));
|
||||||
|
p2 = p2.add(new Point(ent.rect.direction.x, ent.rect.direction.y));
|
||||||
|
}
|
||||||
|
if (brick.breaked.get(p1)) {
|
||||||
|
collision = false;
|
||||||
|
} else {
|
||||||
|
brick.breaked.set(p1, true);
|
||||||
|
brick.breaked.set(p2, true);
|
||||||
|
}
|
||||||
|
if (brick.destroyed) {
|
||||||
|
brick.config = config.getBrick(0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
brick.config = config.getBrick(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (collision) {
|
||||||
|
entities.remove(entity.id);
|
||||||
|
var tank:Tank = cast entities.get(bullet.tankId);
|
||||||
|
tank.onDestroyBullet();
|
||||||
|
changes.push(new GameChange()
|
||||||
|
.setType(GameChangeType.DESTROED)
|
||||||
|
.setObjectType(objectType)
|
||||||
|
.setObjectId(entity.id)
|
||||||
|
);
|
||||||
|
removedEntities.push(entity.key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package ru.m.tankz.map;
|
package ru.m.tankz.map;
|
||||||
|
|
||||||
|
import haxe.ds.HashMap;
|
||||||
|
import ru.m.geom.Point;
|
||||||
import ru.m.tankz.config.Config.BrickConfig;
|
import ru.m.tankz.config.Config.BrickConfig;
|
||||||
import ru.m.tankz.core.IKey;
|
import ru.m.tankz.core.IKey;
|
||||||
|
|
||||||
@@ -9,6 +11,7 @@ class Brick implements IKey {
|
|||||||
type: -1,
|
type: -1,
|
||||||
layer: 2,
|
layer: 2,
|
||||||
armor: 3,
|
armor: 3,
|
||||||
|
breakable: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
public var cellX(default, null):Int;
|
public var cellX(default, null):Int;
|
||||||
@@ -16,10 +19,24 @@ class Brick implements IKey {
|
|||||||
public var key(get, null):String;
|
public var key(get, null):String;
|
||||||
public var config(default, default):BrickConfig;
|
public var config(default, default):BrickConfig;
|
||||||
|
|
||||||
|
public var breaked:HashMap<Point, Bool>;
|
||||||
|
public var destroyed(get, null):Bool;
|
||||||
|
|
||||||
public function new(config:BrickConfig, cellX:Int, cellY:Int) {
|
public function new(config:BrickConfig, cellX:Int, cellY:Int) {
|
||||||
this.cellX = cellX;
|
this.cellX = cellX;
|
||||||
this.cellY = cellY;
|
this.cellY = cellY;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
this.breaked = new HashMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_destroyed():Bool {
|
||||||
|
var i = 0;
|
||||||
|
for (k in breaked.keys()) {
|
||||||
|
if (++i >=4) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_key():String {
|
public function get_key():String {
|
||||||
|
|||||||
Reference in New Issue
Block a user