1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/* -- Include the precompiled libraries -- */
#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif
#include <stdlib.h>
#include "SDL.h"
#define TRUE 1
#define FALSE 0
int main(int argc, char *argv[])
{
SDL_Surface *screen;
SDL_Surface *picture;
SDL_Event event;
SDL_Rect pictureLocation;
int leftPressed, rightPressed, upPressed, downPressed;
const SDL_VideoInfo* videoinfo;
atexit(SDL_Quit);
/* Initialize the SDL library */
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}
screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF | SDL_HWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
SDL_GetError());
exit(1);
}
videoinfo = SDL_GetVideoInfo();
printf("%i", videoinfo->blit_hw);
// Load Picture
picture = SDL_LoadBMP("Iapetus.bmp");
if (picture == NULL) {
fprintf(stderr, "Couldn't load %s: %s\n", "SDL_now.bmp", SDL_GetError());
return 0;
}
while(TRUE) {
if (leftPressed) {
if (pictureLocation.x > 0)
pictureLocation.x--;
}
if (rightPressed) {
if (pictureLocation.x < 640-picture->w)
pictureLocation.x++;
}
if (upPressed) {
if (pictureLocation.y > 0) {
pictureLocation.y--;
}
}
if (downPressed) {
if (pictureLocation.y < 480-picture->h) {
pictureLocation.y++;
}
}
SDL_FillRect(screen, NULL, 1000);
SDL_BlitSurface(picture, NULL, screen, &pictureLocation);
SDL_Flip(screen);
if( SDL_PollEvent( &event ) ){
/* We are only worried about SDL_KEYDOWN and SDL_KEYUP events */
switch( event.type ){
case SDL_KEYDOWN:
switch(event.key.keysym.sym) {
case SDLK_LEFT:
leftPressed = TRUE;
break;
case SDLK_RIGHT:
rightPressed = TRUE;
break;
case SDLK_DOWN:
downPressed = TRUE;
break;
case SDLK_UP:
upPressed = TRUE;
break;
case SDLK_ESCAPE:
exit(0);
default:
break;
}
break;
case SDL_KEYUP:
switch(event.key.keysym.sym) {
case SDLK_LEFT:
leftPressed = FALSE;
break;
case SDLK_RIGHT:
rightPressed = FALSE;
break;
case SDLK_DOWN:
downPressed = FALSE;
break;
case SDLK_UP:
upPressed = FALSE;
break;
default:
break;
}
break;
default:
break;
}
}
}
}
return 0;
}
|