Merge branch 'master' of gitlab.iut-clermont.uca.fr:/maribemont/projet-tut

master
Mathis RIBEMONT 3 years ago
commit 0b9b526892

2
.gitignore vendored

@ -71,6 +71,8 @@ _deps
### binaries ###
bin/
build_debug/
build_release/
Documentation/doxygen/

@ -4,9 +4,8 @@ SET(PROJECT_NAME Pontu)
project(${PROJECT_NAME})
file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
add_executable(${PROJECT_NAME} ${MY_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/entryPoints/main.c)
add_executable(Test ${MY_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/entryPoints/test.c)
add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/entryPoints/main.c)
add_executable(Test ${CMAKE_CURRENT_SOURCE_DIR}/entryPoints/test.c)
@ -18,20 +17,18 @@ find_package(SDL2_ttf REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_mixer REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${SDL2_INCLUDE_DIR})
target_include_directories(Test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${SDL2_INCLUDE_DIR})
SET(OptionGCC -Wall -Wextra -pedantic -Wconversion -std=c17 -Og -g)
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11)
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11)
if (MINGW)
target_link_options(${PROJECT_NAME} PRIVATE -lmingw32 -lSDL2main -lSDL2 -mwindows)
target_compile_options(${PROJECT_NAME} PRIVATE ${OptionGCC} -Dmain=SDL_main -fdiagnostics-color=always)
target_link_options(Test PRIVATE -lmingw32 -lSDL2main -lSDL2 -mwindows)
target_compile_options(Test PRIVATE ${OptionGCC} -Dmain=SDL_main -fdiagnostics-color=always)
elseif(UNIX)
target_compile_options(${PROJECT_NAME} PRIVATE ${OptionGCC} -D_REENTRANT)
target_compile_options(Test PRIVATE ${OptionGCC} -D_REENTRANT)
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
target_compile_options(Test PRIVATE /W4 /WX)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Wno-unused-function)
target_compile_options(Test PRIVATE -Wall -Wextra -Wpedantic -Wno-unused-function)
endif()
target_link_libraries(${PROJECT_NAME} SDL2::Main)
@ -42,3 +39,8 @@ target_link_libraries(${PROJECT_NAME} SDL2::Mixer)
target_link_libraries(Test SDL2::Mixer)
target_link_libraries(${PROJECT_NAME} SDL2::TTF)
target_link_libraries(Test SDL2::TTF)
add_subdirectory(src/debug)
add_subdirectory(src/engine)
add_subdirectory(src/model)
add_subdirectory(src/view)

