Merge branch 'ckcz123'

This commit is contained in:
echo 2017-12-31 01:18:55 +08:00
commit e87adf63ec
24 changed files with 1957 additions and 478 deletions

View File

@ -4,7 +4,7 @@
## 事件的机制
本塔所有的事件都是依靠触发`trigger`完成的。例如,勇士碰到一个门可以触发一个事件`openDoor`,勇士碰到怪物可以触发一个事件`battle`,勇士碰到一个(上面定义的)楼层传送点可以触发一个事件`changeFloor`,勇士穿过路障可以触发一个事件`passNet`包括勇士到达一个指定的`checkBlock`也可以触发一个检查领域、夹击的事件。上面说的这些事件都是系统本身自带的即类似于RMXP中的公共事件。
本塔所有的事件都是依靠触发`trigger`完成的。例如,勇士碰到一个门可以触发一个事件`openDoor`,勇士碰到怪物可以触发一个事件`battle`,勇士碰到一个(上面定义的)楼层传送点可以触发一个事件`changeFloor`,勇士穿过路障可以触发一个事件`passNet`等等。上面说的这些事件都是系统本身自带的即类似于RMXP中的公共事件。
上述这些默认的事件已经存在处理机制,不需要我们操心。我们真正所需要关心的,其实只是一个自定义的事件。
@ -829,7 +829,7 @@ core.insertAction(list) //往当前事件列表中插入一系列事件。使用
请注意,快捷商店默认是不可被使用的。直到至少调用一次自定义事件中的 `{"type": "openShop"}` 打开商店后,才能真正在快捷栏中被使用。
``` java
``` js
"1,0": [ // 金币商店
// 打开商店前,你也可以添加自己的剧情
// 例如通过if来事件来判断是不是第一次访问商店是的则显示一段文字类似宿命的华音那样

BIN
images/lv.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
images/up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 863 B

View File

@ -47,10 +47,14 @@
<p id='floorNameLabel'></p>
</div>
<div id='statusBar' class="clearfix">
<div class="status">
<div class="status" id="floorCol">
<img src='images/floor.png' id="img-floor">
<p class='statusLabel' id='floor'></p>
</div>
<div class="status" id="lvCol">
<img src='images/lv.png' id="img-lv">
<p class='statusLabel' id='lv'></p>
</div>
<div class="status">
<img src='images/hp.png' id="img-hp">
<p class='statusLabel' id='hp'></p>
@ -67,7 +71,7 @@
<img src='images/mdef.png' id="img-mdef">
<p class='statusLabel' id='mdef'></p>
</div>
<div class="status">
<div class="status" id="moneyCol">
<img src='images/money.png' id="img-money">
<p class='statusLabel' id='money'></p>
</div>
@ -75,12 +79,16 @@
<img src='images/experience.png' id="img-experience">
<p class='statusLabel' id='experience'></p>
</div>
<div class="status" id="upCol">
<img src='images/up.png' id="img-up">
<p class='statusLabel' id='up'></p>
</div>
<div class="status">
<span class='statusLabel' id='yellowKey' style="color:#FFCCAA"></span>
<span class='statusLabel' id='blueKey' style="color:#AAAADD"></span>
<span class='statusLabel' id='redKey' style="color:#FF8888"></span>
</div>
<div class="status">
<div class="status" id="debuffCol">
<span class='statusLabel' id='poison' style="color: #AFFCA8;"></span>
<span class='statusLabel' id='weak' style="color: #FECCD0;"></span>
<span class='statusLabel' id='curse' style="color: #C2F4E7;"></span>
@ -96,13 +104,15 @@
<img src="images/settings.png" class="tools" id='img-settings'>
<p class="statusLabel tools" id="hard"></p>
</div>
<div id="curtain"></div>
<canvas class='gameCanvas' id='bg' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='event' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='hero' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='fg' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='hero' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='ui' width='416' height='416'></canvas>
<canvas class='gameCanvas' id='data' width='416' height='416'>此浏览器不支持HTML5</canvas>
</div>
<script id='mainScript' src='main.js'></script>
<script src='libs/thirdparty/mid.js'></script>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -10,12 +10,13 @@ data.prototype.init = function() {
"floorId": "sample0", // 初始楼层ID
"hero": { // 勇士初始数据
"name": "阳光", // 勇士名;可以改成喜欢的
'lv': 1, // 初始等级,该项必须为正整数
"hp": 1000, // 初始生命值
"atk": 100, // 初始攻击
"def": 100, // 初始防御
"mdef": 100, // 初始魔防
"money": 100, // 初始金币
"experience": 1000, // 初始经验
"experience": 0, // 初始经验
"items": { // 初始道具个数
"keys": {
"yellowKey": 0,
@ -57,10 +58,11 @@ data.prototype.init = function() {
{"text": "防御+4", "effect": "status:def+=4"},
{"text": "魔防+10", "effect": "status:mdef+=10"}
// effect只能对status和item进行操作不能修改flag值。
// 中间只能用+=符号(也就是只能增加某个属性或道具)
// 必须是X+=Y的形式其中Y可以是一个表达式以status:xxx或item:xxx为参数
// 其他effect样例
// "item:yellowKey+=1" 黄钥匙+1
// "item:pickaxe+=3" 破墙镐+3
// "status:hp+=2*(status:atk+status:def)" 将生命提升攻防和的数值的两倍
]
},
"expShop1": { // 商店唯一ID
@ -73,13 +75,33 @@ data.prototype.init = function() {
"choices": [
// 在choices中写need可以针对每个选项都有不同的需求。
// 这里的need同样可以以times作为参数比如 "need": "100+20*times"
{"text": "等级+1", "need": "100", "effect": "status:hp+=1000;status:atk+=7;status:def+=7"},
{"text": "等级+1", "need": "100", "effect": "status:lv+=1;status:hp+=1000;status:atk+=7;status:def+=7"},
// 多个effect直接以分号分开即可。如上面的意思是生命+1000攻击+7防御+7。
{"text": "攻击+5", "need": "30", "effect": "status:atk+=5"},
{"text": "防御+5", "need": "30", "effect": "status:def+=5"},
]
},
},
"levelUp": [ // 经验升级所需要的数值,是一个数组
{}, // 第一项为初始等级可以简单留空也可以写name
// 每一个里面可以含有三个参数 need, name, effect
// need为所需要的经验数值是一个正整数。请确保need所需的依次递增
// name为该等级的名称也可以省略代表使用系统默认值本项将显示在状态栏中
// effect为本次升级所执行的操作可由若干项组成由分号分开
// 其中每一项写法和上面的商店完全相同同样必须是X+=Y的形式Y是一个表达式同样可以使用status:xxx或item:xxx代表勇士的某项数值/道具个数
{"need": 20, "name": "第二级", "effect": "status:hp+=2*(status:atk+status:def);status:atk+=10;status:def+=10"}, // 先将生命提升攻防和的2倍再将攻击+10防御+10
// effect也允许写一个function代表本次升级将会执行的操作
{"need": 40, "effect": function () {
core.drawText("恭喜升级!");
core.status.hero.hp *= 2;
core.status.hero.atk += 100;
core.status.hero.def += 100;
}},
// 依次往下写需要的数值即可
]
}
// 各种数值;一些数值可以在这里设置
this.values = {
@ -117,17 +139,26 @@ data.prototype.init = function() {
}
// 系统FLAG在游戏运行中中请不要修改它。
this.flags = {
/****** 角色状态相关 ******/
"enableMDef": true, // 是否涉及勇士的魔防值如果此项为false则状态栏不会显示勇士的魔防值
"enableExperience": true, // 是否涉及经验值如果此项为false则状态栏和怪物手册均将不会显示经验值
/****** 状态栏相关 ******/
"enableFloor": true, // 是否在状态栏显示当前楼层
"enableLv": false, // 是否在状态栏显示当前等级
"enableMDef": true, // 是否在状态栏及战斗界面显示魔防(护盾)
"enableMoney": true, // 是否在状态栏、怪物手册及战斗界面显示金币
"enableExperience": true, // 是否在状态栏、怪物手册及战斗界面显示经验
"enableLevelUp": false, // 是否允许等级提升进阶如果上面enableExperience为false则此项恒视为false
"enableDebuff": true, // 是否涉及毒衰咒如果此项为false则不会在状态栏中显示毒衰咒的debuff
////// 上述的几个开关将直接影响状态栏的显示效果 //////
/****** 道具相关 ******/
"flyNearStair": true, // 是否需要在楼梯边使用传送器
"pickaxeFourDirections": true, // 使用破墙镐是否四个方向都破坏如果false则只破坏面前的墙壁
"bombFourDirections": true, // 使用炸弹是否四个方向都会炸如果false则只炸面前的怪物即和圣锤等价
"bigKeyIsBox": false, // 如果此项为true则视为钥匙盒红黄蓝钥匙+1若为false则视为大黄门钥匙
/****** 怪物相关 ******/
"enableNegativeDamage": true, // 是否支持负伤害(回血)
"zoneSquare": false, // 领域类型。如果此项为true则为九宫格伤害为false则为十字伤害
/****** 系统相关 ******/
"startDirectly": false, // 点击“开始游戏”后是否立刻开始游戏而不显示难度选择界面
"canOpenBattleAnimate": true, // 是否允许用户开启战斗过程如果此项为false则下面两项均强制视为false
"showBattleAnimateConfirm": true, // 是否在游戏开始时提供“是否开启战斗动画”的选项
"battleAnimate": true, // 是否默认显示战斗动画;用户可以手动在菜单栏中开关
"displayEnemyDamage": true, // 是否地图怪物显伤;用户可以手动在菜单栏中开关

View File

@ -5,10 +5,10 @@ function enemys() {
enemys.prototype.init = function () {
// 怪物属性初始化定义:
this.enemys = {
'greenSlime': {'name': '绿头怪', 'hp': 100, 'atk': 120, 'def': 0, 'money': 1, 'experience': 0, 'special': 0},
'greenSlime': {'name': '绿头怪', 'hp': 100, 'atk': 120, 'def': 0, 'money': 1, 'experience': 1, 'special': [1,5,7,8]},
'redSlime': {'name': '红头怪', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'blackSlime': {'name': '青头怪', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'slimelord': {'name': '怪王', 'hp': 100, 'atk': 120, 'def': 0, 'money': 10, 'experience': 0, 'special': 9},
'slimelord': {'name': '怪王', 'hp': 100, 'atk': 120, 'def': 0, 'money': 10, 'experience': 0, 'special': [1,9]},
'bat': {'name': '小蝙蝠', 'hp': 100, 'atk': 120, 'def': 0, 'money': 2, 'experience': 0, 'special': 1},
'bigBat': {'name': '大蝙蝠', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'redBat': {'name': '红蝙蝠', 'hp': 100, 'atk': 120, 'def': 0, 'money': 5, 'experience': 0, 'special': 4},
@ -23,8 +23,8 @@ enemys.prototype.init = function () {
'slimeMan': {'name': '影子战士', 'hp': 100, 'atk': 0, 'def': 0, 'money': 11, 'experience': 0, 'special': 10}, // 模仿怪的攻防设为0就好
'bluePriest': {'name': '初级法师', 'hp': 100, 'atk': 120, 'def': 0, 'money': 3, 'experience': 0, 'special': 2},
'redPriest': {'name': '高级法师', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'brownWizard': {'name': '初级巫师', 'hp': 100, 'atk': 120, 'def': 0, 'money': 16, 'experience': 0, 'special': 15, 'value': 100}, // 领域怪需要加value表示领域伤害的数值
'redWizard': {'name': '高级巫师', 'hp': 1000, 'atk': 1200, 'def': 0, 'money': 160, 'experience': 0, 'special': 15, 'value': 200},
'brownWizard': {'name': '初级巫师', 'hp': 100, 'atk': 120, 'def': 0, 'money': 16, 'experience': 0, 'special': 15, 'value': 100, 'zoneSquare': true}, // 领域怪需要加value表示领域伤害的数值zoneSquare代表是否九宫格伤害
'redWizard': {'name': '高级巫师', 'hp': 1000, 'atk': 1200, 'def': 0, 'money': 160, 'experience': 0, 'special': 15, 'value': 200, 'range': 2}, // range可选代表领域伤害的范围不加默认为1
'yellowGuard': {'name': '初级卫兵', 'hp': 100, 'atk': 120, 'def': 0, 'money': 10, 'experience': 0, 'special': 0},
'blueGuard': {'name': '中级卫兵', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'redGuard': {'name': '高级卫兵', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
@ -41,7 +41,7 @@ enemys.prototype.init = function () {
'poisonSkeleton': {'name': '紫骷髅', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'poisonBat': {'name': '紫蝙蝠', 'hp': 100, 'atk': 120, 'def': 0, 'money': 14, 'experience': 0, 'special': 13},
'steelRock': {'name': '铁面人', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'skeletonPriest': {'name': '骷髅法师', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'skeletonPriest': {'name': '骷髅法师', 'hp': 100, 'atk': 100, 'def': 0, 'money': 0, 'experience': 0, 'special': 18, 'value': 20},
'skeletonKing': {'name': '骷髅王', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'skeletonWizard': {'name': '骷髅巫师', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'redSkeletonCaption': {'name': '骷髅武士', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'special': 0},
@ -58,7 +58,7 @@ enemys.prototype.init = function () {
'badPrincess': {'name': '痛苦魔女', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'badFairy': {'name': '黑暗仙子', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'grayPriest': {'name': '中级法师', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'redSwordsman': {'name': '剑王', 'hp': 100, 'atk': 120, 'def': 0, 'money': 7, 'experience': 0, 'special': 6},
'redSwordsman': {'name': '剑王', 'hp': 100, 'atk': 120, 'def': 0, 'money': 7, 'experience': 0, 'special': 6, 'n': 8}, // 多连击需要在后面指定n代表是几连击
'whiteGhost': {'name': '水银战士', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
'poisonZombie': {'name': '绿兽人', 'hp': 100, 'atk': 120, 'def': 0, 'money': 13, 'experience': 0, 'special': 12},
'magicDragon': {'name': '魔龙', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
@ -76,19 +76,20 @@ enemys.prototype.getEnemys = function (enemyId) {
}
enemys.prototype.hasSpecial = function (special, test) {
return special!=0 && (special%100 == test || this.hasSpecial(parseInt(special/100), test));
return (special instanceof Array)?special.indexOf(test)>=0:(special!=0&&(special%100==test||this.hasSpecial(parseInt(special/100), test)));
}
enemys.prototype.getSpecialText = function (enemyId) {
if (enemyId == undefined) return "";
var special = this.enemys[enemyId].special;
var enemy = this.enemys[enemyId];
var special = enemy.special;
var text = [];
if (this.hasSpecial(special, 1)) text.push("先攻");
if (this.hasSpecial(special, 2)) text.push("魔攻");
if (this.hasSpecial(special, 3)) text.push("坚固");
if (this.hasSpecial(special, 4)) text.push("2连击");
if (this.hasSpecial(special, 5)) text.push("3连击");
if (this.hasSpecial(special, 6)) text.push("4连击");
if (this.hasSpecial(special, 6)) text.push((enemy.n||4)+"连击");
if (this.hasSpecial(special, 7)) text.push("破甲");
if (this.hasSpecial(special, 8)) text.push("反击");
if (this.hasSpecial(special, 9)) text.push("净化");
@ -100,14 +101,57 @@ enemys.prototype.getSpecialText = function (enemyId) {
if (this.hasSpecial(special, 15)) text.push("领域");
if (this.hasSpecial(special, 16)) text.push("夹击");
if (this.hasSpecial(special, 17)) text.push("仇恨");
return text.join(" ");
if (this.hasSpecial(special, 18)) text.push("阻击");
if (this.hasSpecial(special, 19)) text.push("自爆");
if (this.hasSpecial(special, 20)) text.push("无敌");
return text;
}
////// 获得每个属性的文字提示 //////
enemys.prototype.getSpecialHint = function (enemy, special) {
if (!core.isset(special)) {
var hints = [];
for (var i=1;i<100;i++) {
if (this.hasSpecial(enemy.special, i)) {
var hint=this.getSpecialHint(enemy, i);
if (hint!='')
hints.push(hint);
}
}
return hints;
}
switch (special) {
case 1: return "先攻:怪物首先攻击";
case 2: return "魔攻:怪物无视勇士的魔防";
case 3: return "坚固勇士每回合最多只能对怪物造成1点伤害";
case 4: return "2连击怪物每回合攻击2次";
case 5: return "3连击怪物每回合攻击3次";
case 6: return (enemy.n||4)+"连击: 怪物每回合攻击"+(enemy.n||4)+"次";
case 7: return "破甲:战斗前,怪物附加角色防御的"+parseInt(100*core.values.breakArmor)+"%作为伤害";
case 8: return "反击:战斗时,怪物每回合附加角色攻击的"+parseInt(100*core.values.counterAttack)+"%作为伤害,无视角色防御";
case 9: return "净化:战斗前,怪物附加勇士魔防的"+core.values.purify+"倍作为伤害";
case 10: return "模仿:怪物的攻防和勇士攻防相等";
case 11: return "吸血:战斗前,怪物首先吸取角色的"+parseInt(100*enemy.value)+"%生命作为伤害";
case 12: return "中毒:战斗后,勇士陷入中毒状态,每一步损失生命"+core.values.poisonDamage+"点";
case 13: return "衰弱:战斗后,勇士陷入衰弱状态,攻防暂时下降"+core.values.weakValue+"点";
case 14: return "诅咒:战斗后,勇士陷入诅咒状态,战斗无法获得金币和经验";
case 15: return "领域:经过怪物周围"+(enemy.range||1)+"格时自动减生命"+enemy.value+"点";
case 16: return "夹击:经过两只相同的怪物中间,勇士生命值变成一半";
case 17: return "仇恨:战斗前,怪物附加之前积累的仇恨值作为伤害;战斗后,释放一半的仇恨值。(每杀死一个怪物获得"+core.values.hatred+"点仇恨值)";
case 18: return "阻击:经过怪物的十字领域时自动减生命"+enemy.value+"点,同时怪物后退一格";
case 19: return "自爆战斗后勇士的生命值变成1";
case 20: return "无敌:勇士无法打败怪物,除非拥有十字架";
default: break;
}
return ""
}
enemys.prototype.getDamage = function (monsterId) {
var monster = core.material.enemys[monsterId];
var hero_atk = core.status.hero.atk, hero_def = core.status.hero.def, hero_mdef = core.status.hero.mdef;
var mon_hp = monster.hp, mon_atk = monster.atk, mon_def = monster.def, mon_special = monster.special;
var damage = this.calDamage(hero_atk, hero_def, hero_mdef, mon_hp, mon_atk, mon_def, mon_special);
var damage = this.calDamage(hero_atk, hero_def, hero_mdef, mon_hp, mon_atk, mon_def, mon_special, monster.n);
if (damage == 999999999) return damage;
return damage + this.getExtraDamage(monster);
}
@ -130,12 +174,12 @@ enemys.prototype.getCritical = function (monsterId) {
var monster = core.material.enemys[monsterId];
if (this.hasSpecial(monster.special, 3) || this.hasSpecial(monster.special, 10)) return "???";
var last = this.calDamage(core.status.hero.atk, core.status.hero.def, core.status.hero.mdef,
monster.hp, monster.atk, monster.def, monster.special);
if (last == 0) return 0;
monster.hp, monster.atk, monster.def, monster.special, monster.n);
if (last <= 0) return 0;
for (var i = core.status.hero.atk + 1; i <= monster.hp + monster.def; i++) {
var damage = this.calDamage(i, core.status.hero.def, core.status.hero.mdef,
monster.hp, monster.atk, monster.def, monster.special);
monster.hp, monster.atk, monster.def, monster.special, monster.n);
if (damage < last)
return i - core.status.hero.atk;
last = damage;
@ -147,36 +191,41 @@ enemys.prototype.getCritical = function (monsterId) {
enemys.prototype.getCriticalDamage = function (monsterId) {
var c = this.getCritical(monsterId);
if (c == '???') return '???';
if (c == 0) return 0;
if (c <= 0) return 0;
var monster = core.material.enemys[monsterId];
// if (c<=0) return 0;
var last = this.calDamage(core.status.hero.atk, core.status.hero.def, core.status.hero.mdef,
monster.hp, monster.atk, monster.def, monster.special);
monster.hp, monster.atk, monster.def, monster.special, monster.n);
if (last == 999999999) return '???';
return last - this.calDamage(core.status.hero.atk + c, core.status.hero.def, core.status.hero.mdef,
monster.hp, monster.atk, monster.def, monster.special);
monster.hp, monster.atk, monster.def, monster.special, monster.n);
}
// 1防减伤计算
enemys.prototype.getDefDamage = function (monsterId) {
var monster = core.material.enemys[monsterId];
return this.calDamage(core.status.hero.atk, core.status.hero.def, core.status.hero.mdef,
monster.hp, monster.atk, monster.def, monster.special) -
this.calDamage(core.status.hero.atk, core.status.hero.def + 1, core.status.hero.mdef,
monster.hp, monster.atk, monster.def, monster.special)
var nowDamage = this.calDamage(core.status.hero.atk, core.status.hero.def, core.status.hero.mdef,
monster.hp, monster.atk, monster.def, monster.special, monster.n);
var nextDamage = this.calDamage(core.status.hero.atk, core.status.hero.def + 1, core.status.hero.mdef,
monster.hp, monster.atk, monster.def, monster.special, monster.n);
if (nowDamage == 999999999 || nextDamage == 999999999) return "???";
return nowDamage - nextDamage;
}
enemys.prototype.calDamage = function (hero_atk, hero_def, hero_mdef, mon_hp, mon_atk, mon_def, mon_special) {
// 魔攻
if (this.hasSpecial(mon_special,2)) hero_def = 0;
// 坚固
if (this.hasSpecial(mon_special,3) && mon_def < hero_atk - 1) mon_def = hero_atk - 1;
enemys.prototype.calDamage = function (hero_atk, hero_def, hero_mdef, mon_hp, mon_atk, mon_def, mon_special, n) {
if (this.hasSpecial(mon_special, 20) && !core.hasItem("cross")) // 如果是无敌属性,且勇士未持有十字架
return 999999999; // 返回无限大
// 模仿
if (this.hasSpecial(mon_special,10)) {
mon_atk = hero_atk;
mon_def = hero_def;
}
// 魔攻
if (this.hasSpecial(mon_special,2)) hero_def = 0;
// 坚固
if (this.hasSpecial(mon_special,3) && mon_def < hero_atk - 1) mon_def = hero_atk - 1;
if (hero_atk <= mon_def) return 999999999; // 不可战斗时请直接返回999999999
var per_damage = mon_atk - hero_def;
@ -185,7 +234,7 @@ enemys.prototype.calDamage = function (hero_atk, hero_def, hero_mdef, mon_hp, mo
if (this.hasSpecial(mon_special, 4)) per_damage *= 2;
if (this.hasSpecial(mon_special, 5)) per_damage *= 3;
if (this.hasSpecial(mon_special, 6)) per_damage *= 4;
if (this.hasSpecial(mon_special, 6)) per_damage *= (n||4);
var counterDamage = 0;
// 反击
@ -202,11 +251,7 @@ enemys.prototype.calDamage = function (hero_atk, hero_def, hero_mdef, mon_hp, mo
var ans = damage + turn * per_damage + (turn + 1) * counterDamage;
ans -= hero_mdef;
// 魔防回血
// return ans;
// 魔防不回血
return ans <= 0 ? 0 : ans;
return core.flags.enableNegativeDamage?ans:Math.max(0, ans);
}
// 获得当前楼层的怪物列表
@ -229,6 +274,10 @@ enemys.prototype.getCurrentEnemys = function () {
mon_def=core.status.hero.def;
}
var specialText = core.enemys.getSpecialText(monsterId);
if (specialText.length>=3) specialText = "多属性...";
else specialText = specialText.join(" ");
enemys.push({
'id': monsterId,
'name': monster.name,
@ -237,7 +286,7 @@ enemys.prototype.getCurrentEnemys = function () {
'def': mon_def,
'money': monster.money,
'experience': monster.experience,
'special': core.enemys.getSpecialText(monsterId),
'special': specialText,
'damage': this.getDamage(monsterId),
'critical': this.getCritical(monsterId),
'criticalDamage': this.getCriticalDamage(monsterId),

View File

@ -20,12 +20,11 @@ events.prototype.init = function () {
callback();
},
'changeFloor': function (data, core, callback) {
var heroLoc = null;
if (core.isset(data.event.data.loc)) {
var heroLoc = {};
if (core.isset(data.event.data.loc))
heroLoc = {'x': data.event.data.loc[0], 'y': data.event.data.loc[1]};
if (core.isset(data.event.data.direction))
heroLoc.direction = data.event.data.direction;
}
if (core.isset(data.event.data.direction))
heroLoc.direction = data.event.data.direction;
core.changeFloor(data.event.data.floorId, data.event.data.stair,
heroLoc, data.event.data.time, callback);
},
@ -134,6 +133,17 @@ events.prototype.afterChangeFloor = function (floorId) {
this.doEvents(core.floors[floorId].firstArrive);
core.setFlag("visited_"+floorId, true);
}
// 播放BGM
if (floorId == 'sample0') {
core.playBgm('bgm.mp3');
}
if (floorId == 'sample1') {
core.playBgm('star.mid');
}
if (floorId == 'sample2') {
core.playBgm('qianjin.mid');
}
}
////// 实际事件的处理 //////
@ -286,11 +296,6 @@ events.prototype.doAction = function() {
block = block.block;
if (core.isset(block.event) && block.event.trigger=='action') {
// 触发
/*
core.status.event = {'id': 'action', 'data': {
'list': core.clone(block.event.data), 'x': block.x, 'y': block.y, 'callback': core.status.event.data.callback
}}
*/
core.status.event.data.list = core.clone(block.event.data);
core.status.event.data.x=block.x;
core.status.event.data.y=block.y;
@ -299,11 +304,21 @@ events.prototype.doAction = function() {
this.doAction();
break;
case "playSound":
var name=data.name.split(".");
if (name.length==2)
core.playSound(name[0],name[1]);
core.playSound(data.name);
this.doAction();
break;
case "playBgm":
core.playBgm(data.name);
this.doAction();
break
case "pauseBgm":
core.pauseBgm();
this.doAction();
break
case "resumeBgm":
core.resumeBgm();
this.doAction();
break
case "setValue":
try {
var value=core.calValue(data.value);
@ -330,7 +345,6 @@ events.prototype.doAction = function() {
core.status.hero.hp=0;
core.updateStatusBar();
core.events.lose('damage');
}
else {
core.updateStatusBar();
@ -354,8 +368,14 @@ events.prototype.doAction = function() {
core.events.lose(data.reason);
break;
case "function":
if (core.isset(data["function"]))
data["function"]();
var func = data["function"];
if (core.isset(func)) {
if ((typeof func == "string") && func.indexOf("function")==0) {
eval('('+func+')()');
}
else if (func instanceof Function)
func();
}
this.doAction();
break;
case "update":
@ -390,7 +410,12 @@ events.prototype.doAction = function() {
////// 往当前事件列表之前添加一个或多个事件 //////
events.prototype.insertAction = function (action) {
core.unshift(core.status.event.data.list, action)
if (core.status.event.id == null) {
this.doEvents(action);
}
else {
core.unshift(core.status.event.data.list, action)
}
}
////// 打开商店 //////
@ -497,6 +522,30 @@ events.prototype.useItem = function(itemId) {
else core.drawTip("当前无法使用"+core.material.items[itemId].name);
}
////// 加点 //////
events.prototype.addPoint = function (enemy) {
var point = enemy.point;
if (!core.isset(point) || point<=0) return [];
// 加点返回一个choices事件
return [
{"type": "choices",
"choices": [
{"text": "生命+"+(200*point), "action": [
{"type": "setValue", "name": "status:hp", "value": "status:hp+"+(200*point)}
]},
{"text": "攻击+"+(1*point), "action": [
{"type": "setValue", "name": "status:atk", "value": "status:atk+"+(1*point)}
]},
{"text": "防御+"+(2*point), "action": [
{"type": "setValue", "name": "status:def", "value": "status:def+"+(2*point)}
]},
]
}
];
}
/****** 打完怪物 ******/
events.prototype.afterBattle = function(enemyId,x,y,callback) {
@ -520,47 +569,63 @@ events.prototype.afterBattle = function(enemyId,x,y,callback) {
if (core.enemys.hasSpecial(special, 17)) {
core.setFlag('hatred', parseInt(core.getFlag('hatred', 0)/2));
}
// 自爆
if (core.enemys.hasSpecial(special, 19)) {
core.status.hero.hp = 1;
}
// 增加仇恨值
core.setFlag('hatred', core.getFlag('hatred',0)+core.values.hatred);
core.updateStatusBar();
// 如果已有事件正在处理中
if (core.status.lockControl) {
if (core.isset(callback)) callback();
return;
// 事件的处理
var todo = [];
// 如果不为阻击,且该点存在,且有事件
if (!core.enemys.hasSpecial(special, 18) && core.isset(x) && core.isset(y)) {
var event = core.floors[core.status.floorId].afterBattle[x+","+y];
if (core.isset(event)) {
// 插入事件
core.unshift(todo, event);
}
}
// 如果有加点
var point = core.material.enemys[enemyId].point;
if (core.isset(point) && point>0) {
core.unshift(todo, core.events.addPoint(core.material.enemys[enemyId]));
}
// 检查处理后的事件。
var event = core.floors[core.status.floorId].afterBattle[x+","+y];
if (core.isset(event)) {
core.events.doEvents(event, x, y, callback);
// 如果事件不为空,将其插入
if (todo.length>0) {
this.insertAction(todo);
}
//继续行走
else {
// 如果已有事件正在处理中
if (core.status.event.id == null) {
core.continueAutomaticRoute();
if (core.isset(callback)) callback();
}
if (core.isset(callback)) callback();
}
/****** 开完门 ******/
events.prototype.afterOpenDoor = function(doorId,x,y,callback) {
// 如果已有事件正在处理中
if (core.status.lockControl) {
if (core.isset(callback)) callback();
return;
var todo = [];
if (core.isset(x) && core.isset(y)) {
var event = core.floors[core.status.floorId].afterOpenDoor[x+","+y];
if (core.isset(event)) {
core.unshift(todo, event);
}
}
// 检查处理后的事件。
var event = core.floors[core.status.floorId].afterOpenDoor[x+","+y];
if (core.isset(event)) {
core.events.doEvents(event, x, y, callback);
if (todo.length>0) {
this.insertAction(todo);
}
//继续行走
else {
if (core.status.event.id == null) {
core.continueAutomaticRoute();
if (core.isset(callback)) callback();
}
if (core.isset(callback)) callback();
}
/****** 经过路障 ******/
@ -613,6 +678,12 @@ events.prototype.changeLight = function(x, y) {
// 改变灯后的事件
events.prototype.afterChangeLight = function(x,y) {
}
// 使用炸弹/圣锤后的事件
events.prototype.afterUseBomb = function () {
}
// 存档事件前一刻的处理
@ -641,6 +712,13 @@ events.prototype.keyDownCtrl = function () {
}
}
events.prototype.clickConfirmBox = function (x,y) {
if ((x == 4 || x == 5) && y == 7 && core.isset(core.status.event.data.yes))
core.status.event.data.yes();
if ((x == 7 || x == 8) && y == 7 && core.isset(core.status.event.data.no))
core.status.event.data.no();
}
events.prototype.keyUpConfirmBox = function (keycode) {
if (keycode==37) {
core.status.event.selection=0;
@ -663,12 +741,6 @@ events.prototype.keyUpConfirmBox = function (keycode) {
}
}
}
events.prototype.clickConfirmBox = function (x,y) {
if ((x == 4 || x == 5) && y == 7 && core.isset(core.status.event.data.yes))
core.status.event.data.yes();
if ((x == 7 || x == 8) && y == 7 && core.isset(core.status.event.data.no))
core.status.event.data.no();
}
// 正在处理事件时的点击操作...
events.prototype.clickAction = function (x,y) {
@ -733,22 +805,38 @@ events.prototype.keyUpAction = function (keycode) {
events.prototype.clickBook = function(x,y) {
// 上一页
if ((x == 3 || x == 4) && y == 12) {
core.ui.drawEnemyBook(core.status.event.data - 1);
core.ui.drawEnemyBook(core.status.event.data - 6);
return;
}
// 下一页
if ((x == 8 || x == 9) && y == 12) {
core.ui.drawEnemyBook(core.status.event.data + 1);
core.ui.drawEnemyBook(core.status.event.data + 6);
return;
}
// 返回
if (x>=10 && x<=12 && y==12) {
core.ui.closePanel(true);
return;
}
// 怪物信息
// var index = parseInt(y/2);
var data = core.status.event.data;
if (core.isset(data) && y<12) {
var page=parseInt(data/6);
var index=6*page+parseInt(y/2);
core.ui.drawEnemyBook(index);
core.ui.drawBookDetail(index);
}
return;
}
events.prototype.keyDownBook = function (keycode) {
if (keycode==37 || keycode==38) core.ui.drawEnemyBook(core.status.event.data - 1);
else if (keycode==39 || keycode==40) core.ui.drawEnemyBook(core.status.event.data + 1);
if (keycode==37) core.ui.drawEnemyBook(core.status.event.data-6);
if (keycode==38) core.ui.drawEnemyBook(core.status.event.data-1);
if (keycode==39) core.ui.drawEnemyBook(core.status.event.data+6);
if (keycode==40) core.ui.drawEnemyBook(core.status.event.data+1);
if (keycode==33) core.ui.drawEnemyBook(core.status.event.data-6);
if (keycode==34) core.ui.drawEnemyBook(core.status.event.data+6);
return;
}
@ -757,9 +845,22 @@ events.prototype.keyUpBook = function (keycode) {
core.ui.closePanel(true);
return;
}
if (keycode==13 || keycode==32 || keycode==67) {
var data=core.status.event.data;
if (core.isset(data)) {
this.clickBook(6, 2*(data%6));
}
return;
}
}
events.prototype.clickBookDetail = function (x,y) {
core.clearMap('data', 0, 0, 416, 416);
core.status.event.id = 'book';
}
// 飞行器
events.prototype.clickFly = function(x,y) {
if ((x==10 || x==11) && y==9) core.ui.drawFly(core.status.event.data-1);
if ((x==10 || x==11) && y==5) core.ui.drawFly(core.status.event.data+1);
@ -818,12 +919,7 @@ events.prototype.clickShop = function(x,y) {
// 更新属性
choice.effect.split(";").forEach(function (t) {
if (t.indexOf("status:")==0) {
eval(t.replace("status:", "core.status.hero."));
}
else if (t.indexOf("item:")==0) {
eval(t.replace("item:", "core.getItem('").replace("+=", "', ")+")");
}
core.doEffect(t);
});
core.updateStatusBar();
shop.times++;
@ -1110,38 +1206,49 @@ events.prototype.keyUpSL = function (keycode) {
events.prototype.clickSwitchs = function (x,y) {
if (x<5 || x>7) return;
var choices = [
"背景音乐", "战斗动画", "怪物显伤", "领域显伤", "返回主菜单"
"背景音乐", "背景音效", "战斗动画", "怪物显伤", "领域显伤", "返回主菜单"
];
var topIndex = 6 - parseInt((choices.length - 1) / 2);
if (y>=topIndex && y<topIndex+choices.length) {
var selection = y-topIndex;
switch (selection) {
case 0:
if (core.musicStatus.isIOS) {
core.drawTip("iOS设备不支持播放音乐");
return;
}
core.changeSoundStatus();
core.musicStatus.bgmStatus = !core.musicStatus.bgmStatus;
if (core.musicStatus.bgmStatus)
core.resumeBgm();
else
core.pauseBgm();
core.setLocalStorage('bgmStatus', core.musicStatus.bgmStatus);
core.ui.drawSwitchs();
break;
case 1:
core.flags.battleAnimate=!core.flags.battleAnimate;
core.setLocalStorage('battleAnimate', core.flags.battleAnimate);
core.musicStatus.soundStatus = !core.musicStatus.soundStatus;
core.setLocalStorage('soundStatus', core.musicStatus.soundStatus);
core.ui.drawSwitchs();
break;
case 2:
if (!core.flags.canOpenBattleAnimate) {
core.drawTip("本塔不能开启战斗动画!");
}
else {
core.flags.battleAnimate=!core.flags.battleAnimate;
core.setLocalStorage('battleAnimate', core.flags.battleAnimate);
core.ui.drawSwitchs();
}
break;
case 3:
core.flags.displayEnemyDamage=!core.flags.displayEnemyDamage;
core.updateFg();
core.setLocalStorage('enemyDamage', core.flags.displayEnemyDamage);
core.ui.drawSwitchs();
break;
case 3:
case 4:
core.flags.displayExtraDamage=!core.flags.displayExtraDamage;
core.updateFg();
core.setLocalStorage('extraDamage', core.flags.displayExtraDamage);
core.ui.drawSwitchs();
break;
case 4:
case 5:
core.status.event.selection=0;
core.ui.drawSettings(false);
break;
@ -1151,7 +1258,7 @@ events.prototype.clickSwitchs = function (x,y) {
events.prototype.keyDownSwitchs = function (keycode) {
var choices = [
"背景音乐", "战斗动画", "怪物显伤", "领域显伤", "返回主菜单"
"背景音乐", "背景音效", "战斗动画", "怪物显伤", "领域显伤", "返回主菜单"
];
if (keycode==38) {
core.status.event.selection--;
@ -1172,7 +1279,7 @@ events.prototype.keyUpSwitchs = function (keycode) {
return;
}
var choices = [
"背景音乐", "战斗动画", "怪物显伤", "领域显伤", "返回主菜单"
"背景音乐", "背景音效", "战斗动画", "怪物显伤", "领域显伤", "返回主菜单"
];
if (keycode==13 || keycode==32 || keycode==67) {
var topIndex = 6 - parseInt((choices.length - 1) / 2);

View File

@ -4,7 +4,7 @@
main.floors.MT0 = {
"floorId": "MT0", // 楼层唯一标识符,需要和名字完全一致
"title": "主塔 0 层", // 楼层中文名
"name": 0, // 显示在状态栏中的层数
"name": "0", // 显示在状态栏中的层数
"canFlyTo": true, // 该楼能否被楼传器飞到(不能的话在该楼也不允许使用楼传器)
"canUseQuickShop": true, // 该层是否允许使用快捷商店
"defaultGround": "ground", // 默认地面的图块IDterrains中

View File

@ -4,7 +4,7 @@
main.floors.sample0 = {
"floorId": "sample0", // 楼层唯一标识符,需要和名字完全一致
"title": "样板 0 层", // 楼层中文名
"name": 0, // 显示在状态栏中的层数
"name": "0", // 显示在状态栏中的层数
"canFlyTo": true, // 该楼能否被楼传器飞到(不能的话在该楼也不允许使用楼传器)
"canUseQuickShop": true, // 该层是否允许使用快捷商店
"defaultGround": "ground", // 默认地面的图块IDterrains中
@ -16,8 +16,8 @@ main.floors.sample0 = {
[216, 247, 256, 235, 248, 6, 0, 3, 49, 50, 51, 52, 38],
[6, 6, 125, 6, 6, 6, 0, 1, 45, 46, 47, 48, 37],
[224, 254, 212, 232, 204, 5, 0, 1, 31, 32, 34, 33, 36],
[201, 205, 217, 215, 207, 5, 50, 1, 27, 28, 29, 30, 35],
[5, 5, 125, 5, 5, 5, 50, 1, 21, 22, 23, 24, 25],
[201, 205, 217, 215, 207, 5, 0, 1, 27, 28, 29, 30, 35],
[5, 5, 125, 5, 5, 5, 0, 1, 21, 22, 23, 24, 25],
[0, 0, 0, 0, 0, 0, 45, 1, 1, 1, 121, 1, 1],
[4, 4, 126, 4, 4, 4, 0, 0, 0, 0, 0, 85, 124],
[87, 11, 12, 13, 14, 4, 4, 2, 2, 2, 122, 2, 2],
@ -102,7 +102,6 @@ main.floors.sample0 = {
"炸弹是只能炸面前的怪物还是四个方向的怪物由data.js中的系统Flag所决定。\n如只能炸前方怪物则和上面的圣锤等价。\n不能被炸的怪物在enemys中可以定义可参见样板里黑衣魔王和黑暗大法师的写法。",
],
"10,4": ["“上楼”和“下楼”的目标层由 main.js 的 floorIds顺序所决定。"],
"10,3": ["十字架目前未被定义,可能需要自行实现功能。\n有关如何实现一个道具功能参见doc文档。"],
"9,2": ["该道具默认是大黄门钥匙,如需改为钥匙盒直接修改 data.js 中的系统Flag即可。"],
"10,2": ["屠龙匕首目前未被定义,可能需要自行实现功能。\n有关如何实现一个道具功能参见doc文档。"],
},

View File

@ -4,24 +4,24 @@
main.floors.sample1 = {
"floorId": "sample1", // 楼层唯一标识符,需要和名字完全一致
"title": "样板 1 层", // 楼层中文名
"name": 1, // 显示在状态栏中的层数
"name": "1", // 显示在状态栏中的层数
"canFlyTo": true, // 该楼能否被楼传器飞到(不能的话在该楼也不允许使用楼传器)
"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": [ // 第一次到该楼层触发的事件
@ -31,8 +31,9 @@ main.floors.sample1 = {
"4,10": [ // 走到中间时的提示
"\t[样板提示]本层楼将会对各类事件进行介绍。",
"左边是一个仿50层的陷阱做法上方是商店、快捷商店的使用方法右上是一个典型的杀怪开门的例子右下是各类可能的NPC事件。",
"本样板目前支持的事件列表大致有:\ntext: 显示一段文字(比如你现在正在看到的)\ntip: 左上角显示提示\nshow: 使一个事件有效(可见、可被交互)\nhide: 使一个事件失效(不可见、不可被交互)\ntrigger: 触发另一个地点的事件\nbattle: 强制和某怪物战斗\nopenDoor: 无需钥匙开门(例如机关门、暗墙)\nopenShop: 打开一个全局商店\ndisableShop: 禁用一个全局商店\nchangeFloor: 传送勇士到某层某位置\nchangePos: 传送勇士到当层某位置;转向\nsetFg: 更改画面色调",
"move: 移动事件效果\nmoveHero: 移动勇士效果\nplaySound: 播放某个音频\nif: 条件判断\nchoices: 提供选项\nsetValue: 设置勇士属性道具,或某个变量/flag\nupdate: 更新状态栏和地图显伤\nwin: 获得胜利(游戏通关)\nlose: 游戏失败\nsleep: 等待多少毫秒\nexit: 立刻结束当前事件\nrevisit: 立刻结束事件并重新触发\nfunction: 自定义JS脚本\n更多支持的事件还在编写中欢迎您宝贵的意见。",
"本样板目前支持的事件列表大致有:\ntext: 显示一段文字(比如你现在正在看到的)\ntip: 左上角显示提示\nshow: 使一个事件有效(可见、可被交互)\nhide: 使一个事件失效(不可见、不可被交互)\ntrigger: 触发另一个地点的事件\nbattle: 强制和某怪物战斗\nopenDoor: 无需钥匙开门(例如机关门、暗墙)",
"openShop: 打开一个全局商店\ndisableShop: 禁用一个全局商店\nchangeFloor: 传送勇士到某层某位置\nchangePos: 传送勇士到当层某位置;转向\nsetFg: 更改画面色调\nmove: 移动事件效果\nmoveHero: 移动勇士效果\nplayBgm: 播放某个背景音乐\npauseBgm: 暂停背景音乐\nresumeBgm: 恢复背景音乐的播放\nplaySound: 播放某个音频",
"if: 条件判断\nchoices: 提供选项\nsetValue: 设置勇士属性道具,或某个变量/flag\nupdate: 更新状态栏和地图显伤\nwin: 获得胜利(游戏通关)\nlose: 游戏失败\nsleep: 等待多少毫秒\nexit: 立刻结束当前事件\nrevisit: 立刻结束事件并重新触发\nfunction: 自定义JS脚本\n\n更多支持的事件还在编写中欢迎您宝贵的意见。",
"有关各事件的样例可参见本层一些NPC的写法。\n所有事件样例本层都有介绍。\n\n一个自定义事件处理完后需要调用{\"type\": \"hide\"}该事件才不会再次出现。",
{"type": "hide"}
],
@ -273,7 +274,7 @@ main.floors.sample1 = {
},
"changeFloor": { // 楼层转换事件该事件不能和上面的events有冲突同位置点否则会被覆盖
"4,12": {"floorId": "sample0", "loc": [6,0]}, // 由于楼下有多个上楼梯,所以需指定位置而不是简单地写"stair": "upFloor"
"5,5": {"floorId": "sample2", "stair": "downFloor"}
"5,5": {"floorId": "sample2", "stair": "downFloor", "direction": "up"}
},
"afterBattle": { // 战斗后可能触发的事件列表
"9,6": [ // 初级卫兵1

View File

@ -4,10 +4,11 @@
main.floors.sample2 = {
"floorId": "sample2", // 楼层唯一标识符,需要和名字完全一致
"title": "主塔 40 层", // 楼层中文名
"name": 40, // 显示在状态栏中的层数
"name": "40", // 显示在状态栏中的层数
"canFlyTo": false, // 该楼能否被楼传器飞到(不能的话在该楼也不允许使用楼传器)
"canUseQuickShop": true, // 该层是否允许使用快捷商店
"defaultGround": "soil", // 默认地面的图块IDterrains中
"defaultGround": "snowGround", // 默认地面的图块IDterrains中
"color": [255,0,0,0.3], // 可以设置该层的默认背景色调RGBA本项可省略
"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

@ -36,7 +36,7 @@ items.prototype.init = function () {
'fly': {'cls': 'constants', 'name': '楼层传送器', 'text': '可以自由往来去过的楼层'},
'coin': {'cls': 'constants', 'name': '幸运金币', 'text': '持有时打败怪物可得双倍金币'},
'snow': {'cls': 'constants', 'name': '冰冻徽章', 'text': '可以将四周的熔岩变成平地'},
'cross': {'cls': 'constants', 'name': '十字架', 'text': '该道具尚未被定义'},
'cross': {'cls': 'constants', 'name': '十字架', 'text': '持有后无视怪物的无敌属性'},
'knife': {'cls': 'constants', 'name': '屠龙匕首', 'text': '该道具尚未被定义'},
'shoes': {'cls': 'constants', 'name': '绿鞋', 'text': '持有时无视负面地形'},
@ -147,7 +147,7 @@ items.prototype.useItem = function (itemId) {
if (!this.canUseItem(itemId)) return;
var itemCls = core.material.items[itemId].cls;
if (itemId=='book') core.ui.drawEnemyBook(1);
if (itemId=='book') core.ui.drawEnemyBook(0);
if (itemId=='fly') core.ui.drawFly(core.status.hero.flyRange.indexOf(core.status.floorId));
if (itemId == 'earthquake' || itemId == 'bomb' || itemId == 'pickaxe' || itemId=='icePickaxe'
|| itemId == 'snow' || itemId == 'hammer' || itemId=='bigKey') {
@ -157,6 +157,9 @@ items.prototype.useItem = function (itemId) {
core.drawHero(core.getHeroLoc('direction'), core.getHeroLoc('x'), core.getHeroLoc('y'), 'stop');
core.updateFg();
core.drawTip(core.material.items[itemId].name + "使用成功");
if (itemId == 'bomb' || itemId == 'hammer')
core.events.afterUseBomb();
});
}
if (itemId == 'centerFly') {

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,7 +79,8 @@ 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
if (id == 20) tmp.event = {'cls': 'autotile', 'id': 'autotile', 'noPass': true}; // autotile
@ -86,6 +89,7 @@ maps.prototype.getBlock = function (x, y, id) {
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'}; // 黄钥匙
@ -134,6 +138,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'}; // 蓝门
@ -151,6 +158,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'};
@ -165,6 +174,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}; // 单向下箭头
@ -173,6 +184,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'};
@ -235,6 +249,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;
}

701
libs/thirdparty/mid.js vendored Normal file
View File

@ -0,0 +1,701 @@
var sampleRate = 44100; /* hard-coded in Flash player */
function AudioPlayer(context, generator, loop) {
// Uses Webkit Web Audio API if available
sampleRate = context.sampleRate;
var channelCount = 2;
var bufferSize = 4096*4; // Higher for less gitches, lower for less latency
var node = context.createScriptProcessor(bufferSize, 0, channelCount);
node.onaudioprocess = function(e) { process(e) };
function process(e) {
if (generator.finished) {
if (loop) {
generator.reset();
generator.finished = false;
}
else {
node.disconnect();
return;
}
}
var dataLeft = e.outputBuffer.getChannelData(0);
var dataRight = e.outputBuffer.getChannelData(1);
var generate = generator.generate(bufferSize);
for (var i = 0; i < bufferSize; ++i) {
dataLeft[i] = generate[i*2];
dataRight[i] = generate[i*2+1];
}
}
// start
// node.connect(context.destination);
return {
'play': function () {
node.connect(context.destination);
},
'pause': function() {
node.disconnect();
}
}
}
/*
class to parse the .mid file format
(depends on stream.js)
*/
function MidiFile(data) {
function readChunk(stream) {
var id = stream.read(4);
var length = stream.readInt32();
return {
'id': id,
'length': length,
'data': stream.read(length)
};
}
var lastEventTypeByte;
function readEvent(stream) {
var event = {};
event.deltaTime = stream.readVarInt();
var eventTypeByte = stream.readInt8();
if ((eventTypeByte & 0xf0) == 0xf0) {
/* system / meta event */
if (eventTypeByte == 0xff) {
/* meta event */
event.type = 'meta';
var subtypeByte = stream.readInt8();
var length = stream.readVarInt();
switch(subtypeByte) {
case 0x00:
event.subtype = 'sequenceNumber';
if (length != 2) throw "Expected length for sequenceNumber event is 2, got " + length;
event.number = stream.readInt16();
return event;
case 0x01:
event.subtype = 'text';
event.text = stream.read(length);
return event;
case 0x02:
event.subtype = 'copyrightNotice';
event.text = stream.read(length);
return event;
case 0x03:
event.subtype = 'trackName';
event.text = stream.read(length);
return event;
case 0x04:
event.subtype = 'instrumentName';
event.text = stream.read(length);
return event;
case 0x05:
event.subtype = 'lyrics';
event.text = stream.read(length);
return event;
case 0x06:
event.subtype = 'marker';
event.text = stream.read(length);
return event;
case 0x07:
event.subtype = 'cuePoint';
event.text = stream.read(length);
return event;
case 0x20:
event.subtype = 'midiChannelPrefix';
if (length != 1) throw "Expected length for midiChannelPrefix event is 1, got " + length;
event.channel = stream.readInt8();
return event;
case 0x2f:
event.subtype = 'endOfTrack';
if (length != 0) throw "Expected length for endOfTrack event is 0, got " + length;
return event;
case 0x51:
event.subtype = 'setTempo';
if (length != 3) throw "Expected length for setTempo event is 3, got " + length;
event.microsecondsPerBeat = (
(stream.readInt8() << 16)
+ (stream.readInt8() << 8)
+ stream.readInt8()
)
return event;
case 0x54:
event.subtype = 'smpteOffset';
if (length != 5) throw "Expected length for smpteOffset event is 5, got " + length;
var hourByte = stream.readInt8();
event.frameRate = {
0x00: 24, 0x20: 25, 0x40: 29, 0x60: 30
}[hourByte & 0x60];
event.hour = hourByte & 0x1f;
event.min = stream.readInt8();
event.sec = stream.readInt8();
event.frame = stream.readInt8();
event.subframe = stream.readInt8();
return event;
case 0x58:
event.subtype = 'timeSignature';
if (length != 4) throw "Expected length for timeSignature event is 4, got " + length;
event.numerator = stream.readInt8();
event.denominator = Math.pow(2, stream.readInt8());
event.metronome = stream.readInt8();
event.thirtyseconds = stream.readInt8();
return event;
case 0x59:
event.subtype = 'keySignature';
if (length != 2) throw "Expected length for keySignature event is 2, got " + length;
event.key = stream.readInt8(true);
event.scale = stream.readInt8();
return event;
case 0x7f:
event.subtype = 'sequencerSpecific';
event.data = stream.read(length);
return event;
default:
// console.log("Unrecognised meta event subtype: " + subtypeByte);
event.subtype = 'unknown'
event.data = stream.read(length);
return event;
}
event.data = stream.read(length);
return event;
} else if (eventTypeByte == 0xf0) {
event.type = 'sysEx';
var length = stream.readVarInt();
event.data = stream.read(length);
return event;
} else if (eventTypeByte == 0xf7) {
event.type = 'dividedSysEx';
var length = stream.readVarInt();
event.data = stream.read(length);
return event;
} else {
throw "Unrecognised MIDI event type byte: " + eventTypeByte;
}
} else {
/* channel event */
var param1;
if ((eventTypeByte & 0x80) == 0) {
/* running status - reuse lastEventTypeByte as the event type.
eventTypeByte is actually the first parameter
*/
param1 = eventTypeByte;
eventTypeByte = lastEventTypeByte;
} else {
param1 = stream.readInt8();
lastEventTypeByte = eventTypeByte;
}
var eventType = eventTypeByte >> 4;
event.channel = eventTypeByte & 0x0f;
event.type = 'channel';
switch (eventType) {
case 0x08:
event.subtype = 'noteOff';
event.noteNumber = param1;
event.velocity = stream.readInt8();
return event;
case 0x09:
event.noteNumber = param1;
event.velocity = stream.readInt8();
if (event.velocity == 0) {
event.subtype = 'noteOff';
} else {
event.subtype = 'noteOn';
}
return event;
case 0x0a:
event.subtype = 'noteAftertouch';
event.noteNumber = param1;
event.amount = stream.readInt8();
return event;
case 0x0b:
event.subtype = 'controller';
event.controllerType = param1;
event.value = stream.readInt8();
return event;
case 0x0c:
event.subtype = 'programChange';
event.programNumber = param1;
return event;
case 0x0d:
event.subtype = 'channelAftertouch';
event.amount = param1;
return event;
case 0x0e:
event.subtype = 'pitchBend';
event.value = param1 + (stream.readInt8() << 7);
return event;
default:
throw "Unrecognised MIDI event type: " + eventType
}
}
}
stream = Stream(data);
var headerChunk = readChunk(stream);
if (headerChunk.id != 'MThd' || headerChunk.length != 6) {
throw "Bad .mid file - header not found";
}
var headerStream = Stream(headerChunk.data);
var formatType = headerStream.readInt16();
var trackCount = headerStream.readInt16();
var timeDivision = headerStream.readInt16();
if (timeDivision & 0x8000) {
throw "Expressing time division in SMTPE frames is not supported yet"
} else {
ticksPerBeat = timeDivision;
}
var header = {
'formatType': formatType,
'trackCount': trackCount,
'ticksPerBeat': ticksPerBeat
}
var tracks = [];
for (var i = 0; i < header.trackCount; i++) {
tracks[i] = [];
var trackChunk = readChunk(stream);
if (trackChunk.id != 'MTrk') {
throw "Unexpected chunk - expected MTrk, got "+ trackChunk.id;
}
var trackStream = Stream(trackChunk.data);
while (!trackStream.eof()) {
var event = readEvent(trackStream);
tracks[i].push(event);
//console.log(event);
}
}
return {
'header': header,
'tracks': tracks
}
}
function Replayer(midiFile, synth) {
var trackStates = [];
var beatsPerMinute = 120;
var ticksPerBeat = midiFile.header.ticksPerBeat;
var channelCount = 16;
var channels = [];
var nextEventInfo;
var samplesToNextEvent;
function Channel() {
var generatorsByNote = {};
var currentProgram = PianoProgram;
function noteOn(note, velocity) {
if (generatorsByNote[note] && !generatorsByNote[note].released) {
/* playing same note before releasing the last one. BOO */
generatorsByNote[note].noteOff(); /* TODO: check whether we ought to be passing a velocity in */
}
generator = currentProgram.createNote(note, velocity);
synth.addGenerator(generator);
generatorsByNote[note] = generator;
}
function noteOff(note, velocity) {
if (generatorsByNote[note] && !generatorsByNote[note].released) {
generatorsByNote[note].noteOff(velocity);
}
}
function setProgram(programNumber) {
currentProgram = PROGRAMS[programNumber] || PianoProgram;
}
return {
'noteOn': noteOn,
'noteOff': noteOff,
'setProgram': setProgram
}
}
function getNextEvent() {
var ticksToNextEvent = null;
var nextEventTrack = null;
var nextEventIndex = null;
for (var i = 0; i < trackStates.length; i++) {
if (
trackStates[i].ticksToNextEvent != null
&& (ticksToNextEvent == null || trackStates[i].ticksToNextEvent < ticksToNextEvent)
) {
ticksToNextEvent = trackStates[i].ticksToNextEvent;
nextEventTrack = i;
nextEventIndex = trackStates[i].nextEventIndex;
}
}
if (nextEventTrack != null) {
/* consume event from that track */
var nextEvent = midiFile.tracks[nextEventTrack][nextEventIndex];
if (midiFile.tracks[nextEventTrack][nextEventIndex + 1]) {
trackStates[nextEventTrack].ticksToNextEvent += midiFile.tracks[nextEventTrack][nextEventIndex + 1].deltaTime;
} else {
trackStates[nextEventTrack].ticksToNextEvent = null;
}
trackStates[nextEventTrack].nextEventIndex += 1;
/* advance timings on all tracks by ticksToNextEvent */
for (var i = 0; i < trackStates.length; i++) {
if (trackStates[i].ticksToNextEvent != null) {
trackStates[i].ticksToNextEvent -= ticksToNextEvent
}
}
nextEventInfo = {
'ticksToEvent': ticksToNextEvent,
'event': nextEvent,
'track': nextEventTrack
}
var beatsToNextEvent = ticksToNextEvent / ticksPerBeat;
var secondsToNextEvent = beatsToNextEvent / (beatsPerMinute / 60);
samplesToNextEvent += secondsToNextEvent * synth.sampleRate;
} else {
nextEventInfo = null;
samplesToNextEvent = null;
self.finished = true;
}
}
function generate(samples) {
var data = new Array(samples*2);
var samplesRemaining = samples;
var dataOffset = 0;
while (true) {
if (samplesToNextEvent != null && samplesToNextEvent <= samplesRemaining) {
/* generate samplesToNextEvent samples, process event and repeat */
var samplesToGenerate = Math.ceil(samplesToNextEvent);
if (samplesToGenerate > 0) {
synth.generateIntoBuffer(samplesToGenerate, data, dataOffset);
dataOffset += samplesToGenerate * 2;
samplesRemaining -= samplesToGenerate;
samplesToNextEvent -= samplesToGenerate;
}
handleEvent();
getNextEvent();
} else {
/* generate samples to end of buffer */
if (samplesRemaining > 0) {
synth.generateIntoBuffer(samplesRemaining, data, dataOffset);
samplesToNextEvent -= samplesRemaining;
}
break;
}
}
return data;
}
function handleEvent() {
var event = nextEventInfo.event;
switch (event.type) {
case 'meta':
switch (event.subtype) {
case 'setTempo':
beatsPerMinute = 60000000 / event.microsecondsPerBeat
}
break;
case 'channel':
switch (event.subtype) {
case 'noteOn':
channels[event.channel].noteOn(event.noteNumber, event.velocity);
break;
case 'noteOff':
channels[event.channel].noteOff(event.noteNumber, event.velocity);
break;
case 'programChange':
//console.log('program change to ' + event.programNumber);
channels[event.channel].setProgram(event.programNumber);
break;
}
break;
}
}
function reset() {
for (var i = 0; i < midiFile.tracks.length; i++) {
trackStates[i] = {
'nextEventIndex': 0,
'ticksToNextEvent': (
midiFile.tracks[i].length ?
midiFile.tracks[i][0].deltaTime :
null
)
};
}
for (var i = 0; i < channelCount; i++) {
channels[i] = Channel();
}
samplesToNextEvent = 0;
getNextEvent();
}
reset();
var self = {
'reset': reset,
'generate': generate,
'finished': false
}
return self;
}
/* Wrapper for accessing strings through sequential reads */
function Stream(str) {
var position = 0;
function read(length) {
var result = str.substr(position, length);
position += length;
return result;
}
/* read a big-endian 32-bit integer */
function readInt32() {
var result = (
(str.charCodeAt(position) << 24)
+ (str.charCodeAt(position + 1) << 16)
+ (str.charCodeAt(position + 2) << 8)
+ str.charCodeAt(position + 3));
position += 4;
return result;
}
/* read a big-endian 16-bit integer */
function readInt16() {
var result = (
(str.charCodeAt(position) << 8)
+ str.charCodeAt(position + 1));
position += 2;
return result;
}
/* read an 8-bit integer */
function readInt8(signed) {
var result = str.charCodeAt(position);
if (signed && result > 127) result -= 256;
position += 1;
return result;
}
function eof() {
return position >= str.length;
}
/* read a MIDI-style variable-length integer
(big-endian value in groups of 7 bits,
with top bit set to signify that another byte follows)
*/
function readVarInt() {
var result = 0;
while (true) {
var b = readInt8();
if (b & 0x80) {
result += (b & 0x7f);
result <<= 7;
} else {
/* b is the last byte */
return result + b;
}
}
}
return {
'eof': eof,
'read': read,
'readInt32': readInt32,
'readInt16': readInt16,
'readInt8': readInt8,
'readVarInt': readVarInt
}
}
function SineGenerator(freq) {
var self = {'alive': true};
var period = sampleRate / freq;
var t = 0;
self.generate = function(buf, offset, count) {
for (; count; count--) {
var phase = t / period;
var result = Math.sin(phase * 2 * Math.PI);
buf[offset++] += result;
buf[offset++] += result;
t++;
}
}
return self;
}
function SquareGenerator(freq, phase) {
var self = {'alive': true};
var period = sampleRate / freq;
var t = 0;
self.generate = function(buf, offset, count) {
for (; count; count--) {
var result = ( (t / period) % 1 > phase ? 1 : -1);
buf[offset++] += result;
buf[offset++] += result;
t++;
}
}
return self;
}
function ADSRGenerator(child, attackAmplitude, sustainAmplitude, attackTimeS, decayTimeS, releaseTimeS) {
var self = {'alive': true}
var attackTime = sampleRate * attackTimeS;
var decayTime = sampleRate * (attackTimeS + decayTimeS);
var decayRate = (attackAmplitude - sustainAmplitude) / (decayTime - attackTime);
var releaseTime = null; /* not known yet */
var endTime = null; /* not known yet */
var releaseRate = sustainAmplitude / (sampleRate * releaseTimeS);
var t = 0;
self.noteOff = function() {
if (self.released) return;
releaseTime = t;
self.released = true;
endTime = releaseTime + sampleRate * releaseTimeS;
}
self.generate = function(buf, offset, count) {
if (!self.alive) return;
var input = new Array(count * 2);
for (var i = 0; i < count*2; i++) {
input[i] = 0;
}
child.generate(input, 0, count);
childOffset = 0;
while(count) {
if (releaseTime != null) {
if (t < endTime) {
/* release */
while(count && t < endTime) {
var ampl = sustainAmplitude - releaseRate * (t - releaseTime);
buf[offset++] += input[childOffset++] * ampl;
buf[offset++] += input[childOffset++] * ampl;
t++;
count--;
}
} else {
/* dead */
self.alive = false;
return;
}
} else if (t < attackTime) {
/* attack */
while(count && t < attackTime) {
var ampl = attackAmplitude * t / attackTime;
buf[offset++] += input[childOffset++] * ampl;
buf[offset++] += input[childOffset++] * ampl;
t++;
count--;
}
} else if (t < decayTime) {
/* decay */
while(count && t < decayTime) {
var ampl = attackAmplitude - decayRate * (t - attackTime);
buf[offset++] += input[childOffset++] * ampl;
buf[offset++] += input[childOffset++] * ampl;
t++;
count--;
}
} else {
/* sustain */
while(count) {
buf[offset++] += input[childOffset++] * sustainAmplitude;
buf[offset++] += input[childOffset++] * sustainAmplitude;
t++;
count--;
}
}
}
}
return self;
}
function midiToFrequency(note) {
return 440 * Math.pow(2, (note-69)/12);
}
PianoProgram = {
'attackAmplitude': 0.2,
'sustainAmplitude': 0.1,
'attackTime': 0.02,
'decayTime': 0.3,
'releaseTime': 0.02,
'createNote': function(note, velocity) {
var frequency = midiToFrequency(note);
return ADSRGenerator(
SineGenerator(frequency),
this.attackAmplitude * (velocity / 128), this.sustainAmplitude * (velocity / 128),
this.attackTime, this.decayTime, this.releaseTime
);
}
}
StringProgram = {
'createNote': function(note, velocity) {
var frequency = midiToFrequency(note);
return ADSRGenerator(
SineGenerator(frequency),
0.5 * (velocity / 128), 0.2 * (velocity / 128),
0.4, 0.8, 0.4
);
}
}
PROGRAMS = {
41: StringProgram,
42: StringProgram,
43: StringProgram,
44: StringProgram,
45: StringProgram,
46: StringProgram,
47: StringProgram,
49: StringProgram,
50: StringProgram
};
function Synth(sampleRate) {
var generators = [];
function addGenerator(generator) {
generators.push(generator);
}
function generate(samples) {
var data = new Array(samples*2);
generateIntoBuffer(samples, data, 0);
return data;
}
function generateIntoBuffer(samplesToGenerate, buffer, offset) {
for (var i = offset; i < offset + samplesToGenerate * 2; i++) {
buffer[i] = 0;
}
for (var i = generators.length - 1; i >= 0; i--) {
generators[i].generate(buffer, offset, samplesToGenerate);
if (!generators[i].alive) generators.splice(i, 1);
}
}
return {
'sampleRate': sampleRate,
'addGenerator': addGenerator,
'generate': generate,
'generateIntoBuffer': generateIntoBuffer
}
}

View File

@ -334,7 +334,8 @@ ui.prototype.drawSwitchs = function() {
core.status.event.id = 'switchs';
var choices = [
"背景音乐:"+(core.musicStatus.soundStatus ? "[ON]" : "[OFF]"),
"背景音乐:"+(core.musicStatus.bgmStatus ? "[ON]" : "[OFF]"),
"背景音效:"+(core.musicStatus.soundStatus ? "[ON]" : "[OFF]"),
"战斗动画: " + (core.flags.battleAnimate ? "[ON]" : "[OFF]"),
"怪物显伤: " + (core.flags.displayEnemyDamage ? "[ON]" : "[OFF]"),
"领域显伤: " + (core.flags.displayExtraDamage ? "[ON]" : "[OFF]"),
@ -389,12 +390,12 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
hero_hp -= core.enemys.getExtraDamage(monster);
if (core.enemys.hasSpecial(mon_special, 2)) hero_def=0; // 魔攻
if (core.enemys.hasSpecial(mon_special, 3) && mon_def<hero_atk) mon_def=hero_atk-1; // 坚固
if (core.enemys.hasSpecial(mon_special, 10)) { // 模仿
mon_atk=hero_atk;
mon_def=hero_def;
}
if (core.enemys.hasSpecial(mon_special, 2)) hero_def=0; // 魔攻
if (core.enemys.hasSpecial(mon_special, 3) && mon_def<hero_atk) mon_def=hero_atk-1; // 坚固
// 实际操作
var turn = 0; // 0为勇士攻击
@ -404,7 +405,7 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
var turns = 2;
if (core.enemys.hasSpecial(mon_special, 4)) turns=3;
if (core.enemys.hasSpecial(mon_special, 5)) turns=4;
if (core.enemys.hasSpecial(mon_special, 6)) turns=5;
if (core.enemys.hasSpecial(mon_special, 6)) turns=1+(monster.n||4);
// 初始伤害
@ -422,7 +423,7 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
hero_mdef=0;
}
var specialText = core.enemys.getSpecialText(monsterId);
var specialTexts = core.enemys.getSpecialText(monsterId);
var background = core.canvas.ui.createPattern(core.material.ground, "repeat");
@ -430,7 +431,10 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
var left=10, right=416-2*left;
var lines = core.flags.enableExperience?5:4;
// var lines = core.flags.enableExperience?5:4;
var lines = 3;
if (core.flags.enableMDef || core.flags.enableMoney || core.flags.enableExperience) lines=4;
if (core.flags.enableMoney && core.flags.enableExperience) lines=5;
var lineHeight = 60;
var height = lineHeight * lines + 50;
@ -443,6 +447,8 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
core.setAlpha('ui', 1);
core.strokeRect('ui', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2);
core.clearMap('data',0,0,416,416);
clearInterval(core.interval.tipAnimate);
core.setAlpha('data', 1);
core.setOpacity('data', 1);
core.status.boxAnimateObjs = [];
@ -460,7 +466,6 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
core.canvas.ui.textAlign='center';
core.fillText('ui', core.status.hero.name, left+margin+boxWidth/2, top+margin+heroHeight+40, '#FFD700', 'bold 22px Verdana');
core.fillText('ui', "怪物", left+right-margin-boxWidth/2, top+margin+32+40);
var specialTexts = specialText.split(" ");
for (var i=0, j=0; i<specialTexts.length;i++) {
if (specialTexts[i]!='') {
core.fillText('ui', specialTexts[i], left+right-margin-boxWidth/2, top+margin+32+44+20*(++j), '#FF6A6A', '15px Verdana');
@ -513,7 +518,7 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
if (core.flags.enableMDef) {
textTop += lineHeight;
core.canvas.ui.textAlign='left';
core.fillText('ui', "魔防", left_start, textTop, '#DDDDDD', '16px Verdana');
core.fillText('ui', "护盾", left_start, textTop, '#DDDDDD', '16px Verdana');
core.drawLine('ui', left_start, textTop + 8, left_end, textTop + 8, '#FFFFFF', 2);
core.canvas.data.textAlign='right';
core.fillText('data', hero_mdef, left_end, textTop+26, '#DDDDDD', 'bold 16px Verdana');
@ -541,12 +546,14 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
core.canvas.ui.textAlign='left';
core.fillText('ui', mon_def, right_start, textTop+26, '#DDDDDD', 'bold 16px Verdana');
textTop += lineHeight;
core.canvas.ui.textAlign='right';
core.fillText('ui', "金币", right_end, textTop, '#DDDDDD', '16px Verdana');
core.drawLine('ui', right_start, textTop + 8, right_end, textTop + 8, '#FFFFFF', 2);
core.canvas.ui.textAlign='left';
core.fillText('ui', mon_money, right_start, textTop+26, '#DDDDDD', 'bold 16px Verdana');
if (core.flags.enableMoney) {
textTop += lineHeight;
core.canvas.ui.textAlign = 'right';
core.fillText('ui', "金币", right_end, textTop, '#DDDDDD', '16px Verdana');
core.drawLine('ui', right_start, textTop + 8, right_end, textTop + 8, '#FFFFFF', 2);
core.canvas.ui.textAlign = 'left';
core.fillText('ui', mon_money, right_start, textTop + 26, '#DDDDDD', 'bold 16px Verdana');
}
if (core.flags.enableExperience) {
textTop += lineHeight;
@ -562,15 +569,9 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
core.canvas.ui.textAlign='right';
core.fillText("ui", "S", right_start-8, 208+15, "#FFFFFF", "italic bold 40px Verdana");
/*
core.drawLine('data', left + right - margin - boxWidth + 6, top+margin+boxWidth-6,
left+right-margin-6, top+margin+6, '#FF0000', 4);
core.drawLine('data', left + margin + 6, top+margin+heroHeight+(boxWidth-32)-6,
left+margin+boxWidth-6, top+margin+6, '#FF0000', 4);
*/
var battleInterval = setInterval(function() {
core.playSound("attack", "ogg");
core.playSound("attack.ogg");
if (turn==0) {
// 勇士攻击
@ -592,8 +593,7 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
// 反击
if (core.enemys.hasSpecial(mon_special, 8)) {
var counterDamage = parseInt(core.values.counterAttack * hero_atk);
hero_mdef -= counterDamage;
hero_mdef -= parseInt(core.values.counterAttack * hero_atk);
if (hero_mdef<0) {
hero_hp+=hero_mdef;
@ -726,9 +726,9 @@ ui.prototype.drawPagination = function (page, totalPage) {
/**
* 绘制怪物手册
* @param page 页数
* @param index 怪物索引
*/
ui.prototype.drawEnemyBook = function (page) {
ui.prototype.drawEnemyBook = function (index) {
var enemys = core.enemys.getCurrentEnemys();
var background = core.canvas.ui.createPattern(core.material.ground, "repeat");
@ -758,11 +758,12 @@ ui.prototype.drawEnemyBook = function (page) {
return;
}
if (index<0) index=0;
if (index>=enemys.length) index=enemys.length-1;
var perpage = 6;
var page=parseInt(index/perpage)+1;
var totalPage = parseInt((enemys.length - 1) / perpage) + 1;
if (page < 1) page = 1;
if (page > totalPage) page = totalPage;
core.status.event.data = page;
core.status.event.data = index;
var start = (page - 1) * perpage, end = Math.min(page * perpage, enemys.length);
enemys = enemys.slice(start, end);
@ -796,25 +797,34 @@ ui.prototype.drawEnemyBook = function (page) {
core.fillText('ui', enemy.atk, 285, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', '防御', 335, 62 * i + 32, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.def, 365, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', '金币', 165, 62 * i + 50, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.money, 195, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
var damage_offset = 326;
var expOffset = 165;
if (core.flags.enableMoney) {
core.fillText('ui', '金币', 165, 62 * i + 50, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.money, 195, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
expOffset = 255;
}
if (core.flags.enableExperience) {
core.canvas.ui.textAlign = "left";
core.fillText('ui', '经验', 255, 62 * i + 50, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.experience, 285, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
damage_offset = 361;
core.fillText('ui', '经验', expOffset, 62 * i + 50, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.experience, expOffset + 30, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
}
var damageOffet = 281;
if (core.flags.enableMoney && core.flags.enableExperience)
damageOffet = 361;
else if (core.flags.enableMoney || core.flags.enableExperience)
damageOffet = 326;
core.canvas.ui.textAlign = "center";
var damage = enemy.damage;
var color = '#FFFF00';
if (damage >= core.status.hero.hp) color = '#FF0000';
if (damage == 0) color = '#00FF00';
if (damage <= 0) color = '#00FF00';
if (damage >= 999999999) damage = '无法战斗';
var length = core.canvas.ui.measureText(damage).width;
core.fillText('ui', damage, damage_offset, 62 * i + 50, color, 'bold 13px Verdana');
core.fillText('ui', damage, damageOffet, 62 * i + 50, color, 'bold 13px Verdana');
core.canvas.ui.textAlign = "left";
@ -825,11 +835,77 @@ ui.prototype.drawEnemyBook = function (page) {
core.fillText('ui', '1防', 335, 62 * i + 68, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.defDamage, 365, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
if (index == start+i) {
core.strokeRect('ui', 10, 62 * i + 13, 416-10*2, 62, '#FFD700');
}
}
core.setBoxAnimate();
this.drawPagination(page, totalPage);
}
ui.prototype.drawBookDetail = function (index) {
var enemys = core.enemys.getCurrentEnemys();
if (enemys.length==0) return;
if (index<0) index=0;
if (index>=enemys.length) index=enemys.length-1;
var enemy = enemys[index];
var enemyId=enemy.id;
var hints=core.enemys.getSpecialHint(core.enemys.getEnemys(enemyId));
if (hints.length==0) {
core.drawTip("该怪物无特殊属性!");
return;
}
var content=hints.join("\n");
core.status.event.id = 'book-detail';
clearInterval(core.interval.tipAnimate);
core.clearMap('data', 0, 0, 416, 416);
core.setOpacity('data', 1);
var left=10, right=416-2*left;
var content_left = left + 25;
var validWidth = right-(content_left-left)-13;
var contents = core.splitLines("data", content, validWidth, '16px Verdana');
var height = 416 - 10 - Math.min(416-24*(contents.length+1)-65, 250);
var top = (416-height)/2, bottom = height;
// var left = 97, top = 64, right = 416 - 2 * left, bottom = 416 - 2 * top;
core.setAlpha('data', 0.9);
core.fillRect('data', left, top, right, bottom, '#000000');
core.setAlpha('data', 1);
core.strokeRect('data', left - 1, top - 1, right + 1, bottom + 1, '#FFFFFF', 2);
// 名称
core.canvas.data.textAlign = "left";
core.fillText('data', enemy.name, content_left, top + 30, '#FFD700', 'bold 22px Verdana');
var content_top = top + 57;
for (var i=0;i<contents.length;i++) {
// core.fillText('data', contents[i], content_left, content_top, '#FFFFFF', '16px Verdana');
var text=contents[i];
var index=text.indexOf("");
if (index>=0) {
var x1 = text.substring(0, index+1);
core.fillText('data', x1, content_left, content_top, '#FF6A6A', 'bold 16px Verdana');
var len=core.canvas.data.measureText(x1).width;
core.fillText('data', text.substring(index+1), content_left+len, content_top, '#FFFFFF', '16px Verdana');
}
else {
core.fillText('data', contents[i], content_left, content_top, '#FFFFFF', '16px Verdana');
}
content_top+=24;
}
core.fillText('data', '<点击任意位置继续>', 270, top+height-13, '#CCCCCC', '13px Verdana');
}
/**
* 绘制楼传器
* @param page
@ -1044,7 +1120,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 {

46
main.js
View File

@ -20,6 +20,7 @@ function main() {
'toolBar': document.getElementById('toolBar'),
'tools': document.getElementsByClassName('tools'),
'gameCanvas': document.getElementsByClassName('gameCanvas'),
'curtain': document.getElementById('curtain'),
'startButtons': document.getElementById('startButtons'),
'playGame': document.getElementById('playGame'),
'loadGame': document.getElementById('loadGame'),
@ -30,31 +31,40 @@ function main() {
'hardLevel': document.getElementById('hardLevel'),
'data': document.getElementById('data'),
'statusLabels': document.getElementsByClassName('statusLabel'),
'floorCol': document.getElementById('floorCol'),
'lvCol': document.getElementById('lvCol'),
'mdefCol': document.getElementById('mdefCol'),
'moneyCol': document.getElementById('moneyCol'),
'expCol': document.getElementById('expCol'),
'upCol': document.getElementById('upCol'),
'debuffCol': document.getElementById('debuffCol'),
'hard': document.getElementById('hard'),
};
// 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'
];
this.sounds = {
'mp3': ['bgm-loop', 'floor'],
'ogg': ['attack', 'door', 'item']
}
this.bgms = [ // 在此存放所有的bgm和文件名一致。第一项为默认播放项
// 音频名不能使用中文,不能带空格或特殊字符;可以直接改名拼音就好
'058-Slow01.mid', 'bgm.mp3', 'qianjin.mid', 'star.mid'
];
this.sounds = [ // 在此存放所有的SE和文件名一致
// 音频名不能使用中文,不能带空格或特殊字符;可以直接改名拼音就好
'floor.mp3', 'attack.ogg', 'door.ogg', 'item.ogg'
]
this.statusBar = {
'image': {
'floor': document.getElementById('img-floor'),
'lv': document.getElementById('img-lv'),
'hp': document.getElementById("img-hp"),
'atk': document.getElementById("img-atk"),
'def': document.getElementById("img-def"),
'mdef': document.getElementById("img-mdef"),
'money': document.getElementById("img-money"),
'experience': document.getElementById("img-experience"),
'up': document.getElementById("img-up"),
'book': document.getElementById("img-book"),
'fly': document.getElementById("img-fly"),
'toolbox': document.getElementById("img-toolbox"),
@ -64,12 +74,14 @@ function main() {
'settings': document.getElementById("img-settings")
},
'floor': document.getElementById('floor'),
'lv': document.getElementById('lv'),
'hp': document.getElementById('hp'),
'atk': document.getElementById('atk'),
'def': document.getElementById("def"),
'mdef': document.getElementById('mdef'),
'money': document.getElementById("money"),
'experience': document.getElementById("experience"),
'up': document.getElementById('up'),
'yellowKey': document.getElementById("yellowKey"),
'blueKey': document.getElementById("blueKey"),
'redKey': document.getElementById("redKey"),
@ -78,6 +90,8 @@ function main() {
'curse': document.getElementById('curse'),
'hard': document.getElementById("hard")
}
//------------------------ 用户修改内容 ------------------------//
this.version = "0.1"; // 游戏版本号如果更改了游戏内容建议修改此version以免造成缓存问题。
this.useCompress = false; // 是否使用压缩文件
@ -88,6 +102,8 @@ function main() {
this.floorIds = [ // 在这里按顺序放所有的楼层;其顺序直接影响到楼层传送器的顺序和上楼器/下楼器的顺序
"sample0", "sample1", "sample2"
]
//------------------------ 用户修改内容 END ------------------------//
this.floors = {}
this.instance = {};
this.canvas = {};
@ -106,7 +122,7 @@ main.prototype.init = function () {
coreData[name] = main[name];
}
main.loaderFloors(function() {
main.core.init(main.dom, main.statusBar, main.canvas, main.images, main.sounds, main.floorIds, main.floors, coreData);
main.core.init(main.dom, main.statusBar, main.canvas, main.images, main.bgms, main.sounds, main.floorIds, main.floors, coreData);
main.core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight);
})
});
@ -209,18 +225,6 @@ main.dom.body.onselectstart = function () {
return false;
}
document.onmousemove = function() {
try {
main.core.loadSound();
}catch (e) {}
}
document.ontouchstart = function() {
try {
main.core.loadSound();
}catch (e) {}
}
main.dom.data.onmousedown = function (e) {
try {
e.stopPropagation();

BIN
sounds/058-Slow01.mid Normal file

Binary file not shown.

BIN
sounds/qianjin.mid Normal file

Binary file not shown.

BIN
sounds/star.mid Normal file

Binary file not shown.

View File

@ -21,7 +21,7 @@
position: fixed;
top: 10px;
left: 10px;
z-index: 12;
z-index: 13;
}
#startPanel {
@ -32,7 +32,7 @@
left: 0;
background-color: #fff;
overflow: hidden;
z-index: 8;
z-index: 9;
}
#startTop {
@ -42,7 +42,7 @@
top: 0;
left: 0;
background-color: #000;
z-index: 11;
z-index: 12;
}
#startTopProgressBar {
@ -52,7 +52,7 @@
position: absolute;
top: 5%;
background-color: #fff;
z-index: 12;
z-index: 13;
}
#startTopProgress {
@ -67,7 +67,7 @@
position: absolute;
top: 8%;
left: 5%;
z-index: 12;
z-index: 13;
}
#startBackground {
@ -77,12 +77,12 @@
height: 100%;
width: auto;
transform:translate(-50%,-50%);
z-index: 9;
z-index: 10;
}
#startLogo {
position: absolute;
z-index: 9;
z-index: 10;
left: 0;
right: 0;
margin-left: auto;
@ -95,7 +95,7 @@
#startTitle {
position: absolute;
z-index: 10;
z-index: 11;
}
#startButtonGroup {
@ -106,7 +106,7 @@
background-color: #000;
opacity: 0.85;
display: none;
z-index: 9;
z-index: 10;
bottom: 0;
margin-bottom: 7%;
}
@ -142,7 +142,7 @@
display: none;
color: #fff;
background-color: #000;
z-index: 7;
z-index: 8;
}
#logoLabel {
@ -170,7 +170,7 @@
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
background: url(images/ground.png) round;
z-index: 6;
z-index: 7;
display: none;
}
#statusBar .status{
@ -180,8 +180,9 @@
}
.status img{
vertical-align: middle;
width: 1.6em;
height: 1.6em;
width: auto;
height: 100%;
max-height: 1.6em;
}
#statusBar span{
color: white;
@ -198,7 +199,7 @@
#toolBar {
position: absolute;
background: url(images/ground.png) round;
z-index: 5;
z-index: 6;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
@ -232,6 +233,13 @@ span#poison, span#weak, span#curse {
-webkit-box-sizing: border-box;
}
#curtain {
z-index: 5;
position: absolute;
opacity: 0;
background: #000000;
}
#bg {
z-index: 1;
}
@ -240,20 +248,20 @@ span#poison, span#weak, span#curse {
z-index: 2;
}
#hero {
#fg {
z-index: 3;
}
#fg {
#hero {
z-index: 4;
}
#ui {
z-index: 5;
z-index: 6;
}
#data {
z-index: 6;
z-index: 7;
}
.clearfix:before,

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,12 @@
全键盘操作 √
经验升级(进阶) √
增加阻击、多连击等属性;属性显示;加点; √
九宫格领域、大范围领域 √
Ctrl快速跳过对话 √
增加负伤 √
背景音乐 √
支持不同层使用不同的地面素材 √
直接内嵌了诸多默认的terrains素材
支持多个Autotile同时存在 √
直接内嵌了诸多默认的terrains素材 √
自动定位到上次存/读档位置 √
设置储存
每一层可以默认色调