void Display :: _line(SDL_Surface* surf, int x0, int y0, int x1, int y1, Uint32 color) { x0 = std::max(x0, 0); x0 = std::min(x0, surf->w - 1); x1 = std::max(x1, 0); x1 = std::min(x1, surf->w - 1); y0 = std::max(y0, 0); y0 = std::min(y0, surf->h - 1); y1 = std::max(y1, 0); y1 = std::min(y1, surf->h - 1); int dy = y1 - y0; int dx = x1 - x0; int stepx, stepy; if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; } if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; } dy <<= 1; // dy is now 2*dy dx <<= 1; // dx is now 2*dx _put_pixel(surf, color, x0, y0); if (dx > dy) { int fraction = dy - (dx >> 1); // same as 2*dy - dx while (x0 != x1) { if (fraction >= 0) { y0 += stepy; fraction -= dx; // -= 2*dx } x0 += stepx; fraction += dy; // -= 2*dy _put_pixel(surf, color, x0, y0); } }
void Display :: _blit_map() { for (unsigned i = 0; i < _map->get_pixel_w(); ++i) for (unsigned j = 0; j < _map->get_pixel_h(); ++j) if (_map->get_pixel(i, j) == Map::obstacle) _put_pixel(_map_bmp, i, j, 0, 0, 0); else _put_pixel(_map_bmp, i, j, 255, 255, 255); SDL_BlitSurface(_map_bmp, 0, _screen, 0); SDL_UpdateRect(_screen, 0, 0, _w, _h); }
void put_pixel(int x, int y, int color) { int i,j; for(i=0; i<FACTEUR; i++) { for(j=0; j<FACTEUR; j++) { _put_pixel(color,x*FACTEUR+i,y*FACTEUR+j,buffer); } } }
void _put_pixel(SDL_Surface* surf, unsigned x, unsigned y, Uint8 r, Uint8 g, Uint8 b) { _put_pixel(surf, SDL_MapRGB(surf->format, r, g, b), x, y); }
void _put_pixel(SDL_Surface* surf, int x, int y, Uint8 r, Uint8 g, Uint8 b) { _put_pixel(surf, SDL_MapRGB(surf->format, r, g, b), x, y); }