I have a serious problem and I hope that you can help me. The next version of Pixelcraft could have infinite "worlds" to left and right. The problem is with my generator code. It generates well except trees. There is only one block but there should be more.
Sometimes it doesn't even try to generate a full tree(It doesn't generate anything at all but if it would that would miss some parts. :S
Ok, enough of the boring text. These are the codes that I use for generating trees:
Block->Draw Actor
- Code: Select all
if(oldwo != xwo && lefut==0){
sprintf(tmpe,"world%i",xwo);
fajl =fopen(tmpe, "r");
if(fajl != NULL) // file exists
{
loadVars(tmpe, "save");
}else{
ogen();
treegen(cloneindex);
genbb();
if(cloneindex < 104){
if(fagen[cloneindex]==1){
typek[cloneindex]=17;
}else if(fagen[cloneindex]==2){
typek[cloneindex]=24;
}
}
}
type=typek[cloneindex];
setelet();
lefut=1;
CreateTimer("Event Actor", "300", 300);
}
fagen - stores the data for tree generating(1-log 2-leaves)
setelet() - sets the lifepoints for the block
typek - the saveable data of the blocks
type - the block data that is used by the "game engine"
ogen() - cleans the block datas
treegen() - tree generator code
genbb() - terrain generator code
treegen():
- Code: Select all
void treegen(int cli){
int tempo;
int temoo;
fagen[cli]=0;
if(cli < 104){
if(cli > 77){
temoo=rand(10);
if(temoo==2){
fagen[cli]=1;
tempo=cli-26;
fagen[tempo]=1;
tempo=cli-52;
fagen[tempo]=1;
tempo=cli-78;
fagen[tempo]=2;
tempo=cli-27;
fagen[tempo]=2;
tempo=cli-25;
fagen[tempo]=2;
tempo=cli-53;
fagen[tempo]=2;
tempo=cli-51;
fagen[tempo]=2;
}
}
}
}
It only generates a log-block from the tree and in new "worlds" it doesn't even store the fagen data to generate a tree.
I hope it's not too confusing. If you have any clue why isn' this working please tell me.