Strange problem... THis is linked with another problem I posted earlier. A 2 dimensional array is forgotten in a method. Let me show you the code.
typedef struct tagSPRITE {
int x,y;
int width,height;
RECT frames[100];
int counter;
int updatecounter;
int state;
int curframe;
int curanim;
int *anims[20]; //THIS ONE
int curanimframes;
int indexinanim;
int runthroughs;
LPDIRECTDRAWSURFACE7 surf;
} SPRITE, *SPRITEPTR;
An here is the method I use to assign the animation.
void MakeAnimation(SPRITEPTR sprite, int animindex, int numframes, int *anim) {
sprite->anims[animindex]=(int *)malloc((numframes+1)*sizeof(int));
for(int i=0; ianims[animindex]=anim[z];
}
sprite->anims[animindex]=anim;
sprite->curanimframes=numframes;
sprite->indexinanim=0;
}
Now, here, I use this method.
enemy MakeBoss2 () {
enemy me;
CreateSprite(&me.ship,100,100,"bosses.bmp"); //load from enemy.bmp
me.bullet.curframe=0;
CFFromCell(&me.ship,0,2,0); //4-5 are from 1,0 in enemy.bmp
CFFromCell(&me.ship,1,3,0);
CFFromCell(&me.ship,2,2,1);
CFFromCell(&me.ship,3,3,1);
CFFromCell(&me.ship,4,0,3);
CFFromCell(&me.ship,5,1,3);
CFFromCell(&me.ship,6,2,3);
CFFromCell(&me.ship,7,3,3);
int explodea2[] = {4,5,6,7};
CreateSprite(&me.bullet,2,17,"fire.bmp");
CFFromCell(&me.bullet,0,0,0);
me.isthere=true;
me.curstate=attack;
me.oldstate=attack;
me.state.states[attack]=.30;
me.state.states[avoid]=.35;
me.state.states[randommove]=.4;
me.state.states[useold]=.9;
me.state.states[still]=1.0;
me.damage=2;
me.bulletspeed=18;
me.howmuchscore=1000;
me.isbullet=false;
me.explodeframes=3;
MakeAnimation(&me.ship,0,1,fly);
MakeAnimation(&me.ship,1,1,zapa);
MakeAnimation(&me.ship,2,3,explodea2);
me.ship.updatecounter=2;
ChangeAnim(&me.ship,0,1);
me.engspeed=4;
Load_VOC("explode.voc",&me.explodesnd);
Load_VOC("l1.voc", &me.shootsnd);
me.shootsnd.lpdsbuffer->SetFrequency(22050);
me.curhp=me.fullhp=20;
Load_VOC("mis.voc", &me.shootsnd);
return (me);
}
Now, from writing to an output file, I have determined that the makeanimations DO work here. It returns the enemy ship.
Then:
if(enemies[i].ship.runthroughs==1) {
FILE* fp=fopen("debug.txT", "w"); fprintf(fp,"%d",enemies[i].ship.anims[2][0]);fclose(fp);
enemies[i].isthere=false;
score+=enemies[i].howmuchscore;
kills++;
UpdateKills();
}
Here, I print this information again, and the Animation has been forgotten. it is -8590000 or something like that.
I know that the enemy has already been initialized when this code comes around... Does anyone know what is going on?!?!?
Thanks in advance!
Sponge Factory
--Muzlack
Edited by - Muzlack on February 23, 2002 7:54:39 PM
Edited by - Muzlack on February 23, 2002 7:55:56 PM