Proper bridge mask
This commit is contained in:
36
js/mask.js
Normal file
36
js/mask.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
export class Mask {
|
||||||
|
constructor(width, height) {
|
||||||
|
this.mask = [];
|
||||||
|
for (let x = 0; x < width; x++) {
|
||||||
|
this.mask.push(Array(height).fill(false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static from_string(mask_string) {
|
||||||
|
// mask_string: '\n+++\n+++\n'
|
||||||
|
const rows = mask_string.trim().split('\n');
|
||||||
|
// rows: ['+++', '+++']
|
||||||
|
const mask = new Mask(rows[0].length, rows.length);
|
||||||
|
for (let y = 0; y < rows.length; y++) {
|
||||||
|
const row = rows[y];
|
||||||
|
for (let x = 0; x < row.length; x++) {
|
||||||
|
const cell = row[x].toLowerCase();
|
||||||
|
if (cell == '+' || cell == 'x') {
|
||||||
|
mask.set(x, y, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
set(x, y, val) {
|
||||||
|
this.mask[x][y] = val;
|
||||||
|
}
|
||||||
|
update(x, y, src) {
|
||||||
|
for (let xi = 0; xi < src.mask.length; xi++) {
|
||||||
|
const col = src.mask[xi];
|
||||||
|
for (let yi = 0; yi < col.length; yi++) {
|
||||||
|
this.set(x + xi, y + yi, col[yi]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=mask.js.map
|
||||||
1
js/mask.js.map
Normal file
1
js/mask.js.map
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"mask.js","sourceRoot":"","sources":["../ts/mask.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,IAAI;IAGf,YAAY,KAAa,EAAE,MAAc;QAFzC,SAAI,GAAgB,EAAE,CAAC;QAGrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;YAC9B,IAAI,CAAC,IAAI,C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AC;YACzB,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE;gBACtC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;aACnC;SACF;IACH,CAAC;CACF"}
|
||||||
10
js/tiles.js
10
js/tiles.js
@@ -131,6 +131,16 @@ export const RIVER_BL = new SimpleTileFactory('water', 12, 12, '{tileset}/river-
|
|||||||
export const RIVER_TR = new SimpleTileFactory('water', 12, 12, '{tileset}/river-tr.svg');
|
export const RIVER_TR = new SimpleTileFactory('water', 12, 12, '{tileset}/river-tr.svg');
|
||||||
export const RIVER_TL = new SimpleTileFactory('water', 12, 12, '{tileset}/river-tl.svg');
|
export const RIVER_TL = new SimpleTileFactory('water', 12, 12, '{tileset}/river-tl.svg');
|
||||||
export const BRIDGE_LR = new SimpleTileFactory('bridge', 12, 8, '{tileset}/bridge-lr.svg');
|
export const BRIDGE_LR = new SimpleTileFactory('bridge', 12, 8, '{tileset}/bridge-lr.svg');
|
||||||
|
BRIDGE_LR.add_mask('walkable', Mask.from_string(`
|
||||||
|
............
|
||||||
|
...XXXXXX...
|
||||||
|
XXXXXXXXXXXX
|
||||||
|
XXXXXXXXXXXX
|
||||||
|
XXXXXXXXXXXX
|
||||||
|
XXX......XXX
|
||||||
|
............
|
||||||
|
............
|
||||||
|
`));
|
||||||
const tower_fireball1_back = new SimpleTileFactory('surface', 8, 8, 'tower/fireball1-back.svg');
|
const tower_fireball1_back = new SimpleTileFactory('surface', 8, 8, 'tower/fireball1-back.svg');
|
||||||
const tower_fireball1 = new SimpleTileFactory('surface', 8, 8, 'tower/fireball1.svg');
|
const tower_fireball1 = new SimpleTileFactory('surface', 8, 8, 'tower/fireball1.svg');
|
||||||
const tower_fireball1_front = new SimpleTileFactory('surface', 8, 8, 'tower/fireball1-front.svg');
|
const tower_fireball1_front = new SimpleTileFactory('surface', 8, 8, 'tower/fireball1-front.svg');
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -98,7 +98,7 @@ export function main() {
|
|||||||
tower.play('fire');
|
tower.play('fire');
|
||||||
const target_relative_x = rand(-40, 40);
|
const target_relative_x = rand(-40, 40);
|
||||||
const target_relative_y = rand(-20, 40);
|
const target_relative_y = rand(-20, 40);
|
||||||
const factory = new ProjectileTileFactory(tiles.FIREBALL, target_relative_x, target_relative_y, 5, 1.5, 5);
|
const factory = new ProjectileTileFactory(tiles.FIREBALL, target_relative_x, target_relative_y, 5, 3, 10);
|
||||||
grid.add_tile(factory, 62, 54);
|
grid.add_tile(factory, 62, 54);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
grid.add_tile(tiles.FIREBALL_IMPACT, 62 + target_relative_x, 54 + target_relative_y);
|
grid.add_tile(tiles.FIREBALL_IMPACT, 62 + target_relative_x, 54 + target_relative_y);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
42
ts/mask.ts
Normal file
42
ts/mask.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
export class Mask {
|
||||||
|
mask: boolean[][] = [];
|
||||||
|
|
||||||
|
constructor(width: number, height: number) {
|
||||||
|
for (let x = 0; x < width; x++) {
|
||||||
|
this.mask.push(Array(height).fill(false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static from_string(mask_string: string): Mask {
|
||||||
|
// mask_string: '\n+++\n+++\n'
|
||||||
|
const rows = mask_string.trim().split('\n');
|
||||||
|
// rows: ['+++', '+++']
|
||||||
|
|
||||||
|
const mask = new Mask(rows[0].length, rows.length);
|
||||||
|
|
||||||
|
for (let y = 0; y < rows.length; y++) {
|
||||||
|
const row = rows[y];
|
||||||
|
for (let x = 0; x < row.length; x++) {
|
||||||
|
const cell = row[x].toLowerCase();
|
||||||
|
if (cell == '+' || cell == 'x') {
|
||||||
|
mask.set(x, y, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
set(x: number, y: number, val: boolean) {
|
||||||
|
this.mask[x][y] = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
update(x: number, y: number, src: Mask) {
|
||||||
|
for (let xi = 0; xi < src.mask.length; xi++) {
|
||||||
|
const col = src.mask[xi];
|
||||||
|
for (let yi = 0; yi < col.length; yi++) {
|
||||||
|
this.set(x + xi, y + yi, col[yi]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
10
ts/tiles.ts
10
ts/tiles.ts
@@ -143,6 +143,16 @@ export const RIVER_TR = new SimpleTileFactory('water', 12, 12, '{tileset}/river-
|
|||||||
export const RIVER_TL = new SimpleTileFactory('water', 12, 12, '{tileset}/river-tl.svg');
|
export const RIVER_TL = new SimpleTileFactory('water', 12, 12, '{tileset}/river-tl.svg');
|
||||||
|
|
||||||
export const BRIDGE_LR = new SimpleTileFactory('bridge', 12, 8, '{tileset}/bridge-lr.svg');
|
export const BRIDGE_LR = new SimpleTileFactory('bridge', 12, 8, '{tileset}/bridge-lr.svg');
|
||||||
|
BRIDGE_LR.add_mask('walkable', Mask.from_string(`
|
||||||
|
............
|
||||||
|
...XXXXXX...
|
||||||
|
XXXXXXXXXXXX
|
||||||
|
XXXXXXXXXXXX
|
||||||
|
XXXXXXXXXXXX
|
||||||
|
XXX......XXX
|
||||||
|
............
|
||||||
|
............
|
||||||
|
`));
|
||||||
|
|
||||||
const tower_fireball1_back = new SimpleTileFactory('surface', 8, 8, 'tower/fireball1-back.svg');
|
const tower_fireball1_back = new SimpleTileFactory('surface', 8, 8, 'tower/fireball1-back.svg');
|
||||||
const tower_fireball1 = new SimpleTileFactory('surface', 8, 8, 'tower/fireball1.svg');
|
const tower_fireball1 = new SimpleTileFactory('surface', 8, 8, 'tower/fireball1.svg');
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ export function main() {
|
|||||||
tower.play('fire');
|
tower.play('fire');
|
||||||
const target_relative_x = rand(-40, 40);
|
const target_relative_x = rand(-40, 40);
|
||||||
const target_relative_y = rand(-20, 40);
|
const target_relative_y = rand(-20, 40);
|
||||||
const factory = new ProjectileTileFactory(tiles.FIREBALL, target_relative_x, target_relative_y, 5, 1.5, 5);
|
const factory = new ProjectileTileFactory(tiles.FIREBALL, target_relative_x, target_relative_y, 5, 3, 10);
|
||||||
grid.add_tile(factory, 62, 54);
|
grid.add_tile(factory, 62, 54);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
grid.add_tile(tiles.FIREBALL_IMPACT, 62 + target_relative_x, 54 + target_relative_y);
|
grid.add_tile(tiles.FIREBALL_IMPACT, 62 + target_relative_x, 54 + target_relative_y);
|
||||||
|
|||||||
Reference in New Issue
Block a user