/** * \brief Animates and moves player sprite, and updates and centers score sprites. */ void processSprites(void){ //update player sprite if(scrollingOn) //if player is alive, decrement animation alarm { frame_tick--; } if(frame_tick == 0) //animation alarm has been reached, reset alarm and change sprite to next frame { frame_tick = 8; //reset alarm current_frame++; //move forward to next animation frame if(current_frame == max_frames) { current_frame=0; } current_sprite = player_sprites[current_frame+ghost_color]; //change our tracking variable to the correct sprite based on new frame and current color MapSprite2(0, current_sprite, 0); //actually reassign the sprites in memory to the correct images } //move player sprite to player position MoveSprite(0,player_x,player_y,3,3); //map score sprites and move score to correct place MapSprite2(9, numbers[score_ones],0); //assign ones place sprite and center it according to player score MoveSprite(9,score_x, 8,1,2); if(score_tens!=0) //if player score high enough to have tens digit, assign that sprite and move stuff over to recenter { MapSprite2(11, numbers[score_tens],0); MoveSprite(11,score_x, 8, 1, 2); MoveSprite(9,score_x+8, 8, 1, 2); } else //score is below 10, so move tens digit off screen (solves bug where old tens place digit from last game was in the way) { MoveSprite(11,SCREEN_TILES_H << 3, 8, 1, 2); } if(score_hundreds!=0) //score is somehow > 100, assign 100's place digit sprite and recenter score { MapSprite2(13, numbers[score_hundreds],0); MoveSprite(13,score_x, 8, 1, 2); MoveSprite(11,score_x+8, 8, 1, 2); MoveSprite(9,score_x+16, 8, 1, 2); } else //score is < 100, move 100's place digit sprite off screen for the same reason as the ten's digit above { MoveSprite(13,SCREEN_TILES_H << 3, 8, 1, 2); } }
/** * \brief Setup for custom intro */ void initIntro(void) { StopSong(); //don't play song during intro MapSprite2(0, player_sprites[0], 0); //setup blue ghost for drawing player_x = 0; //set ghost to far left player_y = 80; //center ghost vertically SetTileTable(logo_tileset); //setup tiles for drawing uzebox logo }
/** * \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 Draws the custom intro */ void drawIntro(void) { ClearVram(); //wipe screen each frame frame_tick--; if(frame_tick == 0) //animation alarm has been reached, reset alarm and change sprite to next frame { frame_tick = 8; //reset alarm current_frame++; //move forward to next animation frame if(current_frame == max_frames) { current_frame=0; } current_sprite = player_sprites[current_frame]; //change our tracking variable to the correct sprite based on new frame MapSprite2(0, current_sprite, 0); //actually reassign the sprites in memory to the correct images } MoveSprite(0, player_x, player_y, 3, 3); //position ghost sprite DrawMap2(13,12,map_uzeboxlogo); //draw uzebox logo and name if((player_x > 104)&&(player_x<108)) //at the right moment, draw the shiny reflection on the logo DrawMap2(13,12,map_uzeboxlogo2); }
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); } } }
void PerformActions(){ char sdx,sprFlags=(sprDir!=1?SPRITE_FLIP_X:0); if(stopping==true && walkFrame<=5){ MapSprite2(0,map_rwalk1,sprFlags); dy=0; stopFrame++; return; } sdx=dx; if(dx==1 && sx>=110) sdx=0; //if(dx==-1 && sx<=10) sdx=0; //if(dx==1 && sx>=220) sdx=0; switch(action){ case ACTION_WALK: if(frame==0){ MapSprite2(0,map_rwalk2,sprFlags); dy=-1; }else if(frame>0 && frame<=5){ sx+=sdx; }else if(frame==6){ sx+=(sdx*2); }else if(frame==7){ MapSprite2(0,map_rwalk1,sprFlags); dy=0; sx+=(sdx*2); if(stopping){ stopFrame++; } }else if(frame>7 && frame<=11){ sx+=sdx; }else if(frame==12){ MapSprite2(0,map_rwalk2,sprFlags); dy=-1; sx+=(sdx*2); }else if(frame>12 && frame<=15){ sx+=sdx; }else if(frame==16){ sx+=sdx; frame=7; break; }else if(frame==17){ dy=0; MapSprite2(0,map_lskid,sprFlags); sx+=sdx; }else if(frame==18){ sx+=sdx; }else if(frame==19){ frame=7; sx+=sdx; } frame++; walkFrame++; break; case ACTION_JUMP: dy=-( pgm_read_byte(&(waves[jmpPos])) /2 ); if(frame==0){ MapSprite2(0,map_rjump1,sprFlags); sx+=sdx; }else if(frame>0 && frame<=20){ sx+=sdx; }else if(frame==21){ MapSprite2(0,map_rjump2,sprFlags); sx+=sdx; }else if(frame>21 && frame<=42){ sx+=sdx; }else if(frame==43){ sx+=sdx; dy=0; MapSprite2(0,map_rwalk1,sprFlags); action=ACTION_IDLE; } jmpPos+=3; frame++; break; }; }