-
Notifications
You must be signed in to change notification settings - Fork 5
/
game.c
113 lines (100 loc) · 3.07 KB
/
game.c
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
/*
Super Mario Bros
Game.c
Antoine Drabble
Création: 07.01.13
*/
#include <stdlib.h>
#include <stdio.h>
#include <SDL.h>
#include <SDL_image.h>
#include "game.h"
#include "map.h"
#include "char.h"
#include "object.h"
#include "objectevent.h"
#include "event.h"
#include "audio.h"
void game(SDL_Surface* screen)
{
SDL_Event event;
Map* m;
Sprites* S;
Chars mario;
Chars* marioimages;
Object* shroom;
Input in;
int continuer = 0;
int tempsPrecedent = 0, tempsActuel = 0;
char *niveau;
marioimages = malloc(12 * sizeof(Chars));
memset(&in,0,sizeof(in)); //Set toutes les touches à 0
SDL_Rect positionLevel;
SDL_Surface* level;
screen = SDL_SetVideoMode(600, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
level = IMG_Load("images/lvl.jpg"); //Charge l'image du menu
positionLevel.x = screen->w / 2 - level->w / 2; //Définit le menu au centre de la fenêtre
positionLevel.y = 0;
SDL_BlitSurface(level, NULL, screen, &positionLevel);
SDL_Flip(screen);
SDL_FreeSurface(level);
while (!continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
return;
break;
case SDLK_1:
niveau="niveau1.lvl";
continuer=1;
break;
case SDLK_2:
niveau="niveau2.lvl";
continuer=1;
break;
case SDLK_3:
niveau="niveau3.lvl";
continuer=1;
break;
}
break;
}
}
screen = SDL_SetVideoMode( WindowW, WindowH, 32,SDL_HWSURFACE|SDL_DOUBLEBUF);
continuer=0;
S = ChargerImages();
shroom = ChargerObject();
m = ChargerMap(niveau);
ChargerChars(&mario, m, marioimages);
AfficherMap(m, screen, S);
SDL_Flip(screen);
while(!in.key[SDLK_ESCAPE] && !in.quit && !continuer)// simplification de la gestion des touches
{
tempsActuel = SDL_GetTicks();
if (tempsActuel - tempsPrecedent > 4) /* Si 30 ms se sont écoulées depuis le dernier tour de boucle */
{
UpdateEvents(&in);
MapScroll(m, &mario);
Evolue(&in,m,&mario,S, shroom);
AfficherMap(m,screen,S);
objectmove(shroom, &mario, m->xscroll,m->yscroll, m, S);
AfficherObject(screen, shroom, m->xscroll,m->yscroll);
AfficherPerso(&mario,screen,m->xscroll,m->yscroll, marioimages);
SDL_Flip(screen);
continuer = NiveauFini(screen, &mario, m);
tempsPrecedent = tempsActuel; /* Le temps "actuel" devient le temps "precedent" pour nos futurs calculs */
}
else
{
SDL_Delay(4 - (tempsActuel - tempsPrecedent));
}
}
LibererMap(m,S);
LibererChars(&mario, marioimages);
LibererObject(shroom);
}