Quoth Max Countryman , on Fri 22 Aug 2003:
Drake, some code snippets would greatly help me to better understand
what you mean, thanks,
The following '’-delimited C++ source compiles into a small
application demonstrating what my suggestion(s); note that it is not
by any means optimal in all respects.
#include “SDL.h”
int main(int argc, char *argv[])
{
Uint8 *keystate;
bool quit = false;
SDL_Rect rect;
SDL_Surface *screen;
Uint32 color;
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(400, 400, 16, SDL_SWSURFACE);
keystate = SDL_GetKeyState(NULL);
rect.x = rect.y = 200;
rect.w = rect.h = 2;
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
color = SDL_MapRGB(screen->format, 255, 255, 255);
while (!quit) {
SDL_Event ev, pushed;
while (SDL_PollEvent(&ev)) {
switch (ev.type) {
case SDL_KEYDOWN:
switch (ev.key.keysym.sym) {
case SDLK_q:
pushed.type = SDL_QUIT;
SDL_PushEvent(&pushed);
break;
}
break;
case SDL_QUIT:
quit = true;
break;
}
}
if (quit)
break;
if (keystate[SDLK_UP])
rect.y -= 2;
if (keystate[SDLK_DOWN])
rect.y += 2;
if (keystate[SDLK_LEFT])
rect.x -= 2;
if (keystate[SDLK_RIGHT])
rect.x += 2;
SDL_FillRect(screen, &rect, color);
SDL_UpdateRect(screen, rect.x, rect.y, rect.w, rect.h);
SDL_Delay(1);
}
return 0;
}
---> Drake Wilson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030821/70511361/attachment.pgp>