void StateMenu::render(SDL_Surface* target) { spClearTarget( spGetRGB(128,0,0) ); if ( textMode == -1 ) { SDL_SetAlpha( text, SDL_SRCALPHA, (1.0f - (float)textTimer.getTime() / (float)textTimer.getDuration()) * 255.0f ); if ( textTimer.isStopped() ) { textTimer.start( MENU_TEXT_SHOW_TIME ); textMode = 0; SDL_SetAlpha( text, SDL_SRCALPHA, SDL_ALPHA_OPAQUE ); } } else if ( textMode == 0 ) { if ( textTimer.isStopped() ) { textTimer.start( MENU_TEXT_FADE_TIME ); textMode = 1; } } else if ( textMode == 1 ) { SDL_SetAlpha( text, SDL_SRCALPHA, (float)textTimer.getTime() / (float)textTimer.getDuration() * 255.0f ); if ( textTimer.isStopped() ) { ++textIndex; if ( textIndex >= lines.size() ) textIndex = 0; textTimer.start( MENU_TEXT_FADE_TIME ); textMode = -1; SDL_FillRect( text, NULL, spGetRGB( 255, 0, 255 ) ); SDL_SetColorKey( text, SDL_SRCCOLORKEY, spGetRGB( 255, 0, 255 ) ); spSelectRenderTarget( text ); spFontDraw( 20, 10, -1, (unsigned char*) lines[textIndex].first.c_str(), fontDark ); spFontDraw( 20, 10 + MENU_FONT_SIZE, -1, (unsigned char*) lines[textIndex].second.c_str(), fontDark ); spSelectRenderTarget( spGetWindowSurface() ); SDL_SetAlpha( text, SDL_SRCALPHA, SDL_ALPHA_TRANSPARENT ); } } SDL_Rect rect = { 0,0,APP_SCREEN_WIDTH, APP_SCREEN_HEIGHT / 2 }; spUnlockRenderTarget(); SDL_BlitSurface( text, NULL, spGetWindowSurface(), &rect ); spLockRenderTarget(); for ( int I = entries.size()-1; I >= 0; --I ) { if ( choice == I ) { spFontDrawRight( APP_SCREEN_WIDTH, APP_SCREEN_HEIGHT - MENU_FONT_SIZE * (I+1), -1, (unsigned char*) entries[I].name.c_str(), fontBright ); } else { spFontDrawRight( APP_SCREEN_WIDTH, APP_SCREEN_HEIGHT - MENU_FONT_SIZE * (I+1), -1, (unsigned char*) entries[I].name.c_str(), fontDark ); } } }
void StateScore::render( SDL_Surface *target ) { spUnlockRenderTarget(); SDL_BlitSurface( killFrame, NULL, spGetWindowSurface(), NULL ); spLockRenderTarget(); if ( scoreText ) { spFontDrawMiddle( APP_SCREEN_WIDTH / 2, APP_SCREEN_HEIGHT / 2 - SCORE_FONT_SIZE * 2, -1, playerDead ? (unsigned char*) "You died!" : (unsigned char*) "You survived, somehow...", scoreText ); spFontDrawMiddle( APP_SCREEN_WIDTH / 2, APP_SCREEN_HEIGHT / 2 - SCORE_FONT_SIZE, -1, (unsigned char*) ("Score: " + Utility::numToStr( score )).c_str(), scoreText ); if ( run && run->playing ) spFontDrawMiddle( APP_SCREEN_WIDTH / 2, APP_SCREEN_HEIGHT / 2 , -1, (unsigned char*) "Name of this player:", scoreText ); else spFontDrawMiddle( APP_SCREEN_WIDTH / 2, APP_SCREEN_HEIGHT / 2 , -1, (unsigned char*) "Enter your name:", scoreText ); char temp[strlen(name) + caret]; strcpy( temp, name ); if ( caret ) strcat( temp, "_\0" ); spFontDrawMiddle( APP_SCREEN_WIDTH / 2, APP_SCREEN_HEIGHT / 2 + SCORE_FONT_SIZE, -1, (unsigned char*) temp, scoreText); if ( state == 0 ) spFontDrawMiddle( APP_SCREEN_WIDTH / 2, APP_SCREEN_HEIGHT / 2 + SCORE_FONT_SIZE * 3, -1, (unsigned char*) "Press \""SP_BUTTON_START_NAME"\" to confirm name...", scoreText ); else spFontDrawMiddle( APP_SCREEN_WIDTH / 2, APP_SCREEN_HEIGHT / 2 + SCORE_FONT_SIZE * 3, -1, (unsigned char*) "Press \""SP_BUTTON_START_NAME"\" to return to menu...", scoreText ); } }
StateScore::StateScore( StateLevel *level ) : StateBase(), file( FOLDER_DATA "/" FILE_HIGHSCORE_NORMAL ) { SDL_Surface *temp = spCreateSurface( APP_SCREEN_WIDTH, APP_SCREEN_HEIGHT ); killFrame = spCreateSurface( APP_SCREEN_WIDTH, APP_SCREEN_HEIGHT ); spSelectRenderTarget( temp ); level->render( temp ); spUnlockRenderTarget(); SDL_SetAlpha( temp, SDL_SRCALPHA, 128 ); SDL_BlitSurface( temp, NULL, killFrame, NULL ); spLockRenderTarget(); spSelectRenderTarget( spGetWindowSurface() ); spDeleteSurface( temp ); if ( level->player->toBeRemoved ) playerDead = true; else playerDead = false; score = level->scoreKeeper->getScore(); scoreText = spFontLoad( FONT_GENERAL, SCORE_FONT_SIZE ); if ( scoreText ) { spFontAdd( scoreText, SP_FONT_GROUP_ALPHABET SP_FONT_GROUP_GERMAN ".:!\"_", -1 ); spFontAdd( scoreText, SP_FONT_GROUP_NUMBERS, spGetRGB( 255, 128, 0 ) ); } nameBkup[0] = 0; if ( level->run->playing ) { state = 1; caret = false; strcpy( nameBkup, name ); strcpy( name, level->run->info.name.c_str() ); run = level->run; level->run = NULL; } else { caret = true; state = 0; spPollKeyboardInput( name, SCORE_MAX_NAME_LENGTH, NULL ); run = level->run; level->run = NULL; } caretTimer.start( SCORE_CARET_BLINK_TIME ); timers.push_back( &caretTimer ); type = stScore; }
void draw_target(int rotation) { SDL_Surface* screen = spGetWindowSurface(); //drawing on the target_texture spSelectRenderTarget(target_texture); spClearTarget(65535); spSetZSet(0); spSetZTest(0); target_sprite->rotation = 0; spDrawSprite( target_texture->w / 4, target_texture->h / 4, 0, target_sprite ); target_sprite->zoomX = spSin( rotation * 8 ) + spFloatToFixed( 1.5f ); target_sprite->zoomY = spCos( rotation * 6 ) + spFloatToFixed( 1.5f ); spDrawSprite( 3 * target_texture->w / 4, target_texture->h / 4, 0, target_sprite ); target_sprite->rotation = rotation * 4; spDrawSprite( target_texture->w / 4, 3 * target_texture->h / 4, 0, target_sprite ); target_sprite->zoomX = SP_ONE; target_sprite->zoomY = SP_ONE; spDrawSprite( 3 * target_texture->w / 4, 3 * target_texture->h / 4, 0, target_sprite ); //drawing on the target_graph spSelectRenderTarget(target_graph); spClearTarget(01234); spSetZSet(0); spSetZTest(0); Uint16* pixeldata = spGetTargetPixel(); int x; for (x = 0;x < GRAPH_SIZE; x++) { Sint32 sx = spIntToFixed(x-GRAPH_SIZE/2)/16; Sint32 sy = spSin(sx+rotation*16); int y = spFixedToInt(sy*16)+GRAPH_SIZE/2; if (y>=0 && y<GRAPH_SIZE) pixeldata[y*GRAPH_SIZE+x] = 56789; sy = spCos(sx+rotation*32); y = spFixedToInt(sy*16)+GRAPH_SIZE/2; if (y>=0 && y<GRAPH_SIZE) pixeldata[y*GRAPH_SIZE+x] = 45678; } spUnlockRenderTarget(); for (x = 0;x < GRAPH_SIZE-1; x++) { Sint32 sx1 = spIntToFixed(x-GRAPH_SIZE/2)/16; Sint32 sy1 = spTan(sx1+rotation*8); int y1 = spFixedToInt(sy1*16)+GRAPH_SIZE/2; Sint32 sx2 = spIntToFixed(x+1-GRAPH_SIZE/2)/16; Sint32 sy2 = spTan(sx2+rotation*8); int y2 = spFixedToInt(sy2*16)+GRAPH_SIZE/2; spLine(x,y1,0,x+1,y2,0,34567); sy1 = spAcos(sx1/2+spSin(rotation*24)); y1 = spFixedToInt(sy1*16)+GRAPH_SIZE/2; sy2 = spAcos(sx2/2+spSin(rotation*24)); y2 = spFixedToInt(sy2*16)+GRAPH_SIZE/2; spLine(x,y1,0,x+1,y2,0,23456); sy1 = spAsin(sx1/2+spCos(rotation*24)); y1 = spFixedToInt(sy1*16)+GRAPH_SIZE/2; sy2 = spAsin(sx2/2+spCos(rotation*24)); y2 = spFixedToInt(sy2*16)+GRAPH_SIZE/2; spLine(x,y1,0,x+1,y2,0,12345); } //drawing on the screen spSelectRenderTarget(screen); spClearTarget(0); spSetZSet(1); spSetZTest(1); spResetZBuffer(); spIdentity(); spTranslate( 0,0, spFloatToFixed( -7.0f ) ); spRotateX( rotation ); spRotateY( rotation ); spRotateZ( rotation ); //Front / Back spBindTexture(target_texture); spQuadTex3D( -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), 0, target_texture->h - 1, -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), 0, 0, spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), target_texture->w - 1, 0, spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), target_texture->w - 1, target_texture->h - 1, 65535); spQuadTex3D( spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), 0, target_texture->h - 1, spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), 0, 0, -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), target_texture->w - 1, 0, -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), target_texture->w - 1, target_texture->h - 1, 65535 ); //Left / Right spBindTexture(target_graph); spQuadTex3D( -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), 0, target_graph->h - 1, -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), 0, 0, -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), target_graph->w - 1, 0, -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), target_graph->w - 1, target_graph->h - 1, 65535 ); spQuadTex3D( spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), 0, target_graph->h - 1, spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), 0, 0, spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), target_graph->w - 1, 0, spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), target_graph->w - 1, target_graph->h - 1, 65535 ); //Up / Down spBindTexture(target_garfield); spQuadTex3D( spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), 0, target_garfield->h - 1, spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), 0, 0, -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), target_garfield->w - 1, 0, -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), target_garfield->w - 1, target_garfield->h - 1, 65535 ); spQuadTex3D( -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), 0, target_garfield->h - 1, -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), 0, 0, spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), target_garfield->w - 1, 0, spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), target_garfield->w - 1, target_garfield->h - 1, 65535 ); }