/** * \brief Performs setup and re-initialization needed before each new game. * * Resets the player score, resets variables for drawing columns, sets a new random ghost color, moves the player back to the starting position, erases columns from last game, * turns scrolling back on and makes the player visible again. */ static void gameSetup() { randomSky(); //fill screen with tile 1 again to erase menu ClearVram(); for(u8 i = 0; i < 4; i++) //reset column data with 0's to start fresh { pipe_x[i] = 0; pipe_y[i] = 0; } for(u8 k = 0; k < 32; k++) { bg[k] = 1; } //reset all score data from last game to 0 score = 0;//score = 0; score_ones=0; score_tens=0; score_hundreds=0; fake_x = 80; //reset how far we've flown player_x = 80; //reset player position player_y = 40; yspeed = 0; //make sure we start at 0 speed //draw the background for(u8 i = 0; i < VRAM_TILES_H; i++) { pipe_alarm=2; //make sure we never draw a column while we're drawing the starting screen loadNextStripe(); //go through each column and draw the background } //select a random color for the ghost and set the appropriate sprite ghost_color=(prng()%3); //the ghost has 3 frames and 3 color options, so we set the active sprite to the frame count (0 - 2) + the color (0, 3, or 6) to get the correct sprite ghost_color=(ghost_color+(ghost_color<<1)); current_sprite = player_sprites[current_frame+ghost_color]; //assign and move the player image to start the new game MoveSprite(0,player_x,player_y,3,3); MapSprite2(0,current_sprite,0); //make player visible SetSpriteVisibility(true); //reset variables to draw new columns correctly current_pipe=0; build_pipe=0; pipe_alarm = 1; pipe_col_drawn = 0; //turn scrolling on to begin the game scrollingOn=true; }
/** * \brief Helper function to draw the reusable menu frame. */ void drawFrame(void) { SetSpriteVisibility(false); //turn off sprites for now, the menus only use background tiles anyway //to minimize weird problems with drawing a static screen due to mode 3 scrolling, or VRAM_TIES_H vs SCREEN_TILES_H (or something, couldn't figure it out) //scroll the game back to its starting position then turn scrolling back off scrollingOn=true; while(scroll != 0) //reset to align edge of screen to a tile, not part way in between { processScrollSpeed(); } while(drawX != (VRAM_TILES_H-1)) //scroll until the screen is aligned with its starting position (tile position 0 at far left) { processScrollSpeed(); } scrollingOn=false; ClearVram(); //clear screen to prep for drawing the frame u8 drawXTemp = fakemod((drawX+2),VRAM_TILES_H);//variable used for tracking horizontal position of tiles as we draw them. drawing is done top to bottom left to right SetTile(drawXTemp, 1, FRAME_TL); //place top left corner tile for(u8 y=2; y<VRAM_TILES_V-2; y++)//draw lefthand border { SetTile(drawXTemp, y, FRAME_L); } SetTile(drawXTemp, VRAM_TILES_V-2, FRAME_BL); //place bottom left corner tile for(u8 x=0; x<24; x++)//draw middle portion of frame until we reach the right hand side { drawXTemp=fakemod((drawXTemp+1),VRAM_TILES_H); SetTile(drawXTemp, 1, FRAME_T); //draw top piece for(u8 y=2; y<VRAM_TILES_V-2; y++) //fill middle with black { SetTile(drawXTemp, y, BLACK); } SetTile(drawXTemp, VRAM_TILES_V-2, FRAME_B); //draw bottom piece } drawXTemp=fakemod((drawXTemp+1),VRAM_TILES_H); SetTile(drawXTemp, 1, FRAME_TR); //place top right corner tile for(u8 y=2; y<VRAM_TILES_V-2; y++) //draw righthand border { SetTile(drawXTemp, y, FRAME_R); } SetTile(drawXTemp, VRAM_TILES_V-2, FRAME_BR); //place bottom right corner tile }
int main(){ SetTileTable(cTesterTiles); SetSpritesTileTable(cursor); ClearVram(); EnableSnesMouse(0,map_cursor); //Print the basic stuff on the screen DrawMap2(5,26,map_copyright); DrawMap2(0,13,map_divider); //Detect controller types cType[0] = 255; cType[1] = 255; //The controller vars int btnHeld[2] = {0,0}; int btnPressed[2] = {0,0}; int btnReleased[2] = {0,0}; int btnPrev[2] = {0,0}; //Main loop while(1){ //20fps WaitVsync(1); //Update the controller vars btnHeld[0] = ReadJoypad(0); btnHeld[1] = ReadJoypad(1); btnPressed[0] = btnHeld[0] & (btnHeld[0] ^ btnPrev[0]); btnPressed[1] = btnHeld[1] & (btnHeld[1] ^ btnPrev[1]); btnReleased[0] = btnPrev[0] & (btnHeld[0] ^ btnPrev[0]); btnReleased[1] = btnPrev[1] & (btnHeld[1] ^ btnPrev[1]); //Check if controllers changed if((DetectControllers() & 3) != cType[0]){ cType[0] = DetectControllers() & 3; Fill(0,0,30,13,0); if(cType[0] == GAMEPAD){ DrawMap2(9,2,map_gamepad); } else if(cType[0] == MOUSE){ DrawMap2(12,2,map_mouse); DrawMap2(1,4,map_warning); } else if(cType[0] == NOTHING){ DrawMap2(9,6,map_nocontroller); } } if((DetectControllers() & 12) / 4 != cType[1]){ cType[1] = (DetectControllers() & 12) / 4; Fill(0,14,30,12,0); if(cType[1] == GAMEPAD){ DrawMap2(9,15,map_gamepad); SetSpriteVisibility(false); } else if(cType[1] == MOUSE){ DrawMap2(12,15,map_mouse); SetSpriteVisibility(true); EnableSnesMouse(0,map_cursor); } else if(cType[1] == NOTHING){ DrawMap2(9,19,map_nocontroller); SetSpriteVisibility(false); } } //Update the buttons for(unsigned int i = 0; i < 2; i++){ if(cType[i] == MOUSE){ //Check pressed buttons if(btnPressed[i] & BTN_MOUSE_LEFT){ DrawMap2(14,4 + 13*i,map_pmouseb); } if(btnPressed[i] & BTN_MOUSE_RIGHT){ DrawMap2(16,4 + 13*i,map_pmouseb); } //Check released if(btnReleased[i] & BTN_MOUSE_LEFT){ DrawMap2(14,4 + 13*i,map_mouseb); } if(btnReleased[i] & BTN_MOUSE_RIGHT){ DrawMap2(16,4 + 13*i,map_mouseb); } } else if(cType[i] == GAMEPAD){ //Check pressed if(btnPressed[i] & BTN_UP){ DrawMap2(11,6 + 13*i,map_pdpad); } if(btnPressed[i] & BTN_DOWN){ DrawMap2(11,8 + 13*i,map_pdpad); } if(btnPressed[i] & BTN_LEFT){ DrawMap2(10,7 + 13*i,map_pdpad); } if(btnPressed[i] & BTN_RIGHT){ DrawMap2(12,7 + 13*i,map_pdpad); } if(btnPressed[i] & BTN_START){ DrawMap2(16,6 + 13*i,map_pstart); } if(btnPressed[i] & BTN_SELECT){ DrawMap2(14,6 + 13*i,map_pstart); } if(btnPressed[i] & BTN_A){ DrawMap2(20,7 + 13*i,map_pbutton); } if(btnPressed[i] & BTN_B){ DrawMap2(19,8 + 13*i,map_pbutton); } if(btnPressed[i] & BTN_X){ DrawMap2(19,6 + 13*i,map_pbutton); } if(btnPressed[i] & BTN_Y){ DrawMap2(18,7 + 13*i,map_pbutton); } if(btnPressed[i] & BTN_SL){ DrawMap2(10,4 + 13*i,map_pbumper); } if(btnPressed[i] & BTN_SR){ DrawMap2(18,4 + 13*i,map_pbumper); } if(btnReleased[i] & BTN_UP){ DrawMap2(11,6 + 13*i,map_dpad); } if(btnReleased[i] & BTN_DOWN){ DrawMap2(11,8 + 13*i,map_dpad); } if(btnReleased[i] & BTN_LEFT){ DrawMap2(10,7 + 13*i,map_dpad); } if(btnReleased[i] & BTN_RIGHT){ DrawMap2(12,7 + 13*i,map_dpad); } if(btnReleased[i] & BTN_START){ DrawMap2(16,6 + 13*i,map_start); } if(btnReleased[i] & BTN_SELECT){ DrawMap2(14,6 + 13*i,map_start); } if(btnReleased[i] & BTN_A){ DrawMap2(20,7 + 13*i,map_button); } if(btnReleased[i] & BTN_B){ DrawMap2(19,8 + 13*i,map_button); } if(btnReleased[i] & BTN_X){ DrawMap2(19,6 + 13*i,map_button); } if(btnReleased[i] & BTN_Y){ DrawMap2(18,7 + 13*i,map_button); } if(btnReleased[i] & BTN_SL){ DrawMap2(10,4 + 13*i,map_bumper); } if(btnReleased[i] & BTN_SR){ DrawMap2(18,4 + 13*i,map_bumper); } } } btnPrev[0] = btnHeld[0]; btnPrev[1] = btnHeld[1]; } }