Commit 10366e2e authored by Nicolas LIENART's avatar Nicolas LIENART

Fix circle & new menu images + fix money

parent 92c24ce7
......@@ -49,8 +49,8 @@ int main(int argc, char *argv[])
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
case_gameData_init();
gui_init();
sprite_init();
gui_init();
sound_init();
// Position X, Y en pixel ET en indice de case de la souris
......
......@@ -211,7 +211,7 @@ void case_removeConstruction(int caseX, int caseY)
int index_case = case_getCaseIndex(caseX, caseY);
TypeCase type = case_getType(caseX, caseY);
GeneralType generalType = case_getGeneralConstructionType(type);
plateau->joueur->argent += tour_getPrixRevente(type);
player_gagneArgent(tour_getPrixRevente(type));
mapData->cases[index_case] = TERRAIN;
if (generalType == TOUR) {
......
......@@ -454,16 +454,13 @@ void display_printInfos()
void display_drawCircle(int fillMode)
{
float angleStep = 2 * M_PI / 360;
float angleCurrent = 0;
glPolygonMode(GL_FRONT_AND_BACK, fillMode);
glBegin(GL_POLYGON);
glBegin(GL_LINES);
while(angleCurrent < 2 * M_PI) {
glVertex2f(0.5 * cos(angleCurrent), 0.5 * sin(angleCurrent));
angleCurrent += angleStep;
for (int i = 0; i< 180; i++) {
glVertex2f(0.5 * cos(i), 0.5 * sin(i));
glVertex2f(0.5 * cos(i+0.5), 0.5 * sin(i+0.5));
}
glEnd();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
......@@ -704,7 +701,8 @@ void display_drawSingleTower(int caseX, int caseY, TypeCase type)
break;
case TOUR:
tour = case_getTourPointer(caseX, caseY);
glRotatef(tour->angle+45, 0, 0, 1);
// TODO: check angle
glRotatef(tour->angle, 0, 0, 1);
break;
}
switch (type) {
......@@ -809,19 +807,29 @@ void display_setDrawingZone(GUI *section)
void display_drawZoneBasedOnGUI(GUI *section)
{
display_setDrawingZone(section);
if (gameData->default_list == NULL && gameData->gameState == LEVELPLAY) {
display_initDefaultList();
}
glBegin(GL_QUADS);
glVertex2f(0, 0);
glVertex2f(0, section->dimensions->height);
glVertex2f(section->dimensions->width, section->dimensions->height);
glVertex2f(section->dimensions->width, 0);
glEnd();
if (section->display_texture == TRUE) {
glPushMatrix();
glTranslatef(section->dimensions->width/2., section->dimensions->height/2., 0);
glScalef(section->dimensions->width, section->dimensions->height, 1);
sprite_displayFixedTexture(section->texture_name);
glPopMatrix();
}
else {
glBegin(GL_QUADS);
glVertex2f(0, 0);
glVertex2f(0, section->dimensions->height);
glVertex2f(section->dimensions->width, section->dimensions->height);
glVertex2f(section->dimensions->width, 0);
glEnd();
}
}
void display_drawButtonsBasedOnGUI(GUI *section)
{
Button *button = section->buttons;
while (button != NULL) {
display_drawSingleButton(button);
......@@ -834,8 +842,6 @@ void display_drawZoneBasedOnGUI(GUI *section)
else if (section == gameData->topGUI) {
display_printMoney();
}
display_setDrawingZone(gameData->bodyGUI);
}
void display_buttonBackground(Display display)
......@@ -981,17 +987,28 @@ void display_printMoney()
void display_top()
{
glColor3f(1,1,0);
display_setDrawingZone(gameData->topGUI);
display_drawZoneBasedOnGUI(gameData->topGUI);
display_drawButtonsBasedOnGUI(gameData->topGUI);
display_setDrawingZone(gameData->bodyGUI);
}
void display_bottom()
{
glColor3f(1,0,1);
display_setDrawingZone(gameData->bottomGUI);
display_drawZoneBasedOnGUI(gameData->bottomGUI);
display_drawButtonsBasedOnGUI(gameData->bottomGUI);
glColor3f(1,1,1);
display_setDrawingZone(gameData->buttonGUI);
display_drawZoneBasedOnGUI(gameData->buttonGUI);
display_drawButtonsBasedOnGUI(gameData->buttonGUI);
glColor3f(.50,0.7,1);
display_setDrawingZone(gameData->infoGUI);
display_drawZoneBasedOnGUI(gameData->infoGUI);
display_drawButtonsBasedOnGUI(gameData->infoGUI);
display_setDrawingZone(gameData->bodyGUI);
}
void display_left()
......@@ -1013,14 +1030,36 @@ void display_window()
void display_mainMenu()
{
glColor3f(1,0,1);
display_drawZoneBasedOnGUI(gameData->mainMenuGUI);
glColor3f(1,1,1);
display_setDrawingZone(gameData->mainMenuGUI);
glPushMatrix();
glTranslatef(gameData->bodyGUI->dimensions->width/2., gameData->bodyGUI->dimensions->height/2., 0);
glScalef(gameData->bodyGUI->dimensions->width, gameData->bodyGUI->dimensions->height, 1);
sprite_displayFixedTexture(MAINMENU_TEX);
glPopMatrix();
display_drawButtonsBasedOnGUI(gameData->mainMenuGUI);
display_setDrawingZone(gameData->bodyGUI);
}
void display_endMenu()
{
glColor3f(1,0,1);
glColor3f(1,1,1);
display_setDrawingZone(gameData->endMenuGUI);
display_drawZoneBasedOnGUI(gameData->endMenuGUI);
glPushMatrix();
glTranslatef(gameData->bodyGUI->dimensions->width/2., gameData->bodyGUI->dimensions->height/2., 0);
glScalef(gameData->bodyGUI->dimensions->width, gameData->bodyGUI->dimensions->height, 1);
if (gameData->gameState == WINMENU) {
sprite_displayFixedTexture(WINMENU_TEX);
}
else {
sprite_displayFixedTexture(LOSEMENU_TEX);
}
glPopMatrix();
display_drawButtonsBasedOnGUI(gameData->endMenuGUI);
display_setDrawingZone(gameData->bodyGUI);
}
void display_game(GUI *plateau_gui, GLuint idMap, GLuint idGrid)
......
......@@ -66,6 +66,7 @@ void display_window();
void display_left();
void display_top();
void display_drawZoneBasedOnGUI(GUI *section);
void display_drawButtonsBasedOnGUI(GUI *section);
void display_setDrawingZone(GUI *section);
void display_drawSingleButton(Button *button);
#endif //DRAW_MONSTER_H_
......@@ -76,7 +76,8 @@ void gui_changeActionButtonState(Action action, Display state)
currentButton->display = state;
}
GUI *gui_addChildren(SectionName name, int x, int y, int width, int height, GUI *parent)
// TODO: ajout de texture
GUI *gui_addChildren(SectionName name, int x, int y, int width, int height, GUI *parent, TextureName texture_name, Bool display_texture)
{
Div *dimensions = calloc(1, sizeof(Div));
dimensions->x = x;
......@@ -89,8 +90,15 @@ GUI *gui_addChildren(SectionName name, int x, int y, int width, int height, GUI
new->childen = NULL;
new->name = name;
new->dimensions = dimensions;
new->next = parent->childen;
parent->childen = new;
if (parent) {
new->next = parent->childen;
parent->childen = new;
}
new->texture_name = texture_name;
new->display_texture = display_texture;
return new;
}
......@@ -106,16 +114,16 @@ void gui_init()
gameData->bodyGUI->dimensions = dimensions;
gameData->topGUI = gui_addChildren(HEADER, 0, 0, gameData->bodyGUI->dimensions->width, 40, gameData->bodyGUI);
gameData->topGUI = gui_addChildren(HEADER, 0, 0, gameData->bodyGUI->dimensions->width, 40, gameData->bodyGUI, 0, FALSE);
gui_addButton(gameData->topGUI, 600, 20, 45, 45, PAUSE_BTN, CLICKED);
gameData->plateauGUI = gui_addChildren(PLATEAU, 0, 40, gameData->bodyGUI->dimensions->width, 600, gameData->bodyGUI);
gameData->plateauGUI = gui_addChildren(PLATEAU, 0, 40, gameData->bodyGUI->dimensions->width, 600, gameData->bodyGUI, 0, FALSE);
gameData->bottomGUI = gui_addChildren(FOOTER, 0, 640, gameData->bodyGUI->dimensions->width, 160, gameData->bodyGUI);
gameData->bottomGUI = gui_addChildren(FOOTER, 0, 640, gameData->bodyGUI->dimensions->width, 160, gameData->bodyGUI, 0, FALSE);
gameData->infoGUI = gui_addChildren(INFO_SECTION, 0, 0, 600, gameData->bottomGUI->dimensions->height, gameData->bottomGUI);
gameData->infoGUI = gui_addChildren(INFO_SECTION, 0, 0, 600, gameData->bottomGUI->dimensions->height, gameData->bottomGUI, 0, FALSE);
gameData->buttonGUI = gui_addChildren(TOWER_BUTTONS_SECTION, 600, 0, 200, gameData->bottomGUI->dimensions->height, gameData->bottomGUI);
gameData->buttonGUI = gui_addChildren(TOWER_BUTTONS_SECTION, 600, 0, 200, gameData->bottomGUI->dimensions->height, gameData->bottomGUI, 0, FALSE);
gui_addButton(gameData->buttonGUI, 30, 30, 45, 45, LASER_BTN, CLICKED);
gui_addButton(gameData->buttonGUI, 90, 30, 45, 45, MISSILE_BTN, ACTIVE);
......@@ -130,22 +138,28 @@ void gui_init()
gui_addButton(gameData->buttonGUI, 170, 130, 45, 45, REMOVE_BTN, ACTIVE);
gameData->mainMenuGUI = gui_addChildren(MAIN, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, MAINMENU_TEX, FALSE);
/*
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;
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);
gameData->endMenuGUI = gui_addChildren(LOSEMENU, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, 0, FALSE);
/*
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;
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);
}
......@@ -172,6 +186,7 @@ void gui_getAbsoluteCoordinates(GUI *section, int *X, int *Y)
}
}
// TODO: ajout de sprite
void gui_addButton(GUI *section, int x, int y, int width, int height, ButtonName name, Display display_mode)
{
Button *new_button = calloc(1, sizeof(Button));
......@@ -183,9 +198,14 @@ void gui_addButton(GUI *section, int x, int y, int width, int height, ButtonName
dimensions->height = height;
new_button->dimensions = dimensions;
new_button->name = name;
new_button->display = display_mode;
new_button->next = section->buttons;
new_button->texture_name_bg = 0;
new_button->texture_name_fg = 0;
new_button->display_texture = FALSE;
section->buttons = new_button;
}
......@@ -10,7 +10,7 @@ Display gui_getTowerButtonState(TypeCase type);
ButtonName gui_getButtonNameFromTypeCase(TypeCase type);
void gui_changeActionButtonState(Action action, Display state);
void gui_changeTowerButtonState(TypeCase type, Display state);
GUI *gui_addChildren(SectionName name, int x, int y, int width, int height, GUI *parent);
GUI *gui_addChildren(SectionName name, int x, int y, int width, int height, GUI *parent, TextureName texture_name, Bool display_texture);
void gui_init();
void gui_getAbsoluteCoordinates(GUI *section, int *X, int *Y);
void gui_addButton(GUI *section, int x, int y, int width, int height, ButtonName name, Display display_mode);
......
......@@ -40,6 +40,14 @@ TextureName sprite_getTextureNameFromButtonName(ButtonName button_name)
Texture* sprite_importTexture(char image_path[], int totalX, int totalY)
{
GLint internalFormat = GL_RGB;
GLenum format = GL_RGB;
if (strstr(image_path, ".png") != NULL) {
internalFormat = GL_RGBA;
format = GL_RGBA;
}
Texture* new_texture = malloc(sizeof(Texture));
if (!new_texture) {
printf("ERROR ALLOC : new_texture");
......@@ -61,7 +69,8 @@ if(!texture_surface) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_surface->w, texture_surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_surface->pixels);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, texture_surface->w, texture_surface->h, 0, format, GL_UNSIGNED_BYTE, texture_surface->pixels);
// NOTE: Unbinding
glBindTexture(GL_TEXTURE_2D, 0);
......@@ -70,7 +79,7 @@ if(!texture_surface) {
void sprite_init()
{
gameData->textures = calloc(37, sizeof(Texture*));
gameData->textures = calloc(40, 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);
......@@ -116,6 +125,10 @@ void sprite_init()
gameData->textures[CHEMIN_3_TEX] = sprite_importTexture("images/sprite-world/chemin3.png", 1, 1);
gameData->textures[REINE_TEX] = sprite_importTexture("images/sprite-world/arrivee-reine.png", 1, 1);
gameData->textures[MAINMENU_TEX] = sprite_importTexture("images/sprite-gui/MainMenu.jpg", 1, 1);
gameData->textures[LOSEMENU_TEX] = sprite_importTexture("images/sprite-gui/LoseMenu.jpg", 1, 1);
gameData->textures[WINMENU_TEX] = sprite_importTexture("images/sprite-gui/WinMenu.jpg", 1, 1);
}
SpriteTexture* sprite_loadSprite(TextureName texture_name, int loop_duration, Bool loop)
......
......@@ -10,6 +10,7 @@
#include <stdlib.h>
#include <SDL2/SDL_image.h>
#include <string.h>
#include "structures.h"
......
......@@ -8,7 +8,6 @@
#include <GL/glu.h>
#endif
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_ttf.h>
......@@ -215,7 +214,10 @@ typedef enum TextureName {
CHEMIN_1_TEX,
CHEMIN_2_TEX,
CHEMIN_3_TEX,
REINE_TEX
REINE_TEX,
MAINMENU_TEX,
LOSEMENU_TEX,
WINMENU_TEX
} TextureName;
typedef struct Texture {
......@@ -392,8 +394,9 @@ typedef enum Display {
} Display;
typedef struct Button {
SpriteTexture button;
SpriteTexture sprite;
TextureName texture_name_bg;
TextureName texture_name_fg;
Bool display_texture;
TextureText* texture_texte;
Div *dimensions;
Display display;
......@@ -413,6 +416,8 @@ typedef enum SectionName {
} SectionName;
typedef struct GUI {
TextureName texture_name;
Bool display_texture;
SectionName name;
Div *dimensions;
struct GUI *parent;
......
......@@ -313,7 +313,7 @@ void tour_updateShootingAngle(Tour* tour)
if (tour->targetMonster) {
double hypo = sqrt(pow(tour->x - tour->targetMonster->x, 2) + pow(tour->y - tour->targetMonster->y, 2));
double distance = tour->x - tour->targetMonster->x;
double angle = acos(distance/hypo)* 180.0 / M_PI;
double angle = asin(distance/hypo)* 180.0 / M_PI + 180;
tour->angle = angle;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment