T
Wie ich bereits vermutet habe, muss man offensichtlich ein Pollevent anlegen, weil SDL, aus welchen Gründen auch immer _kbhit() blockiert...
so klappts:
#include "stdafx.h"
#include "windows.h"
#include "SDL.h"
#pragma comment(lib, "SDL.lib")
#undef main
void DrawPixel(SDL_Surface *screen, int x, int y,Uint8 R, Uint8 G,Uint8 B) // Pixel zeichnen (16bit)
{
Uint32 color = SDL_MapRGB(screen->format, R, G, B);
SDL_LockSurface(screen);
Uint16 *bufp;
bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
*bufp = color;
SDL_UnlockSurface(screen);
}
int main(int argc, char *argv[])
{
FreeConsole();
int x=100,y=100;
char direction = 'r';
bool done=false;
SDL_Event event;
Uint8 *keys;
SDL_Surface *screen; //GFX
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE);
SDL_Rect dst;dst.x = 0;dst.y = 0;dst.w = 640;dst.h = 480; //Hintergrund rot
SDL_FillRect(screen, &dst, SDL_MapRGB(screen->format, 255, 0, 0));
while (!done) { //Pollevent
while (SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_QUIT:
done = 1;
break; }}
DrawPixel (screen, x, y, 0,0,0); //1 Pixel zeichnen
SDL_Flip(screen);
keys = SDL_GetKeyState(NULL); // Tastaturabfrage über SDL
if (keys[SDLK_UP]) { direction = 'o';}
if (keys[SDLK_DOWN]) { direction = 'u';}
if (keys[SDLK_RIGHT]) { direction = 'r';}
if (keys[SDLK_LEFT]) { direction = 'l';}
if (keys[SDLK_ESCAPE]) {done = TRUE;}
switch(direction){ //Richtung
case 'r': x++;break;
case 'l': x--;break;
case 'o': y--;break;
case 'u': y++;break;}
if (x >= 640) done = TRUE; // Kollision
if (x <= 0) done =TRUE;
if (y <= 0) done =TRUE;
if (y >= 480) done =TRUE;
}
SDL_Quit();
return 0;
}
danke Matze