Bonsoir, j'essaie de suivre les tutoriels sur le net pour m'entraîner à faire des programmes sous librairie SDL, seulement j'arrive à un problème récurrent pour la leçon 18, càd la gestion des collisions par pixel ( http://lazyfoo.net/SDL_tuL_tutorials/lesson18/index.php ).
Le problème est que je n'arrive pas à afficher deux points noirs sur fond blanc, seulement j'ai comparé le code du tuto avec le mien, et apparemment le code est très très similaire (je l'ai vérifié dans l'entièreté au moins 3x pour en être sûr).
L'image du point est présent dans le dossier où se trouve le projet.
Je suppose que le compilateur ne prend pas en compte les arguments X et Y (concernant la position des points) de la classe "Dot".
Voici mon code (abrégée, j'ai gardé les parties intéressantes) :
class Dot
{
private:
int x, y;
std::vector<SDL_Rect> box;
int xVel, yVel;
void shift_boxes();
public:
Dot(int X, int Y);
void handle_input();
void move(std::vector<SDL_Rect> &rects);
void show();
std::vector<SDL_Rect> &get_rects();
};
Dot::Dot(int X, int Y)
{
x = X;
y = Y;
xVel = 0;
yVel = 0;
box.resize(11);
box[0].w = 6;
box[0].h = 1;
box[1].w = 10;
box[1].h = 1;
box[2].w = 14;
box[2].h = 1;
box[3].w = 16;
box[3].h = 2;
box[4].w = 18;
box[4].h = 2;
box[5].w = 20;
box[5].h = 6;
box[6].w = 18;
box[6].h = 2;
box[7].w = 16;
box[7].h = 2;
box[8].w = 14;
box[8].h = 1;
box[9].w = 10;
box[9].h = 1;
box[10].w = 6;
box[10].h = 1;
shift_boxes();
}
int main(int, char**)
{
bool quit = false;
SDL_Surface *screen;
//Classe et position des points
Dot myDot(0, 0), otherDot(20, 20);
Timer fps;
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
//Affichage du point (le fichier)
dot = loadImage("dot.bmp");
while(quit == false)
{
//Début d'un timer
fps.start();
while(SDL_PollEvent(&event))
{
//Gestion des évènements, selon les touches enfoncées
myDot.handle_input();
if(event.type == SDL_QUIT)
{
quit = true;
}
}
//La direction des points en mouvement
myDot.move(otherDot.get_rects());
SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
//Affichage des points sur l'écran
otherDot.show();
myDot.show();
SDL_Flip(screen);
//Régulateur de frames par secondes
if(fps.get_ticks() < 1000 / FRAMES_PER_SECOND)
{
SDL_Delay(( 1000 / FRAMES_PER_SECOND) - fps.get_ticks());
}
}
SDL_FreeSurface(dot);
SDL_Quit;
return 0;
}
Une idée ?
Ou une alternative à cela ?