This commit is contained in:
ckcz123 2017-12-31 22:31:55 +08:00
commit bd1ad3916a
10 changed files with 111 additions and 159 deletions

View File

@ -1,5 +1,7 @@
# 附录:API列表
?> 上次更新时间:* {docsify-updated} *
所有系统支持的API都列在了这里。所有可能被用到的API都在前面用\*标记。
可以在chrome浏览器的控制台中`ctrl+shift+I`找到Console中直接进行调用以查看效果。

View File

@ -1,5 +1,7 @@
# 元件说明
?> 上次更新时间:* {docsify-updated} *
在本章中,将对样板里的各个元件进行说明。各个元件主要包括道具、门、怪物、楼梯等等。
请打开样板0层 `sample0.js` 进行参照对比。
@ -30,7 +32,7 @@
## 怪物
本塔支持的怪物列表参见`enemys.js`。其与images目录下的`enemys.png`素材按顺序一一对应。如不知道怪物素材长啥样的请打开`enemys.png`对比查看。
本塔支持的怪物列表参见`enemys.js`。其与images目录下的`enemys.png`素材按顺序一一对应。如不知道怪物素材长啥样的请打开`enemys.png`对比查看。
如有自己的怪物素材需求请参见[自定义素材](personalization#自定义素材)的内容。
怪物可以有特殊属性,每个怪物可以有多个自定义属性。
@ -70,6 +72,7 @@ enemys.prototype.getSpecialText = function (enemyId) {
多属性可采用数组的写法,比如`'special': [1,3]`视为同时拥有先攻和坚固属性;`'special': [5,10,14,18]`视为拥有3连击、魔防、诅咒、阻击四个属性。
本塔支持战斗动画,在`data.js`中存在三个全局选项:`canOpenBattleAnimate`, `showBattleAnimateConfirm`, `battleAnimate`
- `canOpenBattleAnimate`代表是否允许用户开启战斗动画。如果你添加了一些自定义属性且不想修改战斗界面的UI则可以将其关闭。
- `showBattleAnimateConfirm`代表是否在游戏开始时给用户提供开启动画的选项。对于一些偏向于萌新的塔,可以开启此项。
- `battleAnimate`代表是否默认开启战斗动画。此项会被用户存储的设置给覆盖。
@ -117,7 +120,7 @@ N连击怪物的special是6且我们可以为它定义n代表实际连击数
如有额外需求,可参见[自定义怪物属性](personalization#自定义自定义怪物属性),里面讲了如何设置一个新的怪物属性。
### 路障,楼梯,传送门
## 路障、楼梯、传送门
血网的伤害数值、中毒后每步伤害数值、衰弱时暂时攻防下降的数值,都在 `data.js` 的values内定义。
@ -169,6 +172,7 @@ this.sounds = [ // 在此存放所有的SE和文件名一致
定义完毕后,我们可以调用`playBgm`/`playSound`事件来播放对应的音乐/音效,有关事件的详细介绍请参见[事件](event)。
**另外,考虑到用户的流量问题,将遵循如下规则:**
- **如果用户当前使用的电脑则默认开启音乐效果并播放默认BGM**
- **如果用户当前使用的手机且处于Wifi状态则默认开启音乐效果并播放默认BGM**
- **其他情况,将默认关闭音乐效果,只有在用户在菜单栏中点击“音乐开关”后才会播放音乐**
@ -180,6 +184,7 @@ this.sounds = [ // 在此存放所有的SE和文件名一致
本塔主要支持鼠标(触摸屏)操作和键盘操作。
鼠标(触摸屏)操作说明如下:
- **点状态栏中图标:** 进行对应的操作
- **点任意块:** 寻路并移动
- **点任意块并拖动:** 指定寻路路线
@ -187,6 +192,7 @@ this.sounds = [ // 在此存放所有的SE和文件名一致
- **双击勇士:** 轻按(仅在轻按开关打开时有效)
键盘操作快捷键如下:
- **[CTRL]** 跳过对话
- **[X]** 打开/关闭怪物手册
- **[G]** 打开/关闭楼层传送器
@ -213,4 +219,3 @@ this.sounds = [ // 在此存放所有的SE和文件名一致
==========================================================================================
[继续阅读下一章:事件](event)

View File

@ -1,5 +1,7 @@
# 事件
?> 上次更新时间:* {docsify-updated} *
本章内将对样板所支持的事件进行介绍。
## 事件的机制

View File

@ -19,7 +19,7 @@
repo: 'https://github.com/ckcz123/mota-js',
// basepath: '../docs/',
// Search Support
// Search Support
// search: {
// maxAge: 43200000, // 过期时间,单位毫秒,默认一天
// paths: 'auto',
@ -37,6 +37,9 @@
loadSidebar: '_sidebar.md',
subMaxLevel: 2,
autoHeader: true,
auto2top: true,
mergeNavbar: true,
formatUpdated: '{YYYY}-{MM}-{DD} {HH}:{mm}:{ss}',
}
//离线模式
if (typeof navigator.serviceWorker !== 'undefined') {

View File

@ -1,5 +1,7 @@
# HTML5 魔塔样板说明文档
?> 上次更新时间:* {docsify-updated} *
众所周知魔塔的趋势是向移动端发展贴吧中也常常能见到“求手机魔塔”的帖子。然而现有的工具中NekoRPG有着比较大的局限性游戏感较差更是完全没法在iOS上运行。而一些APP的魔塔虽然可用但是必须要下载安装对于Android和iOS还必须开发不同的版本非常麻烦。
但是现在我们有了HTML5。 HTML5的画布canvas以及它被Android/iOS内置浏览器所支持的特性可以让我们做出真正意义上的全平台覆盖的魔塔。
@ -11,7 +13,7 @@
继续查看文档的详细介绍让你学会如何使用这一个样板来制作属于自己的HTML5魔塔。
视频教程地址http://www.bilibili.com/video/av17608025/ ,配合本教程观看效果更佳~
视频教程地址:[http://www.bilibili.com/video/av17608025/](http://www.bilibili.com/video/av17608025/) ,配合本教程观看效果更佳~
==========================================================================================

View File

@ -1,5 +1,7 @@
# 个性化
?> 上次更新时间:* {docsify-updated} *
有时候只靠样板本身可能是不够的。我们需要一些个性化、自定义的素材,道具效果,怪物属性,等等。
## 自定义素材

View File

@ -1,5 +1,7 @@
# 快速上手
?> 上次更新时间:* {docsify-updated} *
在这一节中,将详细介绍做一部塔的流程。现在,让我们来做一部单层塔!
## 前置需求
@ -8,8 +10,8 @@
- Windows 8以上操作系统Windows 7需要安装.Net Framework 4.0。(能打开同目录下的“启动服务.exe”即可
- 任一款现代浏览器。强烈推荐Chrome。
- 一个很好的文本编辑器。推荐带有高亮染色、错误提示等效果。例如WebStormVSCode或者至少也要Sublime Text。
[VSCode下载地址](https://code.visualstudio.com/),群里的群文件中也有,强烈推荐之。)
- 一个很好的文本编辑器。推荐带有高亮染色、错误提示等效果。例如WebStormVSCode或者至少也要Sublime Text。
- [VSCode下载地址](https://code.visualstudio.com/),群里的群文件中也有,强烈推荐之。)
只要满足了上述条件,你就可以开始做自己的塔啦!

View File

@ -2013,168 +2013,107 @@ core.prototype.drawMap = function (mapName, callback) {
core.canvas.bg.drawImage(blockImage, 0, blockIcon * 32, 32, 32, x * 32, y * 32, 32, 32);
}
}
// 如果存在png
if (core.isset(core.floors[mapName].png)) {
var png = core.floors[mapName].png;
if (core.isset(core.material.images.pngs[png])) {
core.canvas.bg.drawImage(core.material.images.pngs[png], 0, 0, 416, 416);
}
}
var autotileMaps = [];
var mapArr = core.maps.getMapArr(mapName);
for (var b = 0; b < mapBlocks.length; b++) {
// 事件启用
var block = mapBlocks[b];
if (core.isset(block.event) && !(core.isset(block.enable) && !block.enable)) {
if (block.event.cls == 'autotile') {
// core.drawAutotile();
autotileMaps[13*block.x + block.y] = block.event.id;
core.drawAutotile(core.canvas.event, mapArr, block, 32);
continue;
}
else {
if (block.event.id!='none') {
blockIcon = core.material.icons[block.event.cls][block.event.id];
blockImage = core.material.images[block.event.cls];
core.canvas.event.drawImage(core.material.images[block.event.cls], 0, blockIcon * 32, 32, 32, block.x * 32, block.y * 32, 32, 32);
core.addGlobalAnimate(block.event.animate, block.x * 32, block.y * 32, blockIcon, blockImage);
}
blockIcon = core.material.icons[block.event.cls][block.event.id];
blockImage = core.material.images[block.event.cls];
core.canvas.event.drawImage(core.material.images[block.event.cls], 0, blockIcon * 32, 32, 32, block.x * 32, block.y * 32, 32, 32);
core.addGlobalAnimate(block.event.animate, block.x * 32, block.y * 32, blockIcon, blockImage);
}
}
}
core.drawAutotile(mapName, 'event', autotileMaps, 0, 0, 32);
core.setGlobalAnimate(core.values.animateSpeed);
if (core.isset(callback))
callback();
}
////// 绘制Autotile //////
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;
core.prototype.drawAutotile = function(ctx, mapArr, block, size, left, top){
var indexArrs = [ //16种组合的图块索引数组; // 将autotile分割成48块16*16的小块; 数组索引即对应各个小块
// +----+----+----+----+----+----+
[10, 9, 4, 3 ], //0 bin:0000 | 1 | 2 | 3 | 4 | 5 | 6 |
[10, 9, 4, 13], //1 bin:0001 +----+----+----+----+----+----+
[10, 9, 18, 3 ], //2 bin:0010 | 7 | 8 | 9 | 10 | 11 | 12 |
[10, 9, 16, 15], //3 bin:0011 +----+----+----+----+----+----+
[10, 43, 4, 3 ], //4 bin:0100 | 13 | 14 | 15 | 16 | 17 | 18 |
[10, 31, 4, 25], //5 bin:0101 +----+----+----+----+----+----+
[10, 7, 2, 3 ], //6 bin:0110 | 19 | 20 | 21 | 22 | 23 | 24 |
[10, 31, 16, 5 ], //7 bin:0111 +----+----+----+----+----+----+
[48, 9, 4, 3 ], //8 bin:1000 | 25 | 26 | 27 | 28 | 29 | 30 |
[ 8, 9, 4, 1 ], //9 bin:1001 +----+----+----+----+----+----+
[36, 9, 30, 3 ], //10 bin:1010 | 31 | 32 | 33 | 34 | 35 | 36 |
[36, 9, 6, 15], //11 bin:1011 +----+----+----+----+----+----+
[46, 45, 4, 3 ], //12 bin:1100 | 37 | 38 | 39 | 40 | 41 | 42 |
[46, 11, 4, 25], //13 bin:1101 +----+----+----+----+----+----+
[12, 45, 30, 3 ], //14 bin:1110 | 43 | 44 | 45 | 46 | 47 | 48 |
[34, 33, 28, 27] //15 bin:1111 +----+----+----+----+----+----+
];
var drawBlockByIndex = function(ctx, dx, dy, autotileImg, index, size){ //index为autotile的图块索引1-48
var sx = 16*((index-1)%6), sy = 16*(~~((index-1)/6));
ctx.drawImage(autotileImg, sx, sy, 16, 16, dx, dy, size/2, size/2);
}
var isAutotile = function(x, y) {
if (x<0 || x>12 || y<0 || y>12) return 1;
return autotileMaps[13*x+y]==autotileId?1:0;
var getAutotileAroundId = function(currId, x, y){
if(x<0 || y<0 || x>12 || y>12) return 1;
else return mapArr[y][x]==currId ? 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[autotileId], id);
var checkAround = function(x, y){ // 得到周围四个32*32块周围每块都包含当前块的1/4不清楚的话画下图你就明白的数组索引
var currId = mapArr[y][x];
var pointBlock = [];
for(var i=0; i<4; i++){
var bsum = 0;
var offsetx = i%2, offsety = ~~(i/2);
for(var j=0; j<4; j++){
var mx = j%2, my = ~~(j/2);
var b = getAutotileAroundId(currId, x+offsetx+mx-1, y+offsety+my-1);
bsum += b*(Math.pow(2, 3-j));
}
pointBlock.push(bsum);
}
return pointBlock;
}
for (var xx=0;xx<13;xx++) {
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[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[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[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[autotileId], 19);
}
var getAutotileIndexs = function(x, y){
var indexArr = [];
var pointBlocks = checkAround(x, y);
for(var i=0; i<4; i++){
var arr = indexArrs[pointBlocks[i]]
indexArr.push(arr[3-i]);
}
return indexArr;
}
}
// 开始绘制autotile
var top = core.isset(top)? top : 0, left = core.isset(left) ? left : 0;
var x = block.x, y = block.y;
var pieceIndexs = getAutotileIndexs(x, y);
ctx.clearRect(x*size+left, y*size+top, size, size);
////// 绘制Autotile的某一块 //////
core.prototype.drawAutotileBlock = function (floorId, map, x, y, size, autotile, index) {
var canvas = core.canvas[map];
var groundId = core.floors[floorId].defaultGround || "ground";
var blockIcon = core.material.icons.terrains[groundId];
var blockImage = core.material.images.terrains;
switch (index) {
case 0:
canvas.drawImage(autotile, 0, 0, 32, 32, x, y, size, size);
break;
case 1:
canvas.drawImage(autotile, 0, 3 * 32, 16, 32, x, y, size / 2, size);
canvas.drawImage(autotile, 2 * 32 + 16, 3 * 32, 16, 32, x + size / 2, y, size / 2, size);
break;
case 2:
canvas.drawImage(autotile, 2 * 32, 32, 32, 16, x, y, size, size / 2);
canvas.drawImage(autotile, 2 * 32, 3 * 32 + 16, 32, 16, x, y + size / 2, size, size / 2);
break;
case 3:
canvas.drawImage(autotile, 2 * 32, 3 * 32, 32, 32, x, y, size, size);
break;
case 4:
canvas.drawImage(autotile, 0, 1 * 32, 16, 32, x, y, size / 2, size);
canvas.drawImage(autotile, 2 * 32 + 16, 1 * 32, 16, 32, x + size / 2, y, size / 2, size);
break;
case 5:
canvas.drawImage(autotile, 0, 2 * 32, 16, 32, x, y, size / 2, size);
canvas.drawImage(autotile, 2 * 32 + 16, 2 * 32, 16, 32, x + size / 2, y, size / 2, size);
break;
case 6:
canvas.drawImage(autotile, 2 * 32, 1 * 32, 32, 32, x, y, size, size);
break;
case 7:
canvas.drawImage(autotile, 2 * 32, 2 * 32, 32, 32, x, y, size, size);
break;
case 8:
canvas.drawImage(autotile, 0, 32, 32, 16, x, y, size, size / 2);
canvas.drawImage(autotile, 0, 3 * 32 + 16, 32, 16, x, y + size / 2, size, size / 2);
break;
case 9:
canvas.drawImage(autotile, 0, 3 * 32, 32, 32, x, y, size, size);
break;
case 10:
canvas.drawImage(autotile, 32, 32, 32, 16, x, y, size, size / 2);
canvas.drawImage(autotile, 32, 3 * 32 + 16, 32, 16, x, y + size / 2, size, size / 2);
break;
case 11:
canvas.drawImage(autotile, 32, 3 * 32, 32, 32, x, y, size, size);
break;
case 12:
canvas.drawImage(autotile, 0, 32, 32, 32, x, y, size, size);
break;
case 13:
canvas.drawImage(autotile, 0, 2 * 32, 32, 32, x, y, size, size);
break;
case 14:
canvas.drawImage(autotile, 32, 32, 32, 32, x, y, size, size);
break;
case 15:
canvas.drawImage(autotile, 32, 2 * 32, 32, 32, x, y, size, size);
break;
case 16:
canvas.clearRect(x, y, size / 2, size / 2);
canvas.drawImage(blockImage, 0, blockIcon * 32, 16, 16, x, y, size / 2, size / 2);
canvas.drawImage(autotile, 2 * 32, 0, 16, 16, x, y, size / 2, size / 2);
break;
case 17:
canvas.clearRect(x, y, size / 2, size / 2);
canvas.drawImage(blockImage, 0, blockIcon * 32, 16, 16, x, y, size / 2, size / 2);
canvas.drawImage(autotile, 2 * 32 + 16, 0, 16, 16, x, y, size / 2, size / 2);
break;
case 18:
canvas.clearRect(x, y, size / 2, size / 2);
canvas.drawImage(blockImage, 0, blockIcon * 32, 16, 16, x, y, size / 2, size / 2);
canvas.drawImage(autotile, 2 * 32 + 16, 16, 16, 16, x, y, size / 2, size / 2);
break;
case 19:
canvas.clearRect(x, y, size / 2, size / 2);
canvas.drawImage(blockImage, 0, blockIcon * 32, 16, 16, x, y, size / 2, size / 2);
canvas.drawImage(autotile, 2 * 32, 16, 16, 16, x, y, size / 2, size / 2);
break;
//修正四个边角的固定搭配
if(pieceIndexs[0] == 13){
if(pieceIndexs[1] == 16) pieceIndexs[1] = 14;
if(pieceIndexs[2] == 31) pieceIndexs[2] = 19;
}
if(pieceIndexs[1] == 18){
if(pieceIndexs[0] == 15) pieceIndexs[0] = 17;
if(pieceIndexs[3] == 36) pieceIndexs[3] = 24;
}
if(pieceIndexs[2] == 43){
if(pieceIndexs[0] == 25) pieceIndexs[0] = 37;
if(pieceIndexs[3] == 46) pieceIndexs[3] = 44;
}
if(pieceIndexs[3] == 48){
if(pieceIndexs[1] == 30) pieceIndexs[1] = 42;
if(pieceIndexs[2] == 45) pieceIndexs[2] = 47;
}
for(var i=0; i<4; i++){
var index = pieceIndexs[i];
var dx = x*size + size/2*(i%2), dy = y*size + size/2*(~~(i/2));
drawBlockByIndex(ctx, dx+left, dy+top, core.material.images['autotile'][block.event.id], index, size);
}
}

View File

@ -354,5 +354,11 @@ maps.prototype.load = function (data, floorId) {
}
return this.loadFloor(floorId, data[floorId]);
}
maps.prototype.getMapArr = function (floorId){
var floor = core.floors[floorId];
var map=floor.map;
return map;
}
main.instance.maps = new maps();

View File

@ -1083,22 +1083,12 @@ ui.prototype.drawThumbnail = function(floorId, canvas, blocks, x, y, size, heroL
core.canvas[canvas].drawImage(blockImage, 0, blockIcon * 32, 32, 32, x + i * persize, y + j * persize, persize, persize);
}
}
// 如果存在png
if (core.isset(core.floors[floorId].png)) {
var png = core.floors[floorId].png;
if (core.isset(core.material.images.pngs[png])) {
core.canvas[canvas].drawImage(core.material.images.pngs[png], x, y, size, size);
}
}
var autotileMaps = [];
var mapArr = core.maps.getMapArr(floorId);
for (var b in blocks) {
var block = blocks[b];
if (core.isset(block.event) && !(core.isset(block.enable) && !block.enable)) {
if (block.event.cls == 'autotile') {
// core.drawAutotile();
autotileMaps[13*block.x + block.y] = block.event.id;
core.drawAutotile(core.canvas.ui, mapArr, block, persize, x, y);
continue;
}
else {
@ -1110,7 +1100,6 @@ ui.prototype.drawThumbnail = function(floorId, canvas, blocks, x, y, size, heroL
}
}
}
core.drawAutotile(floorId, 'ui', autotileMaps, x, y, persize);
if (core.isset(heroLoc)) {
var heroIcon = core.material.icons.hero[heroLoc.direction];