int main() { char gametype; GameStruct game; SetSpritesTileTable(graveyard_sprites); gametype = 0; memset(&game, 0, sizeof(GameStruct)); for(;;) { switch(gametype) { case 0: gametype = introscreen(&game); break; case 1: gametype = singleloop(&game); break; case 2: gametype = multiloop(&game); break; } } }
/** * Main code */ int main() { SetTileTable(tiles); SetSpritesTileTable(tiles); SetFontTilesIndex(TILE_FIRST_FONT); InitMusicPlayer(patches); TriggerNote(3,SOUND_INTRO_MUSIC,20,0xff); SetUserPostVsyncCallback(vsync_callback); // read custom configuration from eeprom EepromReadBlock(129, &eeprom_data); eeprom_data.id = 129; game(); }
/** * \brief Performs some basic initialization functions. * * Sets up our graphics, initializes a few variables for convenience, loads saved scores and gets the music going. */ static void initialSetup() { SetSpritesTileTable(ghost_sprites); //sets the tiles to be used for our various sprites SetFontTilesIndex(TITLE_TILES_SIZE); //tiles for the font were included immediately after the include for background tiles //therefore this says how many tiles in memory to move forward from the first one //in order to find the beginning of the font tiles SetTileTable(title_tiles); //sets the tiles to be used for the normal background tiles in the game //fonts use this and the index above to set font tiles InitMusicPlayer(patches); //initialize the sound engine SetMasterVolume(0xff); //set volume to max StartSong(midisong); //start playing the main theme ClearVram(); //fill entire screen with first tile in the tileset (blank the screen) //set up some convenience variables for changing player image and drawing the score player_sprites[0]=ghost0; player_sprites[1]=ghost1; player_sprites[2]=ghost2; player_sprites[3]=ghost3; player_sprites[4]=ghost4; player_sprites[5]=ghost5; player_sprites[6]=ghost6; player_sprites[7]=ghost7; player_sprites[8]=ghost8; numbers[0]=num0; numbers[1]=num1; numbers[2]=num2; numbers[3]=num3; numbers[4]=num4; numbers[5]=num5; numbers[6]=num6; numbers[7]=num7; numbers[8]=num8; numbers[9]=num9; //checks if our desired eeprom block is setup correctly, //if not, it wipes it so we don't have to deal with garbage data in the high score list if(checkEeprom()==1) { wipeEeprom(); } //load our top 10 saved scores from eeprom LoadScore(0, 9); }
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]; } }
int main(){ unsigned char i,c,x,y,spr; ClearVram(); //initialize stuff InitMusicPlayer(patches); SetMasterVolume(0xc0); //crank up the volume a bit since the sample is not too loud SetSpritesTileTable(cubes_tileset); SetSpritesOptions(SPR_OVERFLOW_CLIP); //To allocate/deallocate a player's voice //tracks[0].allocated=false; //tracks[1].allocated=false; //tracks[2].allocated=false; //start the beat loop TriggerNote(3,1,23,0xff); //Define the screen sections. for(i=0;i<9;i++){ screenSections[i].tileTableAdress=spritedemo_tileset; } screenSections[0].height=76; screenSections[0].flags=SCT_PRIORITY_SPR; screenSections[1].height=2; screenSections[1].vramBaseAdress=vram+(32*37); screenSections[1].flags=SCT_PRIORITY_BG; screenSections[2].height=3; screenSections[2].vramBaseAdress=vram+(32*37); screenSections[2].flags=SCT_PRIORITY_BG; screenSections[2].scrollY=2; screenSections[3].height=3; screenSections[3].vramBaseAdress=vram+(32*37); screenSections[3].flags=SCT_PRIORITY_BG; screenSections[3].scrollY=5; screenSections[4].height=40; screenSections[4].vramBaseAdress=vram+(32*32); screenSections[4].flags=SCT_PRIORITY_SPR; screenSections[5].height=3; screenSections[5].vramBaseAdress=vram+(32*38); screenSections[5].flags=SCT_PRIORITY_BG; screenSections[6].height=3; screenSections[6].vramBaseAdress=vram+(32*38); screenSections[6].flags=SCT_PRIORITY_BG; screenSections[6].scrollY=3; screenSections[7].height=2; screenSections[7].vramBaseAdress=vram+(32*38); screenSections[7].flags=SCT_PRIORITY_BG; screenSections[7].scrollY=6; screenSections[8].height=76; screenSections[8].flags=SCT_PRIORITY_SPR; screenSections[8].scrollY=132; Fill(0,37,32,1,1); Fill(0,38,32,1,2); for(y=0;y<30;y+=4){ for(x=0;x<30;x+=5){ DrawMap2(x,y,map_bg); } } DrawMap2(0,32,map_logo); for(i=22;i<32;i++){ DrawMap2(i,32,map_bar); } srand(18); c=1; spr=1; for(i=0;i<7;i++){ //randomize positions cubes[i].x=((unsigned char)(rand() % 110))+2; cubes[i].y=((unsigned char)(rand() % 180))+2; cubes[i].rotation=((unsigned char)(rand() % 7)); if((unsigned char)(rand() % 16)<10){ cubes[i].xdir=1; }else{ cubes[i].xdir=-1; } if((unsigned char)(rand() % 16)<8){ cubes[i].ydir=1; }else{ cubes[i].ydir=-1; } } c=0; char w1=0,w2=0; while(1){ //syncronize gameplay on vsync (30 hz) WaitVsync(1); w2++; if(w2==3){ sx3++; if(sx3>X_SCROLL_WRAP) sx3=0; screenSections[1].scrollX=sx3; screenSections[7].scrollX=sx3; w2=0; } w1++; if(w1==2){ sx2++; if(sx2>=X_SCROLL_WRAP) sx2=0; screenSections[2].scrollX=sx2; screenSections[6].scrollX=sx2; w1=0; } sx++; if(sx>=X_SCROLL_WRAP) sx=0; screenSections[3].scrollX=sx; screenSections[4].scrollX=sx; screenSections[5].scrollX=sx; screenSections[0].scrollY++; screenSections[8].scrollY++; spr=1; for(i=0;i<7;i++){ cubes[i].x+=cubes[i].xdir; cubes[i].y+=cubes[i].ydir; if(cubes[i].x>123 && cubes[i].xdir==1){ cubes[i].xdir=-1; } if(cubes[i].x<9 && cubes[i].xdir==-1){ cubes[i].xdir=1; } cubes[i].y+=cubes[i].ydir; if(cubes[i].y>=196 && cubes[i].ydir==1){ cubes[i].ydir=-1; } if(cubes[i].y<10 && cubes[i].ydir==-1){ cubes[i].ydir=1; } if(c==0){ cubes[i].rotation++; if(cubes[i].rotation==14)cubes[i].rotation=0; sprites[spr+0].tileIndex=(cubes[i].rotation*2)+1; sprites[spr+1].tileIndex=(cubes[i].rotation*2)+1+1; sprites[spr+2].tileIndex=(cubes[i].rotation*2)+1+29; sprites[spr+3].tileIndex=(cubes[i].rotation*2)+1+30; } sprites[spr+0].x=cubes[i].x; sprites[spr+0].y=cubes[i].y; sprites[spr+1].x=cubes[i].x+6; sprites[spr+1].y=cubes[i].y; sprites[spr+2].x=cubes[i].x; sprites[spr+2].y=cubes[i].y+8; sprites[spr+3].x=cubes[i].x+6; sprites[spr+3].y=cubes[i].y+8; spr+=4; c+=128; } processControls(); } }
int main(){ TriggerFx(0,0,0); ClearVram(); InitMusicPlayer(patches); SetMasterVolume(0x40); StartSong(midisong); SetSpritesTileTable(mario_sprites_tileset); SetFontTilesIndex(SMB_TILESET_SIZE); SetTileTable(smb_tileset); Screen.scrollHeight = 23; Screen.overlayHeight=4; Screen.overlayTileTable=smb_tileset; DrawMap2(0,Screen.scrollHeight,map_hud); unsigned char c; for(int y=0;y<22;y++){ for(int x=0;x<30;x++){ c=pgm_read_byte(&(map_main[(y*MAP_MAIN_WIDTH)+x+2])); SetTile(x,y+1,c); } } dx=0; sx=50; sy=169-32+8; sprDir=1; goombaX[0]=17; //159; goombaDir[0]=-1; goombaAnim[0]=0; goombaSpr[0]=0; goombaSprIndex[0]=6; goombaX[1]=65 ;//201; goombaDir[1]=1; goombaAnim[1]=0; goombaSpr[1]=0; goombaSprIndex[1]=10; MapSprite2(0,map_rwalk1,0); MapSprite2(6,map_rgoomba1,SPRITE_FLIP_X); MapSprite2(10,map_rgoomba2,0); g=0; MoveSprite(0,sx,sy,2,3); Scroll(0,-1); MoveSprite(goombaSprIndex[0],goombaX[0],176,2,2); MoveSprite(goombaSprIndex[1],goombaX[1],176,2,2); Screen.scrollY=0; Screen.overlayHeight=4;//OVERLAY_LINES; while(1){ WaitVsync(1); processControls(); if((active&1)!=0){ PerformActions(); MoveSprite(0,sx,sy+dy,2,3); }else{ MoveSprite(0,sx,230,2,3); } //animate goombas for(g=0;g<2;g++){ if(goombaX[g]<=0 && goombaDir[g]==-1){ goombaDir[g]=1; } if(goombaX[g] >= (215+15) && goombaDir[g]==1){ goombaDir[g]=-1; } goombaX[g]+=goombaDir[g]; goombaAnim[g]++; if(goombaAnim[g]==8){ goombaSpr[g]^=1; goombaAnim[g]=0; } if(goombaSpr[g]==0){ MapSprite2(goombaSprIndex[g],map_rgoomba1,goombaDir[g]!=1?SPRITE_FLIP_X:0); }else{ MapSprite2(goombaSprIndex[g],map_rgoomba2,goombaDir[g]!=1?SPRITE_FLIP_X:0); } MoveSprite(goombaSprIndex[g],goombaX[g],176-32+8,2,2); } } }