📄 popo.html
字号:
else
{
real_dir = this.Player[n].direct;
}
if (x<=0 || x>=this.MapMaxX || y<=0 || y>=this.MapMaxY) return 0;
if ("b" == this.Map[x][y])
{
var len = parseInt(((real_dir==0||real_dir==1)?this.MapMaxX:this.MapMaxY)/2);
this.Map[x][y] = " ";
var old_x = x;
var old_y = y;
while(len>0){
len--;
switch(real_dir)
{
case 0:
x++;
if (x >= this.MapMaxX) x = 1;
break;
case 1:
y--;
if (y <= 0) y = this.MapMaxY-1;
break;
case 2:
x--;
if (x <= 0) x = this.MapMaxX-1;
break;
case 3:
y++;
if (y >= this.MapMaxY) y = 1;
break;
default:
}
if (len<=0 && this.Map[x][y] != " ") len++;
}
for (var i=0; i<this.BulbMax; i++)
{
if (old_x==this.Bulb[i].x && old_y==this.Bulb[i].y && 1==this.Bulb[i].display)
{
this.Bulb[i].x = x; this.Bulb[i].y = y;
}
}
this.Map[old_x][old_y] = " ";
this.Map[x][y] = "b";
}
}
//四个方向踢
this.Kick = function(n){
this.KickOne(n, 0); this.KickOne(n, 1); this.KickOne(n, 2); this.KickOne(n, 3);
}
//飞碟
this.Fly = function(n){
if (this.Player[n].state != 1) return 0;
this.Player[n].fly = 1;
this.FreshPlayerPos(n);
}
//使用道具
this.UseEquip = function(n){
if (0 == this.Player[n].equip_remain[this.Player[n].equip_current]) return 0;
switch(this.Player[n].equip_current)
{
case 0: //踢泡泡
if (this.GetRnd(3)>1) this.Say(n, '我踢!');
this.Kick(n);
break;
case 1: //马上复活
this.Recovery(n);
if (this.GetRnd(3)>1) this.Say(n, '我又活了!');
break;
case 2: //飞碟
this.Fly(n);
if (this.GetRnd(3)>1) this.Say(n, '坐飞碟咯!');
break;
default:
}
this.Player[n].equip_remain[this.Player[n].equip_current]--;
this.FreshPanel();
}
//换位卡
this.Alternate = function(n){
this.PlaySound("换道具");
var old = this.Player[n].equip_current;
if (this.Player[n].equip_current <= this.Player[n].equip_remain.length-1)
this.Player[n].equip_current++;
if (this.Player[n].equip_current > this.Player[n].equip_remain.length-1)
this.Player[n].equip_current=0;
document.getElementById("panel"+n+"_use_"+this.Player[n].equip_current).style.borderColor = '#ffffff';
document.getElementById("panel"+n+"_use_"+old).style.borderColor = '#3473d2';
var str = "";
var num = this.Player[n].equip_remain[this.Player[n].equip_current];
switch(this.Player[n].equip_current)
{
case 0: str="◇"; break;
case 1: str="╋"; break;
case 2: str="⌒"; break;
}
this.Say(n, str+num);
}
this.SetMove = function(n, who, direct){
if (0==n)
{
this.Player[who].direct = direct;
this.Player[who].go = 1;
}
else
{
this.Player[who].go = 0;
}
this.FreshPlayerPos(who);
}
this.Control = function(n){
//alert(event.keyCode);
switch(event.keyCode){
//player 1
case 37: //left
if (-1!=this.ControlPlayer[0]) this.SetMove(n, this.ControlPlayer[0], 2);
break;
case 38: //up
if (-1!=this.ControlPlayer[0]) this.SetMove(n, this.ControlPlayer[0], 1);
break;
case 39: //right
if (-1!=this.ControlPlayer[0]) this.SetMove(n, this.ControlPlayer[0], 0);
break;
case 40: //down
if (-1!=this.ControlPlayer[0]) this.SetMove(n, this.ControlPlayer[0], 3);
break;
case 13: //enter
if (0 == n && -1!=this.ControlPlayer[0]) this.Fix(this.ControlPlayer[0]);
break;
case 96: // 0
if (0 == n && -1!=this.ControlPlayer[0]) this.UseEquip(this.ControlPlayer[0]);
break;
case 97: //1
if (0 == n && -1!=this.ControlPlayer[0]) this.Alternate(this.ControlPlayer[0]);
break;
//player 2
case 65: //left
if (-1!=this.ControlPlayer[1]) this.SetMove(n, this.ControlPlayer[1], 2);
break;
case 87: //up
if (-1!=this.ControlPlayer[1]) this.SetMove(n, this.ControlPlayer[1], 1);
break;
case 68: //right
if (-1!=this.ControlPlayer[1]) this.SetMove(n, this.ControlPlayer[1], 0);
break;
case 83: //down
if (-1!=this.ControlPlayer[1]) this.SetMove(n, this.ControlPlayer[1], 3);
break;
case 32: //space
if (0 == n && -1!=this.ControlPlayer[1]) if (0 == n) this.Fix(this.ControlPlayer[1]);
break;
case 70: // F
if (0 == n && -1!=this.ControlPlayer[1]) if (0 == n) this.UseEquip(this.ControlPlayer[1]);
break;
case 69: //E
if (0 == n && -1!=this.ControlPlayer[1]) if (0 == n) this.Alternate(this.ControlPlayer[1]);
break;
case 77: //M
if (0==n)
{
if (this.SoundTurn > 0)
{
this.SoundTurn = 0;
}
else
{
this.SoundTurn = 1;
}
}
break;
case 78: //N
if (0==n)
{
if (""==document.getElementById("sound_main").src)
{
this.SwitchMainSound(1);
}
else
{
this.SwitchMainSound(0);
}
}
break;
}
if (0 == n) { this.Play(); }
event.returnValue = false;
}
this.ControlChange = function(playerIndex, Control){
if (-1==Control)
{
this.Player[playerIndex].auto = 1;
}
else
{
this.ControlPlayer[Control] = playerIndex;
this.Player[playerIndex].auto = 0;
}
}
this.InitPanel = function(){
var pos_left = (this.MapMaxX*this.BoxWidth)+10;
var pos_top = 5;
Canvas.insertAdjacentHTML("beforeEnd","<span id='panel' style='position:absolute;left:"+pos_left+";top:"+pos_top+";'>数据读取中...</span>");
var str = "";
str += "说明:<br>"
str += "控制1 方向:↑↓←→ 放泡泡:enter 切换道具:1 使用道具:0"
str += "<br>"
str += "控制2 方向:wsaf 放泡泡:space 切换道具:e 使用道具:f"
str += "<br>背景音乐开关: n 道具音效开关: m<br><hr>"
for (var i=0; i<this.Player.length; i++)
{
str += "<img id='head"+i+"' src='res/player"+i+"/n3.gif' /> Player"+i+" <input type=button name=btn value='控制1' onclick='"+this.ClassName+".ControlChange("+i+",0)' /> <input type=button name=btn value='控制2' onclick='"+this.ClassName+".ControlChange("+i+",1)' /> <input type=button name=btn value='电脑' onclick='"+this.ClassName+".ControlChange("+i+",-1)' /><br>"
str += "<img src='res/equip_n.gif' width='35' height='35' /> × <span id=panel"+i+"_popo>"+this.Player[i].popo+"</span>";
str += " <img src='res/equip_p.gif' width='35' height='35' /> × <span id=panel"+i+"_power>"+this.Player[i].power+"</span>";
str += " <img id='panel"+i+"_use_0' src='res/equip_0.gif' style='border:#ffffff solid 1px' width='35' height='35' /> × <span id=panel"+i+"_equip_0>"+this.Player[i].equip_remain[0]+"</span>";
str += " <img id='panel"+i+"_use_1' src='res/equip_1.gif' style='border:#3473d2 solid 1px' width='35' height='35' /> × <span id=panel"+i+"_equip_1>"+this.Player[i].equip_remain[1]+"</span>";
str += " <img id='panel"+i+"_use_2' src='res/equip_2.gif' style='border:#3473d2 solid 1px' width='35' height='35' /> × <span id=panel"+i+"_equip_2>"+this.Player[i].equip_remain[2]+"</span>";
str += "<br><hr>";
}
document.getElementById("panel").innerHTML = str;
}
this.FreshPanel = function(){
for (var i=0; i<this.Player.length; i++)
{
document.getElementById("panel"+i+"_popo").innerText = this.Player[i].popo;
document.getElementById("panel"+i+"_power").innerText = this.Player[i].power;
document.getElementById("panel"+i+"_equip_0").innerText = this.Player[i].equip_remain[0];
document.getElementById("panel"+i+"_equip_1").innerText = this.Player[i].equip_remain[1];
document.getElementById("panel"+i+"_equip_2").innerText = this.Player[i].equip_remain[2];
}
}
//检查物品
this.AutoFind = function(dir, str, n){
var x = this.Player[n].x;
var y = this.Player[n].y;
if (dir == 0) //水平方向
{
var f1 = x;
var f2 = x;
while (f1>1 && (this.Map[f1][y]==" " || this.Map[f1][y]==str || (1==this.Player[n].fly && this.Map[f1][y]=="k"))) { f1--;}
while (f2<this.MapMaxX-1 && (this.Map[f2][y]==" " || this.Map[f2][y]==str || (1==this.Player[n].fly && this.Map[f2][y]=="k"))) { f2++;}
for (var i=f1; i<=f2; i++)
{
if (this.Map[i][y] == str)
{
return i;
}
}
}
else //竖直方向
{
var f1 = y;
var f2 = y;
while (f1>0 && (this.Map[x][f1]==" " || this.Map[x][f1]==str || (1==this.Player[n].fly && this.Map[x][f1]=="k"))) { f1--;}
while (f2<this.MapMaxY-1 && (this.Map[x][f2]==" " || this.Map[x][f2]==str || (1==this.Player[n].fly && this.Map[x][f2]=="k"))) { f2++;}
for (var i=f1; i<=f2; i++)
{
if (this.Map[x][i] == str)
{
return i;
}
}
}
return 0;
}
//精简路径
this.ShortPath = function(n){
var ubd = this.Player[n].movepath.length-1;
if (0 >= ubd) return 0;
for (var i=0; i<ubd; i++)
{
for (var j=ubd; j>i; j--)
{
if (this.Player[n].movepath[i][0]==this.Player[n].movepath[j][0] && this.Player[n].movepath[i][1]==this.Player[n].movepath[j][1])
{
this.Player[n].movepath.splice(i, j-i);
ubd-=(j-i);
break;
}
}
}
}
//查找从开始位置到结束位置的路径 mode: 0-只捡查 1-捡查并保存路径
this.FindPath = function(x1, y1, x2, y2, n, mode)
{
var x = x1;
var y = y1;
var addx = 0;
var addy = 0;
var c = 2*(Math.abs(x2-x1)+Math.abs(y2-y1)+1);
if (mode > 0) this.Player[n].movepath.length = 0;
var AllowStr = " nprtf"
while (c > 0)
{
addx = x<x2?1:(x>x2?-1:0);
addy = y<y2?1:(y>y2?-1:0);
if (x > this.MapMaxX-1 || y > this.MapMaxY-1) return 0;
if (x==x2 && y==y2) return 1;
if (AllowStr.indexOf(this.Map[x+addx][y])!=-1 || AllowStr.indexOf(this.Map[x][y+addy])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x+addx][y]) || (1==this.Player[n].fly && "k"==this.Map[x][y+addy]) || (1==this.Player[n].direct%2 && "y"==this.Map[x+addx][y]) || (1==this.Player[n].direct%2 && "y"==this.Map[x][y+addy]))
{
if (0==this.GetRnd(1))
{
if (AllowStr.indexOf(this.Map[x+addx][y])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x+addx][y]) || (1==this.Player[n].direct%2 && "y"==this.Map[x+addx][y]))
{
x += addx;
if (mode > 0) this.Player[n].movepath[this.Player[n].movepath.length] = new Array(x, y);
if (x==x2 && y==y2) return 1;
if (AllowStr.indexOf(this.Map[x][y+addy])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x][y+addy]) || (1==this.Player[n].direct%2 && "y"==this.Map[x][y+addy]))
{
y += addy;
if (mode > 0) this.Player[n].movepath[this.Player[n].movepath.length] = new Array(x, y);
if (x==x2 && y==y2) return 1;
}
}
else if (AllowStr.indexOf(this.Map[x][y+addy])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x][y+addy]) || (1==this.Player[n].direct%2 && "y"==this.Map[x][y+addy]))
{
y += addy;
if (mode > 0) this.Player[n].movepath[this.Player[n].movepath.length] = new Array(x, y);
if (x==x2 && y==y2) return 1;
if (AllowStr.indexOf(this.Map[x+addx][y])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x+addx][y]) || (1==this.Player[n].direct%2 && "y"==this.Map[x+addx][y]))
{
x += addx;
if (mode > 0) this.Player[n].movepath[this.Player[n].movepath.length] = new Array(x, y);
if (x==x2 && y==y2) return 1;
}
}
}
else
{
if (AllowStr.indexOf(this.Map[x][y+addy])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x][y+addy]) || (1==this.Player[n].direct%2 && "y"==this.Map[x][y+addy]))
{
y += addy;
if (mode > 0) this.Player[n].movepath[this.Player[n].movepath.length] = new Array(x, y);
if (x==x2 && y==y2) return 1;
if (AllowStr.indexOf(this.Map[x+addx][y])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x+addx][y]) || (1==this.Player[n].direct%2 && "y"==this.Map[x+addx][y]))
{
x += addx;
if (mode > 0) this.Player[n].movepath[this.Player[n].movepath.length] = new Array(x, y);
if (x==x2 && y==y2) return 1;
}
}
else if (AllowStr.indexOf(this.Map[x+addx][y])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x+addx][y]) || (1==this.Player[n].direct%2 && "y"==this.Map[x+addx][y]))
{
x += addx;
if (mode > 0) this.Player[n].movepath[this.Player[n].movepath.length] = new Array(x, y);
if (x==x2 && y==y2) return 1;
if (AllowStr.indexOf(this.Map[x][y+addy])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x][y+addy]) || (1==this.Player[n].direct%2 && "y"==this.Map[x][y+addy]))
{
y += addy;
if (mode > 0) this.Player[n].movepath[this.Player[n].movepath.length] = new Array(x, y);
if (x==x2 && y==y2) return 1;
}
}
}
}
else
{
if (0==addx && 0==addy)
{
return 1;
}
else if (0==addx)
{
addx = x<x1?-1:1;
if (AllowStr.indexOf(this.Map[x+addx][y])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x+addx][y]) || (1==this.Player[n].direct%2 && "y"==this.Map[x+addx][y]))
{
x += addx;
if (mode > 0) this.Player[n].movepath[this.Player[n].movepath.length] = new Array(x, y);
if (x==x2 && y==y2) return 1;
}
else if (AllowStr.indexOf(this.Map[x][y-addy])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x][y-addy]) || (1==this.Player[n].direct%2 && "y"==this.Map[x][y-addy]))
{
y += addy;
if (mode > 0) this.Player[n].movepath[this.Player[n].movepath.length] = new Array(x, y);
if (x==x2 && y==y2) return 1;
}
}
else if (0==addy)
{
addy = y<y1?-1:1;
if (AllowStr.indexOf(this.Map[x][y+addy])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x][y+addy]) || (1==this.Player[n].direct%2 && "y"==this.Map[x][y+addy]))
{
y += addy;
if (mode > 0) this.Player[n].movepath[this.Player[n].movepath.length] = new Array(x, y);
if (x==x2 && y==y2) return 1;
}
else if (AllowStr.indexOf(this.Map[x-addx][y])!=-1 || (1==this.Player[n].fly && "k"==this.Map[x-addx][y]) || (1==this.Player[n].direct%2 && "y"==this.Map[x-addx][y]))
{
x += addx;
if (mode > 0) this.Player[n].movepath[this.Player[n].movepath.length] = new Array(x, y);
if (x==x2 && y==y2) return 1;
}
else
{
return 0;
}
}
}
c--;
}
return 0;
}
//躲开泡泡
this.AutoAvoid = function(n){
if (this.Player[n].movepath.length > 0) return 0;
if (1 == this.AutoIsSafe(this.Player[n].x, this.Player[n].y)) return 1;
var beginx = this.Player[n].x-5;
var endx = this.Player[n].x+5;
if (beginx <= 0) beginx =1;
if (endx >= this.MapMaxX-1) endx = this.MapMaxX-2;
var beginy = this.Player[n].y-5;
var endy = this.Player[n].y+5;
if (beginy <= 0) beginy =1;
if (endy >= this.MapMaxY-1) endy = this.MapMaxY-2;
var arr = new Array();
var AllowStr = " nprtf"
for (var i=beginx; i<=endx; i++)
{
for (var j=beginy; j<endy; j++)
{
if ((AllowStr.indexOf(this.Map[i][j])!=-1 || ("k"==this.Map[i][j] && 1==this.Player[n].fly)) && 1==this.AutoIsSafe(i, j))
{
arr[arr.length] = new Array(i, j);
}
}
}
if (arr.length > 0)
{
//打乱数组
for (var i=0; i<arr.length; i++)
{
var rnd = this.GetRnd(arr.length-1);
var temparr = arr[rnd];
arr[rnd] = arr[i];
arr[i] = temparr;
}
for (var i=0; i<arr.length; i++)
{
if (1 == this.FindPath(this.Player[n].x, this.Player[n].y, arr[i][0], arr[i][1], n, 1))
{
this.ShortPath(n);
this.Say(n, "我逃!");
return 0;
}
}
}
return 1;
}
//周围泡泡检查
this.AutoIsSafe = function(x, y){
for (var i=0; i<this.BulbMax; i++)
{
if (1==this.Bulb[i].display)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -