diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2010-09-12 15:26:06 +0000 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2010-09-12 15:26:06 +0000 |
commit | 2e9827660d5d9fc821d64243c88b8dacd189fdd0 (patch) | |
tree | d950a6ec4d2e7f3867c4156d02fb6a8c0c632e97 | |
parent | 19ecfb8c29a6f105c25e887531072332e29c000c (diff) | |
download | 2010-netlemmings-2e9827660d5d9fc821d64243c88b8dacd189fdd0.tar.gz 2010-netlemmings-2e9827660d5d9fc821d64243c88b8dacd189fdd0.tar.bz2 2010-netlemmings-2e9827660d5d9fc821d64243c88b8dacd189fdd0.zip |
Recompilation en 32 bits de tetris et ajout d'un test DSL : la musique marche, la gestion clavier aussi, mais le son encore. Le mec d'alien avait fait ça comme un goré d'après la doc
git-svn-id: file:///var/svn/2010-netlemmings/trunk@16 077b3477-7977-48bd-8428-443f22f7bfda
-rwxr-xr-x | doc/dependances-ubuntu.sh | 2 | ||||
-rwxr-xr-x | jeu-test/tetris_lan_src/tetris | bin | 193510 -> 162596 bytes | |||
-rwxr-xr-x | sdl-test/compil.sh | 2 | ||||
-rw-r--r-- | sdl-test/main.c | 305 |
4 files changed, 309 insertions, 0 deletions
diff --git a/doc/dependances-ubuntu.sh b/doc/dependances-ubuntu.sh new file mode 100755 index 0000000..19d633b --- /dev/null +++ b/doc/dependances-ubuntu.sh @@ -0,0 +1,2 @@ +#!/bin/sh +aptitude install libsdl1.2-dev libsdl-mixer1.2-dev libsdl-image1.2-dev libsdl-net1.2-dev diff --git a/jeu-test/tetris_lan_src/tetris b/jeu-test/tetris_lan_src/tetris Binary files differindex 1b84aa1..1300100 100755 --- a/jeu-test/tetris_lan_src/tetris +++ b/jeu-test/tetris_lan_src/tetris diff --git a/sdl-test/compil.sh b/sdl-test/compil.sh new file mode 100755 index 0000000..21cb9a3 --- /dev/null +++ b/sdl-test/compil.sh @@ -0,0 +1,2 @@ +#/bin/sh +gcc -I/usr/include/SDL -lSDL_mixer -lSDL_image -g -o main main.c diff --git a/sdl-test/main.c b/sdl-test/main.c new file mode 100644 index 0000000..8b344e3 --- /dev/null +++ b/sdl-test/main.c @@ -0,0 +1,305 @@ +#include <stdlib.h> +#include <stdio.h> +#include <time.h> + +#include "SDL.h" +#include "SDL_mixer.h" +#include "SDL_image.h" + +#define RESS_PATH "../" +#define FPS 12 +#define NUM_WAVES 24 +#define NUM_MIDIS 27 + +char midi_names[NUM_MIDIS][8] = { +"awesome","beastii","beasti","cancan","doggie","lemming1","lemming2","lemming3", +"menace","mountain","tenlemms","tim1","tim2","tim3","tim4","tim5","tim6","tim7", +"tim8","tim9","tim10","tune1","tune2","tune3","tune4","tune5","tune6" +}; +char sound_names[NUM_WAVES][8] = { +"BANG","CHAIN","CHANGEOP","CHINK","DIE","DOOR","ELECTRIC","EXPLODE", +"FIRE","GLUG","LETSGO","MANTRAP","MOUSEPRE","OHNO","OING","SCRAPE", +"SLICER","SPLASH","SPLAT","TENTON","THUD","THUNK","TING","YIPPEE" +}; + +SDL_Surface *screen; +SDL_Surface *background; +/* +#define MAX_UPDATES 3*(1+MAX_SHOTS+MAX_ALIENS) +int numupdates; +SDL_Rect srcupdate[MAX_UPDATES]; +SDL_Rect dstupdate[MAX_UPDATES]; +struct blit { + SDL_Surface *src; + SDL_Rect *srcrect; + SDL_Rect *dstrect; +} blits[MAX_UPDATES]; +*/ + +Mix_Music *music; +Mix_Chunk *sounds[NUM_WAVES]; + + +SDL_Surface *LoadImage(char *datafile, int transparent) { + SDL_Surface *image, *surface; + + image = IMG_Load(datafile); + if ( image == NULL ) { + fprintf(stderr, "Couldn't load image %s: %s\n", + datafile, IMG_GetError()); + return(NULL); + } + if ( transparent ) { + /* Assuming 8-bit BMP image */ + SDL_SetColorKey(image, (SDL_SRCCOLORKEY|SDL_RLEACCEL), + *(Uint8 *)image->pixels); + } + surface = SDL_DisplayFormat(image); + SDL_FreeSurface(image); + return(surface); +} + +void path(char *filepath, char type[], char name[], char ext[]) { + //XXX : ajouter une variable pour la taille de la chaine de sortie pour eviter les buffer overflow + strcpy(filepath,RESS_PATH); + strcat(filepath,type); + strcat(filepath,"/"); + strcat(filepath,name); + strcat(filepath,"."); + strcat(filepath,ext); +} + + +int LoadData(int musicnum, int theme) +{ + int i; + char filepath[255]; + + //SDL_Surface *firstShot; + + /* Load sounds */ + path(filepath,"music",midi_names[musicnum],"mod"); + music = Mix_LoadMUS(filepath); + if ( music == NULL ) { + fprintf(stderr, "Warning: Couldn't load music: %s\n", + Mix_GetError()); + } + + for (i=0;i<NUM_WAVES;i++) { + path(filepath,"sound",sound_names[i],"WAV"); + sounds[i] = Mix_LoadWAV(filepath); + //FIXME : test retour + } + + /* Load graphics */ + background = LoadImage("../jeu-test/aliens-1.0.2/data/background.gif", 0); + + /* Set up the update rectangle pointers + for ( i=0; i<MAX_UPDATES; ++i ) { + blits[i].srcrect = &srcupdate[i]; + blits[i].dstrect = &dstupdate[i]; + } + */ + + return 0; +} + +void FreeData(void) +{ + int i; + + /* Free sounds */ + Mix_FreeMusic(music); + for ( i=0; i<NUM_WAVES; ++i ) { + Mix_FreeChunk(sounds[i]); + } + + /* Free graphics */ + SDL_FreeSurface(background); +} +/* +void DrawObject(object *sprite) +{ + struct blit *update; + + update = &blits[numupdates++]; + update->src = sprite->image; + update->srcrect->x = 0; + update->srcrect->y = 0; + update->srcrect->w = sprite->image->w; + update->srcrect->h = sprite->image->h; + update->dstrect->x = sprite->x; + update->dstrect->y = sprite->y; + update->dstrect->w = sprite->image->w; + update->dstrect->h = sprite->image->h; +} +void EraseObject(object *sprite) +{ + struct blit *update; + int wrap; + + // The background wraps horizontally across the screen + update = &blits[numupdates++]; + update->src = background; + update->srcrect->x = sprite->x%background->w; + update->srcrect->y = sprite->y; + update->srcrect->w = sprite->image->w; + update->srcrect->h = sprite->image->h; + wrap = (update->srcrect->x+update->srcrect->w)-(background->w); + if ( wrap > 0 ) { + update->srcrect->w -= wrap; + } + update->dstrect->x = sprite->x; + update->dstrect->y = sprite->y; + update->dstrect->w = update->srcrect->w; + update->dstrect->h = update->srcrect->h; + + // Assuming sprites can only wrap across one background tile + if ( wrap > 0 ) { + update = &blits[numupdates++]; + update->src = background; + update->srcrect->x = 0; + update->srcrect->y = sprite->y; + update->srcrect->w = wrap; + update->srcrect->h = sprite->image->h; + update->dstrect->x =((sprite->x/background->w)+1)*background->w; + update->dstrect->y = sprite->y; + update->dstrect->w = update->srcrect->w; + update->dstrect->h = update->srcrect->h; + } +} +void UpdateScreen(void) +{ + int i; + + for ( i=0; i<numupdates; ++i ) { + SDL_LowerBlit(blits[i].src, blits[i].srcrect, + screen, blits[i].dstrect); + } + SDL_UpdateRects(screen, numupdates, dstupdate); + numupdates = 0; +} +*/ + +void WaitFrame(void) +{ + static Uint32 next_tick = 0; + Uint32 this_tick; + + /* Wait for the next frame */ + this_tick = SDL_GetTicks(); + if ( this_tick < next_tick ) { + SDL_Delay(next_tick-this_tick); + } + next_tick = this_tick + (1000/FPS); +} + +/* This of course can be optimized :-) */ +void RunGame(void) +{ + int i,j,k; + SDL_Event event; + Uint8 *keys; + + /* Paint the background */ + //numupdates = 0; + for ( i=0; i<screen->w; i += background->w ) { + SDL_Rect dst; + + dst.x = i; + dst.y = 0; + dst.w = background->w; + dst.h = background->h; + SDL_BlitSurface(background, NULL, screen, &dst); + } + SDL_UpdateRect(screen, 0, 0, 0, 0); + + /* Start the music */ + Mix_PlayMusic(music, -1); + + /* Initialize the objects */ + + + //UpdateScreen(); + + while ( 1 ) { + /* Wait for the next frame */ + WaitFrame(); + + /* Poll input queue, run keyboard loop */ + while ( SDL_PollEvent(&event) ) { + switch(event.type) { + case SDL_QUIT: + return; + break; + case SDL_KEYDOWN: + case SDL_KEYUP: + // TODO : procédure qui traite les events clavier et qui met à jour l'état du jeu + switch( event.key.keysym.sym ){ + case SDLK_q: + return; + break; + default: + break; + } + default: + break; + } + } + + + //UpdateScreen(); + + } + + Mix_PlayChannel(1, sounds[NUM_WAVES-1], 0); + + SDL_delay(1000); + + Mix_HaltChannel(-1); + return; +} + +main(int argc, char *argv[]) { + int res; + + /* Initialize the SDL library */ + if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) { + fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); + exit(2); + } + atexit(SDL_Quit); + + /* Open the audio device */ + if ( Mix_OpenAudio(11025, AUDIO_U8, 1, 512) < 0 ) { + fprintf(stderr, + "Warning: Couldn't set 11025 Hz 8-bit audio\n- Reason: %s\n", + SDL_GetError()); + } + + /* Open the display device */ + //FIXME : mettre la bonne résolution ! + screen = SDL_SetVideoMode(640, 480, 0, SDL_SWSURFACE); + if ( screen == NULL ) { + fprintf(stderr, "Couldn't set 640x480 video mode: %s\n", + SDL_GetError()); + exit(2); + } + + /* Initialize the random number generator */ + srandom(time(NULL)); + + /* Load the music and artwork */ + res=LoadData(random()%NUM_MIDIS,0); + if ( res != 0 ) { exit(res); } + + /* Run the game */ + RunGame(); + + /* Free the music and artwork */ + FreeData(); + + /* Quit */ + Mix_CloseAudio(); + exit(0); +} |