CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

SDL clavier

dynoplasmma
dynoplasmma
Niveau 9
13 mai 2005 à 13:34:12

Bonjour, Je vous ramene sur cette page de creation de jeux
:http://www.jeuxvideo.com/forums/1-31-8388722-2-0-
1-0-0.htm

Si vous pouver lire un des dernier messages car je ne comprend pas. thanks.

PS : je ne connaissais pas ce forum, bien camouflé.

dynoplasmma
dynoplasmma
Niveau 9
13 mai 2005 à 23:11:14

Bonjour pour les anglophobles, hello pour les anglophones,Dans le code que je vais mettre, il s´affiche une image 1 de fond,

une image 2 a gauche

une image 3 a droite

Tout s´affiche mais le probleme est que l´image 2 doit bouger, et q´elle ne bouge pas. Voici le code :

  1. include < SDL/SDL.h>

SDL_Surface *screen;
SDL_Surface *firstscreen;
SDL_Event event;
SDL_Rect rect1;
Uint8* keystate;
int x,y ;

void init_SDL()
{
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(1024, 768, 32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
SDL_WM_SetCaption("Ma fenetre",NULL);
SDL_ShowCursor(0);
}

void waitkey()
{
while(1)
{
while(SDL_PollEvent(&))
{
if ( event.type == SDL_KEYDOWN)
{
if ( event.key.keysym.sym == SDLK_RETURN) return;
}
}
}
}

int main(int argc , char **argv)
{
SDL_Rect rect1;
init_SDL();
firstscreen = SDL_LoadBMP("aire.bmp");
rect1.x = 0;
rect1.y = 0;
rect1.w = 1024;
rect1.h = 768;

SDL_BlitSurface(firstscreen,NULL,screen,&1);

firstscreen=SDL_LoadBMP("barre joueur 1.bmp");
rect1.x=0;
rect1.y=332.5;
rect1.w=1024;
rect1.h=768;
SDL_SetColorKey(firstscreen,SDL_SRCCOLORKEY , SDL_MapRGBA(firstscreen->format,255,0,255,0));
SDL_BlitSurface(firstscreen,NULL,screen,&1);

rect1.x=x;
rect1.y=y;
keystate=SDL_GetKeyState(NULL);
if(keystate[SDLK_DOWN])y++;
if(keystate[SDLK_UP])y--;
SDL_FreeSurface(screen);

firstscreen = SDL_LoadBMP("barre joueur 2.bmp");
rect1.x=986;
rect1.y=332.5;
rect1.w=1024;
rect1.h=768;
SDL_SetColorKey(firstscreen,SDL_SRCCOLORKEY , SDL_MapRGBA(firstscreen->format,255,0,255,0));
SDL_BlitSurface(firstscreen,NULL,screen,&1);

SDL_Flip(screen);
waitkey();
SDL_ShowCursor(1);
SDL_Quit();
return 0;
}

Si quelqu´un pourrait m´aider, ce serai sympa, car quand je saurais ca, il me restera d´autres trucs, mais quand je saurais les autres trucs aussi, je voudrais faire plein de mode different pour le ti jeu fait, ce qui est facile si je connais tout, mais qui prend un petit peu de temps.Vous comprenez ?
d´avance et bonne route !

Ciao...

gollumkawder
gollumkawder
Niveau 10
14 mai 2005 à 10:40:56

Si je comprend bien, tu veux bouger ton image au moyen d´une touche sur le clavier, pour cela il te faut une pile d´evenement du style

{
SDL_Event event;

SDL_WaitEvent(&);

switch ( event.type) {
case SDL_KEYDOWN:
bouger.mon_image
SDL_GetKeyName(event.key.keysym.sym));
break;
case SDL_QUIT:
exit(0);
}
}

Tout ça est expliqué dans la documentation officielle

http://www.libsdl.org/intro.fr/usingeventsfr.html

dynoplasmma
dynoplasmma
Niveau 9
15 mai 2005 à 11:06:17

Bonjour, je l´ai adapté a mon programme, toutes les images s´affichent, mais le probleme persiste, j´appui sur la touche du haut, et rien ne se passe, je ne sais pas pourquoi, si quelqu´un si connait, qu´il m´induise dansle droit chemin. Voici le programme :

  1. include < SDL/SDL.h>

SDL_Surface* screen;
SDL_Surface* firstscreen;
SDL_Event event;

