home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ring.yamanashi.ac.jp/pub/pc/freem/action/
/
action.zip
/
baku100.zip
/
baku100
/
Kernel
/
Map
/
Map.tonyu
next >
Wrap
Text File
|
2008-04-18
|
10KB
|
455 lines
extends Sprite;
function set(xx,yy,p,f) {
var rx,ry,tx,ty;
if (!enabled) return;
rx=amod(xx ,width);
ry=amod(yy ,height);
//print (xx+yy*width);
data.set(rx+ry*width,p);
/*if(0){ print (strcat("xx=",xx));
print (strcat("yy=",yy));
print (strcat("mpx=",mpx));
print (strcat("mpy=",mpy));
print (strcat("scx=",scx));
print (strcat("scy=",scy));
print (strcat("scW=",scWidth));
print (strcat("scH=",scHeight));
print (strcat("W=",width));
print (strcat("H=",height));
print (amod( scx+ (xx-mpx) ,scWidth));
print (amod( scy+ (yy-mpy),scHeight));
}*/
tx=xx-mpx;
if (tx<0 || tx>=scWidth) return;
tx=amod( scx+ tx,scWidth);
ty=yy-mpy;
if (ty<0 || ty>=scHeight) return;
ty=amod( scy+ ty ,scHeight);
panel.fillRect(tx*pwidth,ty*pheight,
tx*pwidth+pwidth,ty*pheight+pheight, 0);
panel.drawSprite(tx*pwidth+pwidth/2 ,ty*pheight+pheight/2 ,p );
// data=p;
}
function get(xx,yy) {
if (!enabled) return;
xx=amod(xx , width);
yy=amod(yy , height);
return data.get(xx+yy*width);
}
function getAt(xx,yy) {
//print(xx);
//print(yy);
//print(floor(yy/pwidth));
//print("+++");s
return get(floor(xx/pwidth),floor(yy/pheight));
}
function init(w,h,pw,ph) {
var xx,yy,ndata;
x=0;y=0;
pwidth=pw;pheight=ph;
enabled=0; if (w*h==0) return;
enabled=1;
if (data is Array) {
ndata=new Array();
yy=0;
while (yy<h) {
xx=0;
while (xx<w) {
ndata.add(get(xx,yy));
xx+=1;
}
yy+=1;
}
data=ndata;
} else {
data=new Array();
xx=0;
while (xx<w) {
yy=0;
while (yy<h) {
data.add(-1);
yy=yy+1;
}
xx=xx+1;
}
}
width=w;height=h;
prevSW=0;prevSH=0;
//scWidth=floor($screenWidth/pwidth)+2;
//scHeight=floor($screenHeight/pheight)+2;
//panel=new Panel(scWidth*pwidth,scHeight*pheight);
}
function draw() {
if (!enabled) return;
//fillRect(0,0,100,100,$clpink);
setAdjust(0,0);
panel.zOrder=200;
panel.draw(0,0,$screenWidth,$screenHeight,scfx,scfy);
// drawMapSprite(scfx,scfy,scWidth*pwidth,scHeight*pheight);
}
function scrollLeft(){
var c,d_mpx,d_mpy,d_scx,d_scy;
d_mpx=amod (mpx-1 , width);
d_mpy=amod (mpy , height);
d_scx=amod (scx-1 , scWidth);
d_scy=amod (scy , scHeight);
c=scHeight;
while (c>0) {
panel.fillRect(d_scx*pwidth,d_scy*pheight ,d_scx*pwidth+pwidth,d_scy*pheight+pheight, 0);
panel.drawSprite(d_scx*pwidth+pwidth/2,d_scy*pheight+pheight/2 ,
get(d_mpx,d_mpy) );
d_mpy=amod (d_mpy+1 , height);
d_scy=amod (d_scy+1 , scHeight);
c+=-1;
}
mpx+=-1;
scx+=-1;
}
function scrollRight(){
var c,d_mpx,d_mpy,d_scx,d_scy;
d_mpx=amod(mpx+scWidth , width);
d_mpy=amod(mpy , height);
d_scx=amod(scx ,scWidth);
d_scy=amod(scy ,scHight);
c=scHeight;
while (c>0) {
panel.fillRect(d_scx*pwidth,d_scy*pheight ,d_scx*pwidth+pwidth,d_scy*pheight+pheight, 0);
panel.drawSprite(d_scx*pwidth+pwidth/2,d_scy*pheight+pheight/2
, get(d_mpx,d_mpy) );
d_mpy=amod (d_mpy+1 , height);
d_scy=amod (d_scy+1 , scHeight);
c+=-1;
}
mpx+=1;
scx+=1;
}
function scrollUp(){
var c,d_mpx,d_mpy,d_scx,d_scy;
d_mpx=amod (mpx , width);
d_mpy=amod (mpy-1 , height);
d_scx=amod (scx , scWidth);
d_scy=amod (scy-1 , scHeight);
c=scWidth;
while (c>0) {
panel.fillRect(d_scx*pwidth,d_scy*pheight ,d_scx*pwidth+pwidth,d_scy*pheight+pheight, 0);
panel.drawSprite(d_scx*pwidth+pwidth/2,d_scy*pheight+pheight/2
, get(d_mpx,d_mpy) );
d_mpx=amod (d_mpx+1 , width);
d_scx=amod (d_scx+1 , scWidth);
c+=-1;
}
mpy+=-1;
scy+=-1;
}
function scrollDown(){
var c,d_mpx,d_mpy,d_scx,d_scy;
d_mpx=amod (mpx , width);
d_mpy=amod (mpy+scHeight , height);
d_scx=amod (scx , scWidth);
d_scy=amod (scy , scHeight);
c=scWidth;
while (c>0) {
panel.fillRect(d_scx*pwidth,d_scy*pheight ,d_scx*pwidth+pwidth,d_scy*pheight+pheight, 0);
panel.drawSprite(d_scx*pwidth+pwidth/2 ,d_scy*pheight+pheight/2
, get(d_mpx,d_mpy) );
d_mpx=amod (d_mpx+1 , width);
d_scx=amod (d_scx+1 , scWidth);
c+=-1;
}
mpy+=1;
scy+=1;
}
function scrollTo(d_mpfx,d_mpfy) {
var dpx,dpy;
if(prevSW!=$screenWidth || prevSH!=$screenHeight) {
refreshChips(d_mpfx,d_mpfy);
$viewX=mpfx;$viewY=mpfy;
setAdjust($viewX,$viewY);
return;
}
d_mpfx=trunc(d_mpfx);
d_mpfy=trunc(d_mpfy);
if (enabled) {
mpx=floor(mpfx/pwidth);mpy=floor(mpfy/pheight);
d_mpx=floor(d_mpfx/pwidth);d_mpy=floor(d_mpfy/pheight);
while (mpx>d_mpx) scrollLeft();
while (mpx<d_mpx) scrollRight();
while (mpy>d_mpy) scrollUp();
while (mpy<d_mpy) scrollDown();
scfx=amod (scfx+d_mpfx-mpfx ,scWidth*pwidth);
scfy=amod (scfy+d_mpfy-mpfy ,scHeight*pheight);
scx=floor(scfx/pwidth); scy=floor(scfy/pheight);
}
mpfx=d_mpfx;
mpfy=d_mpfy;
$viewX=mpfx;$viewY=mpfy;
setAdjust($viewX,$viewY);
mpx=floor(mpfx/pwidth);mpy=floor(mpfy/pheight);
}
function refreshChips(ampfx,ampfy) {
var c,nc,xx,yy,cw,ch,xc,yc;
mpfx=ampfx;mpfy=ampfy;
$viewX=mpfx;$viewY=mpfy;
if (!enabled) return;
scWidth=floor($screenWidth/pwidth)+2;
scHeight=floor($screenHeight/pheight)+2;
panel=new Panel(scWidth*pwidth,scHeight*pheight);
prevSW=$screenWidth;
prevSH=$screenHeight;
mpx=floor(mpfx/pwidth);mpy=floor(mpfy/pheight);
//
scfx=amod(mpfx,pwidth);
scfy=amod(mpfy,pheight);
scx=0; scy=0;
yy=0;
yc=mpy;
while (yc<mpy+scHeight) {
xx=0;
xc=mpx;
while (xc<mpx+scWidth) {
panel.fillRect(xx,yy,xx+pwidth,yy+pheight, 0);
panel.drawSprite(xx+pwidth/2,yy+pheight/2,get(xc,yc) );
xx+=pwidth;
xc+=1;
}
yy+=pheight;
yc+=1;
}
}
function setBGColor(c){
$bgcolor=c;
}
function getBGColor() {
return $bgcolor;
}
function setBackGround(c) {
var w,h;
w=getPatWidth(c);
h=getPatHeight(c);
init(1,1,w,h);
set(0,0,c);
}
function mouseDrag(xx,yy,dx,dy,lb,rb) {
if ($_design_Mode){
if (rb) {
// print(mpfx);
// print(-dx+xx);
// print(mpfy);
// print(-dy+yy);
scrBufX+=xx-dx;
scrBufY+=yy-dy;
scrollto(mpfx+trunc(scrBufX/16)*16,mpfy+trunc(scrBufY/16)*16);
if (scrBufX>=16) scrBufX-=16;
if (scrBufX<=-16) scrBufX+=16;
if (scrBufY>=16) scrBufY-=16;
if (scrBufY<=-16) scrBufY+=16;
}
if (lb) {
mouseDown(dx,dy,lb,rb);
}
}
}
function mouseDown(xx,yy,lb,rb) {
var cx,cy;
if (lb && $_editMode==$_emMap) {
cx=floor((xx+mpfx) / pwidth);
cy=floor((yy+mpfy) / pheight);
yy=cy-$_mappen_width;
while (yy<=cy+$_mappen_width) {
xx=cx-$_mappen_width;
while (xx<=cx+$_mappen_width) {
set(xx,yy,$curSelPat); xx+=1;
}
yy+=1;
}
}
if (rb) {
$curSelPat=getAt($viewX+xx,$viewY+yy);
print($curSelPat);
}
}
function getGenerator() {
return _generator;
}
function setGenerator(g) {
_generator=g;
return g;
}
function makeTable(old) {
var i,j,oc,nc,no,o,tbl;
i=0;oc=0;tbl=new Array();
//old.sort();
$_tmp=0;
while (oc<old.size()) {
o=old.get(oc);
while (i<o.off) {
tbl.add(new MapPatDesc("$_tmp",i));
i+=1;
}
if (oc<old.size()-1) {
no=old.get(oc+1);j=0;
while (i<no.off) {
tbl.add(new MapPatDesc(o.name,j));
i+=1;
j+=1;
}
} else {
tbl.add(new MapPatDesc(o.name,0));
}
oc+=1;
}
i=0; nc=0;
while (i<tbl.size()) {
t=tbl.get(i);
tbl.set(i,getGlobal(t.name)+t.off);
//print (strcat(i,strcat("->",getGlobal(t.name)+t.off) ));
i+=1;
}
return tbl;
}
function loadMapFile() {
var tbl,i,ver,s,xx,yy,gen,lastofs;
print ("â}âbâvé≡ô╟é▌ì₧é±é┼éóé▄é╖");
gen=new Resource ( getGenerator() );
s=new ResourceReader(gen);
ver=s.readInt(); //version
if (ver==null) {
s.close();
return;
}
if (ver==1) {
i=s.readInt();
tbl=new Array();
while(i>0) {
tbl.add(new MapPatDesc
( s.readString() , s.readInt() )
);
i-=1;
}
tbl=makeTable(tbl);
}
data=new Array();
yy=0;
if (tbl && tbl.size()>0 ) lastofs=tbl.get(tbl.size()-1)-(tbl.size()-1); else lastofs=0;
while (yy<height) {
xx=0;
while (xx<width) {
t=s.readInt();//print(t);
if (tbl && t<tbl.size() && t>=0) data.add(tbl.get(t));
else data.add(t+lastofs);
xx+=1;
}
yy+=1;
}
s.close();
//print ("");
}
function onGenerate() {
var s,xx,yy,t,gen;
init(width,height,pwidth,pheight);
/*if (datastr) {
s=new BinReader(datastr);
data=new Array();
yy=0;
while (yy<height) {
xx=0;
while (xx<width) {
t=s.readInt();//print(t);
data.add(t);
xx+=1;
}
yy+=1;
}
s.close();
} else */
loadMapFile();
mpfx=0;mpfy=0;
refreshChips(mpfx,mpfy);
}
function saveMapFile() {
var wrt,cc,gen,s,a,b;
gen=new Resource ( getGenerator() );
if (gen && gen.getURL().length()>0) {
// wrt=new DataWriter(new ResourceWriter(gen));
wrt=new ResourceWriter(gen);
wrt.writeInt(1); //version 1 supports pattern é╕éΩéΘ
a=getResource("usr.patterns");
b=a.getSubRes();
wrt.writeInt( b.size() );
for (a in b) {
wrt.writeString ( a.getName() );
wrt.writeInt( getGlobal(a.getName()) );
}
cc=0;
while (cc<width*height) {
wrt.writeInt(data.get(cc));
cc+=1;
}
wrt.close();
}
}
function onSaveToGen() {
setGenInstAttr("width",width);
setGenInstAttr("height",height);
setGenInstAttr("pwidth",pwidth);
setGenInstAttr("pheight",pheight);
setGenInstAttr("mpfx",mpfx);
setGenInstAttr("mpfy",mpfy);
saveMapFile();
}
function getWidth() {
return width;
}
function getHeight() {
return height;
}
function _refreshChips(ampfx,ampfy) {
}