Spaces:
Running
Running
File size: 2,781 Bytes
4ee4376 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
import tile from './tile';
import * as CONST from '../../constants';
export default class edge extends tile {
constructor (options) {
options.type = CONST.T_EDGE;
options.layerDepth = CONST.DEPTH_EDGE;
super(options);
}
check () {
if (!super.check()) return false;
if (this.cell.x != 127 && this.cell.y != 127) return false;
return true;
}
hide (type) {
if (this.sprite.length > 0) {
this.sprite.forEach((sprite) => {
if (!sprite.visible || (type && sprite.subtype != type)) return;
sprite.setVisible(false);
});
}
}
show (type) {
if (this.sprite.length > 0) {
this.sprite.forEach((sprite) => {
if (sprite.visible || (type && sprite.subtype != type)) return;
sprite.setVisible(true);
});
}
}
calculatePosition () {
this.x = this.cell.position.topLeft.x;
this.y = this.cell.position.topLeft.y;
if (this.cell.z < this.cell.scene.city.waterLevel && ([CONST.TERRAIN_SUBMERGED, CONST.TERRAIN_SHORE].includes(this.cell.water.type)))
this.y -= this.cell.position.seaLevel;
}
create () {
this.calculatePosition();
let sprites = [];
let waterDepth = this.cell.scene.city.waterLevel - this.cell.z;
// water
if (this.cell.water.type != CONST.TERRAIN_DRY) {
for (let i = 0; i < waterDepth; i++) {
let offset = Math.abs((CONST.LAYER_OFFSET * i) - this.cell.position.seaLevel);
let sprite = this.cell.scene.add.sprite(this.x, this.y + offset, CONST.TILE_ATLAS).play(this.get(284).image);
sprite.type = this.type;
sprite.subtype = CONST.TERRAIN_WATER;
sprite.cell = this.cell;
sprite.setScale(CONST.SCALE);
sprite.setOrigin(CONST.ORIGIN_X, CONST.ORIGIN_Y);
sprite.setDepth(this.depth.cell + this.depth.layer + this.depth.tile + this.depth.additional + (i * 2));
this.cell.tiles.addSprite(sprite, this.type);
sprites.push(sprite);
}
}
// bedrock
for (let i = 0; i < this.cell.z; i++) {
let offset = CONST.LAYER_OFFSET * (i + 1);
if (this.cell.water.type != CONST.TERRAIN_DRY)
offset = CONST.LAYER_OFFSET * (i + waterDepth + 1);
let sprite = this.cell.scene.add.sprite(this.x, this.y + offset, CONST.TILE_ATLAS, this.get(269).textures[0]);
sprite.type = this.type;
sprite.subtype = CONST.TERRAIN_BEDROCK;
sprite.cell = this.cell;
sprite.setScale(CONST.SCALE);
sprite.setOrigin(CONST.ORIGIN_X, CONST.ORIGIN_Y);
sprite.setDepth(this.depth.cell + this.depth.layer + this.depth.tile + this.depth.additional + (this.cell.z - i * 2) - 32);
this.cell.tiles.addSprite(sprite, this.type);
sprites.push(sprite);
}
this.sprite = sprites;
}
} |