//------------------------------------------------------------------------------ // File: game.c // Author: George Bain, // Date: May 7, 1997 // Description: Star Fighter PSX // Copyright (C) 1997 George Bain, All Rights Reserved //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // I N C L U D E S //------------------------------------------------------------------------------ #include // standard Sony library #include "gfx.h" #include "pad.h" #include "game.h" #include "enemy.h" #include "explode.h" #include "bossone.h" #include "asteroid.h" //------------------------------------------------------------------------------ // G L O B A L S //------------------------------------------------------------------------------ PACKET gpu_work_area[2][PACKETMAX2]; // GPU packet work area extern u_long pad_status; // keep track of buttons activated volatile u_char *bb0, *bb1; // joypad related //------------------------------------------------------------------------------ // Function: StartGame() // Description: The game loop which handles all game related routines // Parameters: none // Returns: void // Notes: This needs much, much improvement with the case statements //------------------------------------------------------------------------------ void StartGame( void ) { pad_status = 0; game_info.game_over = 0; game_info.game_mode = MODE_STORY; GetPadBuf(&bb0, &bb1); // controller reception buffer // start the game loop while( !game_info.game_over ) { ControllerInput(); // get user input switch( game_info.game_mode ) { case MODE_TITLE: { // display title screen until user hits "triangle" if( pad_status & PADRdown ) { ResetGame(); } }break; case MODE_STORY: { // display story screen until user hits "start" if( pad_status & PADstart ) { game_info.game_mode = MODE_TITLE; game_info.level_mode = 0; } }break; case MODE_GAME: { // does player have any more lives? if( game_info.player_lives <= 0 ) game_info.game_mode = MODE_GAME_OVER; // is the boss defeated? if( game_info.boss_energy <= 0 ) { boss_one.state = BOSS_DEAD; //Kaboom(); game_info.boss_dead++; game_info.game_mode = MODE_BONUS; } }break; case MODE_GAME_OVER: { // hit select to select a new game if( pad_status & PADselect ) { game_info.game_mode = MODE_STORY; game_info.level_mode = 0; } else { game_info.level_mode = 0; game_info.game_mode = MODE_GAME_OVER; boss_one.state = BOSS_DEACTIVE; } }break; case MODE_BONUS: { // display bonus screen until user hits "X" if( pad_status & PADRdown ) { if( game_info.boss_dead >= 2 ) { game_info.game_mode = MODE_GAME_OVER; game_info.level_mode = 0; } else { game_info.game_mode = MODE_GAME; game_info.level_mode = LEVEL_TWO; game_info.boss_energy = BOSS_ENERGY; player.state = PLAYER_ALIVE; boss_one.state = BOSS_DEAD; game_info.money += game_info.bonus; ResetRCnt(1); } }// end if down else { game_info.level_mode = 0; game_info.game_mode = MODE_BONUS; boss_one.state = BOSS_DEACTIVE; } }break; }// end switch RefreshScreen(); // redraw the screen }// end while loop }// end StartGame //------------------------------------------------------------------------------ // Function: RefreshScreen() // Description: Updates all the game objects and redraws the screen // Parameters: none // Returns: void // Notes: Special thanx to Mario Perdue and his Walz game //------------------------------------------------------------------------------ void RefreshScreen( void ) { // get the active buffer output_buffer_index = GsGetActiveBuff(); // sets drawing command storage address GsSetWorkBase( (PACKET*)gpu_work_area[output_buffer_index]); // initialises the ordering table GsClearOt( 0, 0, &world_ordering_table[output_buffer_index]); // move objects CheckPlayerLocation(); MoveEnemyLeft(); MoveEnemyRight(); MoveBossOne(); MovePowerUp(); MoveMissiles(); MoveRockets(); if( game_info.level_mode == LEVEL_ONE ) MoveStars(); // check for collision EnemyRightCollide(); EnemyLeftCollide(); PowerUpCollide(); BossOneCollide(); // control all objects ControlEnemy(); ControlBossOne(); ControlPowerUp(); RocketPlayerCollision(); // animate objects AnimateExplosions(); if( game_info.game_mode == MODE_TITLE ) DrawTitleScreen(); if( game_info.game_mode == MODE_STORY ) DrawStoryScreen(); if( game_info.game_mode == MODE_BONUS ) { MoveStars(); DrawBonus(); DrawStars(); } if( game_info.game_mode == MODE_GAME_OVER ) { MoveStars(); DrawGameOver(); DrawStars(); } if( game_info.level_mode == LEVEL_ONE ) { UpdateStatus(); DrawExplosions(); DrawPlayer(); DrawEnemy(); DrawBossOne(); DrawRockets(); DrawPowerUp(); DrawMissiles(); DrawStatusScreen(); DrawStars(); DrawLifeBar(); DrawBorderBar(); } if( game_info.level_mode == LEVEL_TWO ) { Scroll(); UpdateStatus(); DrawExplosions(); DrawPlayer(); DrawEnemy(); DrawBossOne(); DrawRockets(); DrawPowerUp(); DrawMissiles(); DrawStatusScreen(); DrawLifeBar(); DrawCityScreen(); } // wait for all drawing to be completed DrawSync(0); // wait for vertical synchronisation VSync(0); // 0: blocking until vertical synch occurs // swap double buffers, (changes the display buffer and drawing buffer) GsSwapDispBuff(); // registers drawing clear command in OT (e.g. clear to black) GsSortClear( 0x0, 0x0, 0x0, &world_ordering_table[output_buffer_index]); // start execution of the drawing command registered in OT GsDrawOt( &world_ordering_table[output_buffer_index]); }// end RefreshScreen //------------------------------------------------------------------------------ // Function: DrawBonus() // Description: Draw points, bonus points and total points on screen // Parameters: none // Returns: void // Notes: N/A //------------------------------------------------------------------------------ void DrawBonus( void ) { FntLoad(896,256); FntOpen(92,70,SCREEN_WIDTH,SCREEN_HEIGHT,0,512); FntPrint("Points = %d\n\n",game_info.money); FntPrint("Bonus Points = %d\n\n",game_info.bonus); FntPrint("Total Points = %d",game_info.money+game_info.bonus); FntFlush(-1); FntFlush(-1); player.state = PLAYER_DEAD; }// end DrawBonus //------------------------------------------------------------------------------ // Function: DrawGameOver() // Description: Draw GAME OVER ! // Parameters: none // Returns: void // Notes: N/A //------------------------------------------------------------------------------ void DrawGameOver( void ) { FntLoad(896,256); FntOpen(92,85,SCREEN_WIDTH,SCREEN_HEIGHT,0,512); FntPrint("G A M E O V E R\n\n"); FntFlush(-1); FntFlush(-1); }// end DrawGameOver //------------------------------------------------------------------------------ // Function: ResetGame() // Description: Setup the game settings // Parameters: none // Returns: void // Notes: N/A //------------------------------------------------------------------------------ void ResetGame( void ) { game_info.game_mode = MODE_GAME; // set game mode game_info.level_mode = LEVEL_ONE; // start at level one game_info.money = 0; // set money game_info.boss_dead = 0; // boss dead counter game_info.bonus = 2000; // bonus points game_info.player_energy = PLAYER_ENERGY; // set energy level game_info.player_lives = PLAYER_LIVES; // set players lives player.state = PLAYER_ALIVE; // set player state game_info.boss_energy = BOSS_ENERGY; // set boss energy boss_one.state = BOSS_DEAD; // set boss state ResetRCnt(1); // reset the system timer }// end ResetGame //------------------------------------------------------------------------------ // Function: Scroll() // Description: Scroll the city to the left of the screen // Parameters: none // Returns: void // Notes: N/A //------------------------------------------------------------------------------ void Scroll( void ) { game_info.scroll_counter -= 1; if( game_info.scroll_counter <= -SCREEN_WIDTH ) game_info.scroll_counter = 0; }// end Scroll //-----------------------------------EOF----------------------------------------