3D Map Creator: Initialize

From Hack Wars Wiki

Jump to: navigation, search

Initialize

void main() {
    setGlobal("imageMax", 13); //How many images (with 8 frames) are there?
              //Without this, the game could crash/freeze when you switch to a frame/image that does not exist.
 
    setGlobal("terrainHeight", 0);
    setGlobal("terrainHeight+", 0);
    //setTerrain(48);
setViewportX(64);
setViewportY(64);
//setViewportZRotation(90);
setViewportXRotation(-90);
setGlobal("xRotAdd", 0);
 
//setViewportYRotation(90);
setViewportZ(0);
string spriteVarName[]={"script", "image", "frame", "passness", "Z3D", "xRot", "yRot", "height", "width", "depth", "offscreenProcessing", "X", "Y", "renderType", "autoCollide", "ZOffset", "object", "repeatTexture"};
int spriteVarSize[]={      3,        2,        1,        1,        2,      3,      3,      4,        4,       4,              1,           4,  4,      1,               1,         4,          3,          1};
int spriteVarCount=18;
 
 
setGlobal("Z",0.0);
 
setGlobal("hero",-1);
setGlobal("walkFrame",0);
setGlobal("initialFrame",0);
setGlobal("addx",0);
setGlobal("addy",0);
setGlobal("xPos", 0);
setGlobal("yPos", 0);
int spriteCount=load("spriteCount");
if (getGlobal("loadData")=="false") spriteCount=getGlobal("data-spriteCount");
if (getGlobal("loadData")!="false") {
setGlobal("data-spriteCount", spriteCount);
setGlobal("lastSprite", spriteCount-1);
}
debug(spriteCount+"");
if (spriteCount>0) {
 
if (getGlobal("loadData")!="false") {
for(int t=0;t<=spriteVarCount;t++) {
    setGlobal("data-"+spriteVarName[t], load(spriteVarName[t]));
    setGlobal("data-object-"+spriteVarName[t], load("object-"+spriteVarName[t]));
}
}
debug("X:"+strlen(getGlobal("data-X")));
string spriteIDs="";
for(int b=1;b<=spriteCount;b++){
            //debug(b+"-X:"+mapIntValue(spriteX, b)+" Y:"+mapIntValue(spriteY, b)+" Z:"+mapIntValue(spriteZHeight, b)+" height:"+mapIntValue(spriteHeight, b)+" width:"+mapIntValue(spriteWidth, b)+" depth:"+mapIntValue(spriteDepth, b));
            //debug(b+"-Frame:"+mapIntValue(spriteFrame,b)+" rType:"+mapIntValue(spriteRenderType,b)+" autoCollide:"+mapIntValue(spriteAutoCollide,b)+" passable:"+mapIntValue(spritePassness,b)+" offscreen:"+mapIntValue(spriteOffscreenProcessing,b)+" xRot:"+mapIntValue(spriteXRotation,b)+" yRot:"+mapIntValue(spriteYRotation,b));
			int s=createSprite(mapIntValue(getGlobal("data-image"), b),mapIntValue(getGlobal("data-script"), b),mapIntValue(getGlobal("data-X"), b),mapIntValue(getGlobal("data-Y"), b),0);
            spriteIDs+=appendDigits(s+"", 4)+char(92);
			setFrame(s,mapIntValue(getGlobal("data-frame"),b));
			setRenderType(s,mapIntValue(getGlobal("data-renderType"),b));
			setZ(s,mapIntValue(getGlobal("data-Z3D"),b));
			setAutoCollide(s,mapBoolValue(getGlobal("data-autoCollide"),b));
			setPassable(mapIntValue(getGlobal("data-X"),b),mapIntValue(getGlobal("data-Y"),b),mapBoolValue(getGlobal("data-passness"),b));
            setX(s, mapIntValue(getGlobal("data-X"),b));
            setY(s, mapIntValue(getGlobal("data-Y"),b));
            setDepth(s, mapIntValue(getGlobal("data-depth"),b));
            setWidth(s, mapIntValue(getGlobal("data-width"),b));
            setHeight(s, mapIntValue(getGlobal("data-height"),b));
            setOffscreenProcessing(s, mapBoolValue(getGlobal("data-offscreenProcessing"),b));
            setXRotation(s, mapIntValue(getGlobal("data-xRot"),b));
            setYRotation(s, mapIntValue(getGlobal("data-yRot"),b));
            setZOffset(s, mapIntValue(getGlobal("data-ZOffset"), b));
            setRepeatTexture(s, mapBoolValue(getGlobal("data-repeatTexture"), b));
            //setGlobal("sprite-object", mapIntValue(spriteObject,b));
            int object=mapIntValue(getGlobal("data-object"),b);
            int objectN=getGlobal("Object-spriteCount:"+object)+1;
            setGlobal("Object-spriteCount:"+object, objectN);
            setGlobal("Object:"+object+":"+objectN, s);
            setGlobal("sprite:"+s, b);
            setGlobal("loaded-"+s, "true");
}
setGlobal("spriteIDs", spriteIDs);
debug(spriteIDs);
}
//string spriteMask=load("mask");
 
}
string appendDigits(string str, int n) {
    string nn="0";
    int len=strlen(str);
    while(len<n) { str=nn+str; len++; }
return str;  
}
int mapIntValue(string str, int n, int size) {
    int len=strlen(str);
    int count=intValue(getGlobal("data-spriteCount"));
    int size=0;
    string bla="";
    int ret=0;
    if (count>0) {
        size=intValue(len/count);
        n--;
        bla=substr(str, n*size, (n*size)+size);
        if (indexOf(bla, "-", 0)>0) bla=substr(bla, indexOf(bla, "-", 0), strlen(bla));
        if (bla!="") ret=parseInt(bla);
    }
    return ret;
}
boolean mapBoolValue(string str, int n) {
    int len=strlen(str);
    int count=intValue(getGlobal("data-spriteCount")-1);
    int size=0;
    string bla="";
    int ret=0;
    if (count>0) {
        size=intValue(len/count);
        n--;
        bla=substr(str, n*size, (n*size)+size);
    }
    boolean ret=false;
    if (bla=="0") ret=false;
    if (bla=="1") ret=true;
    return ret;
}
Personal tools