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); } } }
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(); } }
/** * \brief The main game loop. This just cycles endlessly, it uses the game's 'state' to determine which screen to show and what to do. */ int main(){ //looping back and forth forever (cards against humanity reference) while(1) { //some basic prep work performed once before our custom intro if(game_state == INTRO) { initialSetup(); initIntro(); } //perform custom intro while(game_state == INTRO) { //wait until the next frame WaitVsync(1); drawIntro(); processIntro(); } //prep the main menu if(game_state == MAIN_MENU) { FadeOut(0,true); ClearVram(); SetTileTable(title_tiles); SetFontTilesIndex(TITLE_TILES_SIZE); drawMainMenu(); FadeIn(0,false); } //draw menu and handle input while(game_state == MAIN_MENU) { WaitVsync(1); drawMenuCursor(); processMainMenu(); } if(game_state== GAME) { //run our setup for the main game ClearVram(); FadeOut(0,true); gameSetup(); FadeIn(0,false); } //when we're in the gameplay portion, draw and accept input for the game while(game_state == GAME) { WaitVsync(1); processScrollSpeed(); //scrolls screen as appropriate updateCity(); //offsets city for parallax processControls(); //accepts and processes controller input processPlayerMotion(); //update player position processSprites(); //updates and moves player image to player position } if(game_state == HIGH_SCORES) { FadeOut(0,true); SetTileTable(title_tiles); SetFontTilesIndex(TITLE_TILES_SIZE); drawLocalHighScoreMenu(); //draw up the high score screen FadeIn(0,false); deathclock=120; //reset death timer to 2 seconds if(score > topscores[9]) { LoadScore(0, 9); //load top 10 saved high scores SaveScore(score); //save our current score if it's high enough drawLocalHighScoreMenu(); //draw up the high score screen } } //draw and accepts input for the local high score screen while(game_state == HIGH_SCORES) { WaitVsync(1); processHighScoreMenu(); } } }