怪物绑定贴图

This commit is contained in:
ckcz123 2021-08-09 12:56:53 +08:00
parent 7e131be145
commit 9dec925995
5 changed files with 72 additions and 14 deletions

View File

@ -617,7 +617,7 @@ table.row {
}
.etable tr > :nth-child(1) {
width: 20%
width: 22%
}
.etable tr > :nth-child(2) {
@ -625,7 +625,7 @@ table.row {
}
.etable tr > :nth-child(3) {
width: 35%;
width: 33%;
}
.etable tr > :nth-child(4) {

View File

@ -139,9 +139,24 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = {
"_leaf": true,
"_type": "event",
"_event": "faceIds",
"_docs": "行走朝向",
"_docs": "行走朝向",
"_data": "行走图朝向。在勇士撞上图块时,或图块在移动时,会自动选择最合适的朝向图块(如果存在定义)来进行绘制。"
},
"bigImage": {
"_leaf": true,
"_type": "material",
"_directory": "./project/images/",
"_transform": (function (one) {
if (one.endsWith('.png')) return one;
return null;
}).toString(),
"_onconfirm": (function (previous, current) {
if (current.length == 0) return null;
return current[0];
}).toString(),
"_docs": "绑定贴图",
"_data": "该怪物绑定的怪物贴图"
},
"hp": {
"_leaf": true,
"_type": "textarea",

View File

@ -2869,8 +2869,7 @@ control.prototype.checkBgm = function() {
control.prototype.setDisplayScale = function (delta) {
var index = core.domStyle.availableScale.indexOf(core.domStyle.scale);
if (index < 0) return;
index += delta;
if (index < 0 || index >= core.domStyle.availableScale.length) return;
index = (index + delta + core.domStyle.availableScale.length) % core.domStyle.availableScale.length;
core.domStyle.scale = core.domStyle.availableScale[index];
core.setLocalStorage('scale', core.domStyle.scale);
core.resize();

View File

@ -978,7 +978,7 @@ maps.prototype.drawBlock = function (block, animate, ctx) {
var blockInfo = this.getBlockInfo(block);
if (blockInfo == null) return;
if (blockInfo.cls != 'tileset') blockInfo.posX = animate % block.event.animate;
if (blockInfo.cls != 'tileset') blockInfo.posX = animate % blockInfo.animate;
blockInfo.opacity = block.opacity;
blockInfo.filter = block.filter;
if (!block.name)
@ -987,7 +987,46 @@ maps.prototype.drawBlock = function (block, animate, ctx) {
this._drawBlockInfo_bgfg(blockInfo, block.name, block.x, block.y, ctx);
}
maps.prototype._drawBlockInfo_bigImage = function (blockInfo, x, y) {
var face = blockInfo.face || "down";
if (["up", "down", "left", "right"].indexOf(face) < 0) face = "down";
var bigImage = blockInfo.bigImage;
var per_width = bigImage.width / 4;
var per_height = bigImage.height / 4;
if (face == 'down' && per_height < per_width / 2) { // 强制视为 1*4 的怪物
per_height = bigImage.height;
}
var sx = blockInfo.posX * per_width;
var sy = core.material.icons.hero[face].loc * per_height;
// 上半部分 - 会遮挡勇士z值高于event2为51
var header = "_bigImage_header_" + x + "_" + y;
// 下半部分 - 会被勇士遮挡z值高于event为31
var body = "_bigImage_body_" + x + "_" + y;
var px = 32 * x - core.bigmap.offsetX;
var py = 32 * y - core.bigmap.offsetY;
switch (face) {
case "down":
var dx = px + 16 - per_width / 2;
var dy = py + 32 - per_height;
core.createCanvas(header, dx, dy, per_width, per_height - 32, 51);
core.drawImage(header, bigImage, sx, sy, per_width, per_height - 32, 0, 0, per_width, per_height - 32);
core.createCanvas(body, dx, dy + per_height - 32, per_width, 32, 31);
core.drawImage(body, bigImage, sx, sy + per_height - 32, per_width, 32, 0, 0, per_width, 32);
break;
case "left":
core.createCanvas(header, px, py + 16 - per_height / 2, per_width, per_height / 2 - 16, 51);
core.drawImage(header, bigImage, sx, sy, per_width, per_height / 2 - 16, 0, 0, per_width, per_height / 2 - 16);
core.createCanvas(body, px, py, per_width, per_height / 2 + 16, 31);
core.drawImage(body, bigImage, sx, sy + per_height / 2 - 16, per_width, per_height / 2 + 16, 0, 0, per_width, per_height / 2 + 16);
break;
}
}
maps.prototype._drawBlockInfo = function (blockInfo, x, y, ctx) {
if (blockInfo.bigImage) return this._drawBlockInfo_bigImage(blockInfo, x, y);
var image = blockInfo.image, posX = blockInfo.posX, posY = blockInfo.posY, height = blockInfo.height;
var px = 32 * x - 32 * core.bigmap.posX;
var py = 32 * y - 32 * core.bigmap.posY;
@ -1825,7 +1864,7 @@ maps.prototype.getBlockInfo = function (block) {
}
var number = block.id, id = block.event.id, cls = block.event.cls, name = block.event.name,
image = null, posX = 0, posY = 0, animate = block.event.animate,
height = block.event.height || 32, faceIds = {};
height = block.event.height || 32, faceIds = {}, face = 'down', bigImage = null;
if (id == 'none') return null;
else if (id == 'airwall') {
@ -1847,14 +1886,23 @@ maps.prototype.getBlockInfo = function (block) {
image = core.material.images[cls];
posY = core.material.icons[cls][id];
faceIds = block.event.faceIds || {};
for (var f in faceIds) {
if (faceIds[f] == id) {
face = f;
break;
}
}
if (core.material.enemys[id]) {
name = core.material.enemys[id].name;
bigImage = core.material.images.images[core.material.enemys[id].bigImage] || null;
if (bigImage != null) animate = 4;
} else if (core.material.items[id]) {
name = core.material.items[id].name;
}
}
return {number: number, id: id, cls: cls, name: name, image: image, posX: posX, posY: posY, height: height, faceIds: faceIds, animate: animate};
return {number: number, id: id, cls: cls, name: name, image: image, posX: posX,
posY: posY, height: height, faceIds: faceIds, animate: animate, face: face, bigImage: bigImage};
}
////// 搜索某个图块出现的所有位置 //////

View File

@ -377,12 +377,8 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
document.getElementById('gameDraw').appendChild(canvas);
var ctx = canvas.getContext('2d');
core.canvas[name] = ctx;
if (core.domStyle.hdCanvas.indexOf('name') >= 0)
core.maps._setHDCanvasSize(ctx, core.__PIXELS__, core.__PIXELS__);
else {
canvas.width = core.__PIXELS__;
canvas.height = core.__PIXELS__;
}
canvas.width = core.__PIXELS__;
canvas.height = core.__PIXELS__;
return canvas;
}