/************************************/ /* */ /* Template for using escotia libs */ /* */ /* Author: ScoTT Campbell */ /* Date: 22/1/98 */ /* */ /************************************/ #include "../escpslib/escpslib.h" /***************** Definitions ******************/ #define SPRITE_ADDRESS (0x80090000) /************* End of Definitions ***************/ /******************* Globals ********************/ int initialVideoMode; // Video mode before this program int quit; // Used to flag user quit GsSPRITE sprite; // Sprite handler /**************** End of Globals ****************/ /************** Function Protoypes **************/ void InitialiseGame(); /* Controls initialisation of game structures */ void UpdateGame(); /* Controls updating of game structures */ void UpdateScreen(); /* Controls screen generation */ void CleanUp(); /* Controls destruction of heap members */ /********** End of Function Prototypes **********/ /******************** Main **********************/ int main() { /* Initialise game structures */ InitialiseGame(); while( !quit ) { /* Update game structures */ UpdateGame(); /* Draw the screen */ UpdateScreen(); }/*while*/ CleanUp(); return 0; }/* main*/ /***************** End of Main ******************/ /************* Function definitions *************/ void InitialiseGame() { // Set up debug font FntLoad(960, 256); FntOpen(30, 20, 256, 200, 0, 512); printf("Debug font Initialised\n"); // Set up the graphics system initialVideoMode = GetVideoMode(); InitGraphics(); printf("Graphics Initialised\n"); // Set up the controllers InitControllers(); printf("Controllers Initialised\n"); // Set up screen clearing to black SetClearScreen(0, 0, 0); printf("Screen clearing Initialised\n"); // Set up the ordering tables InitWorldOTs(); printf("OTs Initialised\n"); /* */ /* TO DO: Add initialisation code */ /* */ InitSprite(&sprite, SPRITE_ADDRESS, SCREEN_WIDTH/2, SCREEN_HEIGHT/2); }/* InitialiseGame */ void UpdateGame() { unsigned long int padValue = ReadControllers(); if((padValue & PAD1_SELECT) && (padValue & PAD1_START)) quit = 1; /* */ /* TO DO: Add structure update code */ /* */ /* Left/Right movement */ if(padValue & PAD1_RIGHT) sprite.x += 5; else if(padValue & PAD1_LEFT) sprite.x -= 5; /* Up/Down movement */ if(padValue & PAD1_UP) sprite.y -= 5; else if(padValue & PAD1_DOWN) sprite.y += 5; /* Rotation */ if(padValue & PAD1_CIRCLE) sprite.rotate += ONE; // 1 degree = ONE = 4096 else if(padValue & PAD1_SQUARE) sprite.rotate -= ONE; // Set sprite.rotate to zero after 360 degrees to stop overflow/underflow problems if(abs(sprite.rotate) == (360 * ONE)) sprite.rotate = 0; /* Scaling */ if((padValue & PAD1_TRIANGLE) && !(sprite.scalex < 200)) { sprite.scalex -= 10; sprite.scaley -= 10; } else if((padValue & PAD1_CROSS) && !(sprite.scalex > ONE*2)) { sprite.scalex += 10; sprite.scaley += 10; } }/* UpdateGame */ void UpdateScreen() { unsigned char vTime; // Find out which buffer we want to draw in int activeBuffer = GsGetActiveBuff(); // Set drawing command storage address GsSetWorkBase((PACKET*)packetArray[activeBuffer]); // Clear the current ordering table GsClearOt(0,0,&worldOT[activeBuffer]); /* */ /* TO DO: Add drawing commands */ /* */ GsSortSprite(&sprite, &worldOT[activeBuffer], 0); // Check if we are in interlace mode #ifndef INTERLACED // Wait for current drawing to finish DrawSync(0); #endif // Wait for screen to finish drawing vTime = VSync(0); FntPrint("VSYNC = %d\n", vTime); FntFlush(-1); // Swap drawing buffer with display buffer GsSwapDispBuff(); // Draw the OT we just processed GsDrawOt(&worldOT[activeBuffer]); }/* UpdateScreen */ void CleanUp() { /* */ /* TO DO: Add destructors here */ /* */ ResetGraph(1); SetVideoMode(initialVideoMode); }/* CleanUp */ /********** End of function definitions *********/