begin process at 2012 05 27 20:07:28
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Jeux

 > JEU : ATTRAPE MOI !

JEU : ATTRAPE MOI !


 Information sur la source

Note :
9 / 10 - par 1 personne
9,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Jeux Classé sous :JEU, Language C, SDL, Debutant, Attrape Niveau :Débutant Date de création :29/04/2009 Vu / téléchargé :3 545 / 315

Auteur : Passio

Ecrire un message privé
Site perso
Commentaire sur cette source (6)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
Un jeu sympathique (SDL), une map est créée, à certains endroits sont disposés des arbustes. Il y a un petit fantôme rouge qui démarre dans un coin de la MAP, et dans l'autre coin, un petit chevalier avec une épée et un bouclier.

Chaque joueur incarne un personnage et peu se déplacer sur la map selon un système de cases. Le but pour le chevalier, c'est d'attraper le fantôme, et le but du fantôme c'est de lui échapper... Pour celà, les deux joueurs disposes chacun de petits pouvoir, le fantôme passe "sous" les arbres, tandis que le chevalier passe "SUR" les arbres... Le fantôme peut se dédoubler, le chevalier lui peu poser des mines, se transforer en arbre lui même ou bien encore inverser la map...
(3 semaines de programmation en C et 2 jour d'apprentissage à la SDL)

Source

  • #include <stdlib.h>
  • #include <stdio.h>
  • #include <SDL/SDL.h>
  • #include <FMOD/fmod.h>
  • #define TAILLE_BLOC 48
  • # define NB_BLOCS_HAUTEUR 14
  • # define NB_BLOCS_LARGEUR 18
  • #define LARGEUR_FENETRE TAILLE_BLOC * NB_BLOCS_LARGEUR
  • #define HAUTEUR_FENETRE TAILLE_BLOC * NB_BLOCS_HAUTEUR
  • enum {VIDE, ARBRE, DYNAMITE};
  • int main(int argc, char *argv[])
  • {
  • long i;
  • long j = 0;
  • int carte[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR] = {VIDE, VIDE, ARBRE, ARBRE, VIDE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, ARBRE, VIDE, VIDE, VIDE,VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, VIDE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, VIDE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, VIDE, ARBRE, VIDE, VIDE};
  • int fin = 0;
  • int choix = 0;
  • int transphormation = 7;
  • int bouger = 20;
  • int inverser = 2;
  • int coupFantome = 0;
  • int dedoublement = 2;
  • int bombeEnPlace = 0;
  • SDL_Rect position;
  • SDL_Rect positionPersonnage;
  • SDL_Rect positionFantome;
  • SDL_Rect positionLeurre;
  • SDL_Rect positionDynamite;
  • positionFantome.x = 0;
  • positionFantome.y = 0;
  • positionDynamite.x = 1555;
  • positionDynamite.y = 1555;
  • SDL_Rect positionFin;
  • positionFin.x = (LARGEUR_FENETRE/2) - (529/2);
  • positionFin.y = (HAUTEUR_FENETRE/2) - (73/2);
  • int continuer = 0;
  • SDL_Event event;
  • SDL_Surface *ecran = NULL;
  • ecran = SDL_SetVideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_HWSURFACE);
  • SDL_WM_SetIcon(SDL_LoadBMP("maison.bmp"), NULL);
  • SDL_WM_SetCaption("Attrape moi si tu peux !", NULL);
  • SDL_Surface *arbre = NULL;
  • SDL_Surface *personnage = NULL;
  • SDL_Surface *fantome = NULL;
  • SDL_Surface *fantomeHAUT = NULL;
  • SDL_Surface *fantomeBAS = NULL;
  • SDL_Surface *fantomeGAUCHE = NULL;
  • SDL_Surface *fantomeDROITE = NULL;
  • SDL_Surface *Fin = NULL;
  • SDL_Surface *dynamite = NULL;
  • SDL_Surface *commandes = NULL;
  • arbre = SDL_LoadBMP("arbre.bmp");
  • personnage = SDL_LoadBMP("personnage.bmp");
  • fantomeHAUT = SDL_LoadBMP("fantomeHAUT.bmp");
  • fantomeBAS = SDL_LoadBMP("fantomeBAS.bmp");
  • fantomeGAUCHE = SDL_LoadBMP("fantomeGAUCHE.bmp");
  • fantomeDROITE = SDL_LoadBMP("fantomeDROITE.bmp");
  • Fin = SDL_LoadBMP("fin.bmp");
  • fantome = fantomeDROITE;
  • dynamite = SDL_LoadBMP("dynamite.bmp");
  • commandes = SDL_LoadBMP("commandes.bmp");
  • SDL_Init(SDL_INIT_VIDEO | SDL_DOUBLEBUF | SDL_INIT_AUDIO);
  • FSOUND_Init(44100, 32, 0);
  • FSOUND_STREAM *musique = NULL;
  • musique = FSOUND_Stream_Open("musique.mp3", 0, 0, 0);
  • FSOUND_Stream_Play(FSOUND_FREE, musique);
  • FSOUND_SetVolume(FSOUND_ALL, 120);
  • positionPersonnage.x = NB_BLOCS_LARGEUR*TAILLE_BLOC - TAILLE_BLOC;
  • positionPersonnage.y = NB_BLOCS_HAUTEUR*TAILLE_BLOC - TAILLE_BLOC;
  • while (!continuer)
  • {
  • SDL_WaitEvent (&event);
  • switch (event.type)
  • {
  • case SDL_QUIT:
  • continuer = 1;
  • break;
  • case SDL_KEYDOWN:
  • continuer = 1;
  • break;
  • }
  • SDL_BlitSurface(commandes, NULL, ecran, &positionFantome);
  • SDL_Flip(ecran);
  • }
  • while(continuer)
  • {
  • coupFantome--;
  • SDL_WaitEvent (&event);
  • switch (event.type)
  • {
  • case SDL_QUIT:
  • continuer = 0;
  • break;
  • case SDL_KEYDOWN:
  • switch(event.key.keysym.sym)
  • {
  • //COMMANDES DU JEU
  • case SDLK_SPACE:
  • ecran = SDL_SetVideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_HWSURFACE | SDL_FULLSCREEN);
  • break;
  • case SDLK_ESCAPE:
  • ecran = SDL_SetVideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_HWSURFACE );
  • break;
  • case SDLK_DELETE:
  • if (dedoublement)
  • {
  • coupFantome = 60;
  • dedoublement--;
  • }
  • break;
  • case SDLK_UP:
  • fantome = fantomeHAUT;
  • positionFantome.y = positionFantome.y-TAILLE_BLOC;
  • break;
  • case SDLK_DOWN:
  • fantome = fantomeBAS;
  • if(positionFantome.y < HAUTEUR_FENETRE - TAILLE_BLOC)
  • positionFantome.y = positionFantome.y+TAILLE_BLOC;
  • break;
  • case SDLK_RIGHT:
  • fantome = fantomeDROITE;
  • if(positionFantome.x < LARGEUR_FENETRE - TAILLE_BLOC)
  • positionFantome.x = positionFantome.x+TAILLE_BLOC;
  • break;
  • case SDLK_LEFT:
  • fantome = fantomeGAUCHE;
  • positionFantome.x = positionFantome.x-TAILLE_BLOC;
  • break;
  • case SDLK_q:
  • transphormation = transphormation - 1;
  • if (transphormation > 0)
  • {
  • if (personnage ==arbre)
  • personnage = SDL_LoadBMP("personnage.bmp");
  • else
  • {
  • personnage = arbre;
  • }
  • }
  • break;
  • case SDLK_TAB:
  • if(inverser)
  • {
  • for (j = 0; j < NB_BLOCS_HAUTEUR; j++)
  • {
  • for (i = 0; i < NB_BLOCS_LARGEUR; i++)
  • {
  • position.x = i*TAILLE_BLOC;
  • position.y = j*TAILLE_BLOC;
  • if( carte[i][j] == ARBRE )
  • {
  • carte[i][j] = VIDE;
  • }
  • else if( carte[i][j] == VIDE )
  • {
  • carte[i][j] = ARBRE;
  • }
  • }
  • }
  • inverser--;
  • }
  • break;
  • case SDLK_e:
  • bombeEnPlace++;
  • positionDynamite.x = positionPersonnage.x;
  • positionDynamite.y = positionPersonnage.y;
  • break;
  • case SDLK_w:
  • if (personnage ==arbre)
  • bouger--;
  • if(!bouger)
  • {personnage = SDL_LoadBMP("personnage.bmp");
  • bouger = 15;
  • }
  • positionPersonnage.y = positionPersonnage.y-TAILLE_BLOC;
  • break;
  • case SDLK_s:
  • if (personnage ==arbre)
  • bouger--;
  • if(!bouger)
  • {personnage = SDL_LoadBMP("personnage.bmp");
  • bouger = 15;
  • }
  • if(positionPersonnage.y < HAUTEUR_FENETRE - TAILLE_BLOC)
  • positionPersonnage.y = positionPersonnage.y+TAILLE_BLOC;
  • break;
  • case SDLK_d:
  • if (personnage ==arbre)
  • bouger--;
  • if(!bouger)
  • {personnage = SDL_LoadBMP("personnage.bmp");
  • bouger = 15;
  • }
  • if(positionPersonnage.x < LARGEUR_FENETRE - TAILLE_BLOC)
  • positionPersonnage.x = positionPersonnage.x+TAILLE_BLOC;
  • break;
  • case SDLK_a:
  • if (personnage ==arbre)
  • bouger--;
  • if(!bouger)
  • {personnage = SDL_LoadBMP("personnage.bmp");
  • bouger = 15;
  • }
  • positionPersonnage.x = positionPersonnage.x-TAILLE_BLOC;
  • break;
  • }
  • break;
  • }
  • positionLeurre.x = positionFantome.x + TAILLE_BLOC + TAILLE_BLOC;
  • positionLeurre.y = positionFantome.y + TAILLE_BLOC;
  • SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
  • SDL_BlitSurface(personnage, NULL, ecran, &positionPersonnage);
  • SDL_BlitSurface(dynamite, NULL, ecran, &positionDynamite);
  • SDL_BlitSurface(fantome, NULL, ecran, &positionFantome);
  • if (coupFantome >0)
  • SDL_BlitSurface(fantome, NULL, ecran, &positionLeurre);
  • for (j = 0; j < NB_BLOCS_HAUTEUR; j++)
  • {
  • for (i = 0; i < NB_BLOCS_LARGEUR; i++)
  • {
  • position.x = i*TAILLE_BLOC;
  • position.y = j*TAILLE_BLOC;
  • if (carte[j][i] == ARBRE)
  • {
  • SDL_BlitSurface(arbre, NULL, ecran, &position);
  • }
  • }
  • }
  • SDL_BlitSurface(dynamite, NULL, ecran, &positionDynamite);
  • SDL_BlitSurface(personnage, NULL, ecran, &positionPersonnage);
  • SDL_Flip(ecran);
  • if((positionLeurre.y == positionPersonnage.y && positionLeurre.x == positionPersonnage.x) || (positionLeurre.y == positionDynamite.y && positionLeurre.x == positionDynamite.x))
  • {
  • coupFantome = 0;
  • positionDynamite.x = 2000;
  • }
  • if ((positionFantome.y == positionPersonnage.y && positionFantome.x == positionPersonnage.x) || (positionDynamite.y == positionFantome.y && positionDynamite.x == positionFantome.x))
  • {
  • for (i=0; i < 500; i++)
  • {
  • SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
  • SDL_BlitSurface(Fin, NULL, ecran, &positionFin);
  • SDL_Flip(ecran);
  • positionPersonnage.x = NB_BLOCS_LARGEUR*TAILLE_BLOC - TAILLE_BLOC;
  • positionPersonnage.y = NB_BLOCS_HAUTEUR*TAILLE_BLOC - TAILLE_BLOC;
  • positionFantome.x = 0;
  • positionFantome.y = 0;
  • }
  • transphormation = 7;
  • bouger = 15;
  • inverser = 4;
  • coupFantome = 0;
  • dedoublement = 1;
  • positionDynamite.x = 1500;
  • }
  • }
  • //liberation de la memoire a faire ou pas (je viens de le voir et j'ai fait ça il y a longtemps)
  • SDL_Quit();
  • FSOUND_Close();
  • return EXIT_SUCCESS;
  • }
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <FMOD/fmod.h>



