Salut a tous !
Je suis en train de créer un GTA like en SDL !
Qui dit SDL, dit jeu 2D !
Qui dit GTA like 2D dit voiture
et qui dit voiture 2D dit rotation pour la piloter !
Donc voilà, je code en C avec la SDL, déjà, il me faudrait une fonction pour les rotation ou une lib, mais pas SDL_gfx, elle marche pas avec Code::Blocks !
Mais j'ai un autre petit prob, en fait, pour les event, j'utilise un SDL_PollEvent, et non pas un WaitEvent !
Enfin, c'est compliqué a expliquer ...
Voici mon code :
- include <stdlib.h>
- include <stdio.h>
- include <SDL/SDL.h>
typedef struct
{
char key[SDLK_LAST];
}Input;
void UpdateEvent(Input *in)
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
in->key[event.key.keysym.sym] = SDL_FALSE;
break;
case SDL_KEYUP:
in->key[event.key.keysym.sym] = SDL_TRUE;
break;
default:
break;
}
}
}
int main (int argc, char** argv)
{
int continuer = 1, speed = 1;
Input in;
SDL_Surface *ecran = NULL, *fond = NULL, *car1 = NULL, *rotation = NULL;
SDL_Rect posFond, posCar1, posCar2, posCar3;
posFond.x = 0;
posFond.y = 0;
posCar1.x = 250;
posCar1.y = 250;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Small Theft Auto", NULL);
fond = SDL_LoadBMP("fond.bmp");
car1 = SDL_LoadBMP("car1.bmp");
SDL_SetColorKey(car1, SDL_SRCCOLORKEY, SDL_MapRGB(car1->format, 255, 255 , 255));
SDL_BlitSurface(fond, NULL, ecran, &posFond);
SDL_BlitSurface(car1, NULL, ecran, &posCar1);
SDL_Flip(ecran);
memset(&in,0,sizeof(in));
while(!in.key[SDLK_ESCAPE])
{
UpdateEvent(&in);
if(in.key[SDLK_UP])
{
posCar1.y++;
}
UpdateEvent(&in);
if(in.key[SDLK_DOWN])
{
posCar1.y--;
}
UpdateEvent(&in);
if(in.key[SDLK_RIGHT])
{
posCar1.x--;
}
UpdateEvent(&in);
if(in.key[SDLK_LEFT])
{
posCar1.x++;
}
UpdateEvent(&in);
SDL_BlitSurface(fond, NULL, ecran, &posFond);
SDL_BlitSurface(car1, NULL, ecran, &posCar1);
SDL_Flip(ecran);
}
SDL_FreeSurface(fond);
SDL_FreeSurface(car1);
SDL_Quit();
return 0;
}
En fait, vous allez me dire, olalala, t'as inversé les axes Y et X, mais justement c'est ça le problème, quand on appuie sur les touches, on voit que les axes sont inversé, mais en appuyant un peu n'importe comment, sa inverse les axes, et donc je peut piloter ma voiture normalement...
Seulement au début, j'appuie sur bas, droite ou gauche une fois, il avance tout seul, alors qu'une fois les axes inversé, tout est comme je veut, notamment les axes inversé et aussi le fait que pour avancer, je doit maintenire enfoncer haut, pour aller a droite, droite...
Merci de vos réponses ;) !