int main() { int x,y; int ancho, alto; int tecla; term_init(); ancho = screenwidth(); alto = screenheight(); /* Rellenamos de verde la pantalla */ textbackground(GREEN); clrscr(); textbackground(BLUE); /* Rellenamos de azul la primera fila */ for (x=0; x<ancho; x++) printf(" "); gotoxy(1,alto); /* Rellenamos de azul la última fila */ for (x=0; x<ancho; x++) printf(" "); gotoxy(2,2); while ((tecla=kbhit2())==0) update_time(); printf("You have pressed: %d\n", tecla); term_defaults(); }
//paint(x,y) : fill a close area int paint(int x,int y) { char *paintmap; int xstart,ystart; int src_col,col; char pm; if (SDL_MUSTLOCK(SDLscreen[c_screen])) SDL_LockSurface(SDLscreen[c_screen]); paintmap= malloc(screenwidth()*screenheight()); xstart=x; ystart=y; src_col=getpixel(SDLscreen[c_screen],x,y);//point(x,y); putpixel(SDLscreen[c_screen],x,y,(Uint32)SDL_MapRGB(SDLdisplay->format,SDLcol.r,SDLcol.g,SDLcol.b));//dot(x,y); col=getpixel(SDLscreen[c_screen],x,y);//point(x,y); pm=2; if (col==src_col)return -1; while(0==0) { //if (point(x,y)==src_col) { if (getpixel(SDLscreen[c_screen],x,y)== src_col) { putpixel(SDLscreen[c_screen],x,y,(Uint32)SDL_MapRGB(SDLdisplay->format,SDLcol.r,SDLcol.g,SDLcol.b));//dot(x,y); paintmap[y*screenwidth()+x]=pm; } //if (point(x+1,y)==src_col && (x+1) < screenwidth()) { if (getpixel(SDLscreen[c_screen],x+1,y)==src_col && (x+1) < screenwidth()) { x=x+1; pm=1; } //else if (point(x-1,y)==src_col && (x-1) > 0 ) { else if (getpixel(SDLscreen[c_screen],x-1,y)==src_col && (x-1) >= 0 ) { x=x-1; pm=2; } //else if (point(x,y+1)==src_col && (y+1) < screenheight()) { else if (getpixel(SDLscreen[c_screen],x,y+1)==src_col && (y+1) < screenheight()) { y=y+1; pm=3; } //else if (point(x,y-1)==src_col && (y-1) > 0) { else if (getpixel(SDLscreen[c_screen],x,y-1)==src_col && (y-1) >= 0) { y=y-1; pm=4; } else { if (x==xstart && y==ystart)break; if (paintmap[y*screenwidth()+x]==1) x=x-1; else if (paintmap[y*screenwidth()+x]==2) x=x+1; else if (paintmap[y*screenwidth()+x]==3) y=y-1; else if (paintmap[y*screenwidth()+x]==4) y=y+1; } } free(paintmap); if (SDL_MUSTLOCK(SDLscreen[c_screen]) ) SDL_UnlockSurface(SDLscreen[c_screen]); if (autotimer()!=0)return -1; return 0; }