static void CheckCheats(void) { if ((NewJoyPadButtons & PadStart) && !(players.AutomapFlags & AF_OPTIONSACTIVE)) { /* Pressed pause? */ if (gamepaused || !(JoyPadButtons&PadUse)) { gamepaused ^= 1; /* Toggle the pause flag */ if (gamepaused) { PauseMusic(); } else { ResumeMusic(); } } } }
void DrownCount(Object* self) { switch(self->routine) { case Routine_Init: self->routine = Routine_BubbleExpanding; self->map = Map_Bub; self->gfx = GFX_Bubble; Obj_SetVisible(self); Obj_SetBehind(self); self->actWid = 16; self->priority = 1; if(BTST(self->subtype, Subtype_Master)) { self->routine = Routine_Master; self->map = Map_Drown; self->gfx = GFX_Master; VAR_B(self, alwaysOneB) = self->subtype & ~Subtype_Master; goto _masterRoutine; } // Bubble self->anim = self->subtype; VAR_W(self, origXW) = self->x; self->velY = -Bubble_Velocity; // fall through case Routine_BubbleExpanding: AnimateSprite(self, Ani_Drown); // fall through case Routine_BubbleRising: // Still underwater? if(self->y >= vWaterpos1) { // Move bubbles with tunnel current if(fWtunnelmode) VAR_W(self, origXW) += 4; // Wobble self->x = VAR_W(self, origXW) + Bubble_Wobble[self->angle & 0x7F]; self->angle++; // Update appearance CheckNumberBubbleConversion(self); SpeedToPos(self); if(Object_IsVisible(self)) DisplaySprite(self); else DeleteObject(self); break; } else { // Reached surface? For small bubbles, this sets their anim to blank and will go routine 6 > 8 and die // Big bubbles actually glitch out when they reach the surface cause there aren't enough enim mappings! self->routine = Routine_BubbleDying; self->anim += 7; } // fall through case Routine_BubbleDying: case Routine_NumberUpdate: _display: // Update appearance CheckNumberBubbleConversion(self); AnimateSprite(self, Ani_Drown); DisplaySprite(self); break; case Routine_BubbleDead: case Routine_NumberDead: DeleteObject(self); break; // Once a number-bubble gets plastered to the screen, it enters this state which handles switching to the // "flashing number" animation. case Routine_NumberTransition: if(v_air > Drown_Air) { DeleteObject(self); break; } if(TimerZero(VAR_W(self, frameTimerW))) { self->routine = Routine_NumberUpdate; self->anim += 7; goto _display; } AnimateSprite(self, Ani_Drown); if(Object_IsVisible(self)) DisplaySprite(self); else DeleteObject(self); break; // The "master" object, spawned when Sonic goes underwater for the first time, goes into this routine forever. // It manages counting down the air meter, spawning bubbles/numbers, and drowning/killing Sonic. case Routine_Master: _masterRoutine: // If we're not currently drowning... if(VAR_W(self, drowningTimeW) == 0) { // Manage counting down the timer and stuff if(Player_IsDead() || !Player_IsUnderwater()) return; // Count down frames until the next second if(TimerNeg(VAR_W(self, frameTimerW), 59)) { VAR_W(self, bubbleFlagsW) = BubbleFlags_Enable; VAR_B(self, spawnTimerB) = RandomNumber(2); if(ShouldDing()) PlaySound_Special(SFX_Warning); // ding-ding else if(v_air <= Drown_Air) { if(v_air == Drown_Air) PlaySound(BGM_Drowning); // uh oh if(TimerNeg(VAR_B(self, sillyTimerB), VAR_B(self, alwaysOneB))) BSET(VAR_W(self, bubbleFlagsW), BubbleFlags_SpawnNumber); } if(TimerNeg(v_air)) { // Drowning time. ResumeMusic(); f_lockmulti = 0x81; PlaySound_Special(SFX_Drown); VAR_B(self, spawnTimerB) = 10; VAR_W(self, bubbleFlagsW) = BubbleFlags_Enable; VAR_W(self, drowningTimeW) = Drown_Length; Player_ResetOnFloor(v_player); Player_SetAnimDrowning(); Player_SetInAir(); v_player->gfx |= 0x80; v_player->velY = 0; v_player->velX = 0; v_player->inertia = 0; f_nobgscroll = true; return; } goto _makeBubble; } } else { // Manage the drowning animation (Sonic falling offscreen) if(TimerZero(VAR_W(self, drowningTimeW))) { Player_SetDead(); return; } SpeedToPos(v_player); v_player->velY += Drown_Velocity; } // Bubble spawning enabled? if(VAR_W(self, bubbleFlagsW)) { if(TimerNeg(VAR_W(self, bubbleTimerW))) { _makeBubble: VAR_W(self, bubbleTimerW) = RandomNumber(16); if(auto bubble = FindFreeObj()) { auto bubble = &v_objspace[slot]; bubble->id = ID_DrownCount; bubble->x v_player->x + (Player_IsFlipped() ? -Bubble_OffsX : Bubble_OffsX); bubble->y = v_player->y; bubble->angle = Player_IsFlipped() ? Bubble_AngleFlipped : 0; bubble->subtype = Subtype_SmallBubble; // If we're doing drowning-bubbles.. if(VAR_W(self, drowningTimeW) != 0) { VAR_W(self, bubbleTimerW) &= 7; bubble->y = v_player->y - Bubble_DrownOffsY; bubble->angle = RandomNumber(256); // 1/4 bubbles are made bigger if((v_framecount & 3) == 0) bubble->subtype = Subtype_MediumBubble; } else if(ShouldSpawnNumberBubble(self)) { BSET(VAR_W(self, bubbleFlagsW), BubbleFlags_NumberSpawned); bubble->subtype = GetCountdownDigit(); VAR_W(bubble, frameTimerW) = NumberBubble_Timer1; } if(TimerNeg(VAR_B(self, spawnTimerB))) VAR_W(self, bubbleFlagsW) = 0; } } } break; } }
int SDLU_EventFilter( const SDL_Event *event ) { switch( event->type ) { // Put keydowns in a buffer case SDL_KEYDOWN: if( s_interestedInTyping && event->key.keysym.sym < 300 && s_keyBufferFilled < sizeof(s_keyBufferASCII) ) { s_keyBufferFilled++; s_keyBufferASCII[s_keyBufferPutAt] = event->key.keysym.unicode; s_keyBufferSDL [s_keyBufferPutAt] = event->key.keysym.sym; s_keyBufferPutAt = (s_keyBufferPutAt + 1) % sizeof(s_keyBufferASCII); } if( ((event->key.keysym.sym == SDLK_F4) && (event->key.keysym.mod & (KMOD_LALT | KMOD_RALT))) || ((event->key.keysym.sym == SDLK_q) && (event->key.keysym.mod & (KMOD_LMETA | KMOD_RMETA))) ) { finished = true; } break; case SDL_MOUSEBUTTONDOWN: if( event->button.button == SDL_BUTTON_LEFT ) s_mouseButton = true; s_mousePosition.y = event->button.y; s_mousePosition.x = event->button.x; break; case SDL_MOUSEBUTTONUP: if( event->button.button == SDL_BUTTON_LEFT ) s_mouseButton = false; s_mousePosition.y = event->button.y; s_mousePosition.x = event->button.x; break; case SDL_MOUSEMOTION: s_mousePosition.y = event->motion.y; s_mousePosition.x = event->motion.x; s_mouseButton = event->motion.state & SDL_BUTTON(1); break; case SDL_QUIT: finished = true; break; // Handle gaining and losing focus (kind of cheesy) case SDL_ACTIVEEVENT: if( (event->active.state & SDL_APPINPUTFOCUS) ) { if( !event->active.gain && s_isForeground ) { FreezeGameTickCount(); PauseMusic(); s_isForeground = false; } else if( event->active.gain && !s_isForeground ) { UnfreezeGameTickCount(); ResumeMusic(); s_isForeground = true; DoFullRepaint(); } } break; } return 0; }
int main(int argc, char *argv[]) { // Initialize the SDL library // This is required to avoid _main errors at runtime. #ifdef UseSDLMixer if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) { #else if ( SDL_Init(SDL_INIT_VIDEO ) < 0 ) { #endif fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } // Init SDL_Image - only applies above 1.2.7 // load support for the JPG and PNG image formats int IMGflags=IMG_INIT_JPG|IMG_INIT_PNG; int initted=IMG_Init(IMGflags); if(initted && IMGflags != IMGflags) { printf("IMG_Init: Failed to init required jpg and png support!\n"); printf("IMG_Init: %s\n", IMG_GetError()); // handle error } #ifdef UseSDLMixer // Initialize SDL mixer. if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) != 0) { fprintf(stderr, "Unable to initialize audio: %s\n", Mix_GetError()); exit(1); } #endif // Retrieve display gamma for reference in fade in/fade out routines. SDL_GetGammaRamp(redGamma, greenGamma, blueGamma); // printf("%u", *redGamma); Initialize( ); LoadPrefs( ); ReserveMonitor( ); ShowTitle( ); ChooseMusic( 13 ); while( !finished ) { if( showStartMenu ) { GameStartMenu( ); showStartMenu = false; } if( !finished ) { DoFullRepaint = NeedRefresh; CheckKeys( ); HandlePlayers( ); UpdateOpponent( ); UpdateBalloon( ); UpdateSound( ); DoFullRepaint = NoPaint; if( needsRefresh ) { RefreshAll(); needsRefresh = false; } if( !showStartMenu && pauseKey ) { FreezeGameTickCount( ); PauseMusic( ); MaskRect( &playerWindowRect[0] ); MaskRect( &playerWindowRect[1] ); WaitForRelease( ); HandleDialog( kPauseDialog ); WaitForRelease( ); RefreshPlayerWindow( 0 ); RefreshPlayerWindow( 1 ); ResumeMusic( ); UnfreezeGameTickCount( ); } } } SavePrefs( ); ReleaseMonitor( ); return 0; } void NoPaint( void ) { } void MaskRect( MRect *r ) { SDL_Rect sdlRect; SDLU_MRectToSDLRect( r, &sdlRect ); SDLU_BlitFrontSurface( backdropSurface, &sdlRect, &sdlRect ); }
int cAudio :: PlayMusic( string filename, int loops, bool force, unsigned int FadeInms ) { if( !bMusic || !bInitialised ) { return 0; } if( !valid_file( filename ) ) { printf( "Couldn't find music file : %s\n", filename.c_str() ); return 0; } ResumeMusic(); if( !isMusicPlaying() || force ) { if( Music ) { if( force ) { HaltMusic(); } Mix_FreeMusic( Music ); Music = NULL; } Music = Mix_LoadMUS( filename.c_str() ); if( Music ) { Music_Played++; if( !FadeInms ) // No Fading { Mix_PlayMusic( Music, loops ); } else // Fade the Music in { Mix_FadeInMusic( Music, loops, FadeInms ); } } else { if( bDebug ) { printf( "PlayMusic couldn't play music file : %s\n", filename.c_str() ); } return 0; } } else { Music = Mix_LoadMUS( filename.c_str() ); } return 1; }