本文整理汇总了C++中SDL_WM_SetCaption函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_WM_SetCaption函数的具体用法?C++ SDL_WM_SetCaption怎么用?C++ SDL_WM_SetCaption使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_WM_SetCaption函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
SDL_Event event;
/* nacteni modelu */
polymodel = modLoad((argc == 2) ? argv[1] : DEFAULT_MODEL);
IZG_CHECK(polymodel, "Failed to read input model");
/* vytvoreni SW rendereru */
#ifdef USE_STUDENT_RENDERER
renderer = studrenCreate();
#else
renderer = renCreate();
#endif /* USE_STUDENT_RENDERER */
/* pocatecni velikost bufferu */
renderer->createBuffersFunc(renderer, DEFAULT_WIDTH, DEFAULT_HEIGHT);
/* inicializace SDL knihovny */
if( SDL_Init(SDL_INIT_VIDEO) == -1 )
{
IZG_SDL_ERROR("Could not initialize SDL library");
}
/* nasteveni okna */
SDL_WM_SetCaption(PROGRAM_TITLE, 0);
/* screen */
screen = SDL_SetVideoMode(DEFAULT_WIDTH, DEFAULT_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE);
/* enable Unicode translation */
SDL_EnableUNICODE(1);
/* kreslime dokud nenarazime na SDL_QUIT event */
while( !quit )
{
/* vycteni udalosti */
while( SDL_PollEvent(&event) )
{
switch( event.type )
{
/* udalost klavesnice */
case SDL_KEYDOWN:
onKeyboard(&event.key);
break;
/* zmena velikosti okna */
case SDL_VIDEORESIZE:
onResize(&event.resize);
break;
/* udalost mysi */
case SDL_MOUSEMOTION:
onMouseMotion(&event.motion);
break;
/* SDL_QUIT event */
case SDL_QUIT:
quit = 1;
break;
default:
break;
}
}
/* vykresleni pres SDL knihovnu */
draw();
}
/* ukonceni SDL */
SDL_FreeSurface(screen);
/* shutdown all SDL subsystems */
SDL_Quit();
/* zrusime co jsme vytvorili a ukoncime program */
modRelease(&polymodel);
renderer->releaseFunc(&renderer);
return 0;
}
示例2: resolver
void conn::conecta(std::string server,std::string port){
bot::team_id id = 1000;
boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
auto endpoint_iterator = resolver.resolve({ server, port });
std::shared_ptr<tcp::socket> socket(new tcp::socket(io_service));
boost::asio::connect(*socket, endpoint_iterator);
bot::field_size field_width;
bot::field_size field_height;
int win_width = 500;
int win_height = 500;
bots Mundo;
boost::mutex state_mutex;
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);
SDL_WM_SetCaption("Superbots", "Superbots");
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
MYscreen.set_screen(win_width, win_height);
SDL_Event event;
bool gameover = false;
bool connected = false;
boost::thread t = boost::thread([this,socket, &state_mutex, &gameover, &connected, &Mundo, &id, &field_width, &field_height, &win_width, &win_height] () { game_thread(socket, gameover, Mundo, id, state_mutex, field_width, field_height, win_width, win_height, connected); } );
while (!gameover) {
if(connected) {
if (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
gameover = true;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_ESCAPE:
case SDLK_q:
gameover = true;
break;
default:
break;
}
break;
case SDL_VIDEORESIZE:
win_width = event.resize.w;
win_height = event.resize.h;
MYscreen.set_screen(win_width, win_height, field_width, field_height);
break;
}
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
{
boost::mutex::scoped_lock lock(state_mutex);
Mundo.for_each_bot([&Mundo] (const bot & the_bot) {
auto t = the_bot.get_team() + 1;
glColor3f(t * 0.2, 1 - t * 0.3, t * 0.1);
const bot::position & pos = the_bot.get_position();
glLoadIdentity();
glTranslatef(pos.first, pos.second, 0);
glBegin(GL_QUADS);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();
});
}
SDL_GL_SwapBuffers();
}
}
if(Mundo.bot_count().size() != 1) {
std::cout << "Shit!" << std::endl;
}
else {
for(auto inmortal : Mundo.bot_count()) {
std::cout << inmortal.first << " se ha pulido a todos!" << std::endl;
}
//.........这里部分代码省略.........
示例3: TRanrotBGenerator
SDL_Surface *initialization(int flags)
{
const SDL_VideoInfo* info = 0;
int bpp = 0;
SDL_Surface *screen;
rg = new TRanrotBGenerator(0);
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Initializing SDL\n");
#endif
if (SDL_Init(SDL_INIT_VIDEO | (sound ? SDL_INIT_AUDIO : 0) | SDL_INIT_JOYSTICK | SDL_INIT_EVENTTHREAD) < 0) {
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Video initialization failed: %s\n", SDL_GetError());
#endif
return 0;
}
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("SDL initialized\n");
#endif
info = SDL_GetVideoInfo();
if (!info) {
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Video query failed: %s\n", SDL_GetError());
#endif
return 0;
}
if (fullscreen) {
bpp = COLOUR_DEPTH;
} else {
bpp = info->vfmt->BitsPerPixel;
}
desktopW = info->current_w;
desktopH = info->current_h;
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Setting OpenGL attributes\n");
#endif
#ifndef HAVE_GLES
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#endif
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("OpenGL attributes set\n");
#endif
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Initializing video mode\n");
#endif
#ifdef HAVE_GLES
fullscreen = true;
flags = SDL_FULLSCREEN;
#else
flags = SDL_OPENGL | flags;
#endif
screen = SDL_SetVideoMode((fullscreen)?desktopW:SCREEN_X, (fullscreen)?desktopH:SCREEN_Y, bpp, flags);
if (screen == 0) {
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Video mode set failed: %s\n", SDL_GetError());
#endif
return 0;
}
#ifdef HAVE_GLES
EGL_Open((fullscreen)?desktopW:SCREEN_X, (fullscreen)?desktopH:SCREEN_Y);
#endif
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Video mode initialized\n");
#endif
calcMinMax((fullscreen)?desktopW:SCREEN_X, (fullscreen)?desktopH:SCREEN_Y);
SDL_WM_SetCaption(application_name, 0);
SDL_WM_SetIcon(SDL_LoadBMP("graphics/f1sicon.bmp"), NULL);
SDL_ShowCursor(SDL_DISABLE);
if (sound) {
//.........这里部分代码省略.........
示例4: SDL_GetTicks
void CAppStateIntro::OnActivate() {
//Surf_Logo = CSurface::OnLoad("test.bmp");
StartTime = SDL_GetTicks();
SDL_WM_SetCaption("Intro State", NULL);
}
示例5: main
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("La grue !", NULL);
SDL_SetVideoMode(LARGEUR_ECRAN, HAUTEUR_ECRAN, 32, SDL_OPENGL);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, LARGEUR_ECRAN, 0, HAUTEUR_ECRAN);
bool continuer = true;
SDL_Event event;
SDLMod mod = KMOD_NONE;
int angle_grand_bras = 45;
int angle_petit_bras = -10;
int longueur_fils = 50;
while (continuer)
{
SDL_WaitEvent(&event);
mod = SDL_GetModState();
switch(event.type)
{
case SDL_QUIT:
continuer = false;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE: /* Appui sur la touche Echap, on arrête le programme */
continuer = false;
break;
case SDLK_UP:
if (longueur_fils > LONGUEUR_FILS_MIN)
longueur_fils -= 1;
break;
case SDLK_DOWN:
if (longueur_fils < LONGUEUR_FILS_MAX)
longueur_fils += 1;
break;
case SDLK_LEFT:
if (mod & KMOD_SHIFT) {
if (angle_grand_bras < ANGLE_GD_BRAS_MAX)
angle_grand_bras += 5;
} else {
if (angle_petit_bras < ANGLE_PT_BRAS_MAX)
angle_petit_bras += 5;
}
break;
case SDLK_RIGHT:
if (mod & KMOD_SHIFT) {
if (angle_grand_bras > ANGLE_GD_BRAS_MIN)
angle_grand_bras -= 5;
} else {
if (angle_petit_bras > ANGLE_PT_BRAS_MIN)
angle_petit_bras -= 5;
}
break;
case SDLK_h:
/* dessinerRepere(50); */
break;
default:
break;
}
break;
default:
break;
}
/* efface le tampon d'affichage */
glClear(GL_COLOR_BUFFER_BIT);
/* dessine */
/* base */
glPushMatrix();
glTranslated(20, 20, 0);
glBegin(GL_QUADS);
glColor3ub(255, 150, 0);
glVertex2d(0, 0);
glVertex2d(0, 40);
glVertex2d(100, 40);
glVertex2d(100, 0);
glEnd();
glPopMatrix();
/* grand bras */
glPushMatrix();
glTranslated(70, 60, 0);
glRotated(angle_grand_bras, 0, 0, 1);
glBegin(GL_QUADS);
glColor3ub(255, 250, 0);
glVertex2d(0, -15);
glVertex2d(0, 15);
glVertex2d(LONGUEUR_GD_BRAS, 15);
glVertex2d(LONGUEUR_GD_BRAS, -15);
glEnd();
//.........这里部分代码省略.........
示例6: main
int main(int argc, char** argv)
{
/* Init SDL */
if ( SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Couldn't load SDL: %s\n", SDL_GetError());
exit(1);
}
/* Clean up on exit */
atexit(SDL_Quit);
/* Set window title */
SDL_WM_SetCaption("Input Deluxe", "input deluxe");
/* Initialize the display */
SDL_Surface *screen;
screen = SDL_SetVideoMode(600, 400, 0, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
exit(1);
}
sge_Update_OFF();
SDL_EnableUNICODE(1); //This is VERY important!!
//Init our text sprites
sge_TextSprite text(screen,"Edit Me!",20,90);
text.show_cursor(true);
sge_TextSprite text2(screen,"Hello World!",100,25);
text.show_cursor(true);
//Set and draw the border box
SDL_Rect r; r.x=1; r.y=81; r.w=598; r.h=318;
text.set_border(r);
sge_Rect(screen,0,80, 599,399, 255,0,0);
//Open a TT font
if(sge_TTF_Init()!=0){fprintf(stderr,"TT error: %s\n",SDL_GetError());exit(1);}
sge_TTFont *font;
font=sge_TTF_OpenFont("/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf", 25);
if(font==NULL){fprintf(stderr,"TT error: %s\n",SDL_GetError());exit(1);}
text.set_ttFont(font,0,255,0); //Use our font
text2.set_ttFont(font,50,50,200);
text.set_pps(60,60); //set speed (pixels/second)
text2.set_pps(-170,0);
text.border_warp(true); //WARP!
text2.border_warp(true);
SDL_UpdateRect(screen, 0,0,0,0); //Update whole screen
//Keyrepeat
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL+50);
SDL_Event event;
do{
//SDL_Delay(1);
/* Check events */
if(SDL_PollEvent(&event)==1){
if(event.type==SDL_QUIT){break;}
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_ESCAPE){break;}
text.check(&event); //Let our text sprite handle the event (editing the text)
}
if(text.update()){ //update() calculates the new pos and returns true if we need to redraw
text.clear(0); //clear text area
text.draw(); //draw text at new pos
sge_Update_ON();
text.UpdateRects(); //Update screen (old pos + new pos)
sge_Update_OFF();
}
if(text2.update()){ //Same thing for the other sprite
text2.clear(0);
text2.draw();
sge_Update_ON();
text2.UpdateRects();
sge_Update_OFF();
}
}while(true);
sge_TTF_CloseFont(font);
return 0;
}
示例7: SDL_WM_SetCaption
Window::Window()
{
// Set window title
SDL_WM_SetCaption("RoboHockey",NULL);
// Create surfaces
mainSurface = SDL_SetVideoMode(1024, 768, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_SRCALPHA);
rinkSurface = IMG_Load("data/surfaces/rink.png");
SDL_SetColorKey(rinkSurface, SDL_RLEACCEL, rinkSurface->format->colorkey);
statSurface = IMG_Load("data/surfaces/stat.png");
puck = IMG_Load("data/objects/puck.png");
SDL_SetColorKey(puck, SDL_RLEACCEL, puck->format->colorkey);
greenPlayer = IMG_Load("data/objects/green_player.png");
SDL_SetColorKey(greenPlayer, SDL_RLEACCEL, greenPlayer->format->colorkey);
bluePlayer = IMG_Load("data/objects/blue_player.png");
SDL_SetColorKey(bluePlayer, SDL_RLEACCEL, bluePlayer->format->colorkey);
// Blit the surfaces
SDL_BlitSurface(rinkSurface, NULL, mainSurface, NULL);
// Statistics surface
statRect.x = rinkSurface->w; statRect.w = mainSurface->w - rinkSurface->w;
statRect.y = 0; statRect.h = mainSurface->h;
SDL_BlitSurface(statSurface, NULL, mainSurface, &statRect);
// Puck
updatePuck();
// Create Font(s)
arcade = TTF_OpenFont("data/fonts/arcade.ttf", 72);
arcadeSmall = TTF_OpenFont("data/fonts/arcade.ttf", 48);
nameFont = TTF_OpenFont("data/fonts/sb.ttf", 12);
// Players
withPuck.x = 44; withPuck.y = 0;
withPuck.w = 44; withPuck.h = 44;
withoutPuck.x = 0; withoutPuck.y = 0;
withoutPuck.w = 44; withoutPuck.h = 44;
updatePlayers();
// Set up text rectangles
clockRect.x = 695; clockRect.y = 65;
clockRect.w = 154; clockRect.h = 34;
homeScore.x = 605; homeScore.y = 175;
homeScore.w = 33; homeScore.h = 34;
period.x = 753; period.y = 195;
period.w = 33; period.h = 34;
awayScore.x = 902; awayScore.y = 175;
awayScore.w = 33; awayScore.h = 34;
homeShots.x = 660; homeShots.y = 340;
homeShots.w = 22; homeShots.h = 23;
awayShots.x = 852; awayShots.y = 340;
awayShots.w = 22; awayShots.h = 23;
// Default texts
drawText(&clockRect, arcade, (Game::instance()->getClock()).c_str());
drawText(&homeScore, arcade, "0");
drawText(&period, arcade, "1");
drawText(&awayScore, arcade, "0");
drawText(&homeShots, arcadeSmall, "0");
drawText(&awayShots, arcadeSmall, "0");
// Swap buffers to show the whole thing
SDL_Flip(mainSurface);
}
示例8: SDL_WM_SetCaption
void GraphicsManager::setWindowTitle(const Common::UString &title) {
SDL_WM_SetCaption(title.c_str(), 0);
}
示例9: start
void start() {
SDL_WM_SetCaption("Tennis game over", 0);
}
示例10: main
int main(int argc, char *argv[])
{
// Erectin' a display
SDL_Surface *screen;
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_HWSURFACE);
SDL_WM_SetCaption("Smuggler Demo", "Smuggler Demo");
bool quit = false;
// Setting up text
TTF_Font* Font=NULL;
TTF_Init();
SDL_Surface* TextSurface = NULL;
Font=TTF_OpenFont("DejaVuSansMono.ttf",16);
SDL_Color color;
color.r=255;
color.g=255;
color.b=255;
int FontSize = 10;
bool growing = true;
// Rendering surfaces
// Set background surface to display optimized
SDL_Surface *background;
SDL_Surface *oldface;
oldface = IMG_Load("backimage.png");
background = SDL_DisplayFormat(oldface);
SDL_FreeSurface(oldface);
// Set player's image to
Player player1("ana.png");
Player player2("character.png");
player2.coordX(500);
player2.coordY(500);
// Load overlay surface and set transparency color to 0
SDL_Surface *overlay = &map();
SDL_SetColorKey(overlay, SDL_SRCCOLORKEY,0);
// Instantiate timer object
Timer fps;
int walkFrames = 2;
while(!quit){
// Start the timer for frame rate limiting
fps.start();
// The input handling function returns a bool. While quit == false, the game will continue to run
quit = input(&player1, movementspeed);
// This function animates through the cycle, using an iterating number that triggers the different frames
// TODO: The walkframes integer should be tucked into the object it is manipulating, in this case, player.
walkFrames=animate(player1.xvel(), player1.yvel(), movementspeed, walkFrames, walkFrameInterval, &player1);
// Renders the background on the bottom
SDL_BlitSurface(background, NULL, screen, NULL);
// Puts the player underneath the overlay, which is basically the map
SDL_BlitSurface(&player1.image(), &player1.frame(), screen, &player1.location());
// Checks for collisions
if (collision(&player1.image(), player1.coordX(), player1.coordY(), 100, &player2.image(), player2.coordX(), player2.coordY(), 100))
{
cout << "COLLIDE!\n";
player2.xvel(0);
player2.yvel(0);
}
else
{
cout << "NO COLLIDE!\n";
player2.ai(player1);
}
// Puts the NPC underneath the overlay
walkFrames=animate(player2.xvel(), player2.yvel(), movementspeed/2, walkFrames, walkFrameInterval, &player2);
SDL_BlitSurface(&player2.image(), &player2.frame(), screen, &player2.location());
// Renders the map
SDL_BlitSurface(overlay, NULL, screen, NULL);
// Renders the text
if (growing == true)
{
FontSize ++;
//.........这里部分代码省略.........
示例11: main
int main(int argc, char** argv)
{
// Create a configuration object, and set the values to the defaults
configuration config;
config.num_threads = NUM_THREADS;
config.video.screen_width = SCREEN_WIDTH;
config.video.screen_height = SCREEN_HEIGHT;
config.video.screen_depth = SCREEN_DEPTH;
config.video.frames_per_second = FPS;
config.input.influence_radius = INFLUENCE_RADIUS;
config.flock.size = NUM_BOIDS;
config.flock.max_velocity = MAX_BOID_VELOCITY;
config.flock.min_separation = MIN_BOID_SEPARATION;
config.flock.max_steering_force = MAX_BOID_STEERING_FORCE;
config.flock.neighborhood_radius = NEIGHBORHOOD_RADIUS;
// Parse arguments
int i;
for(i = 1; i < argc; i++)
{
if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
return print_help();
else if(strcmp(argv[i], "--width") == 0)
config.video.screen_width = atoi(argv[++i]);
else if(strcmp(argv[i], "--height") == 0)
config.video.screen_height = atoi(argv[++i]);
else if(strcmp(argv[i], "--depth") == 0)
config.video.screen_depth = atoi(argv[++i]);
else if(strcmp(argv[i], "--fps") == 0)
config.video.frames_per_second = atoi(argv[++i]);
else if(strcmp(argv[i], "-ir") == 0 || strcmp(argv[i], "--influence-radius") == 0)
config.input.influence_radius = atoi(argv[++i]);
else if(strcmp(argv[i], "-fc") == 0 || strcmp(argv[i], "--flock-count") == 0)
config.flock.size = atoi(argv[++i]);
else if(strcmp(argv[i], "-fs") == 0 || strcmp(argv[i], "--flock-separation") == 0)
config.flock.min_separation = atoi(argv[++i]);
else if(strcmp(argv[i], "-fv") == 0 || strcmp(argv[i], "--flock-velocity") == 0)
config.flock.max_velocity = atoi(argv[++i]);
else if(strcmp(argv[i], "-fn") == 0 || strcmp(argv[i], "--flock-neighborhood") == 0)
config.flock.neighborhood_radius = atoi(argv[++i]);
else if(strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--num-threads") == 0)
config.num_threads = atoi(argv[++i]);
}
srand(time(NULL));
// Init SDL and create our screen
if(SDL_Init(SDL_INIT_VIDEO) < 0) printf("Unable to initialize SDL. %s\n", SDL_GetError());
SDL_Event event;
int flags = SDL_OPENGL;
// Attempt to set the video mode
SDL_Surface* screen = SDL_SetVideoMode(config.video.screen_width, config.video.screen_height,
config.video.screen_depth, flags);
if(!screen) printf("Unable to set video mode.\n");
// Set the window caption
SDL_WM_SetCaption("tinyflock", NULL);
// Create our flock
boid* flock = create_flock(&config);
init_gl(config.video.screen_width, config.video.screen_height);
vector cursor_pos;
vector_init_scalar(&cursor_pos, 0);
int cursor_interaction = 0;
int run = 1;
int update_count = 0;
int frame_count = 0;
flock_update_args update_args = {&run, flock, &config, &cursor_pos, &cursor_interaction, &update_count };
SDL_Thread* update = SDL_CreateThread(flock_update_thread, (void*)&update_args);
status_args stat_args = {&run, &frame_count, &update_count};
SDL_Thread* status = SDL_CreateThread(status_thread, (void*)&stat_args);
// If the frame limit is not greater than 0, don't delay between frames at all.
float delay = (1000 / config.video.frames_per_second);
while(run)
{
run = handle_events(&event, &cursor_pos, &cursor_interaction);
flock_render(flock, &config, screen);
SDL_Delay(delay);
frame_count++;
}
SDL_WaitThread(update, NULL);
SDL_WaitThread(status, NULL);
//.........这里部分代码省略.........
示例12: graphics_viewport_set_title
void graphics_viewport_set_title(char* title) {
SDL_WM_SetCaption(title, title);
}
示例13: main
int
main(int argc, char *argv[])
{
SDL_Surface *screen, *sprite, *door;
SDL_Rect rcSprite, rcWall, rcFloor, rcStatus;
TTF_Font *fntText;
SDL_Surface *sText;
SDL_Rect rcText = { 5, 290, 0, 0 };
SDL_Color clrText = { 192, 192, 192, 0 };
char debug[100];
unsigned int colorkey;
/* Initialize the SDL library: */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
printf("%s: SDL_Init(): %s\n", argv[0], SDL_GetError());
exit(EXIT_FAILURE);
}
/* Clean up SDL on exit: */
if (atexit(SDL_Quit) != 0) {
printf("%s: Cannot register exit function SDL_Quit().\n", argv[0]);
exit(EXIT_FAILURE);
}
/* Initialize SDL TTF engine: */
if (TTF_Init() != 0) {
printf("%s: TTF_Init(): %s\n", argv[0], TTF_GetError());
exit(EXIT_FAILURE);
}
/* Clean up TTF on exit: */
if (atexit(TTF_Quit) != 0) {
printf("%s: Cannot register exit function TTF_Quit().\n", argv[0]);
exit(EXIT_FAILURE);
}
/* Set up video: */
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
if (screen == NULL) {
printf("%s: SDL_SetVideoMode: %s\n", argv[0], SDL_GetError());
exit(EXIT_FAILURE);
}
/* Set the title bar: */
SDL_WM_SetCaption("Open Paradise Cafe", NULL);
/* set keyboard repeat */
SDL_EnableKeyRepeat(70, 70);
/* load sprite damatta */
sprite = load_surface("sprites.bmp");
/* load door */
door = load_surface("porta.bmp");
/* setup sprite colorkey and turn on RLE */
colorkey = SDL_MapRGB(screen->format, 255, 0, 255);
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey);
SDL_SetColorKey(door, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey);
/* posicao inicial do damatta */
rcSprite.x = 150;
rcSprite.y = 150;
/* define o tamanho e o *frame* do boneco */
rcSrc.x = 0;
rcSrc.y = 0;
rcSrc.w = SPRITE_WIDTH;
rcSrc.h = SPRITE_HEIGHT;
/*printf("sprite w=%d %d h=%d %d\n", sprite->w, SPRITE_WIDTH, sprite->h, SPRITE_HEIGHT);*/
/* define o tamanho das portas */
rcSrcDoor.x = 0;
rcSrcDoor.y = 0;
rcSrcDoor.w = 56; /* so a primeira frame */
rcSrcDoor.h = door->h;
/*printf("door w=%d h=%d\n", door->w, door->h);*/
/* posicao inicial da porta */
rcDoor.x = 350;
rcDoor.y = 126;
/* Wall: */
rcWall.x = 0;
rcWall.y = 0;
rcWall.w = SCREEN_WIDTH;
rcWall.h = SCREEN_HEIGHT;
/* Floor: */
rcFloor.x = 0;
rcFloor.y = 262;
rcFloor.w = SCREEN_WIDTH;
rcFloor.h = 24;
/* Status: */
rcStatus.x = 0;
rcStatus.y = 262 + 24;
rcStatus.w = SCREEN_WIDTH;
rcStatus.h = SCREEN_HEIGHT - 262 - 24;
/* load a font and give it a point-size */
//.........这里部分代码省略.........
示例14: main
int main(int argc, char* argv[]) {
// Init
initPath(argv[0]);
SDL_Surface* screen = NULL;
SDL_Event event;
int *seed;
srand((int)seed);
int previousTime = 0, currentTime = 0;
Events *flags = createEventFlags();
SDL_Init(SDL_INIT_VIDEO);
SDL_SetEventFilter(eventFilter);
screen = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_DOUBLEBUF | SDL_NOFRAME);
SDL_WM_SetCaption("Tower Defense", NULL);
Action *actionList = initAction();
Map* map = createMap(getPath("resources/Forest.png"));
_map = map;
SDL_Rect surface = {0, 0, 720, 600};
Viewport* viewport = createViewport(screen, surface, map);
_viewport = viewport;
// FIXME uh? what's this thing?
surface.x = 800 - 80;
surface.y = 0;
surface.h = 80;
surface.w = 600;
// Creation of the enemies
TypeEn *whiteCat = createTypeEn(100, 5, false, true, true, false, 1,getPath("resources/white_transparent_cat.png"));
TypeEn *blackCat = createTypeEn(100, 5, false, true, true, false, 1,getPath("resources/black_transparent_cat.png"));
Enemy *cat1 = createEnemy(1,1,whiteCat);
Enemy *cat2 = createEnemy(1,10,whiteCat);
Enemy *cat3 = createEnemy(5,5,blackCat);
Enemy *cat4 = createEnemy(21,4,blackCat);
TypeEn *zombie = createTypeEn(100,5,false,true,true,false,1,getPath("resources/zombie.png"));
Enemy *zombie1 = createEnemy(4,4,zombie);
Enemy *zombie2 = createEnemy(9,4,zombie);
Enemy *zombie3 = createEnemy(9,9,zombie);
Enemy *zombie4 = createEnemy(7,14,zombie);
//Add enemy in the List
List *catList = newList(cat4);
pushList((void*)catList,cat2);
pushList((void*)catList,cat3);
// pushList((void*)catList,cat1);
List *zombieList = newList(zombie1);
/* pushList((void*)zombieList,zombie2);*/
/* pushList((void*)zombieList,zombie3);*/
/* pushList((void*)zombieList,zombie4);*/
// removeEnemyFromList(cat4,catList);
//TOWER
TypeBul *bullet = createTypeBul(getPath("resources/bullet.png"), 1);
TypeTo *tower = createTypeTo(0,5,0,0,false,false,false,false,bullet,NULL,getPath("resources/tower.png"));
upgradeTypeTo(tower,0.5,getPath("resources/towerUP.png"));
flags->selectedTower = tower->nextType;
Tower *tower1 = createTower(7,7,tower);
List *towerList = newList(tower1);
flags->towerList = towerList;
// Create and Renders the right panel game menu
SDL_Rect surfaceMenu = {720, 0, 800, 600};
Menu* menu = menu_create(screen, surfaceMenu);
menu_loadBackground(menu, "resources/enemyFont.gif");
// For testing only, we add a few random buttons
menu_addButton(menu, button_createBuildButton(tower));
menu_addButton(menu, button_createBuildButton(tower));
menu_addButton(menu, button_createBuildButton(tower));
menu_render(menu);
_cell = *getCase(20,11);
// Main loop
while(actionList[QUIT].boolean == NULL) {
// Managing the events
manageEvents(viewport, flags,actionList);
for(int i=1; i<ACTION_LENGTH; i++) {
if(actionList[i].boolean) {
int repeat = (*actionList[i].action)(viewport,flags,actionList[i].boolean);
if(!repeat) {
actionList[i].boolean = NULL;
}
}
}
// Redraws the map (viewport contents) before blitting stuff on it
updateViewport(viewport);
///////////////////////////// DEBUG WALL /////////////////////////////
SDL_Rect position;
for(int i=0; i < _map->nbCaseW; i++) {
for(int j=0; j < _map->nbCaseH; j++) {
//.........这里部分代码省略.........
示例15: main
int main(int argc, char *argv[])
{
/* Check command line arguments */
argv += get_video_args(argv, &w, &h, &bpp, &flags);
/* Initialize SDL */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
"Couldn't initialize SDL: %s\n", SDL_GetError());
return(1);
}
/* Initialize the display, always use hardware palette */
screen = SDL_SetVideoMode(w, h, bpp, flags | SDL_HWPALETTE);
if ( screen == NULL ) {
fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
w, h, SDL_GetError());
quit(1);
}
/* Set the window manager title bar */
SDL_WM_SetCaption("SDL gamma test", "testgamma");
/* Set the desired gamma, if any */
gamma = 1.0f;
if ( *argv ) {
gamma = (float)atof(*argv);
}
if ( SDL_SetGamma(gamma, gamma, gamma) < 0 ) {
fprintf(stderr, "Unable to set gamma: %s\n", SDL_GetError());
quit(1);
}
#if 0 /* This isn't supported. Integrating the gamma ramps isn't exact */
/* See what gamma was actually set */
float real[3];
if ( SDL_GetGamma(&real[0], &real[1], &real[2]) < 0 ) {
printf("Couldn't get gamma: %s\n", SDL_GetError());
} else {
printf("Set gamma values: R=%2.2f, G=%2.2f, B=%2.2f\n",
real[0], real[1], real[2]);
}
#endif
/* Do all the drawing work */
image = SDL_LoadBMP("sample.bmp");
if ( image ) {
SDL_Rect dst;
dst.x = (screen->w - image->w)/2;
dst.y = (screen->h - image->h)/2;
dst.w = image->w;
dst.h = image->h;
SDL_BlitSurface(image, NULL, screen, &dst);
SDL_UpdateRects(screen, 1, &dst);
}
/* Wait a bit, handling events */
then = SDL_GetTicks();
timeout = (5*1000);
#ifndef EMSCRIPTEN
while ( (SDL_GetTicks()-then) < timeout ) {
#else
emscripten_set_main_loop(&main_loop, 0, 1);
}
void main_loop() {
if ( (SDL_GetTicks()-then) < timeout ) {
#endif
SDL_Event event;
while ( SDL_PollEvent(&event) ) {
switch (event.type) {
case SDL_QUIT: /* Quit now */
timeout = 0;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_SPACE: /* Go longer.. */
timeout += (5*1000);
break;
case SDLK_UP:
gamma += 0.2f;
SDL_SetGamma(gamma, gamma, gamma);
break;
case SDLK_DOWN:
gamma -= 0.2f;
SDL_SetGamma(gamma, gamma, gamma);
break;
case SDLK_ESCAPE:
timeout = 0;
break;
default:
break;
}
break;
}
}
}
//.........这里部分代码省略.........