void init_SDL()
{
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(1024, 768, 32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
SDL_ShowCursor(0);
}

void waitkey()
{
while(1)
{
while(SDL_PollEvent(&))
{
if ( event.type == SDL_KEYDOWN)
{
if ( event.key.keysym.sym == SDLK_RETURN) return;
}
}
}
}

int main(int argc , char **argv)
{
SDL_Rect rect1;
init_SDL();
firstscreen = SDL_LoadBMP("aire.bmp");
rect1.x = 0;
rect1.y = 0;
rect1.w = 1024;
rect1.h = 768;

SDL_BlitSurface(firstscreen,NULL,screen,&1);

firstscreen=SDL_LoadBMP("barre joueur 1.bmp");
rect1.x=20;
rect1.y=332.5;
rect1.w=1024;
rect1.h=768;
SDL_SetColorKey(firstscreen,SDL_SRCCOLORKEY , SDL_MapRGBA(firstscreen->format,255,0,255,0));
SDL_BlitSurface(firstscreen,NULL,screen,&1);

{
SDL_Event event;

SDL_WaitEvent(&);

switch ( event.type)
{
case SDLK_UP:
printf("La touche %s a été préssée!\n",
SDL_GetKeyName(event.key.keysym.sym));
break;
}
}

firstscreen=SDL_LoadBMP("barre joueur 2.bmp");
rect1.x=987;
rect1.y=332.5;
rect1.w=1024;
rect1.h=768;

SDL_SetColorKey(firstscreen,SDL_SRCCOLORKEY,SDL_Ma
pRGBA(firstscreen->format,255,0,255,0));
SDL_BlitSurface(firstscreen,NULL,screen,&1);

SDL_Flip(screen);
waitkey();
SDL_ShowCursor(1);
SDL_Quit();
return 0;
}

:merci: d´´avance a ceux qui pourront m´aider.

dynoplasmma
dynoplasmma
Niveau 9
15 mai 2005 à 23:00:26

Hello

Voici le code, et j´espere que quelqu´un pourrait arranger ce code pour que cela fonctionne. La, je traine, je bloque, je suis coincé, je nepeut plus rien faire, donc ela serait sympathique de delier les liens qui m´attirent vers le gouffre.
Venons en au faite :

  1. include < SDL/SDL.h>

SDL_Surface *screen;
SDL_Surface *firstscreen;
SDL_Event event;
Uint8 *keystate;
SDL_Rect rect1;
int x,y ;

void init_SDL()
{
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(1024, 768, 32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
SDL_WM_SetCaption("Ma fenetre",NULL);
SDL_ShowCursor(0);
}

void waitkey()
{
while(1)
{
while(SDL_PollEvent(&))
{
if ( event.type == SDL_KEYDOWN)
{
if ( event.key.keysym.sym == SDLK_ESCAPE) return;
}
}
}
}

int main(int argc , char **argv)
{
SDL_Rect rect1;
init_SDL();
firstscreen = SDL_LoadBMP("aire.bmp");
rect1.x = 0;
rect1.y = 0;
rect1.w = 1024;
rect1.h = 768;

SDL_BlitSurface(firstscreen,NULL,screen,&1);

firstscreen=SDL_LoadBMP("barre joueur 1.bmp");
rect1.x=0;
rect1.y=333;
rect1.w=1024;
rect1.h=768;
SDL_SetColorKey(firstscreen,SDL_SRCCOLORKEY , SDL_MapRGBA(firstscreen->format,255,0,255,0));
SDL_BlitSurface(firstscreen,NULL,screen,&1);

while(keystate)
{
SDL_FillRect(screen,NULL,0);
rect1.x=x;
rect1.y=y;
SDL_BlitSurface(firstscreen,NULL,screen,&1);
SDL_Flip(screen);
if ( SDL_PollEvent(&) && event.type==SDL_QUIT)
keystate=SDL_GetKeyState(NULL);
if ( keystate[SDLK_DOWN])y++;
if ( keystate[SDLK_UP])y--;
}

firstscreen = SDL_LoadBMP("barre joueur 2.bmp");
rect1.x=986;
rect1.y=333;
rect1.w=1024;
rect1.h=768;
SDL_SetColorKey(firstscreen,SDL_SRCCOLORKEY , SDL_MapRGBA(firstscreen->format,255,0,255,0));
SDL_BlitSurface(firstscreen,NULL,screen,&1);

SDL_Flip(screen);
SDL_FreeSurface(screen);
waitkey();
SDL_ShowCursor(1);
SDL_Quit();
return 0;
}

A plus !

dynoplasmma
dynoplasmma
Niveau 9
16 mai 2005 à 15:33:14

J´ai redirigé le tout, voici le code :

  1. include < SDL/SDL.h>

SDL_Surface* screen;
SDL_Surface* firstscreen;
SDL_Surface* secondscreen;
SDL_Surface* thirdscreen;
SDL_Event event;
Uint8 *keystate;
int x,y;

void init_SDL()
{
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(1024, 768, 32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
SDL_ShowCursor(1);
}

void waitkey()
{
while(1)
{
while(SDL_PollEvent(&))
{
if ( event.type == SDL_KEYDOWN)
{
if ( event.key.keysym.sym == SDLK_ESCAPE) return;
}
}
}
}

int main(int argc , char **argv)
{
SDL_Rect rect1;
init_SDL();
firstscreen = SDL_LoadBMP("aire.bmp");
secondscreen = SDL_LoadBMP("barre joueur 1.bmp");
thirdscreen = SDL_LoadBMP("barre joueur 2.bmp");

while(keystate)
{
rect1.x=x;
rect1.y=y;
if ( SDL_PollEvent(&) && event.type==SDL_QUIT)
keystate=SDL_GetKeyState(NULL);
if ( keystate[SDLK_DOWN])y++;
if ( keystate[SDLK_UP])y--;

rect1.x = 0;
rect1.y = 0;
rect1.w = 1024;
rect1.h = 768;

SDL_FreeSurface(screen);
SDL_BlitSurface(firstscreen,NULL,screen,&1);
SDL_Flip(screen);
}

waitkey();
SDL_ShowCursor(1);
SDL_Quit();
return 0;
}

Par contre l´ecran est tout noir.

dynoplasmma
dynoplasmma
Niveau 9
18 mai 2005 à 18:41:12

Bonjour, j´ai rechangé le programme :

  1. include < SDL/SDL.h>

SDL_Surface* screen;
SDL_Surface* fond;
SDL_Surface* barregauche;
SDL_Surface* barredroite;
SDL_Event event;

void init_SDL()
{
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(1024, 768, 32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
SDL_ShowCursor(0);
}

SDL_Rect Rect(int x,int y,int w=0,int h=0)
{
SDL_Rect r;
r.x=x;
r.y=y;
r.w=w;
r.h=h;
return r;
}

SDL_Surface* LoadBMP(char* fichier,int vram=1)
{
SDL_Surface* f = SDL_LoadBMP(fichier);
SDL_Surface* r=NULL;
if ( vram)
r=SDL_CreateRGBSurface(SDL_HWSURFACE, f->w, f->h, 32, 0, 0, 0, 0);
if ( r==NULL) vram=0;
if ( !vram)
r=SDL_CreateRGBSurface(SDL_SWSURFACE, f->w, f->h, 32, 0, 0, 0, 0);
SDL_Rect R=Rect(0,0,f->w,f->h);
SDL_BlitSurface(f,NULL,r,&);
SDL_FreeSurface(f);
return r;
}

int main(int argc , char **argv)
{
int s=1;
int sx=1,sy=1;
SDL_Rect rect1;
int fini=0;
init_SDL();

fond=LoadBMP("fond.bmp");
rect1.x = 0;
rect1.y = 0;

barregauche=LoadBMP("barre joueur 1.bmp",0);
rect1.x=20;
rect1.y=333;
SDL_SetColorKey(barregauche,SDL_SRCCOLORKEY , SDL_MapRGBA(barregauche->format,255,0,255,0));

barregauche=LoadBMP("barre joueur 2.bmp",0);
rect1.x=120;
rect1.y=333;
SDL_SetColorKey(barredroite,SDL_SRCCOLORKEY , SDL_MapRGBA(barredroite->format,255,0,255,0));

while(1)
{
SDL_PollEvent(&);
if ( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN)
break;
if ( event.type == SDL_KEYDOWN)
{
if ( event.key.keysym.sym == SDLK_UP) rect1.y-=3;
if ( event.key.keysym.sym == SDLK_DOWN) rect1.y+=3;
}
SDL_BlitSurface(fond,NULL,screen,NULL);
SDL_BlitSurface(barregauche,NULL,screen,&1);
SDL_BlitSurface(barredroite,NULL,screen,&1);
SDL_Flip(screen);
}
SDL_ShowCursor(1);
SDL_Quit();
return 0;
}

Aucune erreurs, mais quand je compile, l´ecran reste noir 1 seconde, puis revient a l´etat d´origine. :svp: , repondez moi.

Sous forums
  • Aide à l'achat Mac
  • Création de sites web
  • Internet
  • Macintosh
  • Création de Jeux
  • Linux
  • Programmation
  • Steam Deck
  • Hardware
La vidéo du moment