</s><i>
</i>#include <stdlib.h>
#include <SDL/SDL.h>
int main(int argc, char *argv[])
{
short quit = 0, py = 210, px = 50, height;
SDL_Surface *screen, *image;
SDL_Rect p;
SDL_Event event;
Uint8 *keys;
if (SDL_Init(SDL_INIT_VIDEO) == -1) {
printf("Can't init SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(800, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (screen == NULL) {
printf("Can't set video mode: %s\n", SDL_GetError());
exit(1);
}
while (quit == 0) {
keys = SDL_GetKeyState(NULL);
if (keys[SDLK_UP]) {
if (py > 0) {
py--;
}
}
if (keys[SDLK_DOWN]) {
if (py < 420) {
py++;
}
}
if (keys[SDLK_RIGHT]) {
quit = 1;
}
p.x = 50;
p.y = py;
p.w = 10;
p.h = height;
SDL_FillRect(screen, &p, SDL_MapRGB(screen->format, 0, 0, 255));
SDL_UpdateRect(screen, 0, 0, 0, 0);
SDL_Flip(screen);
}
return 0;
}
<e>