// // SAMPLE TOD ANIMATION PROGRAM //------------------------------- // by Jason Spreadborough // // date = 1-5-99 // /********************************************************************* * The amount of condition statements in this code makes it difficult * * to undestand even though it is actually a pretty simple program. * * See other demos for a much easyier to understand example of * * the tod animation. * *********************************************************************/ // INCLUDE FILES //--------------- #include #include #include "pad.h" /* pad control */ #include "tod.h" /* definition for TOD functions */ #include "IDLists.h" /* TMD ID list (not used) */ #include "graphics.h" /* Various graphic and animation*/ #include "addrs.h" /* Model and TOD addresses */ // DEFINES //------------ #define ALIVE (0) #define DYING (1) #define DEAD (2) #define BORED (0) #define BREATHE (1) #define COMEON (2) #define FOOT (3) #define PUNCH (4) #define PUNCH1 (5) #define PUNCH2 (6) #define RUN (7) #define SIT (8) #define WALK (9) // PROTOTYPES //-------- long UpdateWorld(); void RenderWorld(); void ProcessInput(); // GLOBALS //---------- u_long pad; // For controller GsRVIEW2 view; // For viewing LinkObjectStruct theModel; // The animated model u_long world_time=0; u_long button_held[4] = {FALSE,FALSE,FALSE,FALSE}; // button states // FUNCTIONS //---------- ////////////////////////////////////////////////////////////////////////////////// // Update the animation keeping track of frame speeds // and controlling the animation according to the // animationState varible. long UpdateWorld() { int i; static int flip=0; int hold=FALSE; // control playback. if(theModel.currentTod == SIT) { if(NextFrame(&theModel,FALSE)) { return(DEAD); } return(DYING); } // Play one of the idle animations alternatly when // the character has done nothing for a short while. if(world_time > 400) { if(flip == 0) { ResetAnim(&theModel,BORED); flip=1; } else { ResetAnim(&theModel,COMEON); flip=0; } world_time=0; } // check to see if a button is held down for(i=0;i<4;i++) { if(button_held[i]==TRUE) hold= TRUE; } // Advance animation. If animation reaches end reset // to the default breathing animation. if(hold ==TRUE) { if(button_held[2]==TRUE) { if(!NextFrame(&theModel,FALSE)) { if((world_time==25) && (theModel.currentTod == PUNCH)) ResetAnim(&theModel,PUNCH1); else if((world_time==45) && (theModel.currentTod == PUNCH1)) ResetAnim(&theModel,PUNCH2); } else { ResetAnim(&theModel,PUNCH); world_time=0; } } else { NextFrame(&theModel,TRUE); world_time=0; } } else { if(NextFrame(&theModel,FALSE)) { ResetAnim(&theModel,BREATHE); } } // increment world counter. world_time++; return ALIVE; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Handle Object drawing function calls void RenderWorld() { int i; RenderPrepare(); //create a delay. (Pause should be for ????frames???) for(i=0;i<500;i++){VSync(1);}; DrawObjectLink(theModel.objs); RenderFinish(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////// // Process Joypad controller input. Controls camera positioning. void ProcessInput() { static int camera=0; static int pressed=0; pad = PadRead(); if(pressed==0) { if((pad & PADRleft) > 0) { ResetAnim(&theModel,WALK); world_time=0; pressed=1;button_held[0]=TRUE; } if((pad & PADRup) > 0) { ResetAnim(&theModel,RUN); world_time=0; pressed=1;button_held[1]=TRUE; } if((pad & PADRright) > 0) { ResetAnim(&theModel,FOOT); world_time=0; //pressed=1; } if((pad & PADRdown) > 0) { ResetAnim(&theModel,PUNCH); world_time=0; pressed=1;button_held[2]=TRUE; } if ((pad & PADo)>0){ } if((pad & PADLleft)>0) { camera--; if(camera<0) camera = 9; pressed=1; } if ((pad & PADLright)>0) { camera++; if(camera>9) camera = 0; pressed=1; } if ((pad & PADLdown)>0){} if ((pad & PADLup)>0){} if ((pad & PADh)>0){} if ((pad & PADk)>0) { ResetAnim(&theModel,SIT); world_time=0; } } if(pressed==1) { if(!(pad & PADRleft)) { button_held[0]=FALSE; } if(!(pad & PADRup) ) { button_held[1]=FALSE; } if(!(pad & PADRdown)) { button_held[2]=FALSE; } if(!(pad & PADLleft) && !(pad & PADLright) && (button_held[0]==FALSE) && (button_held[1]==FALSE) && (button_held[2]==FALSE)) { pressed=0; } } // set camera position. switch(camera) { case 0:InitialiseView(&view,100,0,4000,-25000,8000,0,0,0);break; case 1:InitialiseView(&view,100,0,2000,-4000,5000,0,0,0);break; case 2:InitialiseView(&view,100,0,4000,-4000,8000,0,-8000,0);break; case 3:InitialiseView(&view,100,0,0,-8000,30000,0,-8000,0);break; case 4:InitialiseView(&view,100,0,0,-8000,15000,0,-8000,0);break; case 5:InitialiseView(&view,100,0,-15000,-8000,0,0,-8000,0);break; case 6:InitialiseView(&view,100,0,-30000,-8000,0,0,-8000,0);break; case 7:InitialiseView(&view,100,0,0,-8000,-30000,0,-8000,0);break; case 8:InitialiseView(&view,100,0,4000,25000,8000,0,0,0);break; case 9:InitialiseView(&view,100,0,4000,10000,8000,0,0,0);break; } GsSetRefView2(&view); //update camera. } /************************************************************************************************/ // Main routine //-------------- void main() { long running = ALIVE; // Program loop state. // General Initialisations for graphics. PadInit(); Initialise3DGraphics(); InitialiseView(&view,100,0,0,-2000,-4000,0,0,0); InitialiseLights(); //Initialise Model + TOD's. LoadTextures(); InitialiseModelLink(&theModel,16,10,0,0,0,(u_long *)MODEL_TMD); initTod(&theModel,0,NULL,(u_long *)BORED_TOD); initTod(&theModel,1,NULL,(u_long *)BREATHE_TOD); initTod(&theModel,2,NULL,(u_long *)COMEON_TOD); initTod(&theModel,3,NULL,(u_long *)FOOT_TOD); initTod(&theModel,4,NULL,(u_long *)PUNCH_TOD); initTod(&theModel,5,NULL,(u_long *)PUNCH1_TOD); initTod(&theModel,6,NULL,(u_long *)PUNCH2_TOD); initTod(&theModel,7,NULL,(u_long *)RUN_TOD); initTod(&theModel,8,NULL,(u_long *)SIT_TOD); initTod(&theModel,9,NULL,(u_long *)WALK_TOD); //Set animation to first frame. ResetAnim(&theModel,0); //Print instructions to PC printf("\n\n\n\n\nINSTRUCTIONS\n---------------\n\n"); printf("Left = Back cycle through cameras.\n"); printf("Right = Forward cycle through cameras.\n\n"); printf("Triangle = Run\n"); printf("Square = Walk\n"); printf("Circle = Hurting Foot\n"); printf("Cross = Punch\n\n"); printf("Hold the walk or run button for continuous animation.\n\n"); printf("Press the punch button once for a single punch animation.\n"); printf("Hold the punch button through the first animation for a double punch.\n"); printf("Again hold the punch through the first and second punch for a super third punch!\n\n"); printf("Press select to quit (plays end animation).\n\n\n"); //Main program loop while(running == ALIVE || running == DYING) { if(running==ALIVE) ProcessInput(); running = UpdateWorld(); RenderWorld(); } ResetGraph(3); }