int main(int argc, char** argv) { srand(time(0)); SDL_Init(SDL_INIT_VIDEO); SDL_Window* window = SDL_CreateWindow("raindrop", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN); SDL_Renderer* rend = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); SDL_Surface* black_surface = SDL_LoadBMP("black.bmp"); SDL_Surface* rain_surface = SDL_LoadBMP("rain.bmp"); SDL_SetColorKey(rain_surface, SDL_TRUE, SDL_MapRGB(rain_surface->format, 255, 255, 255)); SDL_Texture* black_texture = SDL_CreateTextureFromSurface(rend,black_surface); SDL_Texture* rain_texture = SDL_CreateTextureFromSurface(rend, rain_surface); SDL_SetTextureBlendMode(black_texture, SDL_BLENDMODE_BLEND); SDL_SetTextureAlphaMod(black_texture, 50); SDL_SetTextureBlendMode(rain_texture, SDL_BLENDMODE_BLEND); SDL_Rect window_rect; window_rect.w = WINDOW_WIDTH; window_rect.h = WINDOW_HEIGHT; window_rect.x = 0; window_rect.y = 0; Spot spots[AMOUNT]; int i = 0; for(; i<AMOUNT; ++i) { reset_spot(&spots[i]); spots[i].y = rand() % (WINDOW_HEIGHT + 1); } bool quit = false; SDL_Event event; while(!quit) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) quit = true; } SDL_RenderCopy(rend, black_texture, NULL, &window_rect); for(i = 0; i<AMOUNT; ++i) { draw_rain(&spots[i], rend, rain_texture); SDL_RenderPresent(rend); move_spot(&spots[i]); } SDL_Delay(5); } return 0; }
/* the main game loop */ static int puzzle_loop(void) { int button; #if defined(PUZZLE_SHUFFLE_PICTURE_PRE) int lastbutton = BUTTON_NONE; #endif bool load_success; puzzle_init(); while(true) { button = rb->button_get(true); switch (button) { #ifdef PUZZLE_RC_QUIT case PUZZLE_RC_QUIT: #endif case PUZZLE_QUIT: /* get out of here */ return PLUGIN_OK; case PUZZLE_SHUFFLE: #ifdef PUZZLE_SHUFFLE_PICTURE_PRE if (lastbutton != PUZZLE_SHUFFLE_PICTURE_PRE) break; #endif /* mix up the pieces */ puzzle_init(); break; case PUZZLE_PICTURE: #ifdef PUZZLE_SHUFFLE_PICTURE_PRE if (lastbutton != PUZZLE_SHUFFLE_PICTURE_PRE) break; #endif /* change picture */ picmode = (picmode+1)%PICMODE_LAST_XXX; /* if load_resize_bitmap fails to load bitmap, try next picmode */ do { load_success = load_resize_bitmap(); if( !load_success ) picmode = (picmode+1)%PICMODE_LAST_XXX; } while( !load_success ); /* tell the user what mode we picked in the end! */ rb->splash(HZ,picmode_descriptions[ picmode ] ); draw_playfield(); break; case PUZZLE_LEFT: if ((hole%SPOTS_X)<(SPOTS_X-1) && !puzzle_finished()) move_spot(-1, 0); break; case PUZZLE_RIGHT: if ((hole%SPOTS_X)>0 && !puzzle_finished()) move_spot(1, 0); break; case PUZZLE_UP: if ((hole/SPOTS_X)<(SPOTS_Y-1) && !puzzle_finished()) move_spot(0, -1); break; case PUZZLE_DOWN: if ((hole/SPOTS_X)>0 && !puzzle_finished()) move_spot(0, 1); break; default: if (rb->default_event_handler(button) == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; break; } #if defined(PUZZLE_SHUFFLE_PICTURE_PRE) if (button != BUTTON_NONE) lastbutton = button; #endif } }