Multiple Autotiles

This commit is contained in:
ckcz123 2017-12-27 16:10:47 +08:00
parent 375c92628c
commit e6eca11ead
10 changed files with 101 additions and 55 deletions

BIN
images/autotile1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
images/autotile2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

BIN
images/autotile3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -210,31 +210,24 @@ core.prototype.loader = function (callback) {
for (var i = 0; i < core.images.length; i++) {
core.loadImage(core.images[i], function (imgName, image) {
core.setStartLoadTipText('正在加载图片 ' + imgName + "...");
imgName = imgName.split('-');
imgName = imgName[0];
core.material.images[imgName] = image;
loadedImageNum++;
core.setStartLoadTipText(imgName + ' 加载完毕...');
core.setStartProgressVal(loadedImageNum * (100 / allImageNum));
if (loadedImageNum == allImageNum) {
// 加载音频
for (var key in core.sounds) {
for (var i = 0; i < core.sounds[key].length; i++) {
var soundName=core.sounds[key][i];
soundName = soundName.split('-');
var sound = new Audio();
sound.preload = 'none';
sound.src = 'sounds/' + soundName[0] + '.' + key;
if (soundName[1] == 'loop') {
sound.loop = 'loop';
// 加载Autotile
core.material.images.autotile={};
var autotileIds = Object.keys(core.material.icons.autotile);
for (var x=0;x<autotileIds.length;x++) {
core.loadImage(autotileIds[x], function (autotileId, image) {
core.material.images.autotile[autotileId]=image;
if (Object.keys(core.material.images.autotile).length==autotileIds.length) {
// 音频
core.loadSounds(callback);
}
if (!core.isset(core.material.sounds[key]))
core.material.sounds[key] = {};
core.material.sounds[key][soundName[0]] = sound;
}
})
}
callback();
}
});
}
@ -258,6 +251,26 @@ core.prototype.loadImage = function (imgName, callback) {
}
}
core.prototype.loadSounds = function (callback) {
for (var key in core.sounds) {
for (var i = 0; i < core.sounds[key].length; i++) {
var soundName=core.sounds[key][i];
soundName = soundName.split('-');
var sound = new Audio();
sound.preload = 'none';
sound.src = 'sounds/' + soundName[0] + '.' + key;
if (soundName[1] == 'loop') {
sound.loop = 'loop';
}
if (!core.isset(core.material.sounds[key]))
core.material.sounds[key] = {};
core.material.sounds[key][soundName[0]] = sound;
}
}
callback();
}
core.prototype.loadSound = function() {
if (!core.isset(core.material.sounds.mp3)) return;
if (core.musicStatus.isIOS) return;
@ -444,14 +457,6 @@ core.prototype.keyDown = function(keyCode) {
core.events.keyDownSyncSave(keyCode);
return;
}
/*
if (core.status.event.id == 'save' || core.status.event.id == 'load') {
if (keyCode==37) core.ui.drawSLPanel(core.status.event.data-1);
else if (keyCode==39) core.ui.drawSLPanel(core.status.event.data+1);
return;
}
*/
return;
}
if(!core.status.played) {
@ -1774,7 +1779,7 @@ core.prototype.drawMap = function (mapName, callback) {
if (core.isset(block.event) && !(core.isset(block.enable) && !block.enable)) {
if (block.event.cls == 'autotile') {
// core.drawAutotile();
autotileMaps[13*block.x + block.y] = true;
autotileMaps[13*block.x + block.y] = block.event.id;
continue;
}
else {
@ -1792,17 +1797,29 @@ core.prototype.drawMap = function (mapName, callback) {
callback();
}
core.prototype.drawAutotile = function (floorId, canvas, autotileMaps, left, top, size) {
core.prototype.drawAutotile = function (floorId, canvas, autotileMaps, left, top, size, autotileId) {
if (!core.isset(autotileId)) {
var autotileIds = {};
autotileMaps.forEach(function (t) {
if (core.isset(t)) autotileIds[t]=true;
});
Object.keys(autotileIds).forEach(function (t) {
core.drawAutotile(floorId, canvas, autotileMaps, left, top, size, t);
})
return;
}
var isAutotile = function(x, y) {
if (x<0 || x>12 || y<0 || y>12) return 0;
return autotileMaps[13*x+y]?1:0;
return autotileMaps[13*x+y]==autotileId?1:0;
}
for (var xx=0;xx<13;xx++) {
for (var yy=0;yy<13;yy++) {
if (isAutotile(xx, yy)) {
// 绘制autotile
var id=isAutotile(xx, yy - 1) + 2 * isAutotile(xx - 1, yy) + 4 * isAutotile(xx, yy + 1) + 8 * isAutotile(xx + 1, yy);
core.drawAutotileBlock(floorId, canvas, left + xx * size, top + yy * size, size, core.material.images.autotile, id);
core.drawAutotileBlock(floorId, canvas, left + xx * size, top + yy * size, size, core.material.images.autotile[autotileId], id);
}
}
}
@ -1810,16 +1827,16 @@ core.prototype.drawAutotile = function (floorId, canvas, autotileMaps, left, top
for (var yy=0;yy<13;yy++) {
if (isAutotile(xx, yy) + isAutotile(xx + 1, yy) + isAutotile(xx + 1, yy + 1) + isAutotile(xx, yy + 1) != 3) continue;
if (!isAutotile(xx, yy)) {
core.drawAutotileBlock(floorId, canvas, left + xx * size + size, top + yy * size + size, size, core.material.images.autotile, 16);
core.drawAutotileBlock(floorId, canvas, left + xx * size + size, top + yy * size + size, size, core.material.images.autotile[autotileId], 16);
}
if (!isAutotile(xx + 1, yy)) {
core.drawAutotileBlock(floorId, canvas, left + xx * size + size / 2, top + yy * size + size, size, core.material.images.autotile, 17);
core.drawAutotileBlock(floorId, canvas, left + xx * size + size / 2, top + yy * size + size, size, core.material.images.autotile[autotileId], 17);
}
if (!isAutotile(xx + 1, yy + 1)) {
core.drawAutotileBlock(floorId, canvas, left + xx * size + size / 2, top + yy * size + size / 2, size, core.material.images.autotile, 18);
core.drawAutotileBlock(floorId, canvas, left + xx * size + size / 2, top + yy * size + size / 2, size, core.material.images.autotile[autotileId], 18);
}
if (!isAutotile(xx, yy + 1)) {
core.drawAutotileBlock(floorId, canvas, left + xx * size + size, top + yy * size + size / 2, size, core.material.images.autotile, 19);
core.drawAutotileBlock(floorId, canvas, left + xx * size + size, top + yy * size + size / 2, size, core.material.images.autotile[autotileId], 19);
}
}
}

View File

@ -9,19 +9,19 @@ main.floors.sample1 = {
"canUseQuickShop": true, // 该层是否允许使用快捷商店
"defaultGround": "grass", // 默认地面的图块IDterrains中
"map": [ // 地图数据需要是13x13建议使用地图生成器来生成
[7, 131, 8, 2, 9, 130, 10, 2, 166, 165, 132, 165, 166],
[0, 0, 0, 0, 0, 0, 0, 2, 165, 164, 0, 162, 165],
[2, 2, 2, 2, 121, 2, 2, 2, 0, 0, 229, 0, 0],
[43, 33, 44, 1, 0, 0, 0, 2, 165, 161, 0, 163, 165],
[21, 22, 21, 1, 0, 0, 0, 2, 166, 165, 0, 165, 166],
[1, 245, 1, 1, 0, 87, 0, 2, 2, 2, 85, 2, 2],
[0, 246, 0, 1, 0, 0, 0, 2, 2, 221, 0, 221, 2],
[246, 0, 246, 1, 0, 0, 0, 121, 85, 0, 0, 0, 2],
[1, 246, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2],
[7, 131, 8, 152, 9, 130, 10, 152, 166, 165, 132, 165, 166],
[0, 0, 0, 0, 0, 0, 0, 152, 165, 164, 0, 162, 165],
[152, 152, 152, 152, 121, 152, 152, 152, 0, 0, 229, 0, 0],
[43, 33, 44, 151, 0, 0, 0, 152, 165, 161, 0, 163, 165],
[21, 22, 21, 151, 0, 0, 0, 152, 166, 165, 0, 165, 166],
[151, 245, 151, 151, 0, 87, 0, 152, 152, 152, 85, 153, 153],
[0, 246, 0, 151, 0, 0, 0, 152, 152, 221, 0, 221, 153],
[246, 0, 246, 151, 0, 0, 0, 121, 85, 0, 0, 0, 153],
[151, 246, 151, 151, 0, 153, 153, 153, 153, 153, 153, 153, 153],
[0, 0, 0, 0, 0, 0, 0, 164, 0, 0, 163, 0, 0],
[1, 1, 1, 1, 0, 3, 0, 0, 0, 162, 0, 161, 0],
[1, 0, 123, 1, 0, 3, 124, 0, 121, 0, 122, 0, 126],
[1, 0, 0, 1, 88, 3, 86, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 0, 20, 0, 0, 0, 162, 0, 161, 0],
[1, 0, 123, 1, 0, 20, 124, 0, 121, 0, 122, 0, 126],
[1, 0, 0, 1, 88, 20, 86, 0, 0, 0, 0, 0, 0],
],
"firstArrive": [ // 第一次到该楼层触发的事件

View File

@ -7,7 +7,7 @@ main.floors.sample2 = {
"name": 40, // 显示在状态栏中的层数
"canFlyTo": false, // 该楼能否被楼传器飞到(不能的话在该楼也不允许使用楼传器)
"canUseQuickShop": true, // 该层是否允许使用快捷商店
"defaultGround": "soil", // 默认地面的图块IDterrains中
"defaultGround": "snowGround", // 默认地面的图块IDterrains中
"map": [ // 地图数据需要是13x13建议使用地图生成器来生成
[5, 5, 5, 5, 5, 5, 87, 5, 5, 5, 5, 5, 5],
[5, 4, 4, 4, 4, 1, 0, 1, 4, 4, 4, 4, 5],

View File

@ -209,6 +209,12 @@ icons.prototype.init = function () {
'moneyPocket': 46,
'shoes': 47,
'hammer': 48
},
'autotile': { // 所有的Autotile列表后面的index简单取0即可
'autotile': 0,
'autotile1': 0,
'autotile2': 0,
'autotile3': 0,
}
}
}

View File

@ -61,6 +61,8 @@ maps.prototype.getBlock = function (x, y, id) {
var tmp = {'x': x, 'y': y, 'id': id};
if (enable!=null) tmp.enable = enable;
////////////////////////// 地形部分 //////////////////////////
// 0-20 地形
if (id == 1) tmp.event = {'cls': 'terrains', 'id': 'yellowWall'}; // 黄墙
if (id == 2) tmp.event = {'cls': 'terrains', 'id': 'whiteWall'}; // 白墙
@ -77,13 +79,19 @@ maps.prototype.getBlock = function (x, y, id) {
if (id == 13) tmp.event = {'cls': 'animates', 'id': 'weakNet', 'noPass': false, 'trigger': 'passNet'}; // 衰网
if (id == 14) tmp.event = {'cls': 'animates', 'id': 'curseNet', 'noPass': false, 'trigger': 'passNet'}; // 咒网
if (id == 15) tmp.event = {'cls': 'animates', 'id': 'water', 'noPass': true}; // 水
// 在这里添加更多地形
// 如果空地不足可以从180以后开始继续放只要不和现有的数字冲突即可
// autotile: 20
// Autotile
if (id == 20) tmp.event = {'cls': 'autotile', 'id': 'autotile', 'noPass': true}; // autotile
// 更多的autotile从350继续放
// 更多的autotile从151到160只要不和现有的数字冲突即可
if (id == 151) tmp.event = {'cls': 'autotile', 'id': 'autotile1', 'noPass': true};
if (id == 152) tmp.event = {'cls': 'autotile', 'id': 'autotile2', 'noPass': true};
if (id == 153) tmp.event = {'cls': 'autotile', 'id': 'autotile3', 'noPass': true};
////////////////////////// 物品部分 //////////////////////////
// 21-80 物品
if (id == 21) tmp.event = {'cls': 'items', 'id': 'yellowKey'}; // 黄钥匙
if (id == 22) tmp.event = {'cls': 'items', 'id': 'blueKey'}; // 蓝钥匙
@ -131,6 +139,9 @@ maps.prototype.getBlock = function (x, y, id) {
if (id == 64) tmp.event = {'cls': 'items', 'id': 'shoes'} // 绿鞋
if (id == 65) tmp.event = {'cls': 'items', 'id': 'hammer'} // 圣锤
////////////////////////// 门、楼梯、传送点部分 //////////////////////////
// 81-100 门
if (id == 81) tmp.event = {'cls': 'terrains', 'id': 'yellowDoor', 'trigger': 'openDoor'}; // 黄门
if (id == 82) tmp.event = {'cls': 'terrains', 'id': 'blueDoor', 'trigger': 'openDoor'}; // 蓝门
@ -148,6 +159,8 @@ maps.prototype.getBlock = function (x, y, id) {
if (id == 94) tmp.event = {'cls': 'animates', 'id': 'rightPortal', 'noPass': false}; // 右箭头
////////////////////////// NPC部分 //////////////////////////
// 121-150 NPC
if (id == 121) tmp.event = {'cls': 'npcs', 'id': 'man'};
if (id == 122) tmp.event = {'cls': 'npcs', 'id': 'woman'};
@ -162,6 +175,8 @@ maps.prototype.getBlock = function (x, y, id) {
if (id == 131) tmp.event = {'cls': 'npcs', 'id': 'blueShop'};
if (id == 132) tmp.event = {'cls': 'npcs', 'id': 'princess'};
////////////////////////// 其他部分 //////////////////////////
// 161-200 其他(单向箭头、灯、箱子等等)
if (id == 161) tmp.event = {'cls': 'terrains', 'id': 'arrowUp', 'noPass': false}; // 单向上箭头
if (id == 162) tmp.event = {'cls': 'terrains', 'id': 'arrowDown', 'noPass': false}; // 单向下箭头
@ -170,6 +185,9 @@ maps.prototype.getBlock = function (x, y, id) {
if (id == 165) tmp.event = {'cls': 'terrains', 'id': 'light', 'trigger': 'changeLight', 'noPass': false}; // 灯
if (id == 166) tmp.event = {'cls': 'terrains', 'id': 'darkLight', 'noPass': true}; // 暗灯
////////////////////////// 怪物部分 //////////////////////////
// 201-300 怪物
if (id == 201) tmp.event = {'cls': 'enemys', 'id': 'greenSlime'};
if (id == 202) tmp.event = {'cls': 'enemys', 'id': 'redSlime'};
@ -232,6 +250,9 @@ maps.prototype.getBlock = function (x, y, id) {
if (id == 259) tmp.event = {'cls': 'enemys', 'id': 'darkFairy'};
if (id == 260) tmp.event = {'cls': 'enemys', 'id': 'greenKnight'};
////////////////////////// 待定... //////////////////////////
// 目前ID暂时不要超过400
return tmp;
}

View File

@ -1044,7 +1044,7 @@ ui.prototype.drawThumbnail = function(floorId, canvas, blocks, x, y, size, heroL
if (core.isset(block.event) && !(core.isset(block.enable) && !block.enable)) {
if (block.event.cls == 'autotile') {
// core.drawAutotile();
autotileMaps[13*block.x + block.y] = true;
autotileMaps[13*block.x + block.y] = block.event.id;
continue;
}
else {

10
main.js
View File

@ -33,14 +33,12 @@ function main() {
'mdefCol': document.getElementById('mdefCol'),
'expCol': document.getElementById('expCol'),
};
// console.log('加载游戏容器和开始界面dom对象完成 如下');
// console.log(this.dom);
this.loadList = [
'items', 'icons', 'maps', 'enemys', 'events', 'data', 'ui', 'core'
];
// console.log('加载js文件列表加载完成' + this.loadList);
this.images = [
'animates', 'enemys', 'hero', 'items', 'npcs', 'terrains', "autotile"
'animates', 'enemys', 'hero', 'items', 'npcs', 'terrains'
// Autotile 动态添加
];
this.sounds = {
'mp3': ['bgm-loop', 'floor'],
@ -78,6 +76,8 @@ function main() {
'curse': document.getElementById('curse'),
'hard': document.getElementById("hard")
}
//------------------------ 用户修改内容 ------------------------//
this.version = "0.1"; // 游戏版本号如果更改了游戏内容建议修改此version以免造成缓存问题。
this.useCompress = false; // 是否使用压缩文件
@ -88,6 +88,8 @@ function main() {
this.floorIds = [ // 在这里按顺序放所有的楼层;其顺序直接影响到楼层传送器的顺序和上楼器/下楼器的顺序
"sample0", "sample1", "sample2"
]
//------------------------ 用户修改内容 END ------------------------//
this.floors = {}
this.instance = {};
this.canvas = {};