Téléverser les fichiers vers "/"
This commit is contained in:
164
sdl-glisseur_dots_42.c
Normal file
164
sdl-glisseur_dots_42.c
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "SDL.h"
|
||||||
|
#include "SDL_image.h"
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
#define SDL_VIDEO_FLAGS (SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT | SDL_RESIZABLE)
|
||||||
|
|
||||||
|
|
||||||
|
#define LARGEUR 70
|
||||||
|
#define HAUTEUR 70
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void process_events( void ){
|
||||||
|
|
||||||
|
//#define LARGEUR 26
|
||||||
|
//#define HAUTEUR 16
|
||||||
|
|
||||||
|
//#define LARGEUR 166
|
||||||
|
//#define HAUTEUR 100
|
||||||
|
|
||||||
|
|
||||||
|
/* Our SDL event placeholder. */
|
||||||
|
SDL_Event event;
|
||||||
|
|
||||||
|
/* Grab all the events off the queue. */
|
||||||
|
while( SDL_PollEvent( &event ) ) {
|
||||||
|
switch( event.type ) {
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
/* Handle key presses. */
|
||||||
|
if((&event.key.keysym) ->sym == SDLK_ESCAPE){
|
||||||
|
SDL_Quit();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_QUIT:
|
||||||
|
/* Handle quit requests (like Ctrl-c). */
|
||||||
|
SDL_Quit();
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char * argv[]){
|
||||||
|
SDL_Surface * screen;
|
||||||
|
SDL_Surface * dots[16];
|
||||||
|
char filename[16];
|
||||||
|
unsigned char wall[LARGEUR][HAUTEUR];
|
||||||
|
int i, j;
|
||||||
|
unsigned char n, nn, direction;
|
||||||
|
|
||||||
|
for(i=0;i<16;i++){
|
||||||
|
sprintf(filename,"dots/%X.png",i);
|
||||||
|
dots[i]= IMG_Load(filename);
|
||||||
|
if(!dots[i]){
|
||||||
|
printf ( "IMG_Load: %s\n", IMG_GetError () );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(i=0;i<LARGEUR;i++){
|
||||||
|
for(j=0;j<HAUTEUR;j++){
|
||||||
|
wall[i][j]= 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (SDL_Init(SDL_INIT_VIDEO) == -1){
|
||||||
|
printf("Erreur lors de l'initialisation de SDL: %s\n", SDL_GetError());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
screen = SDL_SetVideoMode(LARGEUR*10, HAUTEUR*10, 24, SDL_VIDEO_FLAGS);
|
||||||
|
printf("Mode video: %dx%dx%d\n", screen->w, screen->h,
|
||||||
|
screen->format->BitsPerPixel);
|
||||||
|
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0)) ;
|
||||||
|
|
||||||
|
// i=13;
|
||||||
|
// j=7;
|
||||||
|
i=LARGEUR / 2;
|
||||||
|
j=(HAUTEUR / 2) -1;
|
||||||
|
|
||||||
|
direction=1;
|
||||||
|
while (1) {
|
||||||
|
if(DEBUG) printf("pos %d / %d col : %d !!! \n",i,j,wall[i][j]);
|
||||||
|
//wall[i][j]= (wall[i][j]+1)%16;
|
||||||
|
n=wall[i][j];
|
||||||
|
switch(n){
|
||||||
|
case 0:
|
||||||
|
nn=7;
|
||||||
|
direction=direction+3;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
nn=11;
|
||||||
|
direction=direction+1;
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
nn=15;
|
||||||
|
direction=direction+1;
|
||||||
|
break;
|
||||||
|
case 15:
|
||||||
|
nn=0;
|
||||||
|
direction=direction+3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
wall[i][j]=nn;
|
||||||
|
direction = direction % 4;
|
||||||
|
SDL_Rect dest={10*i,10*j,0,0};
|
||||||
|
//SDL_BlitSurface(dots[n],NULL,screen,&dest);
|
||||||
|
SDL_BlitSurface(dots[nn],NULL,screen,&dest);
|
||||||
|
//direction = (direction+1 + 2*(((nn/4 )%2))) % 4;
|
||||||
|
|
||||||
|
SDL_UpdateRect(screen,10*i,10*j,10,10);
|
||||||
|
if(DEBUG) printf("direction=%i\n",direction);
|
||||||
|
switch(direction){
|
||||||
|
case 0:
|
||||||
|
j=j-1;
|
||||||
|
if (j<0) {
|
||||||
|
//j=15;
|
||||||
|
j=HAUTEUR -1 ;
|
||||||
|
//direction=direction+2;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
i=i+1;
|
||||||
|
//if (i>25) {
|
||||||
|
if (i> (LARGEUR - 1)) {
|
||||||
|
i=0;
|
||||||
|
//direction=direction+2;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
j=j+1;
|
||||||
|
//if (j>15) {
|
||||||
|
if (j>(HAUTEUR -1)) {
|
||||||
|
j=0;
|
||||||
|
//direction=direction+2;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
i=i-1;
|
||||||
|
if (i<0) {
|
||||||
|
//i=25;
|
||||||
|
i=LARGEUR - 1;
|
||||||
|
//direction=direction+2;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
direction = direction % 4;
|
||||||
|
SDL_Flip(screen);
|
||||||
|
process_events();
|
||||||
|
usleep(2);
|
||||||
|
}
|
||||||
|
SDL_Quit();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user