#define TAILLE_BLOC         48
# define NB_BLOCS_HAUTEUR  14
# define NB_BLOCS_LARGEUR  18
#define LARGEUR_FENETRE     TAILLE_BLOC * NB_BLOCS_LARGEUR
#define HAUTEUR_FENETRE     TAILLE_BLOC * NB_BLOCS_HAUTEUR
enum {VIDE, ARBRE, DYNAMITE};



int main(int argc, char *argv[])
{
    long i;
    long j = 0;
    int carte[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR] = {VIDE, VIDE, ARBRE, ARBRE, VIDE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, VIDE, ARBRE, VIDE, VIDE, VIDE,VIDE, ARBRE, ARBRE, ARBRE, ARBRE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, VIDE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, VIDE, ARBRE, VIDE, VIDE, VIDE, ARBRE, ARBRE, ARBRE, VIDE, VIDE, ARBRE, ARBRE, VIDE, VIDE, VIDE, VIDE, VIDE, ARBRE, VIDE, VIDE};
    int fin = 0;
    int choix = 0;
    int transphormation = 7;
    int bouger = 20;
    int inverser = 2;
    int coupFantome = 0;
    int dedoublement = 2;
    int bombeEnPlace = 0;


    SDL_Rect position;
    SDL_Rect positionPersonnage;
    SDL_Rect positionFantome;
    SDL_Rect positionLeurre;
    SDL_Rect positionDynamite;


    positionFantome.x = 0;
    positionFantome.y = 0;

            positionDynamite.x = 1555;
            positionDynamite.y = 1555;

    SDL_Rect positionFin;
    positionFin.x = (LARGEUR_FENETRE/2) - (529/2);
    positionFin.y = (HAUTEUR_FENETRE/2) - (73/2);


    int continuer = 0;
    SDL_Event event;

    SDL_Surface *ecran = NULL;
    ecran = SDL_SetVideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_HWSURFACE);
    SDL_WM_SetIcon(SDL_LoadBMP("maison.bmp"), NULL);
    SDL_WM_SetCaption("Attrape moi si tu peux !", NULL);

    SDL_Surface *arbre = NULL;
    SDL_Surface *personnage = NULL;
    SDL_Surface *fantome = NULL;
    SDL_Surface *fantomeHAUT = NULL;
    SDL_Surface *fantomeBAS = NULL;
    SDL_Surface *fantomeGAUCHE = NULL;
    SDL_Surface *fantomeDROITE = NULL;
    SDL_Surface *Fin = NULL;
    SDL_Surface *dynamite = NULL;
    SDL_Surface *commandes = NULL;

    arbre = SDL_LoadBMP("arbre.bmp");
    personnage = SDL_LoadBMP("personnage.bmp");
    fantomeHAUT = SDL_LoadBMP("fantomeHAUT.bmp");
    fantomeBAS = SDL_LoadBMP("fantomeBAS.bmp");
    fantomeGAUCHE = SDL_LoadBMP("fantomeGAUCHE.bmp");
    fantomeDROITE = SDL_LoadBMP("fantomeDROITE.bmp");
    Fin = SDL_LoadBMP("fin.bmp");
    fantome = fantomeDROITE;
    dynamite = SDL_LoadBMP("dynamite.bmp");
    commandes = SDL_LoadBMP("commandes.bmp");





    SDL_Init(SDL_INIT_VIDEO | SDL_DOUBLEBUF | SDL_INIT_AUDIO);
    FSOUND_Init(44100, 32, 0);
    FSOUND_STREAM *musique = NULL;
    musique = FSOUND_Stream_Open("musique.mp3", 0, 0, 0);
    FSOUND_Stream_Play(FSOUND_FREE, musique);
    FSOUND_SetVolume(FSOUND_ALL, 120);











    positionPersonnage.x = NB_BLOCS_LARGEUR*TAILLE_BLOC - TAILLE_BLOC;
    positionPersonnage.y = NB_BLOCS_HAUTEUR*TAILLE_BLOC - TAILLE_BLOC;

    while (!continuer)
    {

    SDL_WaitEvent (&event);

        switch (event.type)
        {
            case SDL_QUIT:
            continuer = 1;
            break;
        case SDL_KEYDOWN:
        continuer = 1;
        break;
        }
        SDL_BlitSurface(commandes, NULL, ecran, &positionFantome);
        SDL_Flip(ecran);
    }




    while(continuer)
    {
        coupFantome--;
    SDL_WaitEvent (&event);

        switch (event.type)
        {
            case SDL_QUIT:
            continuer = 0;
            break;
        case SDL_KEYDOWN:
        switch(event.key.keysym.sym)
        {

            //COMMANDES DU JEU




            case SDLK_SPACE:
            ecran = SDL_SetVideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_HWSURFACE | SDL_FULLSCREEN);
            break;

            case SDLK_ESCAPE:
            ecran = SDL_SetVideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_HWSURFACE );
            break;




            case SDLK_DELETE:
            if (dedoublement)
            {
            coupFantome = 60;
            dedoublement--;
            }
            break;


            case SDLK_UP:
            fantome = fantomeHAUT;
            positionFantome.y = positionFantome.y-TAILLE_BLOC;
            break;


            case SDLK_DOWN:
            fantome = fantomeBAS;
            if(positionFantome.y < HAUTEUR_FENETRE - TAILLE_BLOC)
            positionFantome.y = positionFantome.y+TAILLE_BLOC;
            break;

            case SDLK_RIGHT:
            fantome = fantomeDROITE;
            if(positionFantome.x < LARGEUR_FENETRE - TAILLE_BLOC)
            positionFantome.x = positionFantome.x+TAILLE_BLOC;
            break;


            case SDLK_LEFT:
            fantome = fantomeGAUCHE;
            positionFantome.x = positionFantome.x-TAILLE_BLOC;
            break;

            case SDLK_q:
            transphormation = transphormation - 1;
            if (transphormation > 0)
            {
                if (personnage ==arbre)
                personnage = SDL_LoadBMP("personnage.bmp");

            else
            {
            personnage = arbre;
            }
            }

            break;


            case SDLK_TAB:
            if(inverser)
            {

        for (j = 0; j < NB_BLOCS_HAUTEUR; j++)
    {
        for (i = 0; i < NB_BLOCS_LARGEUR; i++)
        {


                position.x = i*TAILLE_BLOC;
                position.y = j*TAILLE_BLOC;



            if( carte[i][j] == ARBRE )
            {
            carte[i][j] = VIDE;
            }
            else if( carte[i][j] == VIDE )
            {
            carte[i][j] = ARBRE;
            }

        }
    }
    inverser--;
            }
            break;

            case SDLK_e:
            bombeEnPlace++;
            positionDynamite.x = positionPersonnage.x;
            positionDynamite.y = positionPersonnage.y;
            break;




            case SDLK_w:
                            if (personnage ==arbre)
                            bouger--;
                            if(!bouger)
                           {personnage = SDL_LoadBMP("personnage.bmp");
                            bouger = 15;
                           }

            positionPersonnage.y = positionPersonnage.y-TAILLE_BLOC;
            break;

            case SDLK_s:
                                        if (personnage ==arbre)
                            bouger--;
                            if(!bouger)
                           {personnage = SDL_LoadBMP("personnage.bmp");
                            bouger = 15;
                           }

            if(positionPersonnage.y < HAUTEUR_FENETRE - TAILLE_BLOC)
            positionPersonnage.y = positionPersonnage.y+TAILLE_BLOC;
            break;

            case SDLK_d:
                                                    if (personnage ==arbre)
                            bouger--;
                            if(!bouger)
                           {personnage = SDL_LoadBMP("personnage.bmp");
                            bouger = 15;
                           }

            if(positionPersonnage.x < LARGEUR_FENETRE - TAILLE_BLOC)
            positionPersonnage.x = positionPersonnage.x+TAILLE_BLOC;
            break;

            case SDLK_a:
                                                    if (personnage ==arbre)
                            bouger--;
                            if(!bouger)
                           {personnage = SDL_LoadBMP("personnage.bmp");
                            bouger = 15;
                           }

            positionPersonnage.x = positionPersonnage.x-TAILLE_BLOC;
            break;
            }
        break;
        }

           positionLeurre.x  = positionFantome.x + TAILLE_BLOC + TAILLE_BLOC;
        positionLeurre.y  = positionFantome.y + TAILLE_BLOC;




SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
SDL_BlitSurface(personnage, NULL, ecran, &positionPersonnage);
SDL_BlitSurface(dynamite, NULL, ecran, &positionDynamite);
SDL_BlitSurface(fantome, NULL, ecran, &positionFantome);
    if (coupFantome >0)
SDL_BlitSurface(fantome, NULL, ecran, &positionLeurre);





    for (j = 0; j < NB_BLOCS_HAUTEUR; j++)
    {
        for (i = 0; i < NB_BLOCS_LARGEUR; i++)
        {
                position.x = i*TAILLE_BLOC;
                position.y = j*TAILLE_BLOC;


        if (carte[j][i] == ARBRE)
        {
            SDL_BlitSurface(arbre, NULL, ecran, &position);
        }


        }
    }



SDL_BlitSurface(dynamite, NULL, ecran, &positionDynamite);
SDL_BlitSurface(personnage, NULL, ecran, &positionPersonnage);


SDL_Flip(ecran);

        if((positionLeurre.y == positionPersonnage.y && positionLeurre.x == positionPersonnage.x) || (positionLeurre.y == positionDynamite.y && positionLeurre.x == positionDynamite.x))
    {
               coupFantome = 0;
            positionDynamite.x = 2000;
    }


        if ((positionFantome.y == positionPersonnage.y && positionFantome.x == positionPersonnage.x) || (positionDynamite.y == positionFantome.y && positionDynamite.x == positionFantome.x))
        {
            for (i=0; i < 500; i++)
            {
                SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
        SDL_BlitSurface(Fin, NULL, ecran, &positionFin);
        SDL_Flip(ecran);
    positionPersonnage.x = NB_BLOCS_LARGEUR*TAILLE_BLOC - TAILLE_BLOC;
    positionPersonnage.y = NB_BLOCS_HAUTEUR*TAILLE_BLOC - TAILLE_BLOC;
    positionFantome.x = 0;
    positionFantome.y = 0;

            }
         transphormation = 7;
         bouger = 15;
         inverser = 4;
         coupFantome = 0;
         dedoublement = 1;
         positionDynamite.x = 1500;
        }
    }


