- 注册时间
- 2018-4-16
- 最后登录
- 2020-2-12
游戏开发者
- 积分
- 5
|

楼主 |
发表于 2019-1-23 20:49:17
|
显示全部楼层
本帖最后由 wushiyo 于 2019-1-24 01:16 编辑
我做的是旅行游戏,想做一个够根据鼠标位置进行滚屏的大地图选单。
游戏界面1280X720 大地图3400X1200 会在地图上设置很多地点坐标按钮。
这些按钮本身含有变量条件,即满足某个条件才会显示某个地点按钮。然后希望这些按钮能跟着大地图滚动一起移动。
目前我基本上是把水螅大的寻路范例全部复制过来用的,但是自己也分不清哪些是实现大地图滚动的QAQ
下面附上代码,特别特别长OTZ
;===============================================================
*start
[iscript]
class cha extends KAGLayer //主角类
{
var cha;
var pic;//图片名
var chat; //状态显示层
var x; //主角在地图上的相对坐标
var y;
var name; //主角姓名
var faceto;//面向
var faceto1;
var step;//行走步数
function cha(win, par)
{
super.KAGLayer(win, par);
if(typeof win.cursorPointed !== "undefined")
cursor = win.cursorPointed;
hitType = htMask;
hitThreshold = 0;
focusable = true;
}
function finalize() // 销毁资源
{
super.finalize(...);
}
function loadImages(storage, key)
{
super.loadImages(storage, key);
super.setSizeToImageSize();
}
function onMouseDown(x, y, button, shift)
{
}
function onMouseUp(x, y, button, shift)
{
}
function onMouseMove(x, y)
{
}
function onKeyDown(key, shift, process){}
function onMouseEnter()
{
chat = window.temporaryLayer;
chat.visible=true;
chat.loadImages("form.png");
chat.setSizeToImageSize();
chat.setPos(646, 0);
chat.font.height=25;
chat.drawText(10, 10, this.name, 0x000000, 255, true, 512, 0x000000, 5, 0, 0);
}
function onMouseLeave()
{
chat.visible=false;
}
function setSize(w, h)
{
super.setSize(w, h);
setImageSize(w, h);
update();
}
function setPos(x, y)
{
this.x=x;
this.y=y;
var aax=x - this.imageWidth/2;
var aay=y - this.imageHeight;
super.setPos(aax, aay);
update();
}
}
class bg extends KAGLayer
{
var bg;
var x;//地图左上角坐标
var y;
var cx;//鼠标点击点坐标
var cy;
function bg(win, par)
{
super.KAGLayer(win, par);
if(typeof win.cursorPointed !== "undefined")
cursor = win.cursorPointed;
hitType = htMask;
hitThreshold = 0;
focusable = true;
}
function finalize()
{
super.finalize(...);
}
function loadImages(storage, key)
{
super.loadImages(storage, key);
super.setSizeToImageSize();
}
function onMouseDown(x, y, button, shift)
{
if (button == mbLeft)
{
if(f.bg.getMainPixel(kag.fore.base.cursorX - this.x + 10,kag.fore.base.cursorY - this.y + 10) == 4679039)
{
this.cx=kag.fore.base.cursorX;
this.cy=kag.fore.base.cursorY;
seachpath(kag.fore.base.cursorX, kag.fore.base.cursorY);
}
}
}
function onKeyDown()
{
tf.left = kag.getKeyState(0x25);
tf.up = kag.getKeyState(0x26);
tf.right = kag.getKeyState(0x27);
tf.down = kag.getKeyState(0x28);
if(tf.left == 1 && tf.up == 0 && tf.right == 0 && tf.down == 0)
{
goleft(f.chas[0]);
}
if(tf.left == 1 && tf.up == 1 && tf.right == 0 && tf.down == 0)
{
golu(f.chas[0]);
}
if(tf.left == 0 && tf.up == 1 && tf.right == 0 && tf.down == 0)
{
goup(f.chas[0]);
}
if(tf.left == 0 && tf.up == 1 && tf.right == 1 && tf.down == 0)
{
goru(f.chas[0]);
}
if(tf.left == 0 && tf.up == 0 && tf.right == 1 && tf.down == 0)
{
goright(f.chas[0]);
}
if(tf.left == 0 && tf.up == 0 && tf.right == 1 && tf.down == 1)
{
gord(f.chas[0]);
}
if(tf.left == 0 && tf.up == 0 && tf.right == 0 && tf.down == 1)
{
godown(f.chas[0]);
}
if(tf.left == 1 && tf.up == 0 && tf.right == 0 && tf.down == 1)
{
gold(f.chas[0]);
}
}
function onKeyUP()
{
tf.left = kag.getKeyState(0x25);
tf.up = kag.getKeyState(0x26);
tf.right = kag.getKeyState(0x27);
tf.down = kag.getKeyState(0x28);
if(tf.left == 0 && tf.up == 0 && tf.right == 0 && tf.down == 0)
{
stop(f.chas[0]);
}
}
function setSize(w, h)
{
super.setSize(w, h);
setImageSize(w, h);
update();
}
function setPos(x, y)
{
this.x=x;
this.y=y;
super.setPos(x, y);
update();
}
var sp = new Timer(spt, "");
function seachpath(x, y)
{
sp.enabled = true;
sp.interval = 30;
}
sf.aa=[];
var i;
function spt()
{
var chx=f.chas[0].x;
var chy=f.chas[0].y;
var cx=this.cx;
var cy=this.cy;
if((cx - chx < 3 && cx - chx > -3) && (cy - chy < 3 && cy - chy > -3))
{
stop(f.chas[0]);
return;
}
if((cy - chy)/(cx - chx) <= 0.577 && (cy - chy)/(cx - chx) >= 0.176 && (cx - chx) > 0)
{
if(f.chas[0].faceto1 == 5)
{
toright(f.chas[0]);
return;
}
if(f.chas[0].faceto1 == 6)
{
tord(f.chas[0]);
return;
}
}
if((cy - chy)/(cx - chx) >= 1.732 && (cy - chy)/(cx - chx) <= 5.671 && (cx - chx) > 0)
{
if(f.chas[0].faceto1 == 6)
{
tord(f.chas[0]);
return;
}
if(f.chas[0].faceto1 == 7)
{
todown(f.chas[0]);
return;
}
}
if((cy - chy)/(cx - chx) <= -1.732 && (cy - chy)/(cx - chx) >= -5.671 && (cy - chy) > 0)
{
if(f.chas[0].faceto1 == 7)
{
todown(f.chas[0]);
return;
}
if(f.chas[0].faceto1 == 8)
{
told(f.chas[0]);
return;
}
}
if((cy - chy)/(cx - chx) >= -0.577 && (cy - chy)/(cx - chx) <= -0.176 && (cy - chy) > 0)
{
if(f.chas[0].faceto1 == 8)
{
told(f.chas[0]);
return;
}
if(f.chas[0].faceto1 == 1)
{
toleft(f.chas[0]);
return;
}
}
if((cy - chy)/(cx - chx) >= 0.176 && (cy - chy)/(cx - chx) <= 0.577 && (cx - chx) < 0)
{
if(f.chas[0].faceto1 == 1)
{
toleft(f.chas[0]);
return;
}
if(f.chas[0].faceto1 == 2)
{
tolu(f.chas[0]);
return;
}
}
if((cy - chy)/(cx - chx) >= 1.732 && (cy - chy)/(cx - chx) <= 5.671 && (cx - chx) < 0)
{
if(f.chas[0].faceto1 == 2)
{
tolu(f.chas[0]);
return;
}
if(f.chas[0].faceto1 == 3)
{
toup(f.chas[0]);
return;
}
}
if((cy - chy)/(cx - chx) <= -1.732 && (cy - chy)/(cx - chx) >= -5.671 && (cy - chy) < 0)
{
if(f.chas[0].faceto1 == 3)
{
toup(f.chas[0]);
return;
}
if(f.chas[0].faceto1 == 4)
{
toru(f.chas[0]);
return;
}
}
if((cy - chy)/(cx - chx) >= -0.577 && (cy - chy)/(cx - chx) <= -0.176 && (cy - chy) < 0)
{
if(f.chas[0].faceto1 == 4)
{
toru(f.chas[0]);
return;
}
if(f.chas[0].faceto1 == 5)
{
toright(f.chas[0]);
return;
}
}
if((cy - chy)/(cx - chx) <= 0.364 && (cy - chy)/(cx - chx) >= -0.364 && (cx - chx) > 0)
{
toright(f.chas[0]);
return;
}
if((cy - chy)/(cx - chx) > 0.364 && (cy - chy)/(cx - chx) < 2.747 && (cx - chx) > 0)
{
tord(f.chas[0]);
return;
}
if(((cy - chy)/(cx - chx) >= 2.747 || (cy - chy)/(cx - chx) <= -2.747) && (cy - chy) > 0)
{
todown(f.chas[0]);
return;
}
if((cy - chy)/(cx - chx) > -2.747 && (cy - chy)/(cx - chx) < -0.364 && (cy - chy) > 0)
{
told(f.chas[0]);
return;
}
if((cy - chy)/(cx - chx) > -0.364 && (cy - chy)/(cx - chx) < 0.364 && (cx - chx) < 0)
{
toleft(f.chas[0]);
return;
}
if((cy - chy)/(cx - chx) > 0.364 && (cy - chy)/(cx - chx) < 2.747 && (cx - chx) < 0)
{
tolu(f.chas[0]);
return;
}
if(((cy - chy)/(cx - chx) > 2.747 || (cy - chy)/(cx - chx) < -2.747) && (cy - chy) < 0)
{
toup(f.chas[0]);
return;
}
if(((cy - chy)/(cx - chx) > -2.747 || (cy - chy)/(cx - chx) < -0.364) && (cy - chy) < 0)
{
toru(f.chas[0]);
return;
}
}
function stop(chaa)
{
sp.enabled = false;
chaa.step=0;
if(chaa.faceto == 1)
{
chaa.loadImages(chaa.pic + "_17");
}
if(chaa.faceto == 2)
{
chaa.loadImages(chaa.pic + "_25");
}
if(chaa.faceto == 3)
{
chaa.loadImages(chaa.pic + "_33");
}
if(chaa.faceto == 4)
{
chaa.loadImages(chaa.pic + "_25");
chaa.flipLR();
}
if(chaa.faceto == 5)
{
chaa.loadImages(chaa.pic + "_17");
chaa.flipLR();
}
if(chaa.faceto == 6)
{
chaa.loadImages(chaa.pic + "_9");
chaa.flipLR();
}
if(chaa.faceto == 7)
{
chaa.loadImages(chaa.pic + "_1");
}
if(chaa.faceto == 8)
{
chaa.loadImages(chaa.pic + "_9");
}
chaa.setPos(chaa.x, chaa.y);
}
function goright(chaa)
{
chaa.faceto1=chaa.faceto;
chaa.faceto=5;
if(f.bg.getMainPixel(chaa.x - this.x + 3 + 10,chaa.y - this.y + 10) == 4679039)
{
chaa.x=chaa.x + 3;
}
if(chaa.step >= 1 && chaa.step <= 8)
{
chaa.step = chaa.step + 1;
if(chaa.step > 8)
{
chaa.step = 1;
}
var tt=(chaa.step + 16)*1;
chaa.loadImages(chaa.pic + "_" + tt);
chaa.flipLR();
}
if(chaa.step < 1 || chaa.step > 8)
{
chaa.step=1;
chaa.loadImages(chaa.pic + "_17");
chaa.flipLR();
}
chaa.setPos(chaa.x, chaa.y);
}
function gord(chaa)
{
chaa.faceto1=chaa.faceto;
chaa.faceto=6;
if(f.bg.getMainPixel(chaa.x - this.x + 2 + 10,chaa.y - this.y + 2 + 10) == 4679039)
{
chaa.x=chaa.x + 2;
chaa.y=chaa.y + 2;
}
if(chaa.step >= 9 && chaa.step <= 16)
{
chaa.step = chaa.step + 1;
if(chaa.step > 16)
{
chaa.step = 9;
}
var tt=chaa.step;
chaa.loadImages(chaa.pic + "_" + tt);
chaa.flipLR();
}
if(chaa.step < 9 || chaa.step > 16)
{
chaa.step=9;
chaa.loadImages(chaa.pic + "_9");
chaa.flipLR();
}
chaa.setPos(chaa.x, chaa.y);
}
function godown(chaa)
{
chaa.faceto1=chaa.faceto;
chaa.faceto=7;
if(f.bg.getMainPixel(chaa.x - this.x + 10,chaa.y - this.y + 3 + 10) == 4679039)
{
chaa.y=chaa.y + 3;
}
if(chaa.step >= 17 && chaa.step <= 24)
{
chaa.step = chaa.step + 1;
if(chaa.step > 24)
{
chaa.step = 17;
}
var tt=(chaa.step - 16)*1;
chaa.loadImages(chaa.pic + "_" + tt);
}
if(chaa.step < 17 || chaa.step > 24)
{
chaa.step=17;
chaa.loadImages(chaa.pic + "_1");
}
chaa.setPos(chaa.x, chaa.y);
}
function gold(chaa)
{
chaa.faceto1=chaa.faceto;
chaa.faceto=8;
if(f.bg.getMainPixel(chaa.x - this.x - 2 + 10,chaa.y - this.y + 2 + 10) == 4679039)
{
chaa.x=chaa.x - 2;
chaa.y=chaa.y + 2;
}
if(chaa.step >= 25 && chaa.step <= 32)
{
chaa.step = chaa.step + 1;
if(chaa.step > 32)
{
chaa.step = 25;
}
var tt=(chaa.step - 16)*1;
chaa.loadImages(chaa.pic + "_" + tt);
}
if(chaa.step < 25 || chaa.step > 32)
{
chaa.step=25;
chaa.loadImages(chaa.pic + "_9");
}
chaa.setPos(chaa.x, chaa.y);
}
function goleft(chaa)
{
chaa.faceto1=chaa.faceto;
chaa.faceto=1;
if(f.bg.getMainPixel(chaa.x - this.x - 3 + 10,chaa.y - this.y) == 4679039)
{
chaa.x=chaa.x - 3;
}
if(chaa.step >= 33 && chaa.step <= 40)
{
chaa.step = chaa.step + 1;
if(chaa.step > 40)
{
chaa.step = 32;
}
var tt=(chaa.step - 16)*1;
chaa.loadImages(chaa.pic + "_" + tt);
}
if(chaa.step < 33 || chaa.step > 40)
{
chaa.step=33;
chaa.loadImages(chaa.pic + "_17");
}
chaa.setPos(chaa.x, chaa.y);
}
function golu(chaa)
{
chaa.faceto1=chaa.faceto;
chaa.faceto=2;
if(f.bg.getMainPixel(chaa.x - this.x - 2 + 10,chaa.y - this.y - 2 + 10) == 4679039)
{
chaa.x=chaa.x - 2;
chaa.y=chaa.y - 2;
}
if(chaa.step >= 41 && chaa.step <= 48)
{
chaa.step = chaa.step + 1;
if(chaa.step > 48)
{
chaa.step = 41;
}
var tt=(chaa.step - 16)*1;
chaa.loadImages(chaa.pic + "_" + tt);
}
if(chaa.step < 41 || chaa.step > 48)
{
chaa.step=41;
chaa.loadImages(chaa.pic + "_25");
}
chaa.setPos(chaa.x, chaa.y);
}
function goup(chaa)
{
chaa.faceto1=chaa.faceto;
chaa.faceto=3;
if(f.bg.getMainPixel(chaa.x - this.x + 10,chaa.y - this.y - 3 + 10) == 4679039)
{
chaa.y=chaa.y - 3;
}
if(chaa.step >= 49 && chaa.step <= 56)
{
chaa.step = chaa.step + 1;
if(chaa.step > 56)
{
chaa.step = 49;
}
var tt=(chaa.step - 16)*1;
chaa.loadImages(chaa.pic + "_" + tt);
}
if(chaa.step < 49 || chaa.step > 56)
{
chaa.step=49;
chaa.loadImages(chaa.pic + "_33");
}
chaa.setPos(chaa.x, chaa.y);
}
function goru(chaa)
{
chaa.faceto1=chaa.faceto;
chaa.faceto=4;
if(f.bg.getMainPixel(chaa.x - this.x + 2 + 10,chaa.y - this.y - 2 + 10) == 4679039)
{
chaa.x=chaa.x + 2;
chaa.y=chaa.y - 2;
}
if(chaa.step >= 57 && chaa.step <= 64)
{
chaa.step = chaa.step + 1;
if(chaa.step > 64)
{
chaa.step = 57;
}
var tt=(chaa.step - 32)*1;
chaa.loadImages(chaa.pic + "_" + tt);
chaa.flipLR();
}
if(chaa.step < 57 || chaa.step > 64)
{
chaa.step=57;
chaa.loadImages(chaa.pic + "_25");
chaa.flipLR();
}
chaa.setPos(chaa.x, chaa.y);
}
}
var ota = new Timer(otat, "");//地图移动和鼠标判定
function ontouch()
{
ota.enabled = true;
ota.interval = 50;
}
function endtouch()
{
ota.enabled = false;
}
function otat()
{
if(kag.fore.base.cursorY <= 720 && kag.fore.base.cursorY >= 0 && kag.fore.base.cursorX <= 1280 && kag.fore.base.cursorX >= 0)
{
if (f.bg.getMainPixel(kag.fore.base.cursorX - f.bg1.x + 10,kag.fore.base.cursorY - f.bg1.y + 10) != 4679039)
{
f.bg1.cursor = "04.ani";
}
if (f.bg.getMainPixel(kag.fore.base.cursorX - f.bg1.x + 10,kag.fore.base.cursorY - f.bg1.y + 10) == 4679039)
{
f.bg1.cursor = "01.cur";
}
}
if (kag.fore.base.cursorX <= 20)
{
tf.ax = 5;
tf.ay = 0;
}
if (kag.fore.base.cursorX >= 1260)
{
tf.ax = -5;
tf.ay = 0;
}
if (kag.fore.base.cursorY <= 20)
{
tf.ax = 0;
tf.ay = 5;
}
if (kag.fore.base.cursorY >= 700)
{
tf.ax = 0;
tf.ay = -5;
}
if (f.bg1.x + tf.ax > 0)
{
tf.ax = 5 - f.bg1.x - tf.ax;
}
if (f.bg1.x + tf.ax < 1280-f.bg1.imageWidth)
{
tf.ax = 1280-f.bg1.imageWidth - f.bg1.x;
}
if (f.bg1.y + tf.ay > 0)
{
tf.ay = 5 - f.bg1.y - tf.ay;
}
if (f.bg1.y + tf.ay < 720-f.bg1.imageHeight)
{
tf.ay = 720-f.bg1.imageHeight - f.bg1.y;
}
if (kag.fore.base.cursorY >= 700 || kag.fore.base.cursorY <= 20 || kag.fore.base.cursorX >= 1260 || kag.fore.base.cursorX <= 20)
{
f.bg1.x=f.bg1.x + tf.ax;
f.bg1.y=f.bg1.y + tf.ay;
f.bg1.cx=f.bg1.cx + tf.ax;
f.bg1.cy=f.bg1.cy + tf.ay;
for (var i = 0; i < f.chas.count; i++)
{
f.chas.x=f.chas.x + tf.ax;
f.chas.y=f.chas.y + tf.ay;
f.chas.setPos(f.chas.x, f.chas.y);
}
f.bg1.setPos(f.bg1.x, f.bg1.y);
f.bg.setPos(f.bg1.x - 10, f.bg1.y - 10);
}
}
var maskt = new Timer(masktt, "");//开始的黑幕消失
function maskf()
{
maskt.enabled = true;
maskt.interval = 100;
}
function masktt()
{
f.mask.opacity = f.mask.opacity - 25;
if(f.mask.opacity <= 10)
{
f.mask.visible=false;
maskt.enabled = false;
}
}
f.chas = [];
//有关于这里我为什么用数组……是因为……这个最初是写来打算做即时战略那样一大群人行走的……如果主角只有一个,其实里边很多东西可以写得更简单些……
f.bg = new MessageLayer(kag, kag.fore.base);
f.bg.visible=true;
f.bg.loadImages("");
f.bg.setSizeToImageSize();
f.bg.setPos(-10, -10);
f.bg1=new bg(kag, kag.fore.base);
f.bg1.visible=true;
f.bg1.loadImages("");
f.bg1.setSizeToImageSize();
f.bg1.setPos(0, 0);
//f.bg1.opacity=100;
f.chas.add(new cha(kag, kag.fore.base));
f.mask = new Layer(kag, kag.fore.base);
f.mask.visible=true;
f.mask.loadImages("bgb");
f.mask.setSizeToImageSize();
f.mask.setPos(0, 0);
maskf();
ontouch();
[endscript]
;=================================================
上面这段是用的jump直接跳过去,然后我接在后面KAG写的任何东西都无法显示or提示无法将void类型变换为Object。
求解答QAQ
|
|