void WinGame(){ while(GetMasterVolume()){ if(GetMasterVolume() > 4) SetMasterVolume(GetMasterVolume()-4); else{ StopSong(); break; } WaitVsync(1); } FadeOut(9,true); SetTileTable(font_tiles); ClearVram(); WaitVsync(45); SetMasterVolume(BB_MASTER_VOLUME); //TriggerNote(4,24,8,255);//StartSong(main_song); FadeIn(2,false); TextWriter(1,0,epilogue_string); while(1){ WaitVsync(1); if(padState & BTN_START && !(oldPadState & BTN_START)) break; } FadeOut(7,true); }
//Callback invoked by UzeboxCore.Initialize() void DisplayLogo(){ #if INTRO_LOGO !=0 #define LOGO_X_POS 18 InitMusicPlayer(logoInitPatches); SetTileTable(uzeboxlogo); //draw logo ClearVram(); WaitVsync(15); #if INTRO_LOGO == 1 TriggerFx(0,0xff,true); #endif DrawMap2(LOGO_X_POS,12,map_uzeboxlogo); WaitVsync(6); DrawMap2(LOGO_X_POS,12,map_uzeboxlogo2); WaitVsync(4); DrawMap2(LOGO_X_POS,12,map_uzeboxlogo); #if INTRO_LOGO == 2 SetMasterVolume(0xc0); TriggerNote(3,0,16,0xff); #endif WaitVsync(64); ClearVram(); WaitVsync(20); #endif }
//Callback invoked by UzeboxCore.Initialize() void DisplayLogo(){ #if INTRO_LOGO !=0 #define LOGO_X_POS 8 InitMusicPlayer(logoInitPatches); screenSections[0].tileTableAdress=uzeboxlogo; //draw logo ClearVram(); WaitVsync(15); #if INTRO_LOGO == 1 TriggerFx(0,0xff,true); #endif DrawMap(LOGO_X_POS,12,map_uzeboxlogo); WaitVsync(3); DrawMap(LOGO_X_POS,12,map_uzeboxlogo2); WaitVsync(2); DrawMap(LOGO_X_POS,12,map_uzeboxlogo); #if INTRO_LOGO == 2 SetMasterVolume(0xc0); TriggerNote(3,0,16,0xff); #endif WaitVsync(65); ClearVram(); WaitVsync(20); #endif }
/** * \brief Handles input for gameplay. Reads player 1 joypad and processes input for the main game. */ void processControls(void){ //read current player 1 input, save in joy variable joy=ReadJoypad(0); if(joy) //if any button at is is being pressed { if(scrollingOn) //if we're scrolling the screen (player is alive) { if(lastbuttons!=joy) //if we're pressing a new button, not holding one { yspeed = -jumpspeed; //make player jump up TriggerFx(4,0x88,true);//play our bouncing sound effects TriggerFx(5,0x88,true); grav_tick=1; //reset gravity ticks. doing this ensures that no matter where the gravity timer was, we always get a consistent jump height } } else if(joy&BTN_START) //if player is dead and start was pressed { if(deathclock<105) game_state = HIGH_SCORES; //exit main game state, enter high score screen state (refer to main function) } if(joy&BTN_SELECT)//alive or note, if select was pressed... { if(lastbuttons!=joy) //if it was JUST pressed and not held { if(mute) //if volume is muted, unmute it { SetMasterVolume(0xff); mute=false; ResumeSong(); } else //if volume is normal, mute it { StopSong(); SetMasterVolume(0x00); mute=true; } } } } //save current input as lastbuttons so we can check if new buttons are pressed next time lastbuttons=joy; }
cSdlTMS9919::cSdlTMS9919() : m_Initialized(false), m_MasterVolume(0), m_ShiftRegister(NOISE_RESET), m_NoiseGenerator(0), m_MixBuffer(NULL) { // FUNCTION_ENTRY ( this, "cSdlTMS9919 ctor", true ); memset(m_VolumeTable, 0, sizeof(m_VolumeTable)); memset(&m_AudioSpec, 0, sizeof(m_AudioSpec)); memset(m_Info, 0, sizeof(m_Info)); SetMasterVolume(50); float volume = 128.0 / 4.0; for (unsigned int i = 0; i < 16 - 1; i++) { m_VolumeTable[i] = (int)volume; volume = (float)(volume / 1.258925412); // Reduce volume by 2dB } m_VolumeTable[15] = 0; SDL_AudioSpec wanted; memset(&wanted, 0, sizeof(SDL_AudioSpec)); // Set the audio format wanted.freq = 44100; wanted.format = AUDIO_S16; wanted.channels = 1; wanted.samples = DEFAULT_SAMPLES; wanted.callback = _AudioCallback; wanted.userdata = this; memcpy(&m_AudioSpec, &wanted, sizeof(SDL_AudioSpec)); /* we don't want to initialize sdl audio here SDL_InitSubSystem(SDL_INIT_AUDIO); // Open the audio device, forcing the desired format if ( SDL_OpenAudio ( &wanted, &m_AudioSpec ) < 0 ) { // ERROR ( "Couldn't open audio: " << SDL_GetError ()); } else { // TRACE ( "Using " << m_AudioSpec.format << "-bit " << m_AudioSpec.freq << "Hz Audio" );*/ m_Initialized = true; m_MixBuffer = new Uint8[m_AudioSpec.samples]; memset(m_MixBuffer, 0, sizeof(Uint8) * m_AudioSpec.samples); // SDL_PauseAudio ( false ); // } // Mix_HookMusic(_AudioCallback, this); NOISE_COLOR_E color = m_NoiseColor; int type = m_NoiseType; m_NoiseColor = (NOISE_COLOR_E)-1; m_NoiseType = -1; SetNoise(color, type); }
void digi_set_master_volume( int volume ) { if (!digi_initialized) return; Config_master_volume = volume; if ( Config_master_volume > 8 ) Config_master_volume = 8; else if ( Config_master_volume < 0 ) Config_master_volume = 0; SetMasterVolume( (Config_master_volume*256)/8 ); }
AudioSystem::AudioSystem(LinearAllocator& alloc) : m_device(nullptr) , m_context(nullptr) , m_sounds() , m_channelPool() , m_channels() , m_masterVolume(1.0f) , m_muted(false) { m_device = alcOpenDevice(nullptr); AL_CHECK; if (m_device == nullptr) { log::Error("Could not open audio device."); return; } m_context = alcCreateContext(m_device, nullptr); AL_CHECK; if (m_context == nullptr) { log::Error("Could not create audio context."); return; } alcMakeContextCurrent(m_context); AL_CHECK; const size_t_32 allocSize = 1024; m_sounds.SetMemory(alloc.Allocate(allocSize, alignof(Sound)), allocSize); const size_t_32 channelPoolSize = GetArraySize<Channel>(MAX_CHANNELS); m_channelPool.SetMemory(alloc.AllocateArray<Channel>(MAX_CHANNELS), channelPoolSize); for (size_t_32 i = 0; i < MAX_CHANNELS; i++) { m_channels[i] = m_channelPool.Obtain(); } SetMasterVolume(m_masterVolume); alListener3f(AL_POSITION, 0.0f, 0.0f, -2.0f); AL_CHECK; }
/** * \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); }
void digi_close() { int i, sound_num; if (!digi_initialized) return; digi_stop_current_song(); SetMasterVolume(master_save); // free the sounds that we have registered. for (i = 0; i < num_sounds; i++) { sound_num = digi_xlat_sound(i); if (sound_num != -1) FreeSound(i); } ReleaseRegisteredSounds(); FinisSoundMusicSystem(); digi_initialized = 0; }
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); } } }
/** * \brief Processes controller input for the main menu. */ void processMainMenu(void) { //read in our player one joypad input joy=ReadJoypad(0); //pressing something and it isn't the same buttons as last frame so it's a new button press, not a hold if(joy!=lastbuttons) { //if player 1 is currently pressing start if(joy&BTN_START) { //if player cursor is at top menu choice, which is 'start game' if(menu_y == 15) { seedprng(start_seed); //switch our game state to game, which pops us out of the main menu and into the game (refer to main function) game_state = GAME; } //if cursor is on second option, which is 'hi scores' else if(menu_y == 17) { seedprng(start_seed); //switch our game state to high scores, which pops us out of the main menu and into the high scores menu (refer to main function) game_state = HIGH_SCORES; } } if(joy&BTN_UP) //player pressed up { if(menu_y > 15) //if we're not at the top menu option { eraseMenuCursor(); //erase the old cursor position menu_y -= 2; //move cursor up one option } } else if (joy&BTN_DOWN) //player pressed down { if(menu_y < 19) //if we're above the bottom option { eraseMenuCursor(); //erase cursor at old position menu_y += 2; //move cursor down one option } } else if ((joy&BTN_LEFT) || (joy&BTN_RIGHT)) //player pressed left or right on d-pad { if(menu_y == 19) //if we're on the third menu option, which is sound on/off { if(mute) //if game is muted, unmute it { SetMasterVolume(0xff); mute=false; } else //if game is not muted, mute it { SetMasterVolume(0x00); mute=true; } refreshMainMenuSound(); //update menu screen to show music as on/off now that it changed } } } lastbuttons=joy; //track which buttons were pressed this frame for comparison next frame start_seed++; }