//liberation de la memoire a faire ou pas (je viens de le voir et j'ai fait ça il y a longtemps) 

SDL_Quit();
FSOUND_Close();
return EXIT_SUCCESS;
    }

 Conclusion

Un jeu simple mais amusant (mes amis au Lycée sont pour ainsi dire "FAN" et on délire avec ça au CDI par exemple ^^)... Plein d'amélioration possible comme un compteur, enregistrer les scores (mais je n'avais pas appris à écrire dans des fichiers et la gestion du temps à l'époque... de plus c'est la misère pour afficher du texte il faut télécharger d'autres librairies...)

remarque : (Ajoutez musique.mp3 dans le répértoire ou se trouve le .exe pour la jouer)

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip Source avec une capture PUISSANCE QUATRE

 Sources de la même categorie

Source avec Zip Source avec une capture JEU DES CARTES par eapaceinfo
PROGRAMME DE JEU DE MPT par KerizGarmm
Source avec Zip Source avec une capture JEUX SERPENT par antho974
Source avec Zip Source avec une capture PENDU EN SDL par Damsou91
Source avec Zip STATE MACHINE MODIFICATION MATH BUCKHAM par billybones79

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture BOMBERMAN 4 PLAYERS LAN (C & SDL) par c1702
Source avec Zip Source avec une capture JEU DE NIM par layto888
Source avec Zip Source avec une capture JEU DÉMINEUR EN C++ GRAPHIQUE PARALLÈLE À CELUI DE WINDOWS par zakmanengineer
Source avec une capture JEU DE PENDU AVEC SDL, FMOD ET TTF par bad_dark_spirit
Source avec Zip Source avec une capture JEU EN SDL "LANGAGE C" par thechef