@ -23,6 +23,7 @@
* Functions in header must be marked as inline
* Don't forget antislashes
*/
#define GENERATE_DYNAMIC_ARRAY(T) \
struct array_##T { \
T* elems; \
@ -31,13 +32,13 @@ struct array_##T { \
}; \
\
/*Contruct an empty array*/ \
inline struct array_##T array_##T##_Create() { \
static struct array_##T array_##T##_Create() { \
struct array_##T array = {.elems=NULL, .size=0, .space=0}; \
return array; \
} \
\
/*Free an array*/ \
inline void array_##T##_Free(struct array_##T* array) { \
static void array_##T##_Free(struct array_##T* array) { \
free(array->elems); \
array->elems = NULL; \
array->size = 0; \
@ -45,7 +46,7 @@ inline void array_##T##_Free(struct array_##T* array) { \
} \
\
/*Reserve space for an array*/\
inline void array_##T##_Reserve(struct array_##T* array, const size_t space) { \
static void array_##T##_Reserve(struct array_##T* array, const size_t space) { \
array->space = space; \
array->elems = realloc(array->elems, sizeof(T)*(array->space)); \
if (array->elems == NULL) { \
@ -54,7 +55,7 @@ inline void array_##T##_Reserve(struct array_##T* array, const size_t space) { \
} \
\
/*Fit space to size for an array*/\
inline void array_##T##_FitToSize(struct array_##T* array) { \
static void array_##T##_FitToSize(struct array_##T* array) { \
array->space = array->size; \
array->elems = realloc(array->elems, sizeof(T)*(array->space)); \
if (array->elems == NULL) { \
@ -63,7 +64,7 @@ inline void array_##T##_FitToSize(struct array_##T* array) { \
} \
\
/*Add an element to an array*/\
inline void array_##T##_AddElement(struct array_##T* array, const T element) { \
static void array_##T##_AddElement(struct array_##T* array, const T element) { \
++(array->size); \
if (array->size > array->space) { \
++(array->space); \
@ -77,7 +78,7 @@ inline void array_##T##_AddElement(struct array_##T* array, const T element) { \
} \
\
/*Remove an element from an array*/\
inline bool array_##T##_RemoveElement(struct array_##T* array, const T element, bool (*areEqual)(const T, const T)) { \
static bool array_##T##_RemoveElement(struct array_##T* array, const T element, bool (*areEqual)(const T, const T)) { \
for (size_t i=0; i<array->size; ++i) { \
if (areEqual(array->elems[i], element)) { \
for (;i<array->size-1; ++i) { \
@ -91,7 +92,7 @@ inline bool array_##T##_RemoveElement(struct array_##T* array, const T element,
} \
\
/*Check if an array contains an element*/\
inline bool array_##T##_Contains(const struct array_##T* const array, const T element, bool (*areEqual)(const T, const T)) { \
static bool array_##T##_Contains(const struct array_##T* const array, const T element, bool (*areEqual)(const T, const T)) { \
for (size_t i = 0; i < array->size; i++) { \
if (areEqual(array->elems[i], element)) { \
return true; \
@ -101,19 +102,19 @@ inline bool array_##T##_Contains(const struct array_##T* const array, const T el
}\
\
/*Apply a function to each element in the array*/\
inline void array_##T##_Foreach(const struct array_##T* const array, void (*func)(const T)) { \
static void array_##T##_Foreach(const struct array_##T* const array, void (*func)(const T)) { \
for(size_t i = 0; i<array->size; ++i) { \
func(array->elems[i]);\
}\
}\
\
/*Return last element*/\
inline T* array_##T##_First(const struct array_##T* const array) {\
static T* array_##T##_First(const struct array_##T* const array) {\
return &array->elems[0];\
}\
\
/*Return last element*/\
inline T* array_##T##_Last(const struct array_##T* const array) {\
static T* array_##T##_Last(const struct array_##T* const array) {\
return &array->elems[array->size-1];\
}\

@ -2,7 +2,17 @@
#define BUTTON_ACTION_INCLUDED
#include "engine/Button.h"
#include "engine/AudioHandler.h"
#include <SDL2/SDL.h>
/**
* @brief Args for the SoundButton
*/
typedef struct
{
AudioHandler audio; //Audio from which we change masterVolume
SDL_Renderer* renderer;
}argsSoundButton;
void action_none(P_Button* caller);
@ -15,7 +25,7 @@ void action_print(P_Button* caller);
void action_setStateToMainMenu(P_Button* caller);
/**
* @brief Button handle wich mute the sound
* @brief Button handle wich mute and unmute the master volume
* @param caller The button clicked
*/
void action_muteSound(P_Button* caller);

