Collapse all terrain
This commit is contained in:
1 parent
1bf0406bec
commit
47c1c8dad6
2 files changed
+7
-12
No files matched your search
@@ -173,10 +173,7 @@ function update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (state === 'land-collapse') {
|
else if (state === 'land-collapse') {
|
||||||
const target = explosion ||projectile;
|
collapseTerrain(terrain);
|
||||||
if (target) {
|
|
||||||
collapseTerrain(terrain, target.x, 100); // FIXME: Hardcoded radius
|
|
||||||
}
|
|
||||||
state = 'land-players';
|
state = 'land-players';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-8
@@ -50,15 +50,13 @@ const TERRAIN_TYPES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cacheImageData(ctx);
|
cacheImageData(ctx);
|
||||||
collapseTerrain(ctx, width/2, width/2);
|
collapseTerrain(ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function collapseTerrain(ctx, ox, r) {
|
export function collapseTerrain(ctx, ) {
|
||||||
const {height} = ctx.canvas;
|
const {width, height} = ctx.canvas;
|
||||||
const width = r * 2 + 10;
|
const imageData = ctx.getImageData(0, 0, width, height);
|
||||||
const left = ox-r-5;
|
|
||||||
const imageData = ctx.getImageData(left, 0, width, height);
|
|
||||||
|
|
||||||
for (let x=0; x<width; x++) {
|
for (let x=0; x<width; x++) {
|
||||||
let land = 0;
|
let land = 0;
|
||||||
@@ -67,8 +65,8 @@ export function collapseTerrain(ctx, ox, r) {
|
|||||||
if (imageData.data[index] > 0) land++;
|
if (imageData.data[index] > 0) land++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.clearRect(left+x, 0, 1, height);
|
ctx.clearRect(0+x, 0, 1, height);
|
||||||
drawRect(ctx, left+x, height-land, 1, land, ctx.color);
|
drawRect(ctx, 0+x, height-land, 1, land, ctx.color);
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheImageData(ctx);
|
cacheImageData(ctx);
|
||||||
|
|||||||
Reference in new issue
Block a user