Commit f1d703bf authored by LibertAntoine's avatar LibertAntoine

Regroup global variable of game in gameData

parent 590dd4c7
......@@ -34,24 +34,9 @@
#include "sprite.h"
Plateau *plateau = NULL;
Texture** textures = NULL;
Mix_Chunk** sound = NULL;
GameState gameState = MAINMENU;
Uint32 beginMomentLevel = NULL;
GameData* gameData = NULL;
MapData* mapData = NULL;
GUI *bodyGUI; //variable globale de l'interface
GUI *plateauGUI;
GUI *bottomGUI;
GUI *topGUI;
GUI *infoGUI;
GUI *buttonGUI;
GUI *buttonGUI;
GUI *mainMenuGUI;
GUI *endMenuGUI;
DefaultList **default_list = NULL;
int main(int argc, char *argv[])
{
......@@ -63,6 +48,7 @@ int main(int argc, char *argv[])
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
gameData_init();
gui_init();
sprite_init();
sound_init();
......@@ -73,17 +59,17 @@ int main(int argc, char *argv[])
/* Boucle principale */
int loop = 1;
int frameFPS = 0;
Uint32 lastCheckFPS = beginMomentLevel;
Uint32 lastCheckFPS = gameData->beginMomentLevel;
while(loop) {
Uint32 startTime = SDL_GetTicks();
/* Placer ici le code de dessin */
glClear(GL_COLOR_BUFFER_BIT);
if(gameState == LEVELPLAY) {
if(gameData->gameState == LEVELPLAY) {
// NOTE: display general GUI
display_window();
display_game(plateauGUI, mapData->idMap, mapData->idGrid);
display_game(gameData->plateauGUI, mapData->idMap, mapData->idGrid);
if (plateau->play == TRUE) {
tour_attackAll();
......@@ -92,17 +78,17 @@ int main(int argc, char *argv[])
if(monster_moveAll() == 1 && plateau->currentWave.next == NULL) {
if(plateau->currentWave.monster_total == 0) {
case_freePlateau();
Mix_PlayChannel(-1, sound[WINLEVEL], 0);
gameState = WINMENU;
Mix_PlayChannel(-1, gameData->sound[WINLEVEL], 0);
gameData->gameState = WINMENU;
}
}
}
} else if (gameState == MAINMENU) {
} else if (gameData->gameState == MAINMENU) {
display_mainMenu();
} else if (gameState == LOSEMENU) {
} else if (gameData->gameState == LOSEMENU) {
display_endMenu();
} else if (gameState == WINMENU) {
} else if (gameData->gameState == WINMENU) {
display_endMenu();
}
......@@ -123,7 +109,7 @@ int main(int argc, char *argv[])
loop = 0;
break;
}
if(gameState == LEVELPLAY) {
if(gameData->gameState == LEVELPLAY) {
Etat *joueur = plateau->joueur;
TypeCase type = joueur->type;
Action action = joueur->action;
......
......@@ -408,4 +408,10 @@ void case_freePlateau() {
free(plateau);
}
void gameData_init() {
gameData = malloc(sizeof(GameData));
gameData->gameState = MAINMENU;
gameData->default_list = NULL;
};
......@@ -241,14 +241,14 @@ GLuint display_initDefaultListIcon(TextureName texture_name)
void display_initDefaultList()
{
default_list = calloc(10, sizeof(DefaultList*));
gameData->default_list = calloc(10, sizeof(DefaultList*));
int position = 0;
char str[12];
GeneralType generalType = TOUR;
for (int i = LASER; i <= MISSILE; i++) {
default_list[i] = calloc(1, sizeof(DefaultList));
gameData->default_list[i] = calloc(1, sizeof(DefaultList));
GLuint idListInfos = glGenLists(1);
glNewList(idListInfos, GL_COMPILE);
......@@ -301,15 +301,15 @@ void display_initDefaultList()
glPopMatrix();
glEndList();
default_list[i]->idListInfos = idListInfos;
default_list[i]->idListIcon = display_initDefaultListIcon(i);
gameData->default_list[i]->idListInfos = idListInfos;
gameData->default_list[i]->idListIcon = display_initDefaultListIcon(i);
position = 0;
}
generalType = BATIMENT;
for (int i = RADAR; i <= MUNITION; i++) {
default_list[i] = calloc(1, sizeof(DefaultList));
gameData->default_list[i] = calloc(1, sizeof(DefaultList));
GLuint idListInfos = glGenLists(1);
glNewList(idListInfos, GL_COMPILE);
......@@ -369,8 +369,8 @@ void display_initDefaultList()
glPopMatrix();
glEndList();
default_list[i]->idListInfos = idListInfos;
default_list[i]->idListIcon = display_initDefaultListIcon(i);
gameData->default_list[i]->idListInfos = idListInfos;
gameData->default_list[i]->idListIcon = display_initDefaultListIcon(i);
position = 0;
}
......@@ -378,7 +378,7 @@ void display_initDefaultList()
int type;
for (int i = SOLDER_DEF; i <= BOSS_DEF; i++) {
type = i - 6;
default_list[i] = calloc(1, sizeof(DefaultList));
gameData->default_list[i] = calloc(1, sizeof(DefaultList));
GLuint idListInfos = glGenLists(1);
glNewList(idListInfos, GL_COMPILE);
......@@ -414,8 +414,8 @@ void display_initDefaultList()
glPopMatrix();
glEndList();
default_list[i]->idListInfos = idListInfos;
default_list[i]->idListIcon = display_initDefaultListIcon(i);
gameData->default_list[i]->idListInfos = idListInfos;
gameData->default_list[i]->idListIcon = display_initDefaultListIcon(i);
position = 0;
}
......@@ -424,11 +424,11 @@ void display_initDefaultList()
void display_printInfos()
{
if (plateau->index_case_hover == -1 && plateau->monster_hover == NULL) {
glCallList(default_list[plateau->joueur->type]->idListInfos);
glCallList(default_list[plateau->joueur->type]->idListIcon);
glCallList(gameData->default_list[plateau->joueur->type]->idListInfos);
glCallList(gameData->default_list[plateau->joueur->type]->idListIcon);
}
else if (plateau->monster_hover) {
glCallList(default_list[plateau->monster_hover->type + 6]->idListInfos);
glCallList(gameData->default_list[plateau->monster_hover->type + 6]->idListInfos);
}
else if (case_getGeneralConstructionType(mapData->cases[plateau->index_case_hover]) == TOUR) {
if (plateau->idListInfos == GL_INVALID_VALUE) {
......@@ -795,7 +795,7 @@ void display_setDrawingZone(GUI *section)
int Y = 0;
gui_getAbsoluteCoordinates(section, &X, &Y);
glViewport(X, bodyGUI->dimensions->height - Y - section->dimensions->height, section->dimensions->width, section->dimensions->height);
glViewport(X, gameData->bodyGUI->dimensions->height - Y - section->dimensions->height, section->dimensions->width, section->dimensions->height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
......@@ -807,7 +807,7 @@ void display_drawZoneBasedOnGUI(GUI *section)
{
display_setDrawingZone(section);
if (default_list == NULL && gameState == LEVELPLAY) {
if (gameData->default_list == NULL && gameData->gameState == LEVELPLAY) {
display_initDefaultList();
}
......@@ -824,14 +824,14 @@ void display_drawZoneBasedOnGUI(GUI *section)
button = button->next;
}
if (section == infoGUI) {
if (section == gameData->infoGUI) {
display_printInfos();
}
else if (section == topGUI) {
else if (section == gameData->topGUI) {
display_printMoney();
}
display_setDrawingZone(bodyGUI);
display_setDrawingZone(gameData->bodyGUI);
}
void display_buttonBackground(Display display)
......@@ -879,7 +879,7 @@ void display_drawSingleButton(Button *button)
display_mode = button->display;
}
if (gameState == LEVELPLAY) {
if (gameData->gameState == LEVELPLAY) {
glScalef(button->dimensions->width, button->dimensions->height, 0);
display_buttonBackground(display_mode);
......@@ -977,17 +977,17 @@ void display_printMoney()
void display_top()
{
glColor3f(1,1,0);
display_drawZoneBasedOnGUI(topGUI);
display_drawZoneBasedOnGUI(gameData->topGUI);
}
void display_bottom()
{
glColor3f(1,0,1);
display_drawZoneBasedOnGUI(bottomGUI);
display_drawZoneBasedOnGUI(gameData->bottomGUI);
glColor3f(1,1,1);
display_drawZoneBasedOnGUI(buttonGUI);
display_drawZoneBasedOnGUI(gameData->buttonGUI);
glColor3f(.50,0.7,1);
display_drawZoneBasedOnGUI(infoGUI);
display_drawZoneBasedOnGUI(gameData->infoGUI);
}
void display_left()
......@@ -1010,21 +1010,21 @@ void display_window()
void display_mainMenu()
{
glColor3f(1,0,1);
display_drawZoneBasedOnGUI(mainMenuGUI);
display_drawZoneBasedOnGUI(gameData->mainMenuGUI);
}
void display_endMenu()
{
glColor3f(1,0,1);
display_drawZoneBasedOnGUI(endMenuGUI);
display_drawZoneBasedOnGUI(gameData->endMenuGUI);
}
void display_game(GUI *plateau_gui, GLuint idMap, GLuint idGrid)
{
Div* plateau_div = plateau_gui->dimensions;
Div* body_div = bodyGUI->dimensions;
Div* body_div = gameData->bodyGUI->dimensions;
glViewport(plateau_div->x, (bodyGUI->dimensions->height - plateau_div->y - plateau_div->height), plateau_div->width, plateau_div->height);
glViewport(plateau_div->x, (gameData->bodyGUI->dimensions->height - plateau_div->y - plateau_div->height), plateau_div->width, plateau_div->height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(1, mapData->Xsplit+1, mapData->Ysplit+1, 1);
......
......@@ -46,7 +46,7 @@ ButtonName gui_getButtonNameFromTypeCase(TypeCase type)
Display gui_getTowerButtonState(TypeCase type)
{
ButtonName button_name = gui_getButtonNameFromTypeCase(type);
Button *currentButton = buttonGUI->buttons;
Button *currentButton = gameData->buttonGUI->buttons;
while (currentButton->name != button_name) {
currentButton = currentButton->next;
}
......@@ -56,7 +56,7 @@ Display gui_getTowerButtonState(TypeCase type)
void gui_changeTowerButtonState(TypeCase type, Display state)
{
ButtonName button_name = gui_getButtonNameFromTypeCase(type);
Button *currentButton = buttonGUI->buttons;
Button *currentButton = gameData->buttonGUI->buttons;
while (currentButton->name != button_name) {
if (currentButton->next == NULL) {
return;
......@@ -69,7 +69,7 @@ void gui_changeTowerButtonState(TypeCase type, Display state)
void gui_changeActionButtonState(Action action, Display state)
{
ButtonName button_name = gui_getButtonNameFromAction(action);
Button *currentButton = buttonGUI->buttons;
Button *currentButton = gameData->buttonGUI->buttons;
while (currentButton->name != button_name) {
currentButton = currentButton->next;
}
......@@ -96,58 +96,58 @@ GUI *gui_addChildren(SectionName name, int x, int y, int width, int height, GUI
void gui_init()
{
bodyGUI = calloc(1, sizeof(GUI));
gameData->bodyGUI = calloc(1, sizeof(GUI));
// TODO: check alloc
bodyGUI->name = BODY;
gameData->bodyGUI->name = BODY;
Div *dimensions = calloc(1, sizeof(Div));
dimensions->width = WINDOW_WIDTH;
dimensions->height = WINDOW_HEIGHT;
bodyGUI->dimensions = dimensions;
gameData->bodyGUI->dimensions = dimensions;
topGUI = gui_addChildren(HEADER, 0, 0, bodyGUI->dimensions->width, 40, bodyGUI);
gui_addButton(topGUI, 600, 20, 45, 45, PAUSE_BTN, CLICKED);
gameData->topGUI = gui_addChildren(HEADER, 0, 0, gameData->bodyGUI->dimensions->width, 40, gameData->bodyGUI);
gui_addButton(gameData->topGUI, 600, 20, 45, 45, PAUSE_BTN, CLICKED);
plateauGUI = gui_addChildren(PLATEAU, 0, 40, bodyGUI->dimensions->width, 600, bodyGUI);
gameData->plateauGUI = gui_addChildren(PLATEAU, 0, 40, gameData->bodyGUI->dimensions->width, 600, gameData->bodyGUI);
bottomGUI = gui_addChildren(FOOTER, 0, 640, bodyGUI->dimensions->width, 160, bodyGUI);
gameData->bottomGUI = gui_addChildren(FOOTER, 0, 640, gameData->bodyGUI->dimensions->width, 160, gameData->bodyGUI);
infoGUI = gui_addChildren(INFO_SECTION, 0, 0, 600, bottomGUI->dimensions->height, bottomGUI);
gameData->infoGUI = gui_addChildren(INFO_SECTION, 0, 0, 600, gameData->bottomGUI->dimensions->height, gameData->bottomGUI);
buttonGUI = gui_addChildren(TOWER_BUTTONS_SECTION, 600, 0, 200, bottomGUI->dimensions->height, bottomGUI);
gameData->buttonGUI = gui_addChildren(TOWER_BUTTONS_SECTION, 600, 0, 200, gameData->bottomGUI->dimensions->height, gameData->bottomGUI);
gui_addButton(buttonGUI, 30, 30, 45, 45, LASER_BTN, CLICKED);
gui_addButton(buttonGUI, 90, 30, 45, 45, MISSILE_BTN, ACTIVE);
gui_addButton(gameData->buttonGUI, 30, 30, 45, 45, LASER_BTN, CLICKED);
gui_addButton(gameData->buttonGUI, 90, 30, 45, 45, MISSILE_BTN, ACTIVE);
gui_addButton(buttonGUI, 30, 80, 45, 45, ARMEMENT_BTN, ACTIVE);
gui_addButton(buttonGUI, 90, 80, 45, 45, MUNITION_BTN, ACTIVE);
gui_addButton(buttonGUI, 30, 130, 45, 45, RADAR_BTN, ACTIVE);
gui_addButton(buttonGUI, 90, 130, 45, 45, CENTRALE_BTN, ACTIVE);
gui_addButton(gameData->buttonGUI, 30, 80, 45, 45, ARMEMENT_BTN, ACTIVE);
gui_addButton(gameData->buttonGUI, 90, 80, 45, 45, MUNITION_BTN, ACTIVE);
gui_addButton(gameData->buttonGUI, 30, 130, 45, 45, RADAR_BTN, ACTIVE);
gui_addButton(gameData->buttonGUI, 90, 130, 45, 45, CENTRALE_BTN, ACTIVE);
gui_addButton(buttonGUI, 170, 30, 45, 45, ADD_BTN, CLICKED);
gui_addButton(buttonGUI, 170, 80, 45, 45, GETINFO_BTN, ACTIVE);
gui_addButton(buttonGUI, 170, 130, 45, 45, REMOVE_BTN, ACTIVE);
gui_addButton(gameData->buttonGUI, 170, 30, 45, 45, ADD_BTN, CLICKED);
gui_addButton(gameData->buttonGUI, 170, 80, 45, 45, GETINFO_BTN, ACTIVE);
gui_addButton(gameData->buttonGUI, 170, 130, 45, 45, REMOVE_BTN, ACTIVE);
mainMenuGUI = calloc(1, sizeof(GUI));
mainMenuGUI->name = MAIN;
gameData->mainMenuGUI = calloc(1, sizeof(GUI));
gameData->mainMenuGUI->name = MAIN;
Div *dimensions_main = calloc(1, sizeof(Div));
dimensions_main->width = WINDOW_WIDTH;
dimensions_main->height = WINDOW_HEIGHT;
mainMenuGUI->dimensions = dimensions_main;
gui_addButton(mainMenuGUI, 400, 400, 250, 45, LEVEL1_BTN, ACTIVE);
gui_addButton(mainMenuGUI, 400, 470, 250, 45, LEVEL2_BTN, ACTIVE);
gui_addButton(mainMenuGUI, 400, 540, 250, 45, LEVEL3_BTN, ACTIVE);
gameData->mainMenuGUI->dimensions = dimensions_main;
gui_addButton(gameData->mainMenuGUI, 400, 400, 250, 45, LEVEL1_BTN, ACTIVE);
gui_addButton(gameData->mainMenuGUI, 400, 470, 250, 45, LEVEL2_BTN, ACTIVE);
gui_addButton(gameData->mainMenuGUI, 400, 540, 250, 45, LEVEL3_BTN, ACTIVE);
endMenuGUI = calloc(1, sizeof(GUI));
endMenuGUI->name =LOSEMENU ;
gameData->endMenuGUI = calloc(1, sizeof(GUI));
gameData->endMenuGUI->name =LOSEMENU ;
Div *dimensions_end = calloc(1, sizeof(Div));
dimensions_end->width = WINDOW_WIDTH;
dimensions_end->height = WINDOW_HEIGHT;
endMenuGUI->dimensions = dimensions_main;
gui_addButton(endMenuGUI, 400, 400, 250, 45, MAINMENU_BTN, ACTIVE);
gui_addButton(endMenuGUI, 400, 470, 250, 45, REPLAY_BTN, ACTIVE);
gameData->endMenuGUI->dimensions = dimensions_main;
gui_addButton(gameData->endMenuGUI, 400, 400, 250, 45, MAINMENU_BTN, ACTIVE);
gui_addButton(gameData->endMenuGUI, 400, 470, 250, 45, REPLAY_BTN, ACTIVE);
}
void gui_getAbsoluteDimensionsButton(GUI *section, Div *button)
......
......@@ -637,7 +637,7 @@ void idt_load(char* itd_path)
void itd_actionMenu(ButtonName button) {
if(gameState == MAINMENU) {
if(gameData->gameState == MAINMENU) {
if (button == LEVEL1_BTN) {
idt_load("level/level1.itd");
} else if (button == LEVEL2_BTN) {
......@@ -648,14 +648,14 @@ void itd_actionMenu(ButtonName button) {
return EXIT_FAILURE;
}
itd_initLevel();
gameState = LEVELPLAY;
} else if (gameState == LOSEMENU || gameState == WINMENU) {
gameData->gameState = LEVELPLAY;
} else if (gameData->gameState == LOSEMENU || gameData->gameState == WINMENU) {
if(button == MAINMENU_BTN) {
itd_freeMapData();
gameState = MAINMENU;
gameData->gameState = MAINMENU;
} else if (button == REPLAY_BTN) {
itd_initLevel();
gameState = LEVELPLAY;
gameData->gameState = LEVELPLAY;
}
}
}
......@@ -674,9 +674,9 @@ void itd_initLevel()
mapData->idMap = glGenLists(1);
display_mapList(mapData->idMap);
beginMomentLevel = SDL_GetTicks();
gameData->beginMomentLevel = SDL_GetTicks();
Mix_PlayChannel(-1, sound[BEGINLEVEL], 0);
Mix_PlayChannel(-1, gameData->sound[BEGINLEVEL], 0);
}
void itd_freeMapData() {
......
......@@ -4,7 +4,7 @@ void keyboard_handleKeypress(SDL_Event *event)
{
SDL_Keycode key = event->key.keysym.sym;
if(gameState == LEVELPLAY) {
if(gameData->gameState == LEVELPLAY) {
Etat *joueur = plateau->joueur;
TypeCase type = joueur->type;
Action action = joueur->action;
......@@ -51,7 +51,7 @@ void keyboard_handleKeypress(SDL_Event *event)
player_switchTowerType(type);
}
}
else if (gameState == MAINMENU) {
else if (gameData->gameState == MAINMENU) {
switch(key) {
case 'a':
itd_actionMenu(LEVEL1_BTN);
......@@ -63,7 +63,7 @@ void keyboard_handleKeypress(SDL_Event *event)
itd_actionMenu(LEVEL3_BTN);
break;
}
} else if (gameState == LOSEMENU || gameState == WINMENU) {
} else if (gameData->gameState == LOSEMENU || gameData->gameState == WINMENU) {
switch(key) {
case 'a':
itd_actionMenu(MAINMENU_BTN);
......
......@@ -134,19 +134,19 @@ void monster_kill(Monster* monster)
switch (monster->type)
{
case SOLDER:
Mix_PlayChannel(-1, sound[SOLD], 0);
Mix_PlayChannel(-1, gameData->sound[SOLD], 0);
break;
case HUGE_SOLDER:
Mix_PlayChannel(-1, sound[HSOLD], 0);
Mix_PlayChannel(-1, gameData->sound[HSOLD], 0);
break;
case GERERAL:
Mix_PlayChannel(-1, sound[GENE], 0);
Mix_PlayChannel(-1, gameData->sound[GENE], 0);
break;
case BOSS:
Mix_PlayChannel(-1, sound[BOS], 0);
Mix_PlayChannel(-1, gameData->sound[BOS], 0);
break;
}
......@@ -225,8 +225,8 @@ int moveMonster(Monster* monster)
// NOTE: Le monstre a atteint l'arrivée.
if (monster->itineraire->next->next == NULL) {
case_freePlateau();
Mix_PlayChannel(-1, sound[LOSELEVEL], 0);
gameState = LOSEMENU;
Mix_PlayChannel(-1, gameData->sound[LOSELEVEL], 0);
gameData->gameState = LOSEMENU;
return 0;
}
......@@ -272,7 +272,7 @@ int monster_moveAll()
} else {
noLifeMonster = FALSE;
moveMonster(currentMonster);
if(gameState == LOSEMENU) {
if(gameData->gameState == LOSEMENU) {
return 0;
}
}
......
......@@ -4,10 +4,10 @@ void mouse_handlePosition()
{
GUI *current_section = mouse_getSection();
if (current_section->name == PLATEAU && gameState == LEVELPLAY) {
if (current_section->name == PLATEAU && gameData->gameState == LEVELPLAY) {
int caseX;
int caseY;
get_casesi(&caseX, &caseY, plateauGUI->dimensions);
get_casesi(&caseX, &caseY, gameData->plateauGUI->dimensions);
TypeCase currentCase_type = case_getType(caseX+1, caseY+1);
......@@ -29,7 +29,7 @@ void mouse_handlePosition()
plateau->monster_hover = NULL;
}
}
else if (gameState == LEVELPLAY) {
else if (gameData->gameState == LEVELPLAY) {
plateau->index_case_hover = -1;
plateau->monster_hover = NULL;
}
......@@ -40,7 +40,7 @@ void mouse_checkIfMonster()
{
float casex_f;
float casey_f;
get_casesf(&casex_f, &casey_f, plateauGUI->dimensions);
get_casesf(&casex_f, &casey_f, gameData->plateauGUI->dimensions);
//printf("%f x %f\n", casex_f, casey_f);
Monster* currentMonster = plateau->listMonsters->firstMonster;
......@@ -60,7 +60,7 @@ void mouse_checkIfMonster()
void mouse_handleButtonClick(ButtonName button_name)
{
if(gameState == LEVELPLAY) {
if(gameData->gameState == LEVELPLAY) {
Etat *joueur = plateau->joueur;
TypeCase type = joueur->type;
Action action = joueur->action;
......@@ -108,7 +108,7 @@ void mouse_handleButtonClick(ButtonName button_name)
player_switchTowerType(type);
}
}
else if (gameState == MAINMENU || gameState == LOSEMENU || gameState == WINMENU) {
else if (gameData->gameState == MAINMENU || gameData->gameState == LOSEMENU || gameData->gameState == WINMENU) {
itd_actionMenu(button_name);
}
}
......@@ -117,12 +117,12 @@ void mouse_handleClick()
{
GUI *current_section = mouse_getSection();
if(gameState == LEVELPLAY) {
if(gameData->gameState == LEVELPLAY) {
if (current_section->name == PLATEAU) {
int casex, casey;
float casex_f, casey_f;
get_casesi(&casex, &casey, plateauGUI->dimensions);
get_casesf(&casex_f, &casey_f, plateauGUI->dimensions);
get_casesi(&casex, &casey, gameData->plateauGUI->dimensions);
get_casesf(&casex_f, &casey_f, gameData->plateauGUI->dimensions);
printf("%d %d\n", casex, casey);
printf("%f %f\n", casex_f, casey_f);
case_handleAction(casex +1, casey +1);
......@@ -133,15 +133,15 @@ void mouse_handleClick()
printf("%d\n", buttonClicked->name +1);
}
}
else if (gameState == MAINMENU) {
Button *buttonClicked = mouse_GUIbutton(mainMenuGUI);
else if (gameData->gameState == MAINMENU) {
Button *buttonClicked = mouse_GUIbutton(gameData->mainMenuGUI);
if (buttonClicked) {
mouse_handleButtonClick(buttonClicked->name);
printf("%d\n", buttonClicked->name +1);
}
}
else if (gameState == LOSEMENU || gameState == WINMENU) {
Button *buttonClicked = mouse_GUIbutton(endMenuGUI);
else if (gameData->gameState == LOSEMENU || gameData->gameState == WINMENU) {
Button *buttonClicked = mouse_GUIbutton(gameData->endMenuGUI);
if (buttonClicked) {
mouse_handleButtonClick(buttonClicked->name);
printf("%d\n", buttonClicked->name +1);
......@@ -163,7 +163,7 @@ Button *mouse_GUIbutton(GUI *section)
GUI *mouse_getSection()
{
GUI *current_section = bodyGUI;
GUI *current_section = gameData->bodyGUI;
while (current_section) {
if (mouse_isWithinSection(current_section)) {
if (current_section->childen != NULL) {
......
......@@ -18,7 +18,7 @@ int create_projectile(Tour* tour, Monster* monster, float degats) {
projectile->next = NULL;
addToProjectiles(projectile);
Mix_PlayChannel(-1, sound[PROJECTILE], 0);
Mix_PlayChannel(-1, gameData->sound[PROJECTILE], 0);
plateau->listProjectiles->nbProjectile++;
}
......
......@@ -6,7 +6,7 @@ void sound_init()
printf("%s", Mix_GetError());
}
sound = malloc(sizeof(Mix_Music*)*10);
gameData->sound = malloc(sizeof(Mix_Music*)*10);
Mix_Music *musique;
musique = Mix_LoadMUS("sound/musique.wav");
......@@ -16,33 +16,33 @@ void sound_init()
Mix_Chunk *son;
son = Mix_LoadWAV("sound/addTower.wav");
sound[TOWER] = son;
gameData->sound[TOWER] = son;
son = Mix_LoadWAV("sound/addCentrale.wav");
sound[CENTRAL] = son;
gameData->sound[CENTRAL] = son;
son = Mix_LoadWAV("sound/projectile.wav");
sound[PROJECTILE] = son;
gameData->sound[PROJECTILE] = son;
son = Mix_LoadWAV("sound/monsterSolder.wav");
sound[SOLD] = son;
gameData->sound[SOLD] = son;
son = Mix_LoadWAV("sound/monsterGeneral.wav");
sound[GENE] = son;
gameData->sound[GENE] = son;
son = Mix_LoadWAV("sound/monsterHuge_Solder.wav");
sound[HSOLD] = son;
gameData->sound[HSOLD] = son;
son = Mix_LoadWAV("sound/monsterBoss.wav");
sound[BOS] = son;
gameData->sound[BOS] = son;
son = Mix_LoadWAV("sound/beginLevel.wav");
sound[BEGINLEVEL] = son;
gameData->sound[BEGINLEVEL] = son;
son = Mix_LoadWAV("sound/levelLose.wav");
sound[LOSELEVEL] = son;
gameData->sound[LOSELEVEL] = son;
son = Mix_LoadWAV("sound/levelWin.wav");
sound[WINLEVEL] = son;
gameData->sound[WINLEVEL] = son;
}
......@@ -66,52 +66,52 @@ if(!texture_surface) {
void sprite_init()
{
textures = calloc(37, sizeof(Texture*));
textures[SOLDER_TEX] = sprite_importTexture("images/sprite-entities/cafard.png", 2, 1);
textures[HUGE_SOLDER_TEX] = sprite_importTexture("images/sprite-entities/punaise.png", 2, 1);
textures[BOSS_TEX] = sprite_importTexture("images/sprite-entities/gendarme.png", 2, 1);
textures[GERERAL_TEX] = sprite_importTexture("images/sprite-entities/larve.png", 2, 1);
textures[CENTRALE_TEX] = sprite_importTexture("images/tests/food.png", 1, 1);
textures[RADAR_TEX] = sprite_importTexture("images/tests/gem1.png", 1, 1);
textures[ARMEMENT_TEX] = sprite_importTexture("images/tests/gem2.png", 1, 1);
textures[MUNITION_TEX] = sprite_importTexture("images/tests/gem3.png", 1, 1);
textures[MISSILE_TEX] = sprite_importTexture("images/sprite-entities/puceron.png", 1, 1);
textures[LASER_TEX] = sprite_importTexture("images/sprite-entities/mouche.png", 1, 1);
textures[ADD_TEX] = sprite_importTexture("images/tests/add.png", 1, 1);
textures[REMOVE_TEX] = sprite_importTexture("images/tests/delete.png", 1, 1);
textures[GETINFO_TEX] = sprite_importTexture("images/tests/info.png", 1, 1);
textures[PAUSE_TEX] = sprite_importTexture("images/tests/pause.png", 1, 1);
textures[PLAY_TEX] = sprite_importTexture("images/tests/play.png", 1, 1);
textures[SPLASH_TEX] = sprite_importTexture("images/sprite_splash.png", 1, 1);
textures[BUTTON_TEX] = sprite_importTexture("images/sprite_Button.png", 1, 1);
textures[PLANK_TEX] = sprite_importTexture("images/tests/plank.png", 1, 1);
textures[PLUS_TEX] = sprite_importTexture("images/tests/plus.png", 1, 1);
textures[TARGET_TEX] = sprite_importTexture("images/tests/target.png", 1, 1);
textures[MONEY_TEX] = sprite_importTexture("images/tests/money.png", 1, 1);
textures[POINTER_TEX] = sprite_importTexture("images/tests/hand.png", 1, 1);
textures[SHIELD_TEX] = sprite_importTexture("images/tests/shield.png", 1, 1);
textures[DAMAGE_TEX] = sprite_importTexture("images/tests/explosion.png", 1, 1);
textures[CADENCE_TEX] = sprite_importTexture("images/tests/munition.png", 1, 1);
textures[SPEED_TEX] = sprite_importTexture("images/tests/speed.png", 1, 1);
textures[LIFE_TEX] = sprite_importTexture("images/tests/heart.png", 1, 1);
textures[FOOD_TEX] = sprite_importTexture("images/tests/cookie.png", 1, 1);
textures[TERRAIN_1_TEX] = sprite_importTexture("images/sprite-world/terrain1.png", 1, 1);
textures[TERRAIN_2_TEX] = sprite_importTexture("images/sprite-world/terrain2.png", 1, 1);
textures[TERRAIN_3_TEX] = sprite_importTexture("images/sprite-world/terrain3.png", 1, 1);
textures[TERRAIN_4_TEX] = sprite_importTexture("images/sprite-world/terrain4.png", 1, 1);
textures[TERRAIN_5_TEX] = sprite_importTexture("images/sprite-world/terrain5.png", 1, 1);
textures[CHEMIN_1_TEX] = sprite_importTexture("images/sprite-world/chemin1.png", 1, 1);
textures[CHEMIN_2_TEX] = sprite_importTexture("images/sprite-world/chemin2.png", 1, 1);
textures[CHEMIN_3_TEX] = sprite_importTexture("images/sprite-world/chemin3.png", 1, 1);
textures[REINE_TEX] = sprite_importTexture("images/sprite-world/arrivee-reine.png", 1, 1);
gameData->textures = calloc(37, sizeof(Texture*));
gameData->textures[SOLDER_TEX] = sprite_importTexture("images/sprite-entities/cafard.png", 2, 1);
gameData->textures[HUGE_SOLDER_TEX] = sprite_importTexture("images/sprite-entities/punaise.png", 2, 1);
gameData->textures[BOSS_TEX] = sprite_importTexture("images/sprite-entities/gendarme.png", 2, 1);
gameData->textures[GERERAL_TEX] = sprite_importTexture("images/sprite-entities/larve.png", 2, 1);
gameData->textures[CENTRALE_TEX] = sprite_importTexture("images/tests/food.png", 1, 1);
gameData->textures[RADAR_TEX] = sprite_importTexture("images/tests/gem1.png", 1, 1);
gameData->textures[ARMEMENT_TEX] = sprite_importTexture("images/tests/gem2.png", 1, 1);