怪物双属性
This commit is contained in:
parent
168ec62cbf
commit
e77762b10f
BIN
images/autotile.png
Normal file
BIN
images/autotile.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
42
libs/core.js
42
libs/core.js
@ -425,11 +425,10 @@ core.prototype.keyDown = function(keyCode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.prototype.keyUp = function(keyCode) {
|
core.prototype.keyUp = function(keyCode) {
|
||||||
if(!core.status.played) {
|
if(!core.status.played)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (core.status.lockControl) {
|
if (core.status.lockControl) {
|
||||||
if (core.status.event.id == 'book' && (keyCode==27 || keyCode==88))
|
if (core.status.event.id == 'book' && (keyCode==27 || keyCode==88))
|
||||||
core.ui.closePanel(true);
|
core.ui.closePanel(true);
|
||||||
if (core.status.event.id == 'fly' && (keyCode==71 || keyCode==27))
|
if (core.status.event.id == 'fly' && (keyCode==71 || keyCode==27))
|
||||||
@ -443,7 +442,7 @@ if (core.status.lockControl) {
|
|||||||
}
|
}
|
||||||
if (core.status.event.id == 'save' && (keyCode==83 || keyCode==27))
|
if (core.status.event.id == 'save' && (keyCode==83 || keyCode==27))
|
||||||
core.ui.closePanel();
|
core.ui.closePanel();
|
||||||
if (core.status.event.id == 'load' && (keyCode==76 || keyCode==27))
|
if (core.status.event.id == 'load' && (keyCode==68 || keyCode==27))
|
||||||
core.ui.closePanel();
|
core.ui.closePanel();
|
||||||
if ((core.status.event.id == 'settings' || core.status.event.id == 'selectShop') && keyCode==27)
|
if ((core.status.event.id == 'settings' || core.status.event.id == 'selectShop') && keyCode==27)
|
||||||
core.ui.closePanel();
|
core.ui.closePanel();
|
||||||
@ -467,7 +466,7 @@ if (core.status.lockControl) {
|
|||||||
core.events.doAction();
|
core.events.doAction();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case 27: // ESC
|
case 27: // ESC
|
||||||
@ -482,7 +481,7 @@ if (core.status.lockControl) {
|
|||||||
case 83: // S
|
case 83: // S
|
||||||
core.save(true);
|
core.save(true);
|
||||||
break;
|
break;
|
||||||
case 76: // L
|
case 68: // D
|
||||||
core.load(true);
|
core.load(true);
|
||||||
break;
|
break;
|
||||||
case 84: // T
|
case 84: // T
|
||||||
@ -502,9 +501,38 @@ if (core.status.lockControl) {
|
|||||||
break;
|
break;
|
||||||
case 40: // DOWN
|
case 40: // DOWN
|
||||||
break;
|
break;
|
||||||
|
case 49: // 快捷键1:破
|
||||||
|
if (core.status.heroStop && core.hasItem('pickaxe')) {
|
||||||
|
if (core.canUseItem('pickaxe')) {
|
||||||
|
core.useItem('pickaxe');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.drawTip('当前不能使用破墙镐');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 50: // 快捷键2:炸
|
||||||
|
if (core.status.heroStop && core.hasItem('bomb')) {
|
||||||
|
if (core.canUseItem('bomb')) {
|
||||||
|
core.useItem('bomb');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.drawTip('当前不能使用炸弹');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 51: // 快捷键3:飞
|
||||||
|
if (core.status.heroStop && core.hasItem('centerFly')) {
|
||||||
|
if (core.canUseItem('centerFly')) {
|
||||||
|
core.useItem('centerFly');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.drawTip('当前不能使用中心对称飞行器');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
core.stopHero();
|
core.stopHero();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
core.prototype.ondown = function (x ,y) {
|
core.prototype.ondown = function (x ,y) {
|
||||||
|
|||||||
@ -107,9 +107,12 @@ data.prototype.init = function() {
|
|||||||
"sword5": 160, // 神圣剑加攻数值
|
"sword5": 160, // 神圣剑加攻数值
|
||||||
"shield5": 160, // 神圣盾加防数值
|
"shield5": 160, // 神圣盾加防数值
|
||||||
"moneyPocket": 500, // 金钱袋加金币的数值
|
"moneyPocket": 500, // 金钱袋加金币的数值
|
||||||
|
/****** 怪物相关 ******/
|
||||||
|
'breakArmor': 0.9, // 破甲的比例(战斗前,怪物附加角色防御的x%作为伤害)
|
||||||
|
'counterAttack': 0.1, // 反击的比例(战斗时,怪物每回合附加角色攻击的x%作为伤害,无视角色防御)
|
||||||
|
'purify': 3, // 净化的比例(战斗前,怪物附加勇士魔防的x倍作为伤害)
|
||||||
/****** 系统相关 ******/
|
/****** 系统相关 ******/
|
||||||
'animateSpeed': 500,
|
'animateSpeed': 500, // 动画时间
|
||||||
}
|
}
|
||||||
// 系统FLAG,在游戏运行中中请不要修改它。
|
// 系统FLAG,在游戏运行中中请不要修改它。
|
||||||
this.flags = {
|
this.flags = {
|
||||||
|
|||||||
@ -50,7 +50,7 @@ enemys.prototype.init = function () {
|
|||||||
'demonPriest': {'name': '魔神法师', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
|
'demonPriest': {'name': '魔神法师', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
|
||||||
'goldHornSlime': {'name': '金角怪', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
|
'goldHornSlime': {'name': '金角怪', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
|
||||||
'redKing': {'name': '红衣魔王', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
|
'redKing': {'name': '红衣魔王', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
|
||||||
'whiteKing': {'name': '白衣武士', 'hp': 100, 'atk': 120, 'def': 0, 'money': 17, 'experience': 0, 'special': 16},
|
'whiteKing': {'name': '白衣武士', 'hp': 100, 'atk': 120, 'def': 0, 'money': 17, 'experience': 0, 'special': 15016},
|
||||||
'blackMagician': {'name': '黑暗大法师', 'hp': 100, 'atk': 120, 'def': 0, 'money': 12, 'experience': 0, 'special': 11, 'value': 1/3, 'bomb': false}, // 吸血怪需要在后面添加value代表吸血比例
|
'blackMagician': {'name': '黑暗大法师', 'hp': 100, 'atk': 120, 'def': 0, 'money': 12, 'experience': 0, 'special': 11, 'value': 1/3, 'bomb': false}, // 吸血怪需要在后面添加value代表吸血比例
|
||||||
'silverSlime': {'name': '银头怪', 'hp': 100, 'atk': 120, 'def': 0, 'money': 15, 'experience': 0, 'special': 14},
|
'silverSlime': {'name': '银头怪', 'hp': 100, 'atk': 120, 'def': 0, 'money': 15, 'experience': 0, 'special': 14},
|
||||||
'swordEmperor': {'name': '剑圣', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
|
'swordEmperor': {'name': '剑圣', 'hp': 0, 'atk': 0, 'def': 0, 'money': 0, 'experience': 0, 'special': 0},
|
||||||
@ -75,26 +75,31 @@ enemys.prototype.getEnemys = function (enemyId) {
|
|||||||
return this.enemys[enemyId];
|
return this.enemys[enemyId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enemys.prototype.hasSpecial = function (special, test) {
|
||||||
|
return parseInt(special/1000) == test || special % 1000 == test;
|
||||||
|
}
|
||||||
|
|
||||||
enemys.prototype.getSpecialText = function (enemyId) {
|
enemys.prototype.getSpecialText = function (enemyId) {
|
||||||
if (enemyId == undefined) return "";
|
if (enemyId == undefined) return "";
|
||||||
var special = this.enemys[enemyId].special;
|
var special = this.enemys[enemyId].special;
|
||||||
if (special == 1) return "先攻";
|
var text = [];
|
||||||
if (special == 2) return "魔攻";
|
if (this.hasSpecial(special, 1)) text.push("先攻");
|
||||||
if (special == 3) return "坚固";
|
if (this.hasSpecial(special, 2)) text.push("魔攻");
|
||||||
if (special == 4) return "2连击";
|
if (this.hasSpecial(special, 3)) text.push("坚固");
|
||||||
if (special == 5) return "3连击";
|
if (this.hasSpecial(special, 4)) text.push("2连击");
|
||||||
if (special == 6) return "4连击";
|
if (this.hasSpecial(special, 5)) text.push("3连击");
|
||||||
if (special == 7) return "破甲";
|
if (this.hasSpecial(special, 6)) text.push("4连击");
|
||||||
if (special == 8) return "反击";
|
if (this.hasSpecial(special, 7)) text.push("破甲");
|
||||||
if (special == 9) return "净化";
|
if (this.hasSpecial(special, 8)) text.push("反击");
|
||||||
if (special == 10) return "模仿";
|
if (this.hasSpecial(special, 9)) text.push("净化");
|
||||||
if (special == 11) return "吸血";
|
if (this.hasSpecial(special, 10)) text.push("模仿");
|
||||||
if (special == 12) return "中毒";
|
if (this.hasSpecial(special, 11)) text.push("吸血");
|
||||||
if (special == 13) return "衰弱";
|
if (this.hasSpecial(special, 12)) text.push("中毒");
|
||||||
if (special == 14) return "诅咒";
|
if (this.hasSpecial(special, 13)) text.push("衰弱");
|
||||||
if (special == 15) return "领域";
|
if (this.hasSpecial(special, 14)) text.push("诅咒");
|
||||||
if (special == 16) return "夹击";
|
if (this.hasSpecial(special, 15)) text.push("领域");
|
||||||
return "";
|
if (this.hasSpecial(special, 16)) text.push("夹击");
|
||||||
|
return text.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
enemys.prototype.getDamage = function (monsterId) {
|
enemys.prototype.getDamage = function (monsterId) {
|
||||||
@ -108,7 +113,7 @@ enemys.prototype.getDamage = function (monsterId) {
|
|||||||
|
|
||||||
enemys.prototype.getExtraDamage = function (monster) {
|
enemys.prototype.getExtraDamage = function (monster) {
|
||||||
var extra_damage = 0;
|
var extra_damage = 0;
|
||||||
if (monster.special == 11) { // 吸血
|
if (this.hasSpecial(monster.special, 11)) { // 吸血
|
||||||
// 吸血的比例
|
// 吸血的比例
|
||||||
extra_damage = core.status.hero.hp * monster.value;
|
extra_damage = core.status.hero.hp * monster.value;
|
||||||
extra_damage = parseInt(extra_damage);
|
extra_damage = parseInt(extra_damage);
|
||||||
@ -119,7 +124,7 @@ enemys.prototype.getExtraDamage = function (monster) {
|
|||||||
// 临界值计算
|
// 临界值计算
|
||||||
enemys.prototype.getCritical = function (monsterId) {
|
enemys.prototype.getCritical = function (monsterId) {
|
||||||
var monster = core.material.enemys[monsterId];
|
var monster = core.material.enemys[monsterId];
|
||||||
if (monster.special == 3 || monster.special == 10) return "???";
|
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,
|
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);
|
||||||
if (last == 0) return 0;
|
if (last == 0) return 0;
|
||||||
@ -160,11 +165,11 @@ enemys.prototype.getDefDamage = function (monsterId) {
|
|||||||
|
|
||||||
enemys.prototype.calDamage = function (hero_atk, hero_def, hero_mdef, mon_hp, mon_atk, mon_def, mon_special) {
|
enemys.prototype.calDamage = function (hero_atk, hero_def, hero_mdef, mon_hp, mon_atk, mon_def, mon_special) {
|
||||||
// 魔攻
|
// 魔攻
|
||||||
if (mon_special == 2) hero_def = 0;
|
if (this.hasSpecial(mon_special,2)) hero_def = 0;
|
||||||
// 坚固
|
// 坚固
|
||||||
if (mon_special == 3 && mon_def < hero_atk - 1) mon_def = hero_atk - 1;
|
if (this.hasSpecial(mon_special,3) && mon_def < hero_atk - 1) mon_def = hero_atk - 1;
|
||||||
// 模仿
|
// 模仿
|
||||||
if (mon_special == 10) {
|
if (this.hasSpecial(mon_special,10)) {
|
||||||
mon_atk = hero_atk;
|
mon_atk = hero_atk;
|
||||||
mon_def = hero_def;
|
mon_def = hero_def;
|
||||||
}
|
}
|
||||||
@ -174,18 +179,18 @@ enemys.prototype.calDamage = function (hero_atk, hero_def, hero_mdef, mon_hp, mo
|
|||||||
if (per_damage < 0) per_damage = 0;
|
if (per_damage < 0) per_damage = 0;
|
||||||
// 2连击 & 3连击
|
// 2连击 & 3连击
|
||||||
|
|
||||||
if (mon_special == 4) per_damage *= 2;
|
if (this.hasSpecial(mon_special, 4)) per_damage *= 2;
|
||||||
if (mon_special == 5) per_damage *= 3;
|
if (this.hasSpecial(mon_special, 5)) per_damage *= 3;
|
||||||
if (mon_special == 6) per_damage *= 4;
|
if (this.hasSpecial(mon_special, 6)) per_damage *= 4;
|
||||||
// 反击
|
// 反击
|
||||||
if (mon_special == 8) per_damage += parseInt(0.1 * hero_atk);
|
if (this.hasSpecial(mon_special, 8)) per_damage += parseInt(core.values.counterAttack * hero_atk);
|
||||||
|
|
||||||
// 先攻
|
// 先攻
|
||||||
var damage = mon_special == 1 ? per_damage : 0;
|
var damage = mon_special == 1 ? per_damage : 0;
|
||||||
// 破甲
|
// 破甲
|
||||||
if (mon_special == 7) damage = parseInt(0.9 * hero_def);
|
if (this.hasSpecial(mon_special, 7)) damage += parseInt(core.values.breakArmor * hero_def);
|
||||||
// 净化
|
// 净化
|
||||||
if (mon_special == 9) damage = 3 * hero_mdef;
|
if (this.hasSpecial(mon_special, 9)) damage = core.values.purify * hero_mdef;
|
||||||
|
|
||||||
var turn = parseInt((mon_hp - 1) / (hero_atk - mon_def));
|
var turn = parseInt((mon_hp - 1) / (hero_atk - mon_def));
|
||||||
var ans = damage + turn * per_damage;
|
var ans = damage + turn * per_damage;
|
||||||
@ -211,9 +216,9 @@ enemys.prototype.getCurrentEnemys = function () {
|
|||||||
var monster = core.material.enemys[monsterId];
|
var monster = core.material.enemys[monsterId];
|
||||||
var mon_atk = monster.atk, mon_def = monster.def;
|
var mon_atk = monster.atk, mon_def = monster.def;
|
||||||
// 坚固
|
// 坚固
|
||||||
if (monster.special == 3 && mon_def < core.status.hero.atk - 1)
|
if (this.hasSpecial(monster.special, 3) && mon_def < core.status.hero.atk - 1)
|
||||||
mon_def = core.status.hero.atk - 1;
|
mon_def = core.status.hero.atk - 1;
|
||||||
if (monster.special==10) {
|
if (this.hasSpecial(monster.special, 10)) {
|
||||||
mon_atk=core.status.hero.atk;
|
mon_atk=core.status.hero.atk;
|
||||||
mon_def=core.status.hero.def;
|
mon_def=core.status.hero.def;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -124,7 +124,7 @@ events.prototype.checkBlock = function (x,y) {
|
|||||||
|
|
||||||
// 领域
|
// 领域
|
||||||
for (var i in enemys) {
|
for (var i in enemys) {
|
||||||
if (enemys[i]!=null && enemys[i].special==15) {
|
if (enemys[i]!=null && core.enemys.hasSpecial(enemys[i].special, 15)) {
|
||||||
damage+=enemys[i].value;
|
damage+=enemys[i].value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,9 +140,9 @@ events.prototype.checkBlock = function (x,y) {
|
|||||||
|
|
||||||
// 夹击
|
// 夹击
|
||||||
var has=false;
|
var has=false;
|
||||||
if (enemys[0]!=null && enemys[2]!=null && enemys[0].id==enemys[2].id && enemys[0].special==16)
|
if (enemys[0]!=null && enemys[2]!=null && enemys[0].id==enemys[2].id && core.enemys.hasSpecial(enemys[0].special, 16))
|
||||||
has=true;
|
has=true;
|
||||||
if (enemys[1]!=null && enemys[3]!=null && enemys[1].id==enemys[3].id && enemys[1].special==16)
|
if (enemys[1]!=null && enemys[3]!=null && enemys[1].id==enemys[3].id && core.enemys.hasSpecial(enemys[1].special, 16))
|
||||||
has=true;
|
has=true;
|
||||||
if (has && core.status.hero.hp>1) { // 1血夹击不死
|
if (has && core.status.hero.hp>1) { // 1血夹击不死
|
||||||
core.status.hero.hp = parseInt(core.status.hero.hp/2);
|
core.status.hero.hp = parseInt(core.status.hero.hp/2);
|
||||||
@ -490,19 +490,19 @@ events.prototype.afterBattle = function(enemyId,x,y,callback) {
|
|||||||
// 毒衰咒的处理
|
// 毒衰咒的处理
|
||||||
var special = core.material.enemys[enemyId].special;
|
var special = core.material.enemys[enemyId].special;
|
||||||
// 中毒
|
// 中毒
|
||||||
if (special==12 && !core.hasFlag('poison')) {
|
if (core.enemys.hasSpecial(special, 12) && !core.hasFlag('poison')) {
|
||||||
core.setFlag('poison', true);
|
core.setFlag('poison', true);
|
||||||
core.updateStatusBar();
|
core.updateStatusBar();
|
||||||
}
|
}
|
||||||
// 衰弱
|
// 衰弱
|
||||||
if (special==13 && !core.hasFlag('weak')) {
|
if (core.enemys.hasSpecial(special, 13) && !core.hasFlag('weak')) {
|
||||||
core.setFlag('weak', true);
|
core.setFlag('weak', true);
|
||||||
core.status.hero.atk-=core.values.weakValue;
|
core.status.hero.atk-=core.values.weakValue;
|
||||||
core.status.hero.def-=core.values.weakValue;
|
core.status.hero.def-=core.values.weakValue;
|
||||||
core.updateStatusBar();
|
core.updateStatusBar();
|
||||||
}
|
}
|
||||||
// 诅咒
|
// 诅咒
|
||||||
if (special==14 && !core.hasFlag('curse')) {
|
if (core.enemys.hasSpecial(special, 14) && !core.hasFlag('curse')) {
|
||||||
core.setFlag('curse', true);
|
core.setFlag('curse', true);
|
||||||
core.updateStatusBar();
|
core.updateStatusBar();
|
||||||
}
|
}
|
||||||
|
|||||||
52
libs/ui.js
52
libs/ui.js
@ -377,28 +377,34 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
|
|||||||
|
|
||||||
hero_hp -= core.enemys.getExtraDamage(monster);
|
hero_hp -= core.enemys.getExtraDamage(monster);
|
||||||
|
|
||||||
if (mon_special==2) hero_def=0; // 魔攻
|
if (core.enemys.hasSpecial(mon_special, 2)) hero_def=0; // 魔攻
|
||||||
if (mon_special==3 && mon_def<hero_atk) mon_def=hero_atk-1; // 坚固
|
if (core.enemys.hasSpecial(mon_special, 3) && mon_def<hero_atk) mon_def=hero_atk-1; // 坚固
|
||||||
if (mon_special==10) { // 模仿
|
if (core.enemys.hasSpecial(mon_special, 10)) { // 模仿
|
||||||
mon_atk=hero_atk;
|
mon_atk=hero_atk;
|
||||||
mon_def=hero_def;
|
mon_def=hero_def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 实际操作
|
||||||
|
var turn = 0; // 0为勇士攻击
|
||||||
|
if (core.enemys.hasSpecial(mon_special, 1)) turn=1;
|
||||||
|
|
||||||
|
// 回合
|
||||||
var turns = 2;
|
var turns = 2;
|
||||||
if (mon_special==4) turns=3;
|
if (core.enemys.hasSpecial(mon_special, 4)) turns=3;
|
||||||
if (mon_special==5) turns=4;
|
if (core.enemys.hasSpecial(mon_special, 5)) turns=4;
|
||||||
if (mon_special==6) turns=5;
|
if (core.enemys.hasSpecial(mon_special, 6)) turns=5;
|
||||||
|
|
||||||
|
|
||||||
// 初始伤害(破甲、净化)
|
// 初始伤害(破甲、净化)
|
||||||
var initDamage = 0;
|
var initDamage = 0;
|
||||||
if (mon_special==7) initDamage=parseInt(0.9 * hero_def);
|
if (core.enemys.hasSpecial(mon_special, 7)) initDamage+=parseInt(core.values.breakArmor * hero_def);
|
||||||
if (mon_special==9) initDamage=parseInt(3*hero_mdef);
|
if (core.enemys.hasSpecial(mon_special, 9)) initDamage=parseInt(core.values.purify * hero_mdef);
|
||||||
hero_mdef-=initDamage;
|
hero_mdef-=initDamage;
|
||||||
if (hero_mdef<0) {
|
if (hero_mdef<0) {
|
||||||
hero_hp+=hero_mdef;
|
hero_hp+=hero_mdef;
|
||||||
hero_mdef=0;
|
hero_mdef=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var specialText = core.enemys.getSpecialText(monsterId);
|
var specialText = core.enemys.getSpecialText(monsterId);
|
||||||
|
|
||||||
var background = core.canvas.ui.createPattern(core.material.ground, "repeat");
|
var background = core.canvas.ui.createPattern(core.material.ground, "repeat");
|
||||||
@ -434,7 +440,12 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
|
|||||||
core.canvas.ui.textAlign='center';
|
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', 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);
|
core.fillText('ui', "怪物", left+right-margin-boxWidth/2, top+margin+32+40);
|
||||||
core.fillText('ui', specialText, left+right-margin-boxWidth/2, top+margin+32+40+24, '#FF6A6A', '15px Verdana');
|
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 图标
|
// 图标
|
||||||
core.clearMap('ui', left + margin, top + margin, boxWidth, heroHeight+boxWidth-32);
|
core.clearMap('ui', left + margin, top + margin, boxWidth, heroHeight+boxWidth-32);
|
||||||
@ -538,9 +549,6 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
|
|||||||
left+margin+boxWidth-6, top+margin+6, '#FF0000', 4);
|
left+margin+boxWidth-6, top+margin+6, '#FF0000', 4);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// 实际操作
|
|
||||||
var turn = 0; // 0为勇士攻击
|
|
||||||
if (mon_special==1) turn=1;
|
|
||||||
var battleInterval = setInterval(function() {
|
var battleInterval = setInterval(function() {
|
||||||
core.playSound("attack", "ogg");
|
core.playSound("attack", "ogg");
|
||||||
|
|
||||||
@ -572,7 +580,7 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
|
|||||||
}, 250);
|
}, 250);
|
||||||
|
|
||||||
var per_damage = mon_atk-hero_def;
|
var per_damage = mon_atk-hero_def;
|
||||||
if (mon_special == 8) per_damage += parseInt(0.1 * hero_atk); // 反击
|
if (core.enemys.hasSpecial(mon_special, 8)) per_damage += parseInt(core.values.counterAttack * hero_atk); // 反击
|
||||||
|
|
||||||
hero_mdef-=per_damage;
|
hero_mdef-=per_damage;
|
||||||
if (hero_mdef<0) {
|
if (hero_mdef<0) {
|
||||||
@ -741,7 +749,14 @@ ui.prototype.drawEnemyBook = function (page) {
|
|||||||
|
|
||||||
// 数据
|
// 数据
|
||||||
core.canvas.ui.textAlign = "center";
|
core.canvas.ui.textAlign = "center";
|
||||||
|
|
||||||
|
if (enemy.special=='') {
|
||||||
core.fillText('ui', enemy.name, 115, 62 * i + 47, '#DDDDDD', 'bold 17px Verdana');
|
core.fillText('ui', enemy.name, 115, 62 * i + 47, '#DDDDDD', 'bold 17px Verdana');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.fillText('ui', enemy.name, 115, 62 * i + 40, '#DDDDDD', 'bold 17px Verdana');
|
||||||
|
core.fillText('ui', enemy.special, 115, 62 * i + 62, '#FF6A6A', 'bold 15px Verdana');
|
||||||
|
}
|
||||||
core.canvas.ui.textAlign = "left";
|
core.canvas.ui.textAlign = "left";
|
||||||
core.fillText('ui', '生命', 165, 62 * i + 32, '#DDDDDD', '13px Verdana');
|
core.fillText('ui', '生命', 165, 62 * i + 32, '#DDDDDD', '13px Verdana');
|
||||||
core.fillText('ui', enemy.hp, 195, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
|
core.fillText('ui', enemy.hp, 195, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
|
||||||
@ -770,15 +785,6 @@ ui.prototype.drawEnemyBook = function (page) {
|
|||||||
core.fillText('ui', damage, damage_offset, 62 * i + 50, color, 'bold 13px Verdana');
|
core.fillText('ui', damage, damage_offset, 62 * i + 50, color, 'bold 13px Verdana');
|
||||||
|
|
||||||
core.canvas.ui.textAlign = "left";
|
core.canvas.ui.textAlign = "left";
|
||||||
// 属性
|
|
||||||
if (enemy.special != '') {
|
|
||||||
core.setFont('data', 'bold 12px Verdana');
|
|
||||||
var length = core.canvas.data.measureText(enemy.special).width;
|
|
||||||
core.setAlpha('data', '0.4');
|
|
||||||
core.fillRect('data', 64 - 4 - length, 62 * i + 46, length + 4, 17, '#000000');
|
|
||||||
core.setAlpha('data', '1');
|
|
||||||
core.fillText('data', enemy.special, 64 - 2 - length, 62 * i + 59, '#FF6A6A', 'bold 12px Verdana')
|
|
||||||
}
|
|
||||||
|
|
||||||
core.fillText('ui', '临界', 165, 62 * i + 68, '#DDDDDD', '13px Verdana');
|
core.fillText('ui', '临界', 165, 62 * i + 68, '#DDDDDD', '13px Verdana');
|
||||||
core.fillText('ui', enemy.critical, 195, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
|
core.fillText('ui', enemy.critical, 195, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
|
||||||
|
|||||||
BIN
test/autotile.png
Normal file
BIN
test/autotile.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
377
test/grassAutotile.html
Normal file
377
test/grassAutotile.html
Normal file
@ -0,0 +1,377 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<style>
|
||||||
|
.gameCanvas {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
body,
|
||||||
|
div,
|
||||||
|
img {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<canvas class='gameCanvas' id='grasspic' width='96' height='128' style='z-index:3;top:208px;left:465px'></canvas>
|
||||||
|
<canvas class='gameCanvas' id='grass_pic' width='530' height='64' style='z-index:3;top:368px;left:465px'></canvas>
|
||||||
|
|
||||||
|
<canvas class='gameCanvas' id='grassLayer' width='416' height='416' style='z-index:2'></canvas>
|
||||||
|
<canvas class='gameCanvas' id='ui' width='416' height='416' style='z-index:100'></canvas>
|
||||||
|
<canvas class='gameCanvas' id='data' width='416' height='416' style='z-index:0'></canvas>
|
||||||
|
<p class='gameCanvas' id='pout' style='top:8px;left:500px'>通过鼠标拖拽或点击添加草地</p>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
var autotile = new Image()
|
||||||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eTTvNFmUlmRE487713dF5EzK+A0tQPM/rS63zSab4o0b/uw54gOXfH+pdBABlJzjIzk7F4MZ90mi/q/RSpyf8E8eQ89nPOaSdMvG9ZmP2O4DifdJov6qO4xeL/SbJH5wUTGZHtqjYg9VnG63zS1XxRANgw+R8knp3X75T2WOz6YW9EPc0nXY3/bJnb2MBta7fEs/OQ+A9odZ+Y+oHIbOsv80mXoyfbNsbYNmwroTw5L/O/zP+2zNiQiRZuWJOLr/NJf8+2bNu2f3933rZl/pe5bRuAABkBMJLx4WzL+1modt4Y27b1Q2Zu2xZ9228mq76cztm2v/78Bwa+//wPiAgxgpRO46oAAAAASUVORK5CYII="
|
||||||
|
|
||||||
|
autotile.src = "autotile.png"
|
||||||
|
|
||||||
|
autotile.onload = function () {
|
||||||
|
console.log("loaded")
|
||||||
|
grasspic.getContext("2d").drawImage(autotile, 0, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
function drawAutotile(canvas, x, y, size, autotile, index) {
|
||||||
|
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(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(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(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(autotile, 2 * 32, 16, 16, 16, x, y, size / 2, size / 2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
imgData = cxt.getImageData(0, 0, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//0001
|
||||||
|
imgData = cxt.getImageData(0, 3 * 32, 16, 32);
|
||||||
|
cxt_.clearRect(0, 0, 32, 32);
|
||||||
|
cxt_.putImageData(imgData, 0, 0);
|
||||||
|
imgData = cxt.getImageData(2 * 32 + 16, 3 * 32, 16, 32);
|
||||||
|
cxt_.putImageData(imgData, 16, 0);
|
||||||
|
imgData = cxt_.getImageData(0, 0, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//0010
|
||||||
|
imgData = cxt.getImageData(2 * 32, 32, 32, 16);
|
||||||
|
cxt_.clearRect(0, 0, 32, 32);
|
||||||
|
cxt_.putImageData(imgData, 0, 0);
|
||||||
|
imgData = cxt.getImageData(2 * 32, 3 * 32 + 16, 32, 16);
|
||||||
|
cxt_.putImageData(imgData, 0, 16);
|
||||||
|
imgData = cxt_.getImageData(0, 0, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//0011
|
||||||
|
imgData = cxt.getImageData(2 * 32, 3 * 32, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//0100
|
||||||
|
imgData = cxt.getImageData(0, 1 * 32, 16, 32);
|
||||||
|
cxt_.clearRect(0, 0, 32, 32);
|
||||||
|
cxt_.putImageData(imgData, 0, 0);
|
||||||
|
imgData = cxt.getImageData(2 * 32 + 16, 1 * 32, 16, 32);
|
||||||
|
cxt_.putImageData(imgData, 16, 0);
|
||||||
|
imgData = cxt_.getImageData(0, 0, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//0101
|
||||||
|
imgData = cxt.getImageData(0, 2 * 32, 16, 32);
|
||||||
|
cxt_.clearRect(0, 0, 32, 32);
|
||||||
|
cxt_.putImageData(imgData, 0, 0);
|
||||||
|
imgData = cxt.getImageData(2 * 32 + 16, 2 * 32, 16, 32);
|
||||||
|
cxt_.putImageData(imgData, 16, 0);
|
||||||
|
imgData = cxt_.getImageData(0, 0, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//0110
|
||||||
|
imgData = cxt.getImageData(2 * 32, 1 * 32, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//0111
|
||||||
|
imgData = cxt.getImageData(2 * 32, 2 * 32, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//1000
|
||||||
|
imgData = cxt.getImageData(0, 32, 32, 16);
|
||||||
|
cxt_.clearRect(0, 0, 32, 32);
|
||||||
|
cxt_.putImageData(imgData, 0, 0);
|
||||||
|
imgData = cxt.getImageData(0, 3 * 32 + 16, 32, 16);
|
||||||
|
cxt_.putImageData(imgData, 0, 16);
|
||||||
|
imgData = cxt_.getImageData(0, 0, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//1001
|
||||||
|
imgData = cxt.getImageData(0, 3 * 32, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//1010
|
||||||
|
imgData = cxt.getImageData(32, 32, 32, 16);
|
||||||
|
cxt_.clearRect(0, 0, 32, 32);
|
||||||
|
cxt_.putImageData(imgData, 0, 0);
|
||||||
|
imgData = cxt.getImageData(32, 3 * 32 + 16, 32, 16);
|
||||||
|
cxt_.putImageData(imgData, 0, 16);
|
||||||
|
imgData = cxt_.getImageData(0, 0, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//1011
|
||||||
|
imgData = cxt.getImageData(1 * 32, 3 * 32, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//1100
|
||||||
|
imgData = cxt.getImageData(0, 32, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//1101
|
||||||
|
imgData = cxt.getImageData(0, 2 * 32, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//1110
|
||||||
|
imgData = cxt.getImageData(32, 32, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//1111
|
||||||
|
imgData = cxt.getImageData(32, 2 * 32, 32, 32);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//s1
|
||||||
|
imgData = cxt.getImageData(2 * 32, 0, 16, 16);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//s2
|
||||||
|
imgData = cxt.getImageData(2 * 32 + 16, 0, 16, 16);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//s3
|
||||||
|
imgData = cxt.getImageData(2 * 32 + 16, 16, 16, 16);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
//s4
|
||||||
|
imgData = cxt.getImageData(2 * 32, 16, 16, 16);
|
||||||
|
grassImageData.push(imgData);
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据状态画图
|
||||||
|
var cxt = grassLayer.getContext("2d");
|
||||||
|
|
||||||
|
grass = function (ii, x, y) {
|
||||||
|
cxt.clearRect(x * 32, y * 32, 32, 32);
|
||||||
|
// cxt.putImageData(grassImageData[ii], x * 32, y * 32);
|
||||||
|
drawAutotile(cxt, x * 32, y * 32, 32, autotile, ii);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearGrass() { cxt.clearRect(0, 0, 416, 416); }
|
||||||
|
|
||||||
|
fullX = 12;
|
||||||
|
fullY = 12;
|
||||||
|
|
||||||
|
map = [];//-1表示空白,-2表示边界,其他对应实体
|
||||||
|
map[fullX + 1 + fullY * (fullX + 1)] = -2;
|
||||||
|
m = function (x, y) {
|
||||||
|
if (x < 0 || x > fullX || y < 0 || y > fullY) return fullX + 1 + fullY * (fullX + 1);
|
||||||
|
return x + y * (fullX + 1);
|
||||||
|
};
|
||||||
|
// ((100+map[m(xx,yy)] || 99)-100) 返回-1for空白-2for越界
|
||||||
|
|
||||||
|
isGrass = function (xx, yy) { return ~~(((100 + map[m(xx, yy)] || 99) - 100) == 1); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
updateGrass = function () {
|
||||||
|
clearGrass();
|
||||||
|
for (var xx = 0; xx <= fullX; xx++) {
|
||||||
|
for (var yy = 0; yy <= fullY; yy++) {
|
||||||
|
if (!isGrass(xx, yy)) continue;
|
||||||
|
var _id = 0;
|
||||||
|
_id += isGrass(xx, yy - 1) + 2 * isGrass(xx - 1, yy) + 4 * isGrass(xx, yy + 1) + 8 * isGrass(xx + 1, yy);
|
||||||
|
//1上2左4下8右
|
||||||
|
grass(_id, xx, yy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var xx = 0; xx < fullX; xx++) {
|
||||||
|
for (var yy = 0; yy < fullY; yy++) {
|
||||||
|
if (isGrass(xx, yy) + isGrass(xx + 1, yy) + isGrass(xx + 1, yy + 1) + isGrass(xx, yy + 1) != 3) continue;
|
||||||
|
if (!isGrass(xx, yy)) {
|
||||||
|
// cxt.clearRect(xx * 32 + 32, yy * 32 + 32, 16, 16);
|
||||||
|
// cxt.putImageData(grassImageData[16], xx * 32 + 32, yy * 32 + 32);
|
||||||
|
drawAutotile(cxt, xx * 32 + 32, yy * 32 + 32, 32, autotile, 16);
|
||||||
|
}
|
||||||
|
if (!isGrass(xx + 1, yy)) {
|
||||||
|
// cxt.clearRect(xx * 32 + 16, yy * 32 + 32, 16, 16);
|
||||||
|
//cxt.putImageData(grassImageData[17], xx * 32 + 16, yy * 32 + 32);
|
||||||
|
drawAutotile(cxt, xx * 32 + 16, yy * 32 + 32, 32, autotile, 17);
|
||||||
|
}
|
||||||
|
if (!isGrass(xx + 1, yy + 1)) {
|
||||||
|
// cxt.clearRect(xx * 32 + 16, yy * 32 + 16, 16, 16);
|
||||||
|
// cxt.putImageData(grassImageData[18], xx * 32 + 16, yy * 32 + 16);
|
||||||
|
drawAutotile(cxt, xx * 32 + 16, yy * 32 + 16, 32, autotile, 18);
|
||||||
|
}
|
||||||
|
if (!isGrass(xx, yy + 1)) {
|
||||||
|
// cxt.clearRect(xx * 32 + 32, yy * 32 + 16, 16, 16);
|
||||||
|
// cxt.putImageData(grassImageData[19], xx * 32 + 32, yy * 32 + 16);
|
||||||
|
drawAutotile(cxt, xx * 32 + 32, yy * 32 + 16, 32, autotile, 19);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
//画背景以及拖拽相关的支持
|
||||||
|
|
||||||
|
function printf(str) {
|
||||||
|
pout.innerText = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
var dc = data.getContext('2d');
|
||||||
|
var colorA = ["#f8f8f8", "#cccccc"];
|
||||||
|
var colorIndex = 1;
|
||||||
|
for (var ii = 0; ii < 13; ii++)
|
||||||
|
for (var jj = 0; jj < 13; jj++) {
|
||||||
|
dc.fillStyle = colorA[colorIndex];
|
||||||
|
colorIndex = 1 - colorIndex;
|
||||||
|
dc.fillRect(ii * 32, jj * 32, 32, 32);
|
||||||
|
}
|
||||||
|
})();//在data内画一个13*13的灰白相间的格子
|
||||||
|
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
var uc = ui.getContext('2d');
|
||||||
|
|
||||||
|
function fillPos(pos) {
|
||||||
|
uc.fillStyle = '#' + ~~(Math.random() * 8) + ~~(Math.random() * 8) + ~~(Math.random() * 8);
|
||||||
|
uc.fillRect(pos.x * 32 + 12, pos.y * 32 + 12, 8, 8);
|
||||||
|
}//在格子内画一个随机色块
|
||||||
|
|
||||||
|
function eToLoc(e) { var loc = { 'x': e.clientX - ui.offsetLeft, 'y': e.clientY - ui.offsetTop, 'size': 32 }; return loc; }//返回可用的组件内坐标
|
||||||
|
|
||||||
|
function locToPos(loc) {
|
||||||
|
pos = { 'x': ~~(loc.x / loc.size), 'y': ~~(loc.y / loc.size) }
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
var holdingPath = 0;
|
||||||
|
var stepPostfix = null;//用于存放寻路检测的第一个点之后的后续移动
|
||||||
|
|
||||||
|
var mouseOutCheck = 2;
|
||||||
|
function clear1() {
|
||||||
|
if (mouseOutCheck > 1) {
|
||||||
|
mouseOutCheck--;
|
||||||
|
setTimeout(clear1, 1000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
holdingPath = 0;
|
||||||
|
stepPostfix = [];
|
||||||
|
uc.clearRect(0, 0, 416, 416);
|
||||||
|
}//用于鼠标移出canvas时的自动清除状态
|
||||||
|
|
||||||
|
ui.onmousedown = function (e) {
|
||||||
|
holdingPath = 1;
|
||||||
|
mouseOutCheck = 2;
|
||||||
|
setTimeout(clear1);
|
||||||
|
e.stopPropagation();
|
||||||
|
uc.clearRect(0, 0, 416, 416);
|
||||||
|
var loc = eToLoc(e);
|
||||||
|
pos = locToPos(loc)
|
||||||
|
stepPostfix = [];
|
||||||
|
stepPostfix.push(pos);
|
||||||
|
fillPos(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.onmousemove = function (e) {
|
||||||
|
|
||||||
|
if (holdingPath == 0) { return; }
|
||||||
|
mouseOutCheck = 2;
|
||||||
|
e.stopPropagation();
|
||||||
|
var loc = eToLoc(e);
|
||||||
|
var pos = locToPos(loc);
|
||||||
|
var pos0 = stepPostfix[stepPostfix.length - 1]
|
||||||
|
var directionDistance = [pos.y - pos0.y, pos0.x - pos.x, pos0.y - pos.y, pos.x - pos0.x]
|
||||||
|
var max = 0, index = 4;
|
||||||
|
for (var i = 0; i < 4; i++) {
|
||||||
|
if (directionDistance[i] > max) {
|
||||||
|
index = i;
|
||||||
|
max = directionDistance[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pos = [{ 'x': 0, 'y': 1 }, { 'x': -1, 'y': 0 }, { 'x': 0, 'y': -1 }, { 'x': 1, 'y': 0 }, false][index]
|
||||||
|
if (pos) {
|
||||||
|
pos.x += pos0.x;
|
||||||
|
pos.y += pos0.y;
|
||||||
|
stepPostfix.push(pos);
|
||||||
|
fillPos(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.onmouseup = function (e) {
|
||||||
|
holdingPath = 0;
|
||||||
|
e.stopPropagation();
|
||||||
|
var loc = eToLoc(e);
|
||||||
|
if (stepPostfix.length) {
|
||||||
|
console.log(stepPostfix);
|
||||||
|
for (var ii = 0; ii < stepPostfix.length; ii++)map[m(stepPostfix[ii].x, stepPostfix[ii].y)] = 1;
|
||||||
|
map[fullX + 1 + fullY * (fullX + 1)] = -2;
|
||||||
|
//console.log(map);
|
||||||
|
updateGrass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user