Compare commits
No commits in common. "f6f303969d37d06813b167cf7775aadecb26e3e2" and "9a36a64c7cbaf7deb7d6fb38f586c7ad5b959c46" have entirely different histories.
f6f303969d
...
9a36a64c7c
|
@ -29,9 +29,7 @@
|
||||||
"libimg.h": "c",
|
"libimg.h": "c",
|
||||||
"stdint.h": "c",
|
"stdint.h": "c",
|
||||||
"transform_component.h": "c",
|
"transform_component.h": "c",
|
||||||
"sprite_component.h": "c",
|
"sprite_component.h": "c"
|
||||||
"texture_manager.h": "c",
|
|
||||||
"image.h": "c"
|
|
||||||
},
|
},
|
||||||
"C_Cpp.default.compilerPath": "/home/ulysse-cura/.local/bin/sh-elf-gcc"
|
"C_Cpp.default.compilerPath": "/home/ulysse-cura/.local/bin/sh-elf-gcc"
|
||||||
}
|
}
|
|
@ -7,9 +7,9 @@
|
||||||
typedef struct animation_system_data_t {
|
typedef struct animation_system_data_t {
|
||||||
sprite_component_data_t *sprite_component_data;
|
sprite_component_data_t *sprite_component_data;
|
||||||
|
|
||||||
bool play :1;
|
bool play :1;
|
||||||
bool loop :1;
|
bool loop :1;
|
||||||
bool reverse :1;
|
bool reverse :1;
|
||||||
|
|
||||||
float frame_delay_ms;
|
float frame_delay_ms;
|
||||||
float frame_timer_ms;
|
float frame_timer_ms;
|
||||||
|
|
|
@ -4,11 +4,9 @@
|
||||||
#include <gint/keycodes.h>
|
#include <gint/keycodes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
/**
|
/* event_t: Events struct
|
||||||
* @brief Store events for inputs
|
Store events for inputs
|
||||||
*
|
@keys Addressable array containing boolean state of each key */
|
||||||
* @param keys Addressable array containing boolean state of each key
|
|
||||||
*/
|
|
||||||
typedef struct event_t {
|
typedef struct event_t {
|
||||||
bool keys[0xa6];
|
bool keys[0xa6];
|
||||||
} event_t;
|
} event_t;
|
||||||
|
|
25
src/game.c
25
src/game.c
|
@ -10,6 +10,10 @@ void game_init(void)
|
||||||
|
|
||||||
entity_manager_init(&game.entity_manager);
|
entity_manager_init(&game.entity_manager);
|
||||||
|
|
||||||
|
game.last_clock_state = clock();
|
||||||
|
|
||||||
|
game.is_running = true;
|
||||||
|
|
||||||
entity_t *player = entity_manager_add_entity(&game.entity_manager, "player");
|
entity_t *player = entity_manager_add_entity(&game.entity_manager, "player");
|
||||||
|
|
||||||
rect_t player_bounds = {10.0f, 10.0f, 32.0f, 32.0f};
|
rect_t player_bounds = {10.0f, 10.0f, 32.0f, 32.0f};
|
||||||
|
@ -19,7 +23,14 @@ void game_init(void)
|
||||||
add_component(player, create_component(ANIMATION_SYSTEM), 4, 0, PLAYER_DEFAULT_IDLE_ANIMATION_SPEED, true, true, false);
|
add_component(player, create_component(ANIMATION_SYSTEM), 4, 0, PLAYER_DEFAULT_IDLE_ANIMATION_SPEED, true, true, false);
|
||||||
add_component(player, create_component(PLAYER_SYSTEM));
|
add_component(player, create_component(PLAYER_SYSTEM));
|
||||||
|
|
||||||
game.is_running = true;
|
//entity_t *enemy = entity_manager_add_entity(&game.entity_manager, "enemy0");
|
||||||
|
|
||||||
|
//rect_t enemy_bounds = {50.0f, 50.0f, 32.0f, 32.0f};
|
||||||
|
|
||||||
|
//add_component(enemy, create_component(TRANSFORM_COMPONENT), enemy_bounds, ENEMY_DEFAULT_SPEED);
|
||||||
|
//add_component(enemy, create_component(SPRITE_COMPONENT), "enemy_idle_sheet");
|
||||||
|
//add_component(enemy, create_component(ANIMATION_SYSTEM), 4, 0, ENEMY_DEFAULT_IDLE_ANIMATION_SPEED, true, true, false);
|
||||||
|
//add_component(enemy, create_component(ENEMY_SYSTEM));
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_handle_event(void)
|
void game_handle_event(void)
|
||||||
|
@ -41,17 +52,11 @@ void game_handle_event(void)
|
||||||
while(key_event.type != KEYEV_NONE);
|
while(key_event.type != KEYEV_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void update_time(void)
|
|
||||||
{
|
|
||||||
clock_t last_clock_state = clock();
|
|
||||||
clock_t start_clock = clock();
|
|
||||||
game.delta_time_ms = (double)(start_clock - last_clock_state) * 1000.0f / CLOCKS_PER_SEC;
|
|
||||||
last_clock_state = start_clock;
|
|
||||||
}
|
|
||||||
|
|
||||||
void game_update(void)
|
void game_update(void)
|
||||||
{
|
{
|
||||||
update_time();
|
clock_t start_clock = clock();
|
||||||
|
game.delta_time_ms = (double)(start_clock - game.last_clock_state) * 1000.0f / CLOCKS_PER_SEC;
|
||||||
|
game.last_clock_state = start_clock;
|
||||||
|
|
||||||
entity_manager_update(&game.entity_manager);
|
entity_manager_update(&game.entity_manager);
|
||||||
}
|
}
|
||||||
|
|
29
src/game.h
29
src/game.h
|
@ -6,53 +6,26 @@
|
||||||
#include "texture_manager.h"
|
#include "texture_manager.h"
|
||||||
#include "ecs/ecs.h"
|
#include "ecs/ecs.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Game data.
|
|
||||||
* There should be only one instance of this struct.
|
|
||||||
*
|
|
||||||
* @param event Events data
|
|
||||||
* @param texture_manager Texture manager instance
|
|
||||||
* @param entity_manager Entity manager instance
|
|
||||||
* @param is_running Game running state
|
|
||||||
* @param delta_time_ms Frame time
|
|
||||||
*/
|
|
||||||
typedef struct game_t {
|
typedef struct game_t {
|
||||||
event_t event;
|
event_t event;
|
||||||
texture_manager_t texture_manager;
|
texture_manager_t texture_manager;
|
||||||
entity_manager_t entity_manager;
|
entity_manager_t entity_manager;
|
||||||
|
|
||||||
bool is_running;
|
bool is_running;
|
||||||
|
clock_t last_clock_state;
|
||||||
double delta_time_ms;
|
double delta_time_ms;
|
||||||
} game_t;
|
} game_t;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Global game instance
|
|
||||||
*/
|
|
||||||
extern game_t game;
|
extern game_t game;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initialise game
|
|
||||||
*/
|
|
||||||
void game_init(void);
|
void game_init(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Handle event like inputs
|
|
||||||
*/
|
|
||||||
void game_handle_event(void);
|
void game_handle_event(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Update game
|
|
||||||
*/
|
|
||||||
void game_update(void);
|
void game_update(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Render game
|
|
||||||
*/
|
|
||||||
void game_render(void);
|
void game_render(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Free game instance
|
|
||||||
*/
|
|
||||||
void game_exit(void);
|
void game_exit(void);
|
||||||
|
|
||||||
#endif // GAME_H
|
#endif // GAME_H
|
|
@ -10,24 +10,22 @@
|
||||||
|
|
||||||
#include <gint/defs/types.h>
|
#include <gint/defs/types.h>
|
||||||
|
|
||||||
/**
|
/* vector2d_t: A point in space
|
||||||
* @brief Point struct.
|
This struct is the base for storing 2D positions.
|
||||||
*
|
|
||||||
* @param x X pos
|
@x X pos of the vector
|
||||||
* @param y Y pos
|
@y Y pos of the vector */
|
||||||
*/
|
|
||||||
typedef struct vector2d_t {
|
typedef struct vector2d_t {
|
||||||
float x, y;
|
float x, y;
|
||||||
} vector2d_t;
|
} vector2d_t;
|
||||||
|
|
||||||
/**
|
/* vector2d_t: A point in space
|
||||||
* @brief Rectangle struct.
|
This struct is the base for storing 2D positions.
|
||||||
*
|
|
||||||
* @param x X pos
|
@x X pos of the rectangle
|
||||||
* @param y Y pos
|
@y Y pos of the rectangle
|
||||||
* @param w Width
|
@w Width of the rectangle
|
||||||
* @param h Height
|
@h Height of the rectangle */
|
||||||
*/
|
|
||||||
typedef struct rect_t {
|
typedef struct rect_t {
|
||||||
float x, y;
|
float x, y;
|
||||||
float w, h;
|
float w, h;
|
||||||
|
@ -41,45 +39,38 @@ __attribute__((const)) float fabsf(float x);
|
||||||
|
|
||||||
#define is_not_zero(X) (fabsf(X) > EPSILON)
|
#define is_not_zero(X) (fabsf(X) > EPSILON)
|
||||||
|
|
||||||
/**
|
/* point_in_rect(): Verify if a point is in a rectangle
|
||||||
* @brief Verify if a point is in a rectangle
|
This function is useful for verify if a point is in a rectangle.
|
||||||
*
|
|
||||||
* @param P Vector2d
|
@P A Vector2d
|
||||||
* @param R Rectangle
|
@R A rectangle
|
||||||
*
|
Return true if the condition is validated else false. */
|
||||||
* @return True if the point is in the rectangle, else false.
|
|
||||||
*/
|
|
||||||
#define point_in_rect(P, R) (((P)->x >= (R)->x) && ((P)->x < ((R)->x + (R)->w)) && \
|
#define point_in_rect(P, R) (((P)->x >= (R)->x) && ((P)->x < ((R)->x + (R)->w)) && \
|
||||||
((P)->y >= (R)->y) && ((P)->y < ((R)->y + (R)->h)))
|
((P)->y >= (R)->y) && ((P)->y < ((R)->y + (R)->h)))
|
||||||
|
|
||||||
/**
|
/* rect_empty(): Verify if a rectangle is empty
|
||||||
* @brief Verify if a rectangle is empty
|
This function is useful for verify if a rectangle exists.
|
||||||
*
|
|
||||||
* @param R Rectangle
|
@R A rectangle
|
||||||
*
|
Return true if the condition is validated else false. */
|
||||||
* @return True if the rectangle is empty, else false.
|
|
||||||
*/
|
|
||||||
#define rect_empty(R) ((!(R)) || (is_equal_to_zero((R)->w)) || (is_equal_to_zero((R)->h)))
|
#define rect_empty(R) ((!(R)) || (is_equal_to_zero((R)->w)) || (is_equal_to_zero((R)->h)))
|
||||||
|
|
||||||
/**
|
/* has_intersection(): Verify if there is a intersction between two rectangles
|
||||||
* @brief Verify if there is a intersction between two rectangles
|
This function is useful for verify intersection between two rectangles.
|
||||||
*
|
|
||||||
* @param A Rectangle A
|
|
||||||
* @param B Rectangle B
|
|
||||||
*
|
|
||||||
* @return True if there is an intersection, else false.
|
|
||||||
*/
|
|
||||||
bool has_intersection(const rect_t *A, const rect_t *B);
|
|
||||||
|
|
||||||
/**
|
@A A rectangle
|
||||||
* @brief Verify if there is an intersection between two rectangles and get the intersection rectangle.
|
@B Another rectangle
|
||||||
*
|
Return true if the condition is validated else false. */
|
||||||
* @param A Rectangle A
|
bool has_intersection(const rect_t *, const rect_t *);
|
||||||
* @param B Rectangle B
|
|
||||||
* @param result The intersection rectangle
|
/* intersect_rect(): Like has_intersection but has a result rectangle
|
||||||
*
|
This function is useful for verify intersection between two rectangles
|
||||||
* @return True if there is an intersection, else false.
|
and get the intersection rectangle.
|
||||||
*/
|
|
||||||
bool intersect_rect(const rect_t *A, const rect_t *B, rect_t *result);
|
@A A rectangle
|
||||||
|
@B Another rectangle
|
||||||
|
@result The intersection rectangle
|
||||||
|
Return true if the condition is validated else false. */
|
||||||
|
bool intersect_rect(const rect_t *, const rect_t *, rect_t *);
|
||||||
|
|
||||||
#endif // VECTOR2D_H
|
#endif // VECTOR2D_H
|
Loading…
Reference in New Issue