本文整理汇总了C++中SDL_FillRect函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_FillRect函数的具体用法?C++ SDL_FillRect怎么用?C++ SDL_FillRect使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_FillRect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fillColor
void ScreenSurface::fillColor(Uint8 r, Uint8 g, Uint8 b) const
{
if ( SDL_FillRect(pScreen, 0, SDL_MapRGB(pScreen->format, r, g, b)) < 0 )
throw ErrorInfo(SDL_GetError());
}
示例2: SDL_main
//-----------------------------------------------------------------------------
int SDL_main(int argc, char *argv[]) {
// NOTE: check for the correct number of arguements
if(argc<2) {
fprintf(stderr, "Error: need a level name.\n");
return -1;
}
// NOTE: add the sqlite db to the levels directory
char filename[0xFF];
sprintf(filename, "levels/%s.db", argv[1]);
// NOTE: open database connection
if(sqlite3_open_v2(filename, &db, SQLITE_OPEN_READONLY, NULL)) {
fprintf(stderr, "sqlite3_open: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return -1;
}
/* === */
start();
/* === */
int wallSprite00Inds[2*3] = {
03, 04,
35, 36,
67, 68
};
SDL_Color wall00Color = {0xFF,0xFF,0xFF,0xFF};
SDL_Surface *wallSprite00 = buildSprite(2, 3, wall00Color, wallSprite00Inds);
int floorSprite00Inds[2*3] = {
17, 18,
49, 50,
81, 82
};
SDL_Color floorSprite00Color = {0x33,0x33,0x33,0xFF};
SDL_Surface *floorSprite00 = buildSprite(2, 3, floorSprite00Color, floorSprite00Inds);
int doorSprite00Inds[2*3] = {
29, 30,
61, 62,
93, 94
};
SDL_Color doorSprite00Color = {0xFF,0xFF,0xFF,0xFF};
SDL_Surface *doorSprite00 = buildSprite(2, 3, doorSprite00Color, doorSprite00Inds);
int wallSprite01Inds[2*3] = {
97, 98,
129, 130,
161, 162
};
SDL_Color wall01Color = {0xFF,0xFF,0xFF,0xFF};
SDL_Surface *wallSprite01 = buildSprite(2, 3, wall01Color, wallSprite01Inds);
int wallSprite02Inds[2*3] = {
105, 106,
137, 138,
169, 170
};
SDL_Color wallSprite02Color = {0xFF,0xFF,0xFF,0xFF};
SDL_Surface *wallSprite02 = buildSprite(2, 3, wallSprite02Color, wallSprite02Inds);
/* === */
while(running) {
/* === */
pollInput();
SDL_RenderClear(renderer);
SDL_FillRect(screen, 0, 0x00);
/* === */
loadTiles();
SDL_Rect tempRect = {
0, 0, SPRITE_W*2, SPRITE_H*3
};
int i, j;
for(j=0; j<12; j++) {
for(i=0; i<30; i++) {
tempRect.x = SPRITE_W*2*i;
tempRect.y = SPRITE_H*3*j;
switch(lvl.tiles[j][i]) {
case 0x01: {
SDL_BlitSurface(wallSprite00, NULL, screen, &tempRect);
} break;
case 0x02: {
SDL_BlitSurface(doorSprite00, NULL, screen, &tempRect);
//.........这里部分代码省略.........
示例3: defined
/**
** Initialize the fog of war.
** Build tables, setup functions.
*/
void CMap::InitFogOfWar()
{
//calculate this once from the settings and store it
FogOfWarColorSDL = Video.MapRGB(TheScreen->format, FogOfWarColor);
Uint8 r, g, b;
SDL_Surface *s;
FogGraphic->Load();
#if defined(USE_OPENGL) || defined(USE_GLES)
if (!UseOpenGL)
#endif
{
//
// Generate Only Fog surface.
//
s = SDL_CreateRGBSurface(SDL_SWSURFACE, PixelTileSize.x, PixelTileSize.y,
32, RMASK, GMASK, BMASK, AMASK);
SDL_GetRGB(FogOfWarColorSDL, TheScreen->format, &r, &g, &b);
Uint32 color = Video.MapRGB(s->format, r, g, b);
SDL_FillRect(s, NULL, color);
OnlyFogSurface = SDL_DisplayFormat(s);
SDL_SetAlpha(OnlyFogSurface, SDL_SRCALPHA | SDL_RLEACCEL, FogOfWarOpacity);
VideoPaletteListRemove(s);
SDL_FreeSurface(s);
//
// Generate Alpha Fog surface.
//
if (FogGraphic->Surface->format->BytesPerPixel == 1) {
s = SDL_DisplayFormat(FogGraphic->Surface);
SDL_SetAlpha(s, SDL_SRCALPHA | SDL_RLEACCEL, FogOfWarOpacity);
} else {
// Copy the top row to a new surface
SDL_PixelFormat *f = FogGraphic->Surface->format;
s = SDL_CreateRGBSurface(SDL_SWSURFACE, FogGraphic->Surface->w, PixelTileSize.y,
f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
SDL_LockSurface(s);
SDL_LockSurface(FogGraphic->Surface);
for (int i = 0; i < s->h; ++i) {
memcpy(reinterpret_cast<Uint8 *>(s->pixels) + i * s->pitch,
reinterpret_cast<Uint8 *>(FogGraphic->Surface->pixels) + i * FogGraphic->Surface->pitch,
FogGraphic->Surface->w * f->BytesPerPixel);
}
SDL_UnlockSurface(s);
SDL_UnlockSurface(FogGraphic->Surface);
// Convert any non-transparent pixels to use FogOfWarOpacity as alpha
SDL_LockSurface(s);
for (int j = 0; j < s->h; ++j) {
for (int i = 0; i < s->w; ++i) {
Uint32 c = *reinterpret_cast<Uint32 *>(&reinterpret_cast<Uint8 *>(s->pixels)[i * 4 + j * s->pitch]);
Uint8 a;
Video.GetRGBA(c, s->format, &r, &g, &b, &a);
if (a) {
c = Video.MapRGBA(s->format, r, g, b, FogOfWarOpacity);
*reinterpret_cast<Uint32 *>(&reinterpret_cast<Uint8 *>(s->pixels)[i * 4 + j * s->pitch]) = c;
}
}
}
SDL_UnlockSurface(s);
}
AlphaFogG = CGraphic::New("");
AlphaFogG->Surface = s;
AlphaFogG->Width = PixelTileSize.x;
AlphaFogG->Height = PixelTileSize.y;
AlphaFogG->GraphicWidth = s->w;
AlphaFogG->GraphicHeight = s->h;
AlphaFogG->NumFrames = 16;//1;
AlphaFogG->GenFramesMap();
AlphaFogG->UseDisplayFormat();
}
VisibleTable.clear();
VisibleTable.resize(Info.MapWidth * Info.MapHeight);
}
示例4: main
//.........这里部分代码省略.........
//Moves udp info to global var
udpInfo.udpSd = udpSd;
strcpy(udpInfo.serverIp, argv[1]);
//Recives the first information from the server
recv(tcpSd, buffer, sizeof(buffer), 0);
myId = atoi(buffer);
//Starts the Recive data thread
pthread_create( &reciveUdpData, NULL, recive_udp_data, &(player));
while (run)
{
//Start the timer
timer_start(&fps);
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE)
{
run = FALSE;
}
handel_input(&event, tcpSd );
}
camera.xCord = -player[myId].xCord;
camera.yCord = -player[myId].yCord;
//From here we draw stuff on the screen
SDL_FillRect(screen,NULL, 0x000000);
//Draws WorldMAps
draw_map(player[myId].xCord,player[myId].yCord, worldMap, screen);
//DISPLAYES YOUR TANK+++++++++++++++++++++++++++++
if (player[myId].team == 1)
{
draw_tank_self(player[myId].tankAngle, blueTank, screen);
draw_cannon_self(player[myId].cannonAngle, blueCannon, screen);
}
else
{
draw_tank_self(player[myId].tankAngle, redTank, screen);
draw_cannon_self(player[myId].cannonAngle, redCannon, screen);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//DISPLAYES OTHER TANKS+++++++++++++++++++++++++++++
for (i = 0; i < MAX_PLAYERS; i++)
{
if (player[i].slot == myId)
{
continue;
}
if (player[i].slot > -1 && player[i].connected == 1)
{
if (player[i].team == 1)
{
draw_tank_other(player[i].xCord,player[i].yCord,camera.xCord,camera.yCord,player[i].tankAngle,blueTank,screen);
示例5: playIntro
// plays the intro sequence
void playIntro()
{
SDL_Surface *text;
int intro = 0;
int iAlpha = 0;
int iPhase = 0;
Sprite *spr;
gBool fade = true;
TTF_Font *font;
SDL_Rect dest;
int fadeSpeed = 1;
Uint8 *keys;
spr = LoadSprite("images/kimmy.png",506,565);
font = TTF_OpenFont("fonts/font1.ttf",60);
while(++intro<1000)
{
SDL_PumpEvents();
keys = SDL_GetKeyState(NULL);
if(keys[SDLK_ESCAPE])
intro = 1000;
ResetBuffer();
if(spr != NULL)
{
fprintf(stderr,"intro: %i iAlpha: %i iPhase: %i\n",intro,iAlpha,iPhase);
SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format, 0,0,0));
switch(iPhase)
{
case 0:
fadeSpeed = 1;
text = TTF_RenderText_Solid(font,"Vincent Scuorzo Presents",color);
dest.x = (screen->w-text->w)*.5;
dest.y = (screen->h-text->h)*.5;
SDL_SetAlpha( text, SDL_SRCALPHA|SDL_RLEACCEL, iAlpha );
SDL_BlitSurface(text,NULL,screen,&dest);
break;
case 1:
fadeSpeed = 1;
SDL_SetAlpha( spr->image, SDL_SRCALPHA|SDL_RLEACCEL, iAlpha );
DrawSprite(spr,screen,(screen->w-spr->w)*.5,(screen->h-spr->h)*.5,0);
break;
default:
intro = 1000;
}
if(iAlpha < (SDL_ALPHA_OPAQUE-fadeSpeed) && fade == true)
iAlpha+=fadeSpeed;
else if(iAlpha > SDL_ALPHA_TRANSPARENT && fade == false)
iAlpha-=fadeSpeed;
else if(iAlpha >= (SDL_ALPHA_OPAQUE-fadeSpeed) )
{
fade = false;
}
else if(iAlpha <= SDL_ALPHA_TRANSPARENT)
{
fade = true;
++iPhase;
}
}
else
intro = 1000;
NextFrame();
}
}
示例6: main
int
main ( int argc, char *argv[] )
{
bool quit = false;
int sprite_x = 0;
int inc_val = 0;
char m[80];
int u = 0;
int bgX = 0;
int bgY = 0;
if( init() == false )
return EXIT_FAILURE;
if( load_files() == false )
return EXIT_FAILURE;
clip[0].x = 0;
clip[0].y = 0;
clip[0].w = 32;
clip[0].h = 32;
//apply_surface( 0, 0, background, screen );
apply_surface( 10, 10, sprite_image, screen, &clip[0] );
//apply_surface( 10, 10, sprite_image, screen );
if( SDL_Flip( screen ) == -1 )
{
return EXIT_FAILURE;
}
next_time = SDL_GetTicks() + TICK_INTERVAL;
while( quit == false ){
SDL_Rect tmp;
SDL_Rect tmp2;
tmp.x = sprite_x;
tmp.y = 0;
tmp.w = 32;
tmp.h = 32;
quit = handle_events( &inc_val );
tmp2.x = 210 + 150;
tmp2.y = 0;
tmp2.w = 16;
tmp2.h = 16;
if( rightdown )
inc_val++;
if( inc_val > 0 && leftdown )
inc_val--;
//rightdown = false;
//leftdown = false;
//
//fprintf(stderr, "x = %d\n", sprite_x);
sprintf( m, "%d", inc_val );
message = TTF_RenderText_Solid( font, m, textColor );
SDL_FillRect( screen, NULL, SDL_MapRGB( screen->format, 0, 0, 0 ) );
//apply_surface( 10, 10, sprite_image, screen, &tmp );
//apply_surface( 100, 100, sprite_image2, screen, &tmp2 );
draw();
bgX -= 2;
if( bgX <= -background->w ){
bgX = 0;
}
/*
if( !updown && u != 50 ){
u = 100;
}
*/
apply_surface( bgX, bgY, background, screen );
apply_surface( bgX + background->w, bgY, background, screen );
apply_surface( 50, 50, message, screen );
//apply_surface( 10, 10, sprite_image, screen );
if( SDL_Flip( screen ) == -1 )
{
return EXIT_FAILURE;
}
sprite_x = (sprite_x + 32) % 256;
//SDL_Delay(30);
SDL_Delay( time_left() );
//SDL_free( tmp );
next_time += TICK_INTERVAL;
}
//SDL_Delay(5000);
return EXIT_SUCCESS;
}/* ---------- end of function main ---------- */
示例7: main
int
main (int argc, char **argv)
{
SDL_Surface *image;
nile_t *nl;
char mem[500000];
uint32_t texture_pixels[TEXTURE_WIDTH * TEXTURE_HEIGHT] = {0};
real angle = 0;
real scale;
if (SDL_Init (SDL_INIT_VIDEO) == -1)
DIE ("SDL_Init failed: %s", SDL_GetError ());
if (!SDL_SetVideoMode (DEFAULT_WIDTH, DEFAULT_HEIGHT, 0,
SDL_HWSURFACE | SDL_ANYFORMAT | SDL_DOUBLEBUF))
DIE ("SDL_SetVideoMode failed: %s", SDL_GetError ());
image = SDL_GetVideoSurface ();
nl = nile_new (NTHREADS, mem, sizeof (mem));
ilInit ();
ilBindImage (iluGenImage ());
if (argc < 3)
return -1;
printf ("loading: %s\n", argv[1]);
ilLoadImage (argv[1]);
ilCopyPixels (0, 0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT, 1, IL_BGRA,
IL_UNSIGNED_BYTE, &texture_pixels);
int filter = atoi (argv[2]);
for (;;) {
angle += 0.001;
scale = fabs (angle - (int) angle - 0.5) * 10;
SDL_Event event;
if (SDL_PollEvent (&event) && event.type == SDL_QUIT)
break;
SDL_FillRect (image, NULL, 0);
SDL_LockSurface (image);
matrix_t M = matrix_new ();
M = matrix_translate (M, 250, 250);
M = matrix_rotate (M, angle);
M = matrix_scale (M, scale, scale);
M = matrix_translate (M, -250, -250);
matrix_t I = matrix_inverse (M);
nile_Kernel_t *texture =
gezira_ReadFromImage_ARGB32 (nl, texture_pixels, TEXTURE_WIDTH,
TEXTURE_HEIGHT, TEXTURE_WIDTH);
/*
*/
texture = nile_Pipeline (nl,
gezira_ImageExtendReflect (nl, TEXTURE_WIDTH, TEXTURE_HEIGHT),
texture, NULL);
if (filter == 2)
texture = gezira_BilinearFilter (nl, texture);
if (filter == 3)
texture = gezira_BicubicFilter (nl, texture);
/*
*/
texture = nile_Pipeline (nl,
gezira_TransformPoints (nl, I.a, I.b, I.c, I.d, I.e - 150, I.f - 125),
texture, NULL);
nile_Kernel_t *pipeline = nile_Pipeline (nl,
gezira_TransformBeziers (nl, M.a, M.b, M.c, M.d, M.e, M.f),
gezira_ClipBeziers (nl, 0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT),
gezira_Rasterize (nl),
gezira_ApplyTexture (nl, texture),
gezira_WriteToImage_ARGB32 (nl, image->pixels,
DEFAULT_WIDTH, DEFAULT_HEIGHT,
image->pitch / 4),
NULL);
nile_feed (nl, pipeline, path, 6, path_n, 1);
nile_sync (nl);
SDL_UnlockSurface (image);
SDL_Flip (image);
}
nile_free (nl);
printf ("done\n");
return 0;
}
示例8: graphics
int graphics( float heading)
{
SDL_Rect outerRingposition;
SDL_Rect compassNeedlePosition;
SDL_Rect topLine1;
topLine1.x = 20;
topLine1.y = 100;
topLine1.w = 0;
topLine1.h = 0;
SDL_Color colorWhite = {255,255,255,0};
char headingString[8] = "";
//Clear previous image
SDL_FillRect(screen, NULL, 0x000000);
//Convert heading value which is a float to a string
snprintf(headingString, 7, "%7.3f", heading);
textSurface = TTF_RenderText_Solid(font, headingString, colorWhite);
//Rotate the heading
currentDegressRotated = rotozoomSurface(textSurface, TEXTANGLE, 1.0, 0);
//Position the outer ring in the center of display
outerRingposition.x = (SCREEN_WIDTH - compatibleOuterRing->w)/2;
outerRingposition.y = (SCREEN_HEIGHT - compatibleOuterRing->h)/2;
//Position compass needle
compassNeedlePosition.x = (SCREEN_WIDTH - compatibleCompassNeedle->w)/2;
compassNeedlePosition.y = 20;
//Rotate needle based on angle. Add 90 degrees for correction.
rotation = rotozoomSurface(compatibleCompassNeedle, heading+90, 1.0, 0);
if (rotation == NULL) printf("error rotating needle\n");
//recenter pivote for rotation
compassNeedlePosition.x -= rotation->w/2-compatibleCompassNeedle->w/2;
compassNeedlePosition.y -= rotation->h/2-compatibleCompassNeedle->h/2;
// put the image on the screen surface
SDL_BlitSurface(currentDegressRotated, NULL, screen, &topLine1);
SDL_BlitSurface(compatibleOuterRing, NULL, screen, &outerRingposition);
SDL_BlitSurface(rotation, NULL, screen, &compassNeedlePosition);
// send the screen surface to be displayed
SDL_Flip(screen);
SDL_FreeSurface(currentDegressRotated);
SDL_FreeSurface(textSurface);
SDL_FreeSurface(screen);
SDL_FreeSurface(rotation);
return 0;
}
示例9: SDL_FillRect
void Screen::preRender() {
SDL_FillRect(screen,NULL,0x00FF00);
}
示例10: options_menu
//.........这里部分代码省略.........
while(!available[selection]) selection=(selection+1)%nb;
}
else if(in.key[SDLK_UP])
{
in.key[SDLK_UP]=0;
if(!(selection)) selection=nb-1;
else selection=(selection-1)%nb;
while(!available[selection])
{
if(!selection) selection=nb-1;
else selection=(selection-1)%nb;
}
}
else if(in.key[SDLK_LEFT])
{
in.key[SDLK_LEFT]=0;
if(selection==0) {
if(cfg->nb_players>0)
{
available[cfg->nb_players+1]=0;
cfg->nb_players=cfg->nb_players-1;
sprintf(options[1], "%d", cfg->nb_players);
}
}
else if(selection==2 || selection==3) {
if(cfg->players[selection-2].character == PACMAN) cfg->players[selection-2].character = GHOST;
else if(cfg->players[selection-2].character == GHOST) cfg->players[selection-2].character = PACMAN;
}
}
else if(in.key[SDLK_RIGHT])
{
in.key[SDLK_RIGHT]=0;
if(selection==0)
{
if(cfg->nb_players<2) {
available[cfg->nb_players+2]=1;
cfg->nb_players=(cfg->nb_players+1);
sprintf(options[1], "%d", cfg->nb_players);
}
}
else if(selection==2 || selection==3) {
if(cfg->players[selection-2].character == PACMAN) cfg->players[selection-2].character = GHOST;
else if(cfg->players[selection-2].character == GHOST) cfg->players[selection-2].character = PACMAN;
}
}
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
couleur[selection]=jaune;
p1.x=300; p1.y=50;
aff_pol(title, 50, p1, jaune); //Le titre
p1.x=310; p1.y=150;
aff_pol(options[0], 30, p1, couleur[0]); //Nb players
pos.x=p1.x+120; pos.y=p1.y;
SDL_BlitSurface(fleche[1], NULL, screen, &pos);
p1.x+=150;
aff_pol(options[1], 30, p1, couleur[1]); //Nb players
pos.x+=50;
SDL_BlitSurface(fleche[0], NULL, screen, &pos);
//Afficher des fleches
j=(j+1)%2;
p1.x=250; p1.y=225;
pos.x=p1.x+10; pos.y=p1.y+50;
aff_pol(options[2], 30, p1, couleur[2]); //Player 1
SDL_BlitSurface(fleche[1], NULL, screen, &pos);
pos.x+=25;
if(cfg->players[0].character == GHOST) SDL_BlitSurface(ghost[j], NULL, screen, &pos);
else SDL_BlitSurface(pac[j], NULL, screen, &pos);
pos.x+=25;
SDL_BlitSurface(fleche[0], NULL, screen, &pos);
//Afficher des fleches
p1.x+=200;
pos.x=p1.x+10;
aff_pol(options[3], 30, p1, couleur[3]); //Player 2
SDL_BlitSurface(fleche[1], NULL, screen, &pos);
pos.x+=25;
if(cfg->players[1].character == GHOST) SDL_BlitSurface(ghost[j], NULL, screen, &pos);
else SDL_BlitSurface(pac[j], NULL, screen, &pos);
pos.x+=25;
SDL_BlitSurface(fleche[0], NULL, screen, &pos);
//Afficher des fleches
p1.x=250; p1.y+=100;
aff_pol(options[4], 30, p1, couleur[4]); //Sound
//Afficher des images pour le son
p1.x=250; p1.y+=75;
aff_pol(options[5], 30, p1, couleur[5]); //Reset score
p1.x=150; p1.y+=100;
for(i=6; i<nb; i++)
{
aff_pol(options[i], 30, p1, couleur[i]);
p1.x+=225;
}
SDL_Flip(screen);
}
}
示例11: jeu
//.........这里部分代码省略.........
default :
break;
}
j++;
}
}
//////////////////////////////////////////////
int pourcent[TAILLE_MAX] = {0},pourcentFinal=0,totalNotes=0;//Pour le pourcentage de réussite
int k=0;//notes 1,2,3....
int tempsDebut=SDL_GetTicks();//SDL_GetTicks donne le temps qu'il s'est écoulé depuis le lancement du programme, on retire donc le temps qu'il s'est écoulé entre le lancement et le début du morceau
int a=0,z=0,e=0,r=0,t=0,y=0,u=0;//notes
int tempsPrecedent = 0, tempsActuel = 0, tempsNote[7]; //Timer (temps note permet de savoir a quel instant t la note a été jouée
int continuer = 1;
//Boucle jeu
if (ArduinoClavier) arduino(1);//On lance arduino pour avoir le numéro port série qui correspond
while (continuer)
{
/* On joue la musique au bon moment de manière à ce qu'elle soit synchronisée avec les notes qui défilent */
if ((tempsActuel>=2700)&&(tempsActuel<=2750))FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, musique, 0,NULL);
/* On efface l'écran */
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255,255, 255));//255,255, 255 veut dire qu'on met un ecran noir
/* On remet le fond */
SDL_BlitSurface(imageDeFond, NULL, ecran, &positionFond);
tempsActuel = SDL_GetTicks() - tempsDebut; //temps
/************************************************
+ On affiche les notes
+ On fait descendre les notes le long des lignes
J'ai galeré pour ca !
*************************************************/
if(tempsActuel>=debut[k+1]) k++; // passage à la note suivante
int l=k;
do
{
if (tempsActuel>=debut[0]) positionNote[l].y= positionNote[l].y+tempsActuel/10*2-tempsPrecedent/10*2;//descente de la note en utilisant le temps comme réference (elle met du coup 2.7sec a desendre) (la condition corrige le bug de la 1ere note)
if (positionNote[l].y>575) positionNote[l].y=10000; // si la note arrive en bas on la fait "disparaitre"
SDL_BlitSurface(Note, NULL, ecran, &positionNote[l]);//on affiche les notes
l--;
}while(l>=0);
示例12: main
int main(int argc, char* args[])
{
bool quit = false;
if (!initialize())
{
return 1;
}
if (!loadFiles())
{
return 1;
}
Timer fps;
Input input;
// Prepare calculations to track the FPS.
Timer fpsTrack, fpsTrackUpdate;
int frame = 0;
fpsTrack.start();
fpsTrackUpdate.start();
// Initalize map.
Map map;
map.load("maps/test.map");
// Create character.
Character character(0, 0, 32, 32, map);
// Handle player input.
input.input();
// Start main game loop.
while (!quit)
{
fps.start(); // Update FPS counter.
while (SDL_PollEvent(&event))
{
// Check for quit.
if (event.type == SDL_QUIT)
{
quit = true; // Quit loop.
}
}
// Fill the screen with a background color.
SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xac, 0xc6, 0xd7));
// Draw map tiles.
map.draw();
// Move character according to inputs and collision.
//std::cout << character.getX() << " " << character.getY() << " " << character.getYVel() << "\n";
character.move(&input);
// Draw character.
character.draw();
// Flip screen.
if (SDL_Flip(screen) == -1)
{
return 1;
}
frame++;
// Display the realtime FPS.
//if (fpsTrackUpdate.get() > 1000)
//{
// std::cout << frame / (fpsTrack.get()/1000.f) << "\n";
// fpsTrackUpdate.start(); // Reset fpsTrackUpdate. We only want to periodically get the FPS.
//}
// Regulate frames.
int fpsDiv = 1000/FPS;
if (fps.get() < fpsDiv)
{
SDL_Delay(fpsDiv - fps.get());
}
}
// Clean up used resources.
cleanUp();
return 0;
}
示例13: main
//.........这里部分代码省略.........
bool running = true;
while (running) {
/* Obtain any user input */
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
running = false;
}
}
/* Based on the sample rate and the current time,
* figure out what position to read the audio file from */
double seconds = (current_time - start_time) / 1000.0;
//printf("Current time: %.2f\n", seconds);
sf_count_t sample_pos = (int) sfinfo.samplerate * seconds;
int result = sf_seek(music_file, sample_pos, SEEK_SET);
if (result == -1) {
running = false;
}
/* Read the samples */
int samples_read = sf_readf_double(music_file, samples,
SAMPLE_COUNT);
if (samples_read <= 0) {
running = false;
}
/* Calculate the FFT */
fftw_execute(plan);
/* Fill the screen with black first */
SDL_Rect surf_rect;
surf_rect.w = WINDOW_WIDTH;
surf_rect.h = WINDOW_HEIGHT;
surf_rect.x = 0;
surf_rect.y = 0;
SDL_FillRect(surface, &surf_rect, SDL_MapRGB(surface->format,
0, 0, 0));
/* Draw all the rectangles */
int x_pos;
for (x_pos = 0; x_pos < WINDOW_WIDTH; x_pos += 1) {
SDL_Rect rect;
/* Based on the rectangle's position, get a different
* frequency; the second half of the buffer is useless
* data, so ignore that portion */
double relative_pos = x_pos * 1.0f / WINDOW_WIDTH;
int buf_range_max = out_buffer_size / 2;
int index = (int) (relative_pos * buf_range_max);
/* Figure out the normalized magnitude of the frequency */
double mag = sqrt(output[index][0] * output[index][0] +
output[index][1] * output[index][1]);
double norm_mag = mag * (1 / sqrt(buffer_size));
//printf("%d: %f\n", index, norm_mag);
/* Set the rectangle's size */
rect.w = 1;
rect.h = norm_mag * WINDOW_HEIGHT;
/* Set the rectangle's lower left corner */
rect.x = x_pos;
rect.y = WINDOW_HEIGHT - rect.h;
/* Draw the rectangle to the screen */
SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format,
0, 0, 255));
}
/* Update the display */
SDL_UpdateWindowSurface(window);
/* Ensure that it runs around 30 FPS and also update the
* timer variables */
current_time = SDL_GetTicks();
int delta = current_time - last_time;
if (delta <= 33) {
SDL_Delay(33 - delta);
}
last_time = current_time;
}
/* Stop the music and free its memory */
Mix_HaltMusic();
Mix_FreeMusic(music);
/* Clean up and exit */
SDL_FreeSurface(surface);
SDL_DestroyWindow(window);
fftw_destroy_plan(plan);
sf_close(music_file);
return EXIT_SUCCESS;
}
示例14: clearScreen
void clearScreen()
{
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
}
示例15: main
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL, *menu = NULL, *manuel = NULL;
SDL_Rect positionMenu;
SDL_Event event;
int continuer = 1, afficherManuel = 0;
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetIcon(IMG_Load("caisse.jpg"), NULL); // L'ic�ne doit �tre charg�e avant SDL_SetVideoMode
ecran = SDL_SetVideoMode(408, 408, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
//ecran = SDL_SetVideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Naruto Sokoban", NULL);
menu = IMG_Load("menu.png");
manuel = IMG_Load("GFX/manuel.png");
positionMenu.x = 0;
positionMenu.y = 0;
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE: // Veut arr�ter le jeu
if (afficherManuel != 1)
{
continuer = 0;
}
else
{
afficherManuel = 0;
}
break;
case SDLK_1: // Demande � jouer
if (afficherManuel != 1)
{
menuNiveau(ecran, 1);
}
else
{
afficherManuel = 0;
}
break;
case SDLK_2: // Demande l'�diteur de niveaux
if (afficherManuel != 1)
{
menuNiveau(ecran, 0);
}
else
{
afficherManuel = 0;
}
break;
case SDLK_3:
//afficher image avec les r�gles
if (afficherManuel == 0)
{
afficherManuel = 1;
}
else
{
afficherManuel = 0;
}
break;
}
break;
}
// Effacement de l'�cran
ecran = SDL_SetVideoMode(408, 408, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
if (afficherManuel == 1)
{
SDL_BlitSurface(manuel, NULL, ecran, &positionMenu);
}
else
{
SDL_BlitSurface(menu, NULL, ecran, &positionMenu);
}
SDL_Flip(ecran);
}
SDL_FreeSurface(menu);
SDL_FreeSurface(manuel);
SDL_Quit();
return EXIT_SUCCESS;
}