Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
// (find-es "sdl" "cga-tron") // http://www.lazyfoo.net/SDL_tutorials/lesson01/index2.php // (find-load81file "om") // (find-fline "~/IMAGES/littlelangs.png") // http://sdl.beuc.net/sdl.wiki/SDL_image // (find-es "sdl" "lazy-foo-tutorial") // (defun c () (interactive) (find-sh "cd ~/SDL/; rm -fv 2 2.o; gcc -o 2 2.c -lSDL && ./2")) // (defun c () (interactive) (find-sh "cd ~/SDL/; rm -fv 2 2.o; gcc -o 2 2.c -lSDL && ./2 -geometry +100+100")) // (find-libcnode "Pseudo-Random Numbers") // From: (find-angg "ICON/tron.icn") // 10 KEY OFF:SCREEN 1:COLOR 0,0:CLS:RANDOMIZE TIMER // 20 LINE (0,0)-(319,192),,b:X=150:Y=90:DX=1:DY=0:PTS=0 // 30 GOSUB 110:GOSUB 100 // 40 C=POINT(X,Y):IF C=3 THEN 90 ELSE PSET(X,Y),3 // 50 IF C=2 THEN PTS=PTS+1:GOSUB 100:GOSUB 110:SOUND 200,,2 // 60 A$=INKEY$:IF A$="" THEN 80 ELSE ND=INSTR("WASZwasz",A$)-1:IF ND<0 GOTO 80 // 70 MM=(ND AND 2)-1:H=ND AND 1:IF (H=1)<>(DX<>0) THEN DX=H*MM:DY=(1-H)*MM // 80 X=X+DX:Y=Y+DY:GOTO 40 // 90 END // 100 LOCATE 25,1:PRINT "Score:";PTS;:LOCATE 1,1:RETURN // 110 H=RND*316+1:V=RND*188+1:LINE(H,V)-(H+2,V+2),2,BF:RETURN /* * (eepitch-shell2) * (eepitch-kill) * (eepitch-shell2) convert red.xpm red.bmp convert yellow.xpm yellow.bmp convert black.xpm black.bmp rm -fv 2 2.o # gcc -o 2 `sdl-config --cflags` `sdl-config --libs` 2.c # or: # g++ -o 2 2.c -lSDL * (eepitch-shell2) * (eepitch-kill) * (eepitch-shell2) rm -fv 2 2.o gcc -o 2 2.c -lSDL ./2 */ //Include SDL functions and datatypes #include "SDL/SDL.h" static SDL_Surface* screen = NULL; static SDL_Surface* colors[4]; static char point[320][200]; static int x=150, y=90, dx=1, dy=0, pts=0; static SDL_Event event; void update_screen () { SDL_Flip(screen); } void pset(int x, int y, int c) { SDL_Rect offset; offset.x = x*2; offset.y = y*2; SDL_BlitSurface(colors[c], NULL, screen, &offset ); point[x][y] = c; } void draw_red_square () { int h=(rand()%316)+1, v=(rand()%188)+1, x, y; for (x=h; x<=h+2; ++x) for (y=v; y<=v+2; ++y) pset(x, y, 2); } void draw_score () {} void hit_red_pixel () { draw_red_square(); ++pts; draw_score(); update_screen(); SDL_Delay(100); // noise(); } int main( int argc, char* args[] ) { int i, j; SDL_Init(SDL_INIT_EVERYTHING); screen = SDL_SetVideoMode(640, 400, 32, SDL_SWSURFACE); colors[0] = SDL_LoadBMP("black.bmp"); colors[1] = NULL; colors[2] = SDL_LoadBMP("red.bmp"); colors[3] = SDL_LoadBMP("yellow.bmp"); for (i=0; i<=319; ++i) for (j=0; j<=192; ++j) pset(i, j, 0); for (i=0; i<=319; ++i) { pset(i, 0, 3); pset(i, 192, 3); } for (j=0; j<=192; ++j) { pset(0, j, 3); pset(319, j, 3); } x=150; y=90; dx=1; dy=0; pts=0; pset(x, y, 3); draw_red_square(); draw_score(); update_screen(); WALK: SDL_Delay(50); if (SDL_PollEvent(&event)) { // If there's an event to handle if (event.type == SDL_KEYDOWN) { // If a key was pressed switch (event.key.keysym.sym) { case SDLK_UP: dx=0; dy=-1; break; case SDLK_DOWN: dx=0; dy=1; break; case SDLK_LEFT: dx=-1; dy=0; break; case SDLK_RIGHT: dx=1; dy=0; break; // To do: on q/Q/esc goto END } } else if (event.type == SDL_QUIT) { // user closed the window goto END; } } x=x+dx; y=y+dy; if (point[x][y] == 3) goto END; if (point[x][y] == 2) hit_red_pixel(); pset(x, y, 3); update_screen(); goto WALK; END: SDL_Delay( 2000 ); SDL_Quit(); return 0; } // static TTF_Font *font = NULL; // static SDL_Color textColor = { 0, 0, 0 }; // font = TTF_OpenFont( "lazy.ttf", 72 ); // if (font == NULL) { return false; } // upMessage = TTF_RenderText_Solid( font, "Up was pressed.", textColor );