Commentaires et avis

Commentaire de cdd59554 le 29/04/2009 10:09:34

Tu tente de battre le record du plus gros main ??? Tu devrais diviser ton code en plusieurs fonctions pour le rendre plus lisible

Commentaire de swonder le 04/05/2009 11:38:05

Rigolo, j'ai envie de tester ça. Par contre, je suis pas mal rouillé en C++, mais il ne manquerait pas quelque chose dans le ZIP ? Un point EXE par exemple.

Commentaire de Renfield le 04/05/2009 15:48:18 administrateur CS

pas d'.exe dans les zip.

si tu en veux un, compile le^^

Commentaire de theWKM le 02/08/2009 14:52:43

sa ne marche pas , car quand je veux le compiler il me donne une erreur en me disant que le fichier fmod.h n'existe pas !!

Commentaire de wilhelmneko le 13/12/2009 00:52:25

Ca c' est les pbs de lib.
A toi de les dl et de les ajouter ensuite dans ton builder (windows) ou ta commande de compilation (Unix/Linux).

Commentaire de Yame0 le 30/08/2011 13:02:19 9/10

"Ca c' est les pbs de lib.
A toi de les dl et de les ajouter ensuite dans ton builder (windows) ou ta commande de compilation (Unix/Linux)."
Oui mais une fois ajouté il ne reconnait pas les commandes...

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

