/** Make actor to stop falling */ void stopFalling() { // ReceptionObj() int32 fall; if (currentlyProcessedActorIdx == 0) { fall = heroYBeforeFall - processActorY; if (fall >= 0x1000) { addExtraSpecial(processActorPtr->X, processActorPtr->Y + 1000, processActorPtr->Z, kHitStars); processActorPtr->life--; initAnim(kLandingHit, 2, 0, currentlyProcessedActorIdx); } else if (fall >= 0x800) { addExtraSpecial(processActorPtr->X, processActorPtr->Y + 1000, processActorPtr->Z, kHitStars); processActorPtr->life--; initAnim(kLandingHit, 2, 0, currentlyProcessedActorIdx); } else if (fall > 10) { initAnim(kLanding, 2, 0, currentlyProcessedActorIdx); } else { initAnim(kStanding, 0, 0, currentlyProcessedActorIdx); } heroYBeforeFall = 0; } else { initAnim(kLanding, 2, processActorPtr->animExtra, currentlyProcessedActorIdx); } processActorPtr->dynamicFlags.bIsFalling = 0; }
SpriteAnimation::SpriteAnimation(SDL_Surface* image, const Vec2& pos, SDL_Rect srcRect, Uint8 alpha, Uint16 frameWidth, Uint16 frameHeight, Uint16 startFrame, Uint16 numFrames, float frameRate) : Sprite(image, pos, srcRect, alpha), frameWidth_(frameWidth), frameHeight_(frameHeight), numFrames_(numFrames), startFrame_(startFrame), currFrame_(0), frameRate_(frameRate), frameTime_(0.0f), framesWide_(0), framesHigh_(0), isLooped_(false), isPlaying_(false) { initAnim(); }
/** Set hero behaviour @param behaviour behaviour value to set */ void setBehaviour(int32 behaviour) { int32 bodyIdx; switch (behaviour) { case kNormal: heroBehaviour = kNormal; sceneHero->entityDataPtr = heroEntityNORMAL; break; case kAthletic: heroBehaviour = kAthletic; sceneHero->entityDataPtr = heroEntityATHLETIC; break; case kAggressive: heroBehaviour = kAggressive; sceneHero->entityDataPtr = heroEntityAGGRESSIVE; break; case kDiscrete: heroBehaviour = kDiscrete; sceneHero->entityDataPtr = heroEntityDISCRETE; break; case kProtoPack: heroBehaviour = kProtoPack; sceneHero->entityDataPtr = heroEntityPROTOPACK; break; }; bodyIdx = sceneHero->body; sceneHero->entity = -1; sceneHero->body = -1; initModelActor(bodyIdx, 0); sceneHero->anim = -1; sceneHero->animType = 0; initAnim(kStanding, 0, 255, 0); }
void AnimMesh::render() { Face *facelist; TVertex *tvertex1, *tvertex2; Vertex *animvertex1, *animvertex2 = 0; // "= 0" just to shut up the compiler Vertex animvertex; float step, step2; int a, b, c; int ta, tb, tc; int f, i; glColor3f(1, 1, 1); glBegin(GL_TRIANGLES); for (f = 0; f < numfacegroups; f++) { facelist = face[f]; tvertex1 = tvertex[0]; tvertex2 = tvertex[1]; animvertex1 = (Vertex*)lastvdata; // TODO: segmentation fault here? animvertex2 = (Vertex*)(anim[currentanim].vdata + (animframe * numvertices)); step2 = (1.0 / (float)(anim[currentanim].speed)) * (float)animcount; step = 1.0 - step2; for (i = 0; i < numfaces[f]; i++) { // get a,b,c, indices a = facelist[i].a; b = facelist[i].b; c = facelist[i].c; ta = facelist[i].ta; tb = facelist[i].tb; tc = facelist[i].tc; // defineer de 3 vertices van de triangle animvertex.x = (animvertex1[a].x * step) + (animvertex2[a].x * step2); animvertex.y = (animvertex1[a].y * step) + (animvertex2[a].y * step2); animvertex.z = (animvertex1[a].z * step) + (animvertex2[a].z * step2); glTexCoord2f(tvertex1[ta].u, tvertex1[ta].v); glVertex3f(animvertex.x, animvertex.y, animvertex.z); animvertex.x = (animvertex1[b].x * step) + (animvertex2[b].x * step2); animvertex.y = (animvertex1[b].y * step) + (animvertex2[b].y * step2); animvertex.z = (animvertex1[b].z * step) + (animvertex2[b].z * step2); glTexCoord2f(tvertex1[tb].u, tvertex1[tb].v); glVertex3f(animvertex.x, animvertex.y, animvertex.z); animvertex.x = (animvertex1[c].x * step) + (animvertex2[c].x * step2); animvertex.y = (animvertex1[c].y * step) + (animvertex2[c].y * step2); animvertex.z = (animvertex1[c].z * step) + (animvertex2[c].z * step2); glTexCoord2f(tvertex1[tc].u, tvertex1[tc].v); glVertex3f(animvertex.x, animvertex.y, animvertex.z); } } glEnd(); // handle animation animcount++; if (animcount > anim[currentanim].speed) { lastvdata = animvertex2; animframe++; if (animframe >= anim[currentanim].numframes) { if (anim[currentanim].loop) { animframe = 0; } else { initAnim(lastanim); } } animcount = 0; } }
int main(int argc, char *argv[]) { SDL_Surface *ecran = NULL; SDL_Surface *background = IMG_Load("0000100000.pcx"); SDL_Surface *heu = IMG_Load("0000100001.pcx"); SDL_Rect position; Evenement key; Personnage joueur1, joueur2; taille tai, tai2; int test=0; key.quit=0; SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); SDL_WM_SetCaption("VanPri", NULL); Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024); Mix_Music *musique=Mix_LoadMUS("AcademyGrounds.ogg"); Mix_PlayMusic(musique, -1); ecran = SDL_SetVideoMode(640, 480, 24, SDL_DOUBLEBUF); joueur1.image= IMG_Load("anim.png"); joueur2.image= IMG_Load("anim"); joueur1.position.x=50; joueur1.position.y=190; joueur2.position.x=NULL; joueur2.position.y=NULL; initAnim(&joueur1.anim); initAnim(&joueur2.anim); joueur2.anim.n[0]=25; joueur2.anim.c=1; joueur1.anim.n[0]=12; joueur1.anim.c=2; tai2.x=640; tai2.y=480; tai.x=216; tai.y=278; SDL_Rect p,v,front1; position.x=-300; position.y=-480; v.y=487-267; v.x=position.x; SDL_SetColorKey(heu, SDL_SRCCOLORKEY, SDL_MapRGB(heu->format,255,0,0)); while(key.quit==0) { key=Event(); joueur1.anim.o=0; joueur1.anim.o=0; if(key.touche[SDLK_ESCAPE]==1) key.quit=1; camera(&position,key,&joueur1,&tai); //remise en positif des RECT p=position; front1=v; //mise des images dans l'ordre des calques SDL_BlitSurface(background,NULL,ecran,&p); //affichage du personnage affichage_joueur(ecran,joueur1, &tai); //front surface SDL_BlitSurface(heu,NULL,ecran,&front1); if(key.touche[SDLK_SPACE]==1) affichage_anim(ecran,joueur2, &tai2,&joueur2.anim); SDL_Flip(ecran); animation(&joueur1.anim); SDL_Delay(33); } return 0; }