Update startGame

This commit is contained in:
oc 2018-12-02 01:41:35 +08:00
parent 379dbd0348
commit f8ead89d90
8 changed files with 121 additions and 37 deletions

View File

@ -281,7 +281,7 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
"_type": "event",
"_event": "firstArrive",
"_range": "thiseval==null || thiseval instanceof Array",
"_data": "使用画布绘制开始菜单。可以在这里自定义需要的标题界面等内容。"
"_data": "标题界面事件化,可以使用事件流的形式来绘制开始界面等。\n需要开启startUsingCanvas这个开关。\n详见文档-个性化-标题界面事件化。"
},
"startText": {
"_leaf": true,

View File

@ -2113,7 +2113,7 @@ if (core.getFlag("door",0)==2) {
core.stopReplay();
core.waitHeroToStop(function() {
core.removeGlobalAnimate(0,0,true);
core.clearMap('all'); // 清空全地图
core.clearMap('all'); core.clearMap('curtain'); // 清空全地图
core.drawText([
"\t[恭喜通关]你的分数是${status:hp}。"
], function () {

View File

@ -17,10 +17,10 @@ HTML5魔塔是使用画布canvas来绘制存在若干个图层它们
- fg前景层绘制前景图层素材fgmap和前景贴图
- damage显伤层主要用来绘制怪物显伤和领域显伤
- animate动画层主要用来绘制动画。showImage事件绘制的图片也是在这一层。
- image图片层主要用来绘制显示图片
- weather天气层主要用来绘制天气雨/雪)
- route路线层主要用来绘制勇士的行走路线图也用来绘制图块的淡入/淡出效果,图块的移动等。
- curtain色调层用来控制当前楼层的画面色调
- image图片层主要用来绘制显示图片该层之所以在curtain层上是为了可以在全黑时贴大头像图
- uiUI层用来绘制一切UI窗口如剧情文本、怪物手册、楼传器、系统菜单等等
- data数据层用来绘制一些顶层的或更新比较快的数据如左上角的提示战斗界面中数据的变化等等。
@ -560,6 +560,23 @@ this.myfunc = function(x) {
通过这种将脚本和自定义事件混用的方式可以达到和RM中公共事件类似的效果即一个调用触发一系列事件。
-->
## 标题界面事件化
从V2.5.3开始,我们可以将标题界面的绘制和游戏开始用事件来完成。可以通过绘制画布、
全塔属性flags中的startUsingCanvas可以决定是否开启标题界面事件化。
然后就可以使用“事件流”的形式来绘制标题界面、提供选项等等。
在这里可以调用任意事件。例如,可以贴若干个图,可以事件切换楼层到某个剧情层再执行若干事件,等等。
关于选项样板默认给出的是最简单的choices事件你也可以使用贴按钮图循环处理+等待操作来定制自己的按钮点击效果。
!> 开始游戏、读取存档、录像回放的效果已经默认给出,请不要修改或删减这些内容,以免出现问题。
标题界面事件全部处理完后将再继续执行startText事件。
## 自定义状态栏(新增显示项)
在V2.2以后,我们可以自定义状态栏背景图(全塔属性 - statusLeftBackground等等。

View File

@ -221,6 +221,7 @@ control.prototype.showStartAnimate = function (noAnimate, callback) {
core.status.played = false;
core.clearStatus();
core.clearMap('all');
core.clearMap('curtain');
if (core.flags.startUsingCanvas) {
core.dom.startTop.style.display = 'none';
@ -1033,7 +1034,7 @@ control.prototype.updateViewport = function() {
////// 绘制勇士 //////
control.prototype.drawHero = function (direction, x, y, status, offset) {
if (!core.isPlaying() || core.status.isStarting) return;
if (!core.isPlaying()) return;
var scan = {
'up': {'x': 0, 'y': -1},
@ -1510,16 +1511,13 @@ control.prototype.setFg = function(color, time, callback) {
////// 更新全地图显伤 //////
control.prototype.updateDamage = function (floorId, canvas) {
if (!core.isset(floorId)) floorId = core.status.floorId;
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
if (!core.isset(canvas)) {
canvas = core.canvas.damage;
core.clearMap('damage');
}
// 正在开始游戏中
if (core.status.isStarting) return;
// 更新显伤
var mapBlocks = core.status.maps[floorId].blocks;
// 没有怪物手册
@ -1673,7 +1671,6 @@ control.prototype.chooseReplayFile = function () {
}
if (core.flags.startUsingCanvas) {
core.status.isStarting = false;
core.startGame('', obj.seed, core.decodeRoute(obj.route));
}
else {

View File

@ -91,14 +91,12 @@ events.prototype.initGame = function () {
////// 游戏开始事件 //////
events.prototype.startGame = function (hard, seed, route, callback) {
if (core.status.isStarting) return;
core.status.isStarting = true;
var start = function () {
console.log('开始游戏');
core.resetStatus(core.firstData.hero, hard, core.firstData.floorId, null, core.initStatus.maps);
core.status.isStarting = true;
core.resetStatus(core.firstData.hero, hard, null, null, core.initStatus.maps);
var nowLoc = core.clone(core.getHeroLoc());
core.setHeroLoc('x', -1);
core.setHeroLoc('y', -1);
if (core.isset(seed)) {
core.setFlag('__seed__', seed);
@ -106,19 +104,15 @@ events.prototype.startGame = function (hard, seed, route, callback) {
}
else core.utils.__init_seed();
if (!core.flags.startUsingCanvas)
core.events.setInitData(hard);
core.clearMap('all');
core.clearMap('curtain');
core.clearStatusBar();
var post_start = function () {
core.status.isStarting = false;
core.control.triggerStatusBar('show');
core.changeFloor(core.status.floorId, null, core.status.hero.loc, null, function() {
core.changeFloor(core.firstData.floorId, null, nowLoc, null, function() {
if (core.isset(callback)) callback();
}, true);
@ -164,6 +158,7 @@ events.prototype.startGame = function (hard, seed, route, callback) {
});
}
else {
core.events.setInitData(hard);
real_start();
}
@ -1334,6 +1329,7 @@ events.prototype.trigger = function (x, y) {
events.prototype.setFloorName = function (floorId) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
// 根据文字判断是否斜体
var floorName = core.status.maps[floorId].name || "";
if (typeof floorName == 'number') floorName = ""+floorName;
@ -1358,7 +1354,11 @@ events.prototype.setFloorName = function (floorId) {
////// 楼层切换 //////
events.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback, fromLoad) {
if (!core.isset(floorId)) floorId = core.status.floorId;
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) {
if (core.isset(callback)) callback();
return;
}
if (floorId == ':before') {
var index=core.floorIds.indexOf(core.status.floorId);

View File

@ -211,6 +211,7 @@ maps.prototype.save = function(maps, floorId) {
////// 更改地图画布的尺寸
maps.prototype.resizeMap = function(floorId) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
core.bigmap.width = core.floors[floorId].width || 13;
core.bigmap.height = core.floors[floorId].height || 13;
var cwidth = core.bigmap.width * 32;
@ -229,7 +230,7 @@ maps.prototype.resizeMap = function(floorId) {
////// 将存档中的地图信息重新读取出来 //////
maps.prototype.load = function (data, floorId) {
if (floorId == undefined) {
if (!core.isset(floorId)) {
var map = {};
core.floorIds.forEach(function (id) {
map[id] = core.maps.loadFloor(id, data[id]);
@ -266,7 +267,8 @@ maps.prototype.canMoveHero = function(x,y,direction,floorId) {
if (!core.isset(x)) x=core.getHeroLoc('x');
if (!core.isset(y)) y=core.getHeroLoc('y');
if (!core.isset(direction)) direction=core.getHeroLoc('direction');
if (!core.isset(floorId)) floorId=core.status.floorId;
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return false;
// 检查当前块的cannotMove
if (core.isset(core.floors[floorId].cannotMove)) {
@ -394,6 +396,7 @@ maps.prototype.drawBlock = function (block, animate, dx, dy) {
maps.prototype.getBgFgMapArray = function (floorId, name) {
floorId = floorId||core.status.floorId;
if (!core.isset(floorId)) return [];
var width = core.floors[floorId].width || 13;
var height = core.floors[floorId].height || 13;
@ -417,6 +420,7 @@ maps.prototype.getBgFgMapArray = function (floorId, name) {
////// 背景/前景图块的绘制 //////
maps.prototype.drawBgFgMap = function (floorId, canvas, name) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
var width = core.floors[floorId].width || 13;
var height = core.floors[floorId].height || 13;
@ -455,6 +459,11 @@ maps.prototype.drawBgFgMap = function (floorId, canvas, name) {
////// 绘制某张地图 //////
maps.prototype.drawMap = function (mapName, callback) {
mapName = mapName || core.status.floorId;
if (!core.isset(mapName)) {
if (core.isset(callback))
callback();
return;
}
core.clearMap('all');
core.removeGlobalAnimate(null, null, true);
@ -707,7 +716,8 @@ maps.prototype.enemyExists = function (x, y, id,floorId) {
////// 获得某个点的block //////
maps.prototype.getBlock = function (x, y, floorId, showDisable) {
if (!core.isset(floorId)) floorId=core.status.floorId;
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return null;
var blocks = core.status.maps[floorId].blocks;
for (var n=0;n<blocks.length;n++) {
if (blocks[n].x==x && blocks[n].y==y && core.isset(blocks[n].event)) {
@ -1064,16 +1074,17 @@ maps.prototype.animateBlock = function (loc,type,time,callback) {
}
////// 将某个块从禁用变成启用状态 //////
maps.prototype.showBlock = function(x, y, floodId) {
floodId = floodId || core.status.floorId;
var block = core.getBlock(x,y,floodId,true);
maps.prototype.showBlock = function(x, y, floorId) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
var block = core.getBlock(x,y,floorId,true);
if (block==null) return; // 不存在
block=block.block;
// 本身是禁用事件,启用之
if (block.disable) {
block.disable = false;
// 在本层,添加动画
if (floodId == core.status.floorId && core.isset(block.event)) {
if (floorId == core.status.floorId && core.isset(block.event)) {
core.drawBlock(block);
core.addGlobalAnimate(block);
core.syncGlobalAnimate();
@ -1085,6 +1096,7 @@ maps.prototype.showBlock = function(x, y, floodId) {
////// 只隐藏但不删除某块 //////
maps.prototype.hideBlock = function (x, y, floorId) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
var block = core.getBlock(x,y,floorId,true);
if (block==null) return; // 不存在
@ -1106,6 +1118,7 @@ maps.prototype.hideBlock = function (x, y, floorId) {
////// 将某个块从启用变成禁用状态 //////
maps.prototype.removeBlock = function (x, y, floorId) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
var block = core.getBlock(x,y,floorId,true);
if (block==null) return; // 不存在
@ -1129,6 +1142,8 @@ maps.prototype.removeBlock = function (x, y, floorId) {
////// 根据block的索引删除该块 //////
maps.prototype.removeBlockById = function (index, floorId) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
var blocks = core.status.maps[floorId].blocks, block = blocks[index];
var x=block.x, y=block.y;
@ -1154,6 +1169,8 @@ maps.prototype.removeBlockById = function (index, floorId) {
////// 一次性删除多个block //////
maps.prototype.removeBlockByIds = function (floorId, ids) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
ids.sort(function (a,b) {return b-a}).forEach(function (id) {
core.removeBlockById(id, floorId);
});
@ -1162,6 +1179,7 @@ maps.prototype.removeBlockByIds = function (floorId, ids) {
////// 改变图块 //////
maps.prototype.setBlock = function (number, x, y, floorId) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
if (!core.isset(number) || !core.isset(x) || !core.isset(y)) return;
if (x<0 || x>=core.bigmap.width || y<0 || y>=core.bigmap.height) return;
@ -1187,6 +1205,7 @@ maps.prototype.setBlock = function (number, x, y, floorId) {
////// 改变图层块 //////
maps.prototype.setBgFgBlock = function (name, number, x, y, floorId) {
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
if (!core.isset(number) || !core.isset(x) || !core.isset(y)) return;
if (x<0 || x>=core.bigmap.width || y<0 || y>=core.bigmap.height) return;
if (name!='bg' && name!='fg') return;
@ -1338,7 +1357,8 @@ maps.prototype.setFloorImage = function (type, loc, floorId, callback) {
if (type!='show') type='hide';
if (typeof loc[0] == 'number' && typeof loc[1] == 'number')
loc = [loc];
floorId = floorId||core.status.floorId;
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
if (loc.length==0) return;
loc.forEach(function (t) {
@ -1360,7 +1380,8 @@ maps.prototype.setBgFgMap = function (type, name, loc, floorId, callback) {
if (name!='fg') name='bg';
if (typeof loc[0] == 'number' && typeof loc[1] == 'number')
loc = [loc];
floorId = floorId||core.status.floorId;
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
if (loc.length==0) return;
loc.forEach(function (t) {
@ -1379,7 +1400,8 @@ maps.prototype.setBgFgMap = function (type, name, loc, floorId, callback) {
}
maps.prototype.resetMap = function(floorId) {
var floorId = floorId||core.status.floorId;
floorId = floorId || core.status.floorId;
if (!core.isset(floorId)) return;
core.status.maps[floorId] = this.loadFloor(floorId);
if (floorId==core.status.floorId) {
this.drawMap(floorId, function () {

View File

@ -104,6 +104,10 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
"steps": 0
},
"startCanvas": [
{
"type": "comment",
"text": "在这里可以用事件来自定义绘制标题界面的背景图等"
},
{
"type": "showImage",
"name": "bg.jpg",
@ -112,12 +116,24 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
0
]
},
{
"type": "comment",
"text": "给用户提供选择项这里简单的使用了choices事件"
},
{
"type": "comment",
"text": "也可以贴按钮图然后使用循环处理+等待操作来完成"
},
{
"type": "choices",
"choices": [
{
"text": "开始游戏",
"action": [
{
"type": "comment",
"text": "检查bgm状态下同"
},
{
"type": "function",
"function": "function(){\ncore.control.checkBgm()\n}"
@ -126,20 +142,32 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
"type": "if",
"condition": "core.flags.startDirectly",
"true": [
{
"type": "comment",
"text": "直接开始游戏,设置初始化数据"
},
{
"type": "function",
"function": "function(){\ncore.events.setInitData('')\n}"
}
],
"false": [
{
"type": "comment",
"text": "动态生成难度选择项"
},
{
"type": "function",
"function": "function(){\n// 动态生成难度选择项\nvar choices = [];\nmain.levelChoose.forEach(function (one) {\n\tchoices.push({\"text\": one[0], \"action\": [\n\t\t{\"type\": \"function\", \"function\": \"function() { core.status.hard = '\"+one[1]+\"'; core.events.setInitData('\"+one[1]+\"'); }\"}\n\t]});\n})\ncore.insertAction({\"type\": \"choices\", \"choices\": choices});\n}"
"function": "function(){\nvar choices = [];\nmain.levelChoose.forEach(function (one) {\n\tchoices.push({\"text\": one[0], \"action\": [\n\t\t{\"type\": \"function\", \"function\": \"function() { core.status.hard = '\"+one[1]+\"'; core.events.setInitData('\"+one[1]+\"'); }\"}\n\t]});\n})\ncore.insertAction({\"type\": \"choices\", \"choices\": choices});\n}"
}
]
},
{
"type": "showImage"
},
{
"type": "comment",
"text": "成功选择难度"
}
]
},
@ -153,9 +181,17 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
{
"type": "showImage"
},
{
"type": "comment",
"text": "这段代码会结束事件,打开读档页面,读取存档或重新开始"
},
{
"type": "function",
"function": "function(){\ncore.insertAction([{\"type\": \"exit\"}], null, null, function() {\n\tcore.status.played = false;\n\tcore.status.isStarting = false;\n\tcore.load();\n})\n}"
"function": "function(){\ncore.insertAction([{\"type\": \"exit\"}], null, null, function() {\n\tcore.status.played = false;\n\tcore.load();\n})\n}"
},
{
"type": "comment",
"text": "不管读档有没有成功,都会重新开始,这个地方不会被执行到"
}
]
},
@ -166,13 +202,25 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
"type": "function",
"function": "function(){\ncore.control.checkBgm()\n}"
},
{
"type": "comment",
"text": "这段代码会结束事件,选择录像文件,播放录像或重新开始"
},
{
"type": "function",
"function": "function(){\ncore.insertAction([{\"type\": \"exit\"}], null, null, function() {\n\tcore.restart();\n\tcore.chooseReplayFile();\n})\n}"
},
{
"type": "comment",
"text": "不管录像有没有成功,都会重新开始,这个地方不会被执行到"
}
]
}
]
},
{
"type": "comment",
"text": "接下来会执行startText中的事件"
}
],
"startText": [
@ -320,7 +368,7 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
"hatredDecrease": true,
"betweenAttackCeil": false,
"useLoop": false,
"startUsingCanvas": true,
"startUsingCanvas": false,
"startDirectly": false,
"canOpenBattleAnimate": true,
"showBattleAnimateConfirm": false,

View File

@ -59,7 +59,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
core.stopReplay();
core.waitHeroToStop(function() {
core.removeGlobalAnimate(0,0,true);
core.clearMap('all'); // 清空全地图
core.clearMap('all'); core.clearMap('curtain'); // 清空全地图
// 请注意:
// 成绩统计时是按照hp进行上传并排名因此光在这里改${status:hp}是无效的
// 如需按照其他的的分数统计方式请先将hp设置为你的得分