le dur chemin du debutant...? [ par zevince ] Salut,je decouvre ce site.. et ca a l'air bien cool et y'a l'air d'y avoir du passage.. ca tombe bien !moi : je connais bien html, xml, xslt et j'ai d Jeu mario avec SDL (problème) [ par dmontavon ] bonjour, je suis en train de fair un super mario avec SDL... J'en suis qu'au d&#233;but, j'ai d&#233;ja r&#233;ussi &#224; le faire&nbsp;avancer &#224 [SDL - OpenGL - POO] cherche collaborateurs pour jeu 2D [ par MrdJack ] salut, je projetes de faire un jeu 2D de type bomberman/dynablaster en SDL/OpenGL/POO, je cherche des programmeurs interress&#233; ayant juste des not Recrutement jeu SDL en 2D [ par toun1 ] Bonjours nous recrutons des codeurs C/C++ pour un jeu de shoot 2D en SDL.Lien: http://www.ggame.derniersmots.comJ'en profite pour mettre le lien de mo jeu sdl [ par cheikhouna ] SLT je suis debutant en sdl et j'aimerai avoir un bon projet de jeu ou d'animation 2d merci jeu SDL [ par uzixucf ] bonjour tout le monde, je suis nouveau d'entre vousje suis entrain de developper un jeu en SDL (language C)  qui se présente ainsi                     Petit Probleme SDL... [ par nahoof ] Voila, c'est le premier "vrai" programme (codé en C) que je realise et j'ai un petit problème avec la SDL :   Je suis en train de creer un jeu de poke Programme SDL qui s'arrête subitement au clic... [ par Rflx ] Bonjour, Je programme actuellement, pour mes études, un jeu labyrinthe en C++ avec interface graphique gérée avec SDL. Parfois, je peux jouer sans allocation dynamique d'un fichier en SDL [ par atefth ] Salut: Mon probléme est que j'ai un programme SDL qui utilise enormement de la mémoire. Je pensais alors : D'utiliser une allocation dynamique pour me


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,671 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales