From 5d4ad790c9e2a1c2b4458ccf50d5df47ee871591 Mon Sep 17 00:00:00 2001 From: llebasca <llebasca@insa-rennes.fr> Date: Tue, 2 Mar 2021 12:05:36 +0100 Subject: [PATCH] Personnage and DS initialization --- GAME/include/DS.h | 6 ++++-- GAME/include/personnage.h | 8 +++++--- GAME/src/DS.c | 37 +++++++++++++++++++++++++++++++++ GAME/src/personnage.c | 43 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 GAME/src/DS.c create mode 100644 GAME/src/personnage.c diff --git a/GAME/include/DS.h b/GAME/include/DS.h index db84301..9f14359 100644 --- a/GAME/include/DS.h +++ b/GAME/include/DS.h @@ -21,9 +21,11 @@ * \brief DS structure */ -struct DS { +typedef struct { int door; /**< Integer representing the door number i.e. the DS location. */ char * image_DS; /**< Source image of the DS. */ -}; +} DS; + +int init_DS(DS * exam, int door_DS, char * path); #endif /*INSAGAME_DS_H*/ diff --git a/GAME/include/personnage.h b/GAME/include/personnage.h index 62dc285..62428cb 100644 --- a/GAME/include/personnage.h +++ b/GAME/include/personnage.h @@ -9,7 +9,7 @@ * \version 1 * \date 25/02/2021 * - * Character structure definiton. + * Character structure and functions definiton. * */ @@ -21,13 +21,15 @@ * \brief Character structure */ -struct personnage { +typedef struct { int x_pers; /**< Position : abscissa */ int y_pers; /**< Position : ordinate */ int long_pers; /**< Size : length */ int larg_pers; /**< Size : width */ int speed_pers; /**< Charater speed */ char * image_pers; /**< Source image of the character. */ -}; +}Personnage; + +int init_pers(Personnage * character, int x, int y, int length, int width, int speed, char * path); #endif /*GAME_INSA_PROJECT_PERSONNAGE_H*/ diff --git a/GAME/src/DS.c b/GAME/src/DS.c new file mode 100644 index 0000000..024c1b2 --- /dev/null +++ b/GAME/src/DS.c @@ -0,0 +1,37 @@ +/* +// Created by Lucile on 02/03/2021. +*/ + +/*! + * \file DS.c + * \brief Exam Source File + * \authors Lucile + * \version 1 + * \date 02/03/2021 + * + * Character function implementation. + * + */ + +#include <stdio.h> +#include <SDL2/SDL.h> +#include <SDL2/SDL_image.h> +#include "DS.h" + +/*! + * \fn int init_DS(DS * exam, int door_DS, char * path) + * \brief This function initialize a DS : position (the door number) and the path to the DS's image. + * + * \param [in] exam a DS pointer + * \param [in] door_DS a door number corresponding to the DS location + * \param [in] path the DS image path + * \return 1 if the initialization went right. + */ + +int init_DS(DS * exam, int door_DS, char * path){ + exam->door=door_DS; + exam->image_DS = malloc(strlen(path)); + strcpy(exam->image_DS, path); + return 1; + +} \ No newline at end of file diff --git a/GAME/src/personnage.c b/GAME/src/personnage.c new file mode 100644 index 0000000..52ea600 --- /dev/null +++ b/GAME/src/personnage.c @@ -0,0 +1,43 @@ +/* +// Created by Lucile on 25/02/2021. +*/ + +/*! + * \file personnage.c + * \brief Character Source File + * \authors Lucile + * \version 1 + * \date 02/03/2021 + * + * Character function implementation. + * + */ + +#include <stdio.h> +#include <SDL2/SDL.h> +#include <SDL2/SDL_image.h> +#include "personnage.h" + +/*! + * \fn int init_pers(Personnage * character, int x, int y, int length, int width, int speed, char * path) + * \brief This function initialize the character : position of the character's top left corner (x,y), size (length, width), speed and also the path to the character's image. + * + * \param [in] character a pointer on the character + * \param [in] x the character's abscissa + * \param [in] y the character's ordinate + * \param [in] length the character's length + * \param [in] width the character's width + * \param [in] path the path to the character's image + * \return 1 if the initialization went right. + */ + +int init_pers(Personnage * character, int x, int y, int length, int width, int speed, char * path){ + character->x_pers=x; + character->y_pers=y; + character->long_pers=length; + character->larg_pers=width; + character->speed_pers=speed; + character->image_pers = malloc(strlen(path)); + strcpy(character->image_pers, path); + return 1; +} \ No newline at end of file -- GitLab