@ -11,13 +11,14 @@
#include "model/Coord.h"
#include "engine/Button.h"
#include "engine/TextInput.h"
/**
* \enum InputType
* \brief Different types for input
*/
typedef enum {InputType_None, InputType_ClickGame, InputType_MoveGame, InputType_ActivateUI, InputType_Window_Resize, InputType_Window_Close, InputType_ButtonChanged} InputType;
typedef enum {InputType_None, InputType_ClickGame, InputType_MoveGame, InputType_ActivateUI, InputType_Window_Resize, InputType_Window_Close, InputType_ButtonChanged, InputType_TextInput} InputType;
/**
* \enum UIAction
@ -55,6 +56,8 @@ typedef struct {
ButtonEvent event;
} buttonEvent;
TextInput* textInput;
} data; ///< Informations about the input
InputType type; ///< Type of input
@ -99,4 +102,6 @@ InputElement createInputElementCloseWindow();
InputElement createInputElementButtonClicked(P_Button* button, const ButtonEvent event);
InputElement createInputElementTextInput(TextInput* textInput);
#endif // INPUT_ELEMENT_INCLUDED

@ -35,6 +35,8 @@ typedef struct
TTF_Font* textFont;
}TextInput;
bool addStringToInputTextValue(TextInput* textInput, const char* strToAdd);
/**
* \brief Add a character on the right place on the textInput
* \param[in,out] textInput Memmory address of the TextInput to modify

@ -0,0 +1,16 @@
set(SOURCES
printer.c
)
target_sources(
${PROJECT_NAME}
PUBLIC
${SOURCES}
)
target_sources(
Test
PUBLIC
${SOURCES}
)

@ -2,6 +2,7 @@
#include "engine/GeneralState.h"
#include "engine/AudioHandler.h"
int soundMuted=0;
void action_none(P_Button* caller) {
//return nothing
@ -19,9 +20,21 @@ void action_setStateToMainMenu(P_Button* caller)
void action_muteSound(P_Button* caller)
{
//Mute sound -> Master Volume = 0
AudioHandler audioHandler = *((AudioHandler*)caller->arg);
argsSoundButton argsSoundB = *(argsSoundButton*)caller->arg;
AudioHandler audioHandler = argsSoundB.audio;
//fprintf(stderr,"Sound muted = %d\n",soundMuted);
if(!soundMuted)
{
changeMasterVol(&audioHandler,0);
soundMuted=1;
}
else
{
changeMasterVol(&audioHandler,10);
soundMuted=0;
}
//Change Icon -> Mute icon
//caller->texture = createTextureFromPath(renderer,"rsrc/img/MuteResized.png");

@ -0,0 +1,30 @@
set(SOURCES
AudioHandler.c
Button.c
ButtonActions.c
ColorPicker.c
Colors.c
FontLoader.c
FontUtils.c
GameInputProcessor.c
InputElement.c
InputProcessor.c
TextInput.c
TextLabel.c
TextureHandler.c
TextureLoader.c
UIElementUtils.c
)
target_sources(
${PROJECT_NAME}
PUBLIC
${SOURCES}
)
target_sources(
Test
PUBLIC
${SOURCES}
)

@ -39,6 +39,15 @@ InputElement createInputElementButtonClicked(P_Button* button, const ButtonEvent
return i;
}
InputElement createInputElementTextInput(TextInput* textInput) {
InputElement i = {
.type = InputType_TextInput,
.data.textInput=textInput
};
return i;
}
InputElement createInputElementCloseWindow(){
InputElement i = {.type = InputType_Window_Close};
return i;

@ -34,6 +34,7 @@ InputElement proccessInput(InputProcessor *inputProcessor)
P_Button* b = &inputProcessor->tabButton.elems[i];
if (isHover(b)) {
b->onClick(b);
break;
}
}
bool textInputClicked = false;
@ -81,14 +82,17 @@ InputElement proccessInput(InputProcessor *inputProcessor)
}
break;
case SDL_TEXTINPUT:
addStringToInputTextValueAtCursor(inputProcessor->selectedTextInput, event.text.text);
addStringToInputTextValue(inputProcessor->selectedTextInput, event.text.text);
return createInputElementTextInput(inputProcessor->selectedTextInput);
break;
case SDL_TEXTEDITING:
inputProcessor->selectedTextInput->cursorPosition = event.edit.start;
return createInputElementTextInput(inputProcessor->selectedTextInput);
break;
case SDL_KEYDOWN:
if (inputProcessor->selectedTextInput != NULL && event.key.keysym.sym == SDLK_BACKSPACE) {
removeCharacterToInputTextValueAtCursor(inputProcessor->selectedTextInput);
return createInputElementTextInput(inputProcessor->selectedTextInput);
}
break;
}

@ -1,5 +1,21 @@
#include "engine/TextInput.h"
bool addStringToInputTextValue(TextInput* textInput, const char* strToAdd) {
if(textInput == NULL)
{
fprintf(stderr, "WARNING: Can't add text to NULL textInput\n");
return false;
}
const size_t lenText = strlen(textInput->value);
const size_t lenStrToAdd = strlen(strToAdd);
textInput->value = (char*) realloc(textInput->value, sizeof(char) * (lenText+lenStrToAdd+1));
strcat(textInput->value, strToAdd);
textInput->cursorPosition += lenStrToAdd;
return true;
}
bool addStringToInputTextValueAtCursor(TextInput* textInput, const char* strToAdd)
{
if(textInput == NULL)
@ -99,7 +115,7 @@ bool drawTextInputOnRenderer(SDL_Renderer* renderer, const TextInput* textInput)
fprintf(stderr, "WARNING: Can't create TextInput texture: %s\n", SDL_GetError());
return false;
}
char textValue[strlen(textInput->value)+1];
char textValue[strlen(textInput->value)+2];
SDL_Rect size = {.x=0, .y=0, .w=textInput->size.w, .h=textInput->size.h};
if(textInput->textFont == NULL)
{

@ -0,0 +1,23 @@
set(SOURCES
Board.c
Coord.c
Game.c
Island.c
IslandOrBridge.c
Piece.c
Player.c
PlayersColors.c
)
target_sources(
${PROJECT_NAME}
PUBLIC
${SOURCES}
)
target_sources(
Test
PUBLIC
${SOURCES}
)

@ -1,6 +1,6 @@
#include "model/Game.h"
#include "model/IslandOrBridge.h"
#include "engine/ArrayUtils.h"
#include "model/arrayCoord.h"
#include <assert.h>
// Not defined in header to not pollute inferface

@ -0,0 +1,24 @@
set(SOURCES
BoardDrawer.c
GameCreationMenu.c
GameInterface.c
GameMain.c
MainMenu.c
MenuEndGame.c
PiecesDrawer.c
Settings.c
ToRect.c
)
target_sources(
${PROJECT_NAME}
PUBLIC
${SOURCES}
)
target_sources(
Test
PUBLIC
${SOURCES}
)

@ -378,6 +378,7 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState, AudioH
array_P_Button_AddElement(&inputProcessor.tabButton, validateBtn);
array_P_Button_AddElement(&inputProcessor.tabButton, cancelBtn);
// Displaying menu
drawGameCreationMenu(renderer, labels, nbLabels, buttons, nbButtons, lines, *nbPlayers, &bg);
while(*generalState == GS_GameCreationMenu)
@ -401,6 +402,10 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState, AudioH
break;
}
break;
case InputType_TextInput:
drawTextInputOnRenderer(renderer, inputElement.data.textInput);
SDL_RenderPresent(renderer);
break;
default:
break;
}
@ -415,7 +420,7 @@ bool gameCreationMenu(SDL_Renderer* renderer, GeneralState* generalState, AudioH
drawGameCreationMenu(renderer, labels, nbLabels, buttons, nbButtons, lines, *nbPlayers, &bg);
viewChanged=false;
}
SDL_Delay(20);
SDL_Delay(5);
}

@ -1,26 +0,0 @@
#include "view/GameDrawer.h"
#include "view/BoardDrawer.h"
#include "view/PiecesDrawer.h"
bool drawGame(SDL_Renderer* renderer, const SDL_Rect* windowSize, const SDL_Rect* boardRect, const Game* game,TextureHandler* textureHandler)
{
//SDL_Texture* menuTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 50, 70);
/*SDL_SetRenderTarget(renderer, menuTexture);
SDL_SetRenderDrawColor(renderer, 150, 243, 59, 255);
SDL_Rect buttonRect = {.x = 0,.y = 0,.w = 50,.h = 70};
SDL_RenderFillRect(renderer, &buttonRect);
SDL_SetRenderTarget(renderer, NULL);*/
//P_Button menu = createButton(menuTexture, NULL, (windowSize->w*5)/100, (windowSize->h*5)/100, 50, 70, NULL);
//P_Button menu = createButton(menuTexture, NULL, 10, 10, 50, 70, NULL);
//drawBoard(renderer, boardRect, &(game->board), textureHandler->textures[TEXTURE_Island], textureHandler->textures[TEXTURE_Bridge], textureHandler->textures[TEXTURE_Water]);
/*drawPiecesPlayer(renderer, boardRect, game->board.arrPieces, game->board.nbPieces, 0, textureHandler->textures[TEXTURE_PieceRed]);
drawPiecesPlayer(renderer, boardRect, game->board.arrPieces, game->board.nbPieces, 1, textureHandler->textures[TEXTURE_PieceViolet]);
*/
return true;
}

@ -10,11 +10,9 @@
struct array_P_Button createGameInterfaceButtons(SDL_Renderer* renderer, FontHandler* fontHandler, GeneralState* generalState, AudioHandler audioHandler) {
SDL_Color menuBorderColor= {0,0,255,255};
SDL_Color menuBackgroundColor = {0,255,0,255};
//SDL_Color menuBackgroundColor = {0,0,255,255};
//struct argsBouton
int sizex=20,sizey=20;
@ -38,9 +36,9 @@ struct array_P_Button createGameInterfaceButtons(SDL_Renderer* renderer, FontHan
array_P_Button_AddElement(&buttons, createButton(settingsButtonTexture, settingsButtonHoverTexture, 750,10,50,50,&action_print)); //top right corner (square or circle)
// Mute/Unmute
argsSoundButton argsSoundButt = {audioHandler, renderer};
array_P_Button_AddElement(&buttons, createButton(muteButtonTexture, muteButtonHoverTexture, 825,10,50,50,&action_muteSound)); //top right cornre (square or circle)
array_P_Button_Last(&buttons)->arg = (void*)&audioHandler;
array_P_Button_Last(&buttons)->arg = (void*)&argsSoundButt;
return buttons;
}

@ -94,6 +94,9 @@ void testTextInputProcessor() {
break;
}
case InputType_TextInput:
drawTextInputOnRenderer(renderer, inputElement.data.textInput);
needToPresent = true;
default:
break;
}
@ -101,8 +104,6 @@ void testTextInputProcessor() {
}
drawTextInputOnRenderer(renderer, textInput);
needToPresent = true;
if (needToPresent) {
SDL_RenderPresent(renderer);

@ -22,33 +22,20 @@ Nous développerons successivement les versions suivantes :
## Comment télécharger, compiler et executer Pontu
### Sur Linux:
Utiliser l'option -DCMAKE_BUILD_TYPE=Debug pour build en debug
-DCMAKE_BUILD_TYPE=Release pour build en release
```BASH
git clone [urlToThisRepo]
cd [thisRepo]/Pontu
git submodule init
git submodule update
mkdir bin
mkdir bin #ou un autre nom de fichier comme "build_debug" ou "build_release"
cd bin
cmake ..
make
make # ou mingw32-make avec Mingw
cd .. #Se mettre dans le dossier Pontu
./bin/Pontu
```
### Sur Windows:
```BASH
git clone [urlToThisRepo]
cd [thisRepo]/Pontu
git submodule init
git submodule update
mkdir bin
cd bin
cmake ..
mingw32-make
cd .. #Se mettre dans le dossier Pontu
./bin/Pontu.exe
```

@ -0,0 +1,9 @@
Package: pontu-game
Description: A board game by Grain de créa on your computer
Version: 0.8
Maintainer: Théotime "LR06" Maillarbaux, Érina Point, Ms Hater, Martin Rouault MANM, Jack Thomas
Architecture: all
Depends: libsdl2-2.0-0, libsdl2-mixer-2.0-0, libsdl2-ttf-2.0-0, libsdl2-image-2.0-0
Built-Using: gcc-8.3.0 (= 8.3.0-6)
Section: games
Loading…
Cancel
Save