Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "SDL/SDL.h"
- #include <ctime>
- #include <string>
- using namespace std;
- void exit();
- //surfaces
- SDL_Surface *screen = NULL;
- SDL_Surface *cpp = NULL;
- SDL_Surface *java = NULL;
- SDL_Surface *background = NULL;
- //slotsakerna
- SDL_Surface *lisp = NULL;
- SDL_Surface *gml = NULL;
- SDL_Surface *c = NULL;
- //variables
- int random[3];
- Uint8 *key;
- SDL_Event event;
- void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination) {
- SDL_Rect offset;
- offset.x = x;
- offset.y = y;
- SDL_BlitSurface(source, NULL, destination, &offset);
- }
- void slot();
- void keyinput();
- int main(int argc, char *args []) {
- srand(time(NULL));
- SDL_Init(SDL_INIT_EVERYTHING);
- cpp = SDL_LoadBMP("image/cpp.bmp");
- java = SDL_LoadBMP("image/java.bmp");
- background = SDL_LoadBMP("image/background.bmp");
- lisp = SDL_LoadBMP("image/lisp.bmp");
- c = SDL_LoadBMP("image/c.bmp");
- gml = SDL_LoadBMP("image/gml.bmp");
- screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
- apply_surface(0, 0, background, screen);
- slot();
- keyinput();
- SDL_Flip(screen);
- SDL_Delay(2000);
- exit();
- SDL_Quit();
- return 0;
- }
- void exit() {
- SDL_FreeSurface(cpp);
- SDL_FreeSurface(java);
- SDL_FreeSurface(background);
- SDL_FreeSurface(lisp);
- SDL_FreeSurface(gml);
- SDL_FreeSurface(c);
- }
- void slot() {
- int place[3];
- place[0] = 90;
- place[1] = 250;
- place[2] = 400;
- int y = 220;
- for(int i=0; i<3; i++) {
- random[i] = rand() % 5 + 1;
- if(random[i] == 1) {
- apply_surface(place[i], y, cpp, screen);
- } else if(random[i] == 2) {
- apply_surface(place[i], y, java, screen);
- } else if(random[i] == 3) {
- apply_surface(place[i], y, lisp , screen);
- } else if(random[i] == 4) {
- apply_surface(place[i], y, gml, screen);
- } else if(random[i] == 5) {
- apply_surface(place[i], y, c, screen);
- }
- }
- SDL_Flip(screen);
- }
- void keyinput() {
- while(true) {
- if( SDL_PollEvent (&event)) {
- if(event.type == SDL_KEYDOWN) {
- switch(event.key.keysym.sym) {
- case SDLK_SPACE:
- slot();
- break;
- case SDLK_ESCAPE:
- exit();
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment