summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdoc/dependances-ubuntu.sh2
-rwxr-xr-xjeu-test/tetris_lan_src/tetrisbin193510 -> 162596 bytes
-rwxr-xr-xsdl-test/compil.sh2
-rw-r--r--sdl-test/main.c305
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
index 1b84aa1..1300100 100755
--- a/jeu-test/tetris_lan_src/tetris
+++ b/jeu-test/tetris_lan_src/tetris
Binary files differ
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);
+}