本文整理汇总了C++中SDL_Delay函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_Delay函数的具体用法?C++ SDL_Delay怎么用?C++ SDL_Delay使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_Delay函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: remove_blindfold
possible_end_play_signal playmp_controller::play_human_turn(){
LOG_NG << "playmp::play_human_turn...\n";
remove_blindfold();
int cur_ticks = SDL_GetTicks();
show_turn_dialog();
if (!preferences::disable_auto_moves()) {
HANDLE_END_PLAY_SIGNAL(execute_gotos());
}
if (!linger_ || is_host()) {
end_turn_enable(true);
}
while(!end_turn_) {
turn_info_send send_safe(turn_data_);
config cfg;
if(network_reader_.read(cfg)) {
turn_info::PROCESS_DATA_RESULT res;
HANDLE_END_PLAY_SIGNAL( res = turn_data_.process_network_data(cfg, skip_replay_) );
//PROCESS_RESTART_TURN_TEMPORARY_LOCAL should be impossible because that's means the currently active side (that's us) left.
if (res == turn_info::PROCESS_RESTART_TURN || res == turn_info::PROCESS_RESTART_TURN_TEMPORARY_LOCAL)
{
// Clean undo stack if turn has to be restarted (losing control)
if ( undo_stack_->can_undo() )
{
font::floating_label flabel(_("Undoing moves not yet transmitted to the server."));
SDL_Color color = {255,255,255,255};
flabel.set_color(color);
SDL_Rect rect = gui_->map_area();
flabel.set_position(rect.w/2, rect.h/2);
flabel.set_lifetime(150);
flabel.set_clip_rect(rect);
font::add_floating_label(flabel);
}
while( undo_stack_->can_undo() )
undo_stack_->undo();
end_turn_struct ets = {static_cast<unsigned>(gui_->playing_side())};
return possible_end_play_signal(ets);
//throw end_turn_exception(gui_->playing_side());
}
else if(res == turn_info::PROCESS_END_LINGER)
{
if(!linger_)
replay::process_error("Received unexpected next_scenario durign the game");
else
{
//we end the turn immidiately to prevent receiving data of the next scenario while we are not playing it.
end_turn();
}
}
}
HANDLE_END_PLAY_SIGNAL( play_slice() );
HANDLE_END_PLAY_SIGNAL( check_end_level() );
if (!linger_ && (current_team().countdown_time() > 0) && saved_game_.mp_settings().mp_countdown) {
SDL_Delay(1);
const int ticks = SDL_GetTicks();
int new_time = current_team().countdown_time()-std::max<int>(1,(ticks - cur_ticks));
if (new_time > 0 ){
current_team().set_countdown_time(new_time);
cur_ticks = ticks;
if(current_team().is_human() && !beep_warning_time_) {
beep_warning_time_ = new_time - WARNTIME + ticks;
}
if(counting_down()) {
think_about_countdown(ticks);
}
} else {
// Clock time ended
// If no turn bonus or action bonus -> defeat
const int action_increment = saved_game_.mp_settings().mp_countdown_action_bonus;
if ( (saved_game_.mp_settings().mp_countdown_turn_bonus == 0 )
&& (action_increment == 0 || current_team().action_bonus_count() == 0)) {
// Not possible to end level in MP with throw end_level_exception(DEFEAT);
// because remote players only notice network disconnection
// Current solution end remaining turns automatically
current_team().set_countdown_time(10);
}
return possible_end_play_signal(end_turn_exception().to_struct());
//throw end_turn_exception();
}
}
gui_->draw();
}
return boost::none;
}
示例2: jhi_delay_seconds
void jhi_delay_seconds(int seconds)
{
SDL_Delay(seconds * 1000.0);
}
示例3: main
int main(int argc, const char * argv[])
{
int i;
char deviceName[128];
if (init() != true)
{
return 1;
}
SDL_Delay(2000);
// try to get the dispatch queue for the GPU
dispatch_queue_t queue = gcl_create_dispatch_queue(CL_DEVICE_TYPE_GPU, NULL);
// in the event that the system does not have an OpenCL GPU, we can use the CPU instead
if (queue == NULL)
{
queue = gcl_create_dispatch_queue(CL_DEVICE_TYPE_CPU, NULL);
}
// let's print some data on the device we're usng! かわいいです!
cl_device_id gpu = gcl_get_device_id_with_dispatch_queue(queue);
clGetDeviceInfo(gpu, CL_DEVICE_NAME, 128, deviceName, NULL);
fprintf(stdout, "Created a dispatch queue using the %s\n", deviceName);
// let's hardcode some handy test data that's easy to understand
float* test_in = (float*)malloc(sizeof(cl_float) * NUM_VALUES);
for (i = 0; i < NUM_VALUES; i++)
{
test_in[i] = (cl_float)i;
}
// Once the computation using the CL is done, we'll need space in RAM for the output
float* test_out = (float*)malloc(sizeof(cl_float) * NUM_VALUES);
// Now we're going to allocate the buffers again in the OpenCL device's memory space
// CL_MEM_COPY_HOST_PTR will copy the values of test_in to mem_in
void* mem_in = gcl_malloc(sizeof(cl_float) * NUM_VALUES, test_in, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR);
void* mem_out = gcl_malloc(sizeof(cl_float) * NUM_VALUES, NULL, CL_MEM_WRITE_ONLY);
// DISPATCH THE KERNEL PROGRAM
dispatch_sync(queue, ^{
//workgroup size, I think
size_t wgs;
//information on sizing of dimensions
gcl_get_kernel_block_workgroup_info(square_kernel, CL_KERNEL_WORK_GROUP_SIZE, sizeof(wgs), &wgs, NULL);
cl_ndrange range = {
1,
{0, 0, 0},
{NUM_VALUES, 0, 0},
{wgs, 0, 0}
};
// call the kernel
square_kernel(&range, (cl_float*)mem_in, (cl_float*)mem_out);
//copy the output into memory
gcl_memcpy(test_out, mem_out, sizeof(cl_float) * NUM_VALUES);
});
示例4: I_uSleep
void I_uSleep(unsigned long usecs)
{
SDL_Delay(usecs/1000);
}
示例5: main
int main(int argc, char *argv[])
{
auto t_start = std::chrono::high_resolution_clock::now();
GLfloat directionx, directiony, directionz;
directionx = 0.0f;
directiony = 0.0f;
directionz = 1.0f;
GLboolean quit = GL_FALSE;
GLenum errorValue;
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
std::cerr << "SDL video initialization failed! Error: " << SDL_GetError() << std::endl;
quit = GL_TRUE;
SDL_Delay(5000);
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_Window* window = SDL_CreateWindow("OpenGL tutorial", 100, 100, width, height, SDL_WINDOW_OPENGL);
SDL_GLContext context = SDL_GL_CreateContext(window);
// Initialize GLEW
glewExperimental = GL_TRUE;
glewInit();
// Error checking
errorValue = glGetError();
if (errorValue != 0)
{
std::cerr << "GL_Error after GLEW init: " << errorValue << std::endl;
}
// Create Vertex Array Objects, don't bind yet
/*
VAOs are used to store all of the links between the vertex attributes and VBOs with raw vertex data.
Since VBOs are just containers for the raw data that the graphics card reads and manipulates,
the meaning and usage of the data has to be specified for each VBO & shader program.
This might be quite cumbersome, if many shader programs are used, since the layout of the attributes would
have to be specified every time. This is wheree VAOs come in: they can be used to store the links between
VBO and the specified attributes. This way, a new VAO can be bound for each different shader program,
which can then be changed easily at will by just calling glUseProgram(shaderProg1);.
The graphics card then knows how to use the raw data in the VBO, since its usage and meaning has been
specified beforehand and the links between VBOs and attributes has been saved to the VAO.
As soon as VAO has been bound, all glVertexAttribPointer calls store the information to that VAO.
*/
GLuint vaoCube, vaoQuad;
glGenVertexArrays(1, &vaoCube);
glGenVertexArrays(1, &vaoQuad);
// Create a Vertex Buffer Objects and upload vertex data
/*
VBOs are used to upload the vertex data to the graphics card.
glGenBuffers(); creates a VBO, which can then be made active by binding it
with glBindBuffer();. When the VBO has been set as active by binding it,
the vertex data can be loaded to it with glBufferData();.
Note that VBO/OpenGL doesn't know what the data means or is used for, it's just raw data.
The usage of the data has to be specified, meaning which indices in the data correspond to which
attribute (pos, color, texcoord, etc.).
*/
GLuint vboCube, vboQuad;
glGenBuffers(1, &vboCube);
glGenBuffers(1, &vboQuad);
glBindBuffer(GL_ARRAY_BUFFER, vboCube);
glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices), cubeVertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, vboQuad);
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), quadVertices, GL_STATIC_DRAW);
// Error checking
errorValue = glGetError();
if (errorValue != 0)
{
std::cerr << "GL_Error after VBOs: " << errorValue << std::endl;
}
// Generate shader programs
GLuint sceneVertexShader, sceneFragmentShader, sceneShaderProgram;
createShaderprogram(sceneVertexSource, sceneFragmentSource, sceneVertexShader, sceneFragmentShader, sceneShaderProgram);
GLuint screenVertexShader, screenFragmentShader, screenShaderProgram;
createShaderprogram(screenVertexSource, screenFragmentSource, screenVertexShader, screenFragmentShader, screenShaderProgram);
// Error checking
errorValue = glGetError();
if (errorValue != 0)
{
std::cerr << "GL_Error after generating shader programs: " << errorValue << std::endl;
}
// Specify the layout of the vertex data (bind vertex arrays)
/*
Since OpenGL doesn't know how the attributes of the vertices are
specified in the arrays containing the vertex information (position, color, texture coordinates),
//.........这里部分代码省略.........
示例6: run
void run(){
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Surface* temp;
SDL_Texture* tbullet;
SDL_Event e;
int i, quit = 0;
Bullet* bulletarray[MAXBULLETS];
unsigned int lastshooting = 0;
/* Initialise generic */
SDL_Init(SDL_INIT_EVERYTHING);
window = SDL_CreateWindow("Shoot", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_SetRenderDrawColor(renderer, 90, 90, 90, 0);
temp = SDL_LoadBMP("bullet.bmp");
tbullet = SDL_CreateTextureFromSurface(renderer, temp);
SDL_FreeSurface(temp);
temp = NULL;
/* Initialise bulletarray */
for(i = 0; i < MAXBULLETS ; i++){
bulletarray[i] = NULL;
}
/* Event loop */
do{
SDL_PollEvent(&e);
if(e.type == SDL_QUIT){
quit = 1;
}
/* Fire bullet from centre*/
if(e.type == SDL_MOUSEBUTTONDOWN){
if(e.button.button == SDL_BUTTON_LEFT && (SDL_GetTicks() - lastshooting) > TIMEBETWEENSHOOT){
for(i = 0; i <MAXBULLETS; i++){
if(bulletarray[i] == NULL){
bulletarray[i] = createbullet((WIDTH-BULLETSIZE)/2, (HEIGHT-BULLETSIZE)/2);
i = MAXBULLETS;
}
}
lastshooting = SDL_GetTicks();
}
}
deletebulletatboundary(bulletarray);
bulletmovement(bulletarray);
/* Update Screen */
SDL_RenderClear(renderer);
renderbullets(renderer, tbullet, bulletarray);
SDL_RenderPresent(renderer);
SDL_Delay(20);
}while(quit == 0);
/* Memory Cleanup */
SDL_DestroyTexture(tbullet);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
tbullet = NULL;
renderer = NULL;
window = NULL;
SDL_Quit();
}
示例7: wrefresh
// This is how we're actually going to handle input events, SDL getch
// is simply a wrapper around this.
input_event input_manager::get_input_event(WINDOW *win) {
// standards note: getch is sometimes required to call refresh
// see, e.g., http://linux.die.net/man/3/getch
// so although it's non-obvious, that refresh() call (and maybe InvalidateRect?) IS supposed to be there
if(win == NULL) win = mainwin;
wrefresh(win);
lastchar=ERR;//ERR=-1
input_event rval;
if (inputdelay < 0)
{
do
{
rval.type = CATA_INPUT_ERROR;
CheckMessages();
if (lastchar!=ERR) break;
SDL_Delay(1);
}
while (lastchar==ERR);
}
else if (inputdelay > 0)
{
unsigned long starttime=SDL_GetTicks();
unsigned long endtime;
bool timedout = false;
do
{
rval.type = CATA_INPUT_ERROR;
CheckMessages();
endtime=SDL_GetTicks();
if (lastchar!=ERR) break;
SDL_Delay(1);
timedout = endtime >= starttime + inputdelay;
if (timedout) {
rval.type = CATA_INPUT_TIMEOUT;
}
}
while (!timedout);
}
else
{
CheckMessages();
}
if (rval.type != CATA_INPUT_TIMEOUT) {
if (lastchar == ERR) {
rval.type = CATA_INPUT_ERROR;
} else if (lastchar_isbutton) {
rval.type = CATA_INPUT_GAMEPAD;
rval.add_input(lastchar);
} else if (lastchar_is_mouse) {
rval.type = CATA_INPUT_MOUSE;
rval.add_input(lastchar);
SDL_GetMouseState(&rval.mouse_x, &rval.mouse_y);
} else {
rval.type = CATA_INPUT_KEYBOARD;
rval.add_input(lastchar);
}
}
return rval;
}
示例8: main
//.........这里部分代码省略.........
clip.w = screen->w-(2*32);
clip.h = screen->h-(2*32);
SDL_SetClipRect(screen, &clip);
}
/* Wait for a keystroke */
lastticks = SDL_GetTicks();
done = 0;
mouse_pressed = 0;
#ifndef EMSCRIPTEN
while ( !done ) {
#else
emscripten_run_script("report(true);");
emscripten_set_main_loop(&main_loop, 30, 1);
}
void main_loop() {
#endif
/* Update the frame -- move the sprite */
if ( mouse_pressed ) {
MoveSprite(screen, light);
mouse_pressed = 0;
} else {
MoveSprite(screen, NULL);
}
#ifndef EMSCRIPTEN
/* Slow down the loop to 30 frames/second */
ticks = SDL_GetTicks();
if ( (ticks-lastticks) < FRAME_TICKS ) {
#ifdef CHECK_SLEEP_GRANULARITY
fprintf(stderr, "Sleeping %d ticks\n", FRAME_TICKS-(ticks-lastticks));
#endif
SDL_Delay(FRAME_TICKS-(ticks-lastticks));
#ifdef CHECK_SLEEP_GRANULARITY
fprintf(stderr, "Slept %d ticks\n", (SDL_GetTicks()-ticks));
#endif
}
lastticks = ticks;
#endif
/* Check for events */
while ( SDL_PollEvent(&event) ) {
switch (event.type) {
case SDL_VIDEORESIZE:
screen = SDL_SetVideoMode(event.resize.w, event.resize.h, video_bpp, videoflags);
if ( screen ) {
FillBackground(screen);
}
break;
/* Attract sprite while mouse is held down */
case SDL_MOUSEMOTION:
if (event.motion.state != 0) {
AttractSprite(event.motion.x,
event.motion.y);
mouse_pressed = 1;
}
break;
case SDL_MOUSEBUTTONDOWN:
if ( event.button.button == 1 ) {
AttractSprite(event.button.x,
event.button.y);
mouse_pressed = 1;
} else {
SDL_Rect area;
示例9: message
/*
====================================================================
Display a info message (gray screen a bit and display text),
send a MSG_READY when player has clicked and wait for a remote answer
(timeout 10 secs). Waiting may be cancelled by pressing ESCAPE which
results in sending a MSG_GAME_EXITED.
Return Value: True if both peers clicked to continue, False if the
connection was cancelled for some reason.
====================================================================
*/
int display_info( StkFont *font, char *str, NetSocket *peer )
{
#if 0
char error[128];
Net_Msg msg;
SDL_Event event;
int ret = 0, leave = 0;
SDL_Surface *buffer =
stk_surface_create( SDL_SWSURFACE, stk_display->w, stk_display->h );
SDL_SetColorKey(buffer, 0, 0);
#ifdef AUDIO_ENABLED
stk_sound_play( wav_click );
#endif
event_clear_sdl_queue();
stk_surface_blit( stk_display, 0,0,-1,-1, buffer, 0,0 );
draw_confirm_screen( font, buffer, str );
stk_display_update( STK_UPDATE_ALL );
stk_wait_for_input();
net_write_empty_msg( peer, MSG_READY );
draw_confirm_screen( font, buffer,
_("Waiting for remote answer...") );
stk_display_update( STK_UPDATE_ALL );
event_clear_sdl_queue();
while ( !leave ) {
if ( SDL_PollEvent( &event ) )
if ( (event.type == SDL_KEYDOWN &&
event.key.keysym.sym == SDLK_ESCAPE) ||
event.type == SDL_QUIT ) {
net_write_empty_msg( peer, MSG_GAME_EXITED );
leave = 1;
break;
}
if ( net_read_msg( peer, &msg, 0 ) )
switch ( msg.type ) {
case MSG_READY:
ret = 1; leave = 1;
break;
case MSG_GAME_EXITED:
ret = 0; leave = 1;
sprintf( error, /* xgettext:no-c-format */ _("remote player cancelled the game\n") );
confirm( font, error, CONFIRM_ANY_KEY );
break;
}
SDL_Delay( 10 );
}
#ifdef AUDIO_ENABLED
stk_sound_play( wav_click );
#endif
stk_surface_blit( buffer, 0,0,-1,-1, stk_display, 0,0 );
stk_display_update( STK_UPDATE_ALL );
SDL_FreeSurface(buffer);
/* reset the relative position so paddle wont jump */
SDL_GetRelativeMouseState(0,0);
return ret;
#endif
return 1;
}
示例10: decode_thread
int decode_thread( void *thread_arg )
{
VideoState *is = (VideoState *) thread_arg;
AVFormatContext *pFormatCtx;
AVPacket pkt1, *packet = &pkt1;
//global_video_state = is;
url_set_interrupt_cb(decode_interrupt_cb); // will interrupt blocking functions if we quit!
// is->filename[0] = *"./foo.mkv";
strcpy(is->filename, "./foo.mkv");
int i;
//AVCodecContext *pCodecCtx;
//AVCodecContext *aCodecCtx;
// Open video file
if( av_open_input_file(&pFormatCtx, is->filename, NULL, 0, NULL) != 0 )
return -1; // Couldn't open file
is->pFormatCtx = pFormatCtx;
// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0)
return -1; // Couldn't find stream information
// Dump information about file onto standard error
//dump_format(pFormatCtx, 0, is->filename, 0);
// Find the video stream and audio stream
int videoStream = -1;
int audioStream = -1;
is->videoStream = -1;
is->audioStream = -1;
for( i=0; i<pFormatCtx->nb_streams; i++ )
{
if( pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO ) {
videoStream = i;
}
if( pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO && audioStream < 0 ) {
audioStream = i;
}
}
if(videoStream == -1)
return -1; // Didn't find a video stream
if(audioStream == -1)
printf( "No audio stream\n" );
else
stream_component_open( is, audioStream );
stream_component_open( is, videoStream );
if(is->videoStream < 0 ) {
fprintf(stderr, "%s: could not open codecs\n", is->filename);
goto fail;
}
// Decode loop
for(;;) {
if(is->quit) {
break;
}
if(is->audioq.size > MAX_AUDIOQ_SIZE ||
is->videoq.size > MAX_VIDEOQ_SIZE) {
SDL_Delay(10);
continue;
}
/*
if( av_read_frame(is->pFormatCtx, packet) < 0 ) {
if( url_ferror((ByteIOContext *)&pFormatCtx->pb) == 0 ) {
SDL_Delay(100); // no error; wait for user input
continue;
} else {
break;
}
}
// Queue the packets into the right queue
if(packet->stream_index == is->videoStream) {
packet_queue_put(&is->videoq, packet);
} else if(packet->stream_index == is->audioStream) {
packet_queue_put(&is->audioq, packet);
} else {
av_free_packet(packet);
}
*/
}
while(!is->quit) {
SDL_Delay(100);
}
fail:
if(1){
SDL_Event event;
event.type = FF_QUIT_EVENT;
event.user.data1 = is;
SDL_PushEvent(&event);
}
return 0;
//.........这里部分代码省略.........
示例11: main
void main (){
// Initialize everything
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
fprintf(stderr, "Couldn't initialize SDL (%s)\n", SDL_GetError());
exit(1);
}
atexit(quit);
// SDL_PauseAudio(false);
//InitAll(1, "./be");
cSIDInit();
unsigned int now = 0;
// sid_write(uint32 adr, uint32 byte, cycle_t now, bool rmw);
csid_write(0,0xd6, now, 123);
now+=5;
csid_write(1,0x1c, now, 123);
now+=5;
csid_write(7,0x55, now, 123);
now+=5;
csid_write(8,0x24, now, 123);
now+=5;
csid_write(4,0x11, now, 123);
now+=5;
csid_write(11,0x11, now, 123);
SDL_Delay(1000);
csid_write(4,0x10, now, 123);
now+=5;
csid_write(11,0x10, now, 123);
SDL_Delay(1000);
csid_write(5,0xa8, now, 123);
now+=5;
csid_write(6,0xff, now, 123);
now+=5;
csid_write(12,0xa8, now, 123);
now+=5;
csid_write(13,0xFF, now, 123);
now+=5;
csid_write(4,0x11, now, 123);
now+=5;
csid_write(11,0x11, now, 123);
SDL_Delay(1000);
csid_write(4,0x10, now, 123);
now+=5;
csid_write(11,0x10, now, 123);
SDL_Delay(1000);
while (true) {
SDL_Event e;
if (SDL_WaitEvent(&e)) {
if (e.type == SDL_QUIT)
break;
}
}
// SIDInit() -> void SIDCalcBuffer(uint8 *buf, int count) -> calc_buffer -> desired.callback = calc_buffer;
// ExitAll();
cSIDExit();
// makefile: #define SID_PLAYER 0
// make CFLAGS=-DMACRO
}
示例12: menu
int menu(SDL_Surface * screen) {
SDL_Event event;
Background * menuBackground = new Background("img/menu/menu.bmp");
menuBackground->setCoords(0,0);
Background * arrow = new Background("img/menu/arrow.bmp");
menuMusic = Mix_LoadMUS("sound/menubgm.wav");
menuSFX = Mix_LoadWAV("sound/arrow.wav");
int arrowX = 250;
int arrowY = 515;
arrow->setCoords(arrowX,arrowY);
int arrowPos = 0;
int step = 83;
while(1) {
int stage;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
stage = handle_menu_key(event.key.keysym.sym, arrowPos);
break;
case SDL_KEYUP:
stage = handle_menu_keyup(event.key.keysym.sym, arrowPos);
break;
}
if (stage == EXIT) {
delete menuBackground;
delete arrow;
Mix_FreeChunk(menuSFX);
Mix_HaltMusic();
Mix_FreeMusic(menuMusic);
menuMusic = NULL;
return EXIT;
}
else if (stage == MULTIPLE) {
delete menuBackground;
delete arrow;
Mix_FreeChunk(menuSFX);
Mix_HaltMusic();
Mix_FreeMusic(menuMusic);
menuMusic = NULL;
return MULTIPLE;
}
}
arrow->setCoords(arrowX, arrowY+arrowPos*step);
menuBackground->setCoords(0,0);
menuBackground->blit(screen);
arrow->blit(screen);
if (Mix_PlayingMusic() == 0) {
if (Mix_PlayMusic(menuMusic, -1) == -1)
fprintf(stderr, "Unable to play WAV file: %s\n", Mix_GetError());
}
SDL_Flip(screen);
SDL_Delay(10);
}
return 0;
}
示例13: eventLoop
//.........这里部分代码省略.........
}
background->blit(screen);
if (Mix_PlayingMusic() == 0) {
if (Mix_PlayMusic(mainMusic, -1) == -1)
fprintf(stderr, "Unable to play WAV file: %s\n", Mix_GetError());
}
for (int j = 0; j < bombGroup.size(); j++) {
bombGroup.at(j)->blit(screen);
}
for (int j = 0; j < explosionGroup.size(); j++) {
SDL_Rect tmp = explosionGroup.at(j)->getShowPart();
explosionGroup.at(j)->blit(screen, &tmp);
}
for (int i = 0; i < blocks.size(); i++) {
blocks.at(i)->blit(screen);
}
for (int i = 0; i < upgradeGroup.size(); i++) {
upgradeGroup.at(i)->blit(screen);
}
for(map<int, Hero* >::iterator it=heroGroup.begin(); it!=heroGroup.end(); ++it) {
it->second->blit(screen);
}
for(map<int, Hero* >::iterator it=heroGroup.begin(); it!=heroGroup.end(); ++it) {
sprintf(textbuf[it->first], "Player %d = %d", it->first+1, it->second->getLife());
text_image[it->first] = TTF_RenderText_Solid(text_font, textbuf[it->first], font_color);
int offsetX = it->first<2 ? 0:1;
int offsetY = it->first%2==0 ? 0:1;
textDest[it->first].x = 50+750*offsetX;
textDest[it->first].y = 10+50*offsetY;
textDest[it->first].w = text_image[it->first]->w;
textDest[it->first].h = text_image[it->first]->h;
SDL_BlitSurface(text_image[it->first], NULL, screen, &(textDest[it->first]));
SDL_FreeSurface(text_image[it->first]);
}
// game over
bool iWin = false;
if (heroGroup[myId]->getLife()!=0) {
iWin = true;
for(map<int, Hero* >::iterator it=heroGroup.begin(); it!=heroGroup.end(); ++it) {
if (it->first != myId) {
if (it->second->getLife() != 0) {
iWin = false;
break;
}
}
}
}
bool iLose=false;
if (heroGroup[myId]->getLife()==0) {
iLose = true;
int counter = 0;
for(map<int, Hero* >::iterator it=heroGroup.begin(); it!=heroGroup.end(); ++it) {
if (it->first != myId) {
if (it->second->getLife() != 0) {
counter++;
if (counter>1) {
iLose = false;
break;
}
}
}
}
}
if (iWin) {
animationCounter++;
if (animationCounter>20) {
winScreen->blit(screen);
SDL_Flip(screen);
SDL_Delay(3000);
gameLoopCleanUp();
return MENU;
}
}
else if (iLose) {
animationCounter++;
if (animationCounter>20) {
loseScreen->blit(screen);
SDL_Flip(screen);
SDL_Delay(3000);
gameLoopCleanUp();
return MENU;
}
}
/* since its double buffered, make
the changes show up*/
SDL_Flip(screen);
SDL_Delay(50);
}
return 0;
}
示例14: SDL_Delay
void Time::Sleep(uint32 time) {
SDL_Delay(time);
}
示例15: main
//.........这里部分代码省略.........
setButtons_and_Frames();
create_Tooltips();
//start frame counter
frame = 0;
//play music
//Mix_PlayMusic(mainMusic, -1);
//the player
Player *player0 = NULL;
//while in game
while(quit == false)
{
//start frame timer
fps.start();
//while events to handle
while(SDL_PollEvent(&event))
{
//player0 ship movement/ shooting
if(isPaused == false)
player0->handle_input();
else
quit = handle_menu_input();
//if user closes window
if(event.type == SDL_QUIT)
{
quit = true;
}
}
if(isPaused == false)
{
//background
apply_surface(0, 0, background, screen, &camera);
if(gameMode == 0)
{
doMainGame(player0);
}
else if(gameMode == 1)
doArcadeMode(player0);
//control units
player0->doUnit();
doGrunts();
doBoomers();
doStealths();
doCarriers();
doExplosions();
//HUD
renderHUD(player0);
}
else if(quit == false) //paused, show some sort of menu;
{
switch(menu) //show menu based on menu variable
{
case 0:
quit = doMainMenu();
//going to mainMenu, reset everything
if(player0 != NULL)
delete player0;
player0 = new Player;
reset();
break;
case 1: instructionsMenu(); break;
case 2: doPauseMenu(); break;
case 3: doSkillMenu(player0); break;
case 4: gameOverMenu(); break;
//case 5: doShopMenu(player0); break;
//if not valid menu, unpause game
case 6: victoryMenu(); break;
default: isPaused = false;
}
}
//update screen
if(SDL_Flip(screen) == -1)
return 1;
//cap frame rate
if(fps.get_ticks() < 1000 / FRAMES_PER_SECOND)
{
SDL_Delay((1000 / FRAMES_PER_SECOND) - fps.get_ticks());
}
frame++;
}
clean_up();
return 0;
}