jQuery
En savoir plus
Adobe Flex & Flash
En savoir plus
ASP.NET
En savoir plus

Inscris-toi au e-camp "Héberge ton jeu Facebook sur Azure" de Microsoft vendredi 25 mai à 13h30 !
Le problème de ce sujet a été résolu
| Page 1 2 3 4 ... 31 32 33 34 Suivante | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Auteur | Message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 visiteur sur ce sujet (1 Anonyme) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Page 1 2 3 4 ... 31 32 33 34 Suivante | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
paraze
|
# Posté le 05/02/2011 à 19:32:59 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Tiësto is the best![]()
Ville : Gex |
The first, la liberté...
The second, la restriction... The third, La SDL ! Puisqu'il n'y a pas eu de pseudo-vrai-concours-non-officiel depuis un petit bout de temps, je vous propose d'en créer un qui consiste à créer un programme utilisant la !En effet, j'ai pu constater dans les deux concours lancés par camboui, que plusieurs zéros voulaient en avoir un concernant la SDL. Un concours SDL est très instructif, les membres de ce site l'ont bien compris.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Créateur | Programme | Topic d'avancement du projet |
|---|---|---|
| schadocalex | Delthera (dèltéra) | NULL |
| Tixlegeek | Matixlegeek | Existant |
| perimgui | Tours de Hanoï | Existant |
| lucas-84 | Zério, le Mario du Site du Zéro | Existant |
| Keriz | Zpong | Existant |
| yoch | démineur | NULL |
| sydzero | Naval Battle | Existant |
| Odolwan | Funky Drums | NULL |
| Til0u | Casse-Briques | Existant |
| sercus i | Ovarium | NULL |
| gobelin97 | SURVIVAL | NULL |
| Pouet_forever | Rubik's cube | NULL |
| paraze | Linefactor | Existant |
| macmist | SDLectronicKeyboard | Existant |
| LordOfWar | Lord of War | NULL |
| shamanas | SDFx | Existant |
| Ptitlue | zTaquin | Existant |
| personne@ | Bataille navale | NULL |
| nerem | JetPack 2011 | NULL |
| sismic | Naruto Sokoban | Existant |
| HomerEro | Space Invaders | Existant |
| Créateur | Programme | Topic d'avancement du projet |
|---|---|---|
| florent m | Snake | NULL |
| Krypt | PaintDémineur | Existant |
| darkipod | PONG | Existant |
| tsunami33 | Shaak | NULL |
| _Fender_ | Bar's Ball | Existant |
), les correcteurs auront le temps qu'ils souhaitent pour analyser et noter les codes (sûrement moins de 2 mois).
boon

Ville : Tourrette-levens
Pays : France métropolitaine
Études : Epitech Nice
GurneyH

paraze

Ville : Gex
Pays : France métropolitaine

Keriz


C159

Ville : Sébazac
Pays : France métropolitaine

paraze

Ville : Gex
Pays : France métropolitaine

schadocalex

Ville : Saran
Pays : France métropolitaine
paraze

Ville : Gex
Pays : France métropolitaine
schadocalex

Ville : Saran
Pays : France métropolitaine
mokimok

HomerEro

Ville : Paris
Pays : France métropolitaine
. En espérant qu'il y ais moins de gens à ce faire avoir dans ce Catch'em pourris .
,franchement
, je commence vraiment à douter de l'intelligence de certains ...
) mais ça sert à que dalle . Donc crée par jolfo
)




Je remarque aussi qu'il à dû sombrer dans l’alcoolisme ...
)
) .
paraze

Ville : Gex
Pays : France métropolitaine
) comme juré. Mise en place des critères de notation.
schadocalex

Ville : Saran
Pays : France métropolitaine
Palarradu03

Ville : Yzeure
Pays : France métropolitaine
paraze

Ville : Gex
Pays : France métropolitaine
Palarradu03

Ville : Yzeure
Pays : France métropolitaine
darkipod

Ville : Oloron
Pays : France métropolitaine
C159

Ville : Sébazac
Pays : France métropolitaine

Palarradu03

Ville : Yzeure
Pays : France métropolitaine
KevkevVTT

Ville : Neulliac
Pays : France métropolitaine

reino

)?
schadocalex

Ville : Saran
Pays : France métropolitaine
Cette réponse a aidé l'auteur du sujet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : main.c function : Fonction main author : schadocalex */ #include "main.h" #include "MySDL.h" #include "map.h" #include "game.h" int main(int argc, char** argv) { /* Pour enlever les deux warnings */ if(argc || argv){} return game(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : main.h function : Inclusions principales (bibliotèque standard + SDL) et #define pour la SDL author : schadocalex */ #ifndef MAIN_H_INCLUDED #define MAIN_H_INCLUDED #include <stdio.h> #include <SDL/SDL.h> /* Nécéssaire à la modification des pixels */ #if SDL_BYTEORDER == SDL_BIG_ENDIAN #define MASQUE_ROUGE 0xff000000 #define MASQUE_VERT 0x00ff0000 #define MASQUE_BLEU 0x0000ff00 #define MASQUE_ALPHA 0x000000ff #else #define MASQUE_ROUGE 0x000000ff #define MASQUE_VERT 0x0000ff00 #define MASQUE_BLEU 0x00ff0000 #define MASQUE_ALPHA 0xff000000 #endif #endif /* MAIN_H_INCLUDED */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : map.c function : Fonction de chargement, initialisation et libération de mémoire de la map author : schadocalex */ #include "map.h" #include "MySDL.h" /* Calcule le nombre de lignes du curseur jusqu'au caractère stop_c sans affecter la position du curseur */ int numberLines(const char stop_c, FILE* f) { long actualPosition = ftell(f); char c; int i = 0; do { c = fgetc(f); if(c == '\n') i++; } while(c != stop_c && c != EOF); fseek(f, actualPosition, SEEK_SET); return i; } int loadMapFloor(Map *map, FILE* f) { int i; map->nomberCaseFloor = numberLines(EOF, f); if(!(map->floor = malloc(map->nomberCaseFloor * sizeof(Case)))) return 1; for(i = 0; i < map->nomberCaseFloor; i++) { fscanf(f, "%hu %hu %hu %hu\n", &map->floor[i].position.x, &map->floor[i].position.y, &map->floor[i].chipset.x, &map->floor[i].chipset.y); map->floor[i].position.x *= 32; map->floor[i].position.y *= 32; map->floor[i].chipset.x *= 32; map->floor[i].chipset.y *= 32; map->floor[i].chipset.w = 32; map->floor[i].chipset.h = 32; } return 0; } /* Charge la map dans la structure map */ int loadMap(Map *map, const char* url) { /* Initialisations */ FILE* f = NULL; if(!(f = fopen(url, "r"))) { fprintf(stderr, "Impossible de charger la map %s", url); return 1; } /* Récupération de la largeur et de la hauteur */ fscanf(f, "%d %d\n\n", &map->w, &map->h); /* Chargement de la map */ if(loadMapFloor(map, f)) return 1; fprintf(stdout, "Chargement de la map réussi.\n"); return 0; } /* Charge la map dans la structure map */ void loadMapChipset(Map *map, const char* url, const char* url_masque) { map->chipset = loadImage(url); map->chipset_masque = loadImage(url_masque); } int initialiseMap(Map *map, int nb_map) { if(nb_map == 1) { if(loadMap(map, "map/1.map")) return 1; loadMapChipset(map, "img/grass.png", "img/grass_masque.png"); } return 0; } void freeMap(Map *map) { free(map->floor); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : map.h function : Structures (Case, Map) et prototypes des fonctions de map.c author : schadocalex */ #ifndef MAP_H_INCLUDED #define MAP_H_INCLUDED #include "main.h" typedef struct { SDL_Rect chipset; SDL_Rect position; } Case; typedef struct { SDL_Surface* chipset; SDL_Surface* chipset_masque; int w; int h; int nomberCaseFloor; Case* floor; Case* PF; } Map; int numberLines(const char stop_c, FILE* f); int loadMapFloor(Map *map, FILE* f); int loadMap(Map *map, const char* url); void loadMapChipset(Map *map, const char* url, const char* url_masque); int initialiseMap(Map *map, int nb_map); void freeMap(Map *map); #endif /* MAP_H_INCLUDED */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : events.c function : Gestion des events propre author : schadocalex (remerciements à Fvirtman pour son tutoriel) */ #include "main.h" #include "events.h" /* Mis à jour des events Enregistrement du moment ou l'on a appuyé sur une touche, Pour une meilleure gestion des events */ void UpdateEvents(Input* in) { SDL_Event event; while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: if(in->key[event.key.keysym.sym] == 0) in->key[event.key.keysym.sym] = SDL_GetTicks(); break; case SDL_KEYUP: in->key[event.key.keysym.sym] = 0; break; case SDL_QUIT: in->quit = 1; break; default: break; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : events.h function : Structure (Input) et prototype de events.c author : schadocalex (remerciements à Fvirtman pour son tutoriel) */ #ifndef EVENTS_H_INCLUDED #define EVENTS_H_INCLUDED typedef struct { int key[SDLK_LAST]; char quit; } Input; void UpdateEvents(Input* in); #endif /* EVENTS_H_INCLUDED */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : pixel.c function : Fonctions d'écriture et de lecture de pixels author : schadocalex (remerciements à Piwaï pour son tutoriel) */ #include "main.h" #include "pixel.h" Uint32 getPixel(SDL_Surface* surface, int x, int y) { int BytesPerPixel = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * BytesPerPixel; switch(BytesPerPixel) { case 1: return *p; case 2: return *(Uint16 *)p; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) return p[0] << 16 | p[1] << 8 | p[2]; else return p[0] | p[1] << 8 | p[2] << 16; case 4: return *(Uint32 *)p; default: return 0; } } void setPixel(Uint32 pixel, SDL_Surface *surface, int x, int y) { int BytesPerPixel = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * BytesPerPixel; switch(BytesPerPixel) { case 1: *p = pixel; break; case 2: *(Uint16 *)p = pixel; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break; case 4: *(Uint32 *)p = pixel; break; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : pixel.h function : Structure (Pixel) et prototypes de pixel.c author : schadocalex (remerciements à Piwaï pour son tutoriel) */ #ifndef PIXEL_H_INCLUDED #define PIXEL_H_INCLUDED typedef struct { Uint8 r; Uint8 g; Uint8 b; Uint8 a; } Pixel; Uint32 getPixel(SDL_Surface* surface, int x, int y); void setPixel(Uint32 pixel, SDL_Surface *surface, int x, int y); #endif /* PIXEL_H_INCLUDED */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : MySDL.c function : Extension de la SDL author : schadocalex */ #include <SDL/SDL_Image.h> #include "main.h" #include "MySDL.h" /* Charge une image */ SDL_Surface* loadImage(const char* url) { SDL_Surface* img = IMG_Load(url); if(!img) { fprintf(stderr, "Impossible d'ouvrir %s\n", url); exit(EXIT_FAILURE); } else fprintf(stdout, "Chargement de %s\n", url); return img; } /* Initialise la SDL et la fenêtre */ SDL_Surface* MySDL_Init(int largeur, int hauteur) { /* Initialisation de la SDL */ if(SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Impossible d'initialiser la SDL : %s\n", SDL_GetError()); exit(EXIT_FAILURE); } else fprintf(stdout, "Initialisation de la SDL\n"); /* On ferme la SDL à la fin du programme */ atexit(SDL_Quit); /* Création de la fenêtre */ SDL_Surface* screen = SDL_SetVideoMode(largeur, hauteur, 32, SDL_SWSURFACE | SDL_DOUBLEBUF); if(!screen) { fprintf(stderr, "Impossible de créer une fenêtre de %dx%d : %s\n", largeur, hauteur, SDL_GetError()); exit(EXIT_FAILURE); } else fprintf(stdout, "Création de la fenêtre\n"); SDL_WM_SetCaption("Delthera - build 1", NULL); return screen; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : MySDL.h function : Prototype de MySDL.c author : schadocalex */ #ifndef MYSDL_H_INCLUDED #define MYSDL_H_INCLUDED SDL_Surface* loadImage(const char* url); SDL_Surface* MySDL_Init(int largeur, int hauteur); #endif /* MYSDL_H_INCLUDED */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : game.c function : Fonction game qui sert de boucle principale du jeu author : schadocalex */ #include "main.h" #include "map.h" #include "game.h" #include "MySDL.h" #include "player.h" #include "events.h" int game() { Map map; Player player; SDL_Surface *screen, *screenMasque; char continuer = 1; int i; if(initialiseMap(&map, 1)) return 1; /* screen */ if((screen = MySDL_Init(map.w * 32, map.h * 32)) == NULL) return 1; SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255)); /* screen masque */ screenMasque = SDL_CreateRGBSurface(SDL_HWSURFACE, map.w * 32, map.h * 32, 32, 0, 0, 0, 0); SDL_FillRect(screenMasque, NULL, SDL_MapRGB(screen->format, 255, 255, 255)); /* décor */ for(i = 0; i < map.nomberCaseFloor; i++) { SDL_BlitSurface(map.chipset, &map.floor[i].chipset, screen, &map.floor[i].position); SDL_BlitSurface(map.chipset_masque, &map.floor[i].chipset, screenMasque, &map.floor[i].position); } player_initialise(&player, "img/player.png"); SDL_Rect temp; Input in; memset(&in,0, sizeof(in)); while(continuer) { UpdateEvents(&in); if(in.quit || in.key[SDLK_ESCAPE]) continuer = 0; temp.x = player.position.x; temp.y = player.position.y + 2; temp.w = player.player_act.w; temp.h = player.player_act.h; if(in.key[SDLK_LEFT] > in.key[SDLK_RIGHT]) player.v_x = -4; else if(in.key[SDLK_RIGHT]) player.v_x = 4; else player.v_x = 0; if(in.key[SDLK_UP] && collision(screenMasque, temp)) { if(player.v_s <= 0) player.v_s = 6; } player_animation(&player, 60, screenMasque); player_move(&player, screenMasque); SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255)); for(i = 0; i < map.nomberCaseFloor; i++) { SDL_BlitSurface(map.chipset, &map.floor[i].chipset, screen, &map.floor[i].position); SDL_BlitSurface(map.chipset_masque, &map.floor[i].chipset, screenMasque, &map.floor[i].position); } SDL_BlitSurface(player.charset, &player.player_act, screen, &player.position); SDL_Delay(40); SDL_Flip(screen); } freeMap(&map); SDL_free(screenMasque); return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : game.h function : Prototype des fonctions de game.c author : schadocalex */ #ifndef GAME_H_INCLUDED #define GAME_H_INCLUDED int game(void); #endif /* GAME_H_INCLUDED */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : player.c function : Fonctions relatives au joueur (initialisation, déplacements, animation etc.) author : schadocalex */ #include "main.h" #include "player.h" #include "pixel.h" #include "MySDL.h" /* Initialise un personnage pour le joueur */ void player_initialise(Player *player, const char* url) { player->charset = loadImage(url); player->v_x = 0; player->v_y = 5; player->v_s = 0; player->player_act.x = 0; player->player_act.y = 0; player->player_act.w = PLAYER_WIDTH; player->player_act.h = player->charset->h / 4; player->position.x = 0; player->position.y = 100; player->jump = 0; } /* Change la frame du personnage si elle a été changée depuis plus de x ms */ void player_animation(Player *player, unsigned int x, SDL_Surface* screenMasque) { static unsigned int previousTime = 0; if(SDL_GetTicks() - previousTime < x) return; else previousTime = SDL_GetTicks(); /* Pour tester si le joueur est proche du sol ou d'une plateforme */ SDL_Rect temp; temp.x = player->position.x; temp.y = player->position.y + 30; temp.w = PLAYER_WIDTH; temp.h = PLAYER_HEIGHT; int nextToFloor = collision(screenMasque, temp); int player_direction = (player->player_act.y < PLAYER_Y_LEFT) ? 0 : PLAYER_Y_LEFT; /** GAUCHE <-> DROITE **/ if(player->v_x < 0 && player->player_act.y < PLAYER_Y_LEFT) /* Si le perso va à gauche, mais qu'il ne regarde pas à gauche */ player->player_act.y += PLAYER_Y_LEFT; else if(player->v_x > 0 && player->player_act.y >= PLAYER_Y_LEFT) /* Sinon si le perso va à droite, mais qu'il ne regarde pas à droite */ player->player_act.y -= PLAYER_Y_LEFT; /** JUMPING **/ if(player->jump == 0 && player->v_s > 0) /* Si le perso doit sauter mais qu'il n'est pas prêt */ { player->jump = 1; player->player_act.x = PLAYER_X_CAN_JUMP; player->player_act.y = (player_direction + PLAYER_Y_JUMPING); } else if(player->jump) /* Sinon si il peut sauter ou qu'il est entrain de sauter */ { if(player->v_s <= 0 && nextToFloor) /* Si le joueur va atterir sur un sol ou une plateforme */ { if(player->player_act.x > PLAYER_X_STOP_JUMPING) /* Si le perso n'est pas prêt pour courir */ player->player_act.x -= PLAYER_WIDTH; else { player->jump = 0; player->player_act.x = PLAYER_WIDTH; player->player_act.y = player_direction; } } else { player->player_act.x += PLAYER_WIDTH; if(player->player_act.x >= player->charset->w) player->player_act.x = player->charset->w - PLAYER_WIDTH; } } /** NORMAL **/ if(player->player_act.y == player_direction && player->v_s <= 0) /* S'il est entrain de courir */ { if(player->v_x == 0) /* Si le joueur n'avance plus */ player->player_act.x = 0; else { player->player_act.x += PLAYER_WIDTH; if(player->player_act.x >= player->charset->w) player->player_act.x = PLAYER_WIDTH; } } } /* Teste si il y a collision */ int collision(SDL_Surface* screenMasque, SDL_Rect player) { SDL_LockSurface(screenMasque); Uint32 pixel; Uint8 r, g, b; int i, j; player.x += 10; player.w -= 20; player.h -= 1; if(screenMasque->w < player.x + player.w + 5 || screenMasque->h < player.y + player.h || player.x < 0 || player.y < 0) return 1; for(i = 0; i <= player.w; i++) for(j = 0; j <= player.h; j++) { pixel = getPixel(screenMasque, player.x + i, player.y + j); SDL_GetRGB(pixel, screenMasque->format, &r, &g, &b); if(r < 20 && g < 20 && b < 20) { SDL_UnlockSurface(screenMasque); return 1; } } SDL_UnlockSurface(screenMasque); return 0; } /* Incémente ou décrémente n pour se rapprocher de 0, ou ne fait rien si n = 0 */ int goZero(int n) { return (n < 0) ? (n + 1) : ((n > 0) ? n - 1 : 0); } /* Bouge le joueur grâce au vecteur vitesse (v_x;v_y) ainsi qu'au vecteur vertical de saut v_s */ void player_move(Player *player, SDL_Surface* screenMasque) { int dx = (int)player->v_x, dy = (int)player->v_y; /* Pour tester si le joueur est proche du sol ou d'une plateforme */ SDL_Rect temp; temp.x = player->position.x; temp.y = player->position.y + 40; temp.w = PLAYER_WIDTH; temp.h = PLAYER_HEIGHT; int i = 0; int limitey = (dy < 0) ? -1 : 1; /* saut */ if(player->v_s > 0 && player->jump) /* Si le joueur doit sauter */ { dy = -player->v_s; player->v_s -= 0.5; if(player->v_s < 0) player->v_s = 0; } /* Boucle avec le vecteur vitesse attendu */ while(1) { if(dy == limitey) break; temp.x = player->position.x + dx; temp.y = player->position.y + dy; if(!collision(screenMasque, temp)) { player->position.x += dx; player->position.y += dy; return; } if(i % 2 == 0) dx = goZero(dx); else dy = goZero(dy); i++; } /* Si ce n'est pas concluant, boucle avec un vecteur vitesse horizontal */ dx = (int)player->v_x; dy = 1; while(1) { if(dx == 0) break; temp.x = player->position.x + dx; temp.y = player->position.y + dy; if(!collision(screenMasque, temp)) { player->position.x += dx; player->position.y += dy; return; } if(i % 2 == 0) dx = goZero(dx); else dy--; i++; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | /* ____ _____ _ _____ _ _ _____ _____ _____ | __ \ | ___| | | |_ _| | | | | | ___| | _ | | _ | | | | | | |_ | | | | | |_| | | |_ | |_| | | |_| | | | | | | _| | | | | | _ | | _| | _ / | _ | | |__| | | |___ | |___ | | | | | | | |___ | | \ \ | | | | |____ / |_____| |_____| |_| |_| |_| |_____| |_| \_\ |_| |_| name : player.h function : Structure (Player), prototypes de player.c et #define des frames du charset author : schadocalex */ #ifndef PLAYER_H_INCLUDED #define PLAYER_H_INCLUDED #define PLAYER_WIDTH 27 #define PLAYER_HEIGHT 39 #define PLAYER_Y_RIGHT 0 #define PLAYER_Y_LEFT (2*PLAYER_HEIGHT) #define PLAYER_X_CAN_JUMP (5*PLAYER_WIDTH) #define PLAYER_X_STOP_JUMPING (8*PLAYER_WIDTH) #define PLAYER_Y_JUMPING PLAYER_HEIGHT typedef struct { SDL_Rect player_act; /* Frame du charset actuelle */ SDL_Rect position; /* Position dans l'écran */ SDL_Surface* charset; /* Image charset du joueur */ double v_x, v_y, v_s; /* (v_x;v_y) => coordonées du vecteur vitesse */ /* v_s => Hauteur du saut, influe sur v_y */ char jump; /* Est positionné pour sauter ou est entrain de sauter*/ } Player; void player_initialise(Player *player, const char* url); int player_direction(Player *player); void player_animation(Player *player, unsigned int x, SDL_Surface* screenMasque); int collision(SDL_Surface* screenMasque, SDL_Rect player); int goZero(int n); void player_move(Player *player, SDL_Surface* screenMasque); #endif /* PLAYER_H_INCLUDED */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 12 7 0 6 0 0 1 6 0 0 2 6 1 0 3 5 3 0 3 6 2 0 4 4 4 0 4 5 2 0 4 6 0 1 5 4 5 0 5 5 7 0 5 6 0 1 6 5 8 0 6 6 0 1 7 5 1 1 7 6 0 1 8 4 3 1 8 5 2 1 8 6 0 1 9 4 4 1 9 5 0 1 9 6 0 1 10 3 5 1 10 4 2 1 10 5 0 1 10 6 0 1 11 3 6 1 11 4 0 1 11 5 0 1 11 6 0 1 |



paraze

Ville : Gex
Pays : France métropolitaine

schadocalex

Ville : Saran
Pays : France métropolitaine
Lucas-84

Ville : Uchaux
Pays : France métropolitaine
Pouet_forever



schadocalex

Ville : Saran
Pays : France métropolitaine
En 3 mois, j'ai le temps.
qnope
paraze

Ville : Gex
Pays : France métropolitaine

Retour au forum "Langage C" ou à la liste des forums
