Compare commits

..

4 Commits

7 changed files with 135 additions and 8 deletions

12
TODO.md
View File

@ -8,15 +8,13 @@
- [ ] Add compression into asset builder and asset manager
- [ ] Make functionnal hitboxes between entities and map
- [ ] Make triggers
- [ ] Add triggers into map loading
- [ ] Make physics component use acceleration
- [ ] Make camera use acceleration
- [ ] Create lua component
###### Bugs
- [ ] Fix transparency issues
@ -26,10 +24,12 @@
### In progress
- [ ] Create lua component
### Done
- [x] Make functionnal hitboxes between entities and map
- [x] Make physics component use acceleration
- [x] Rethink makefile structure
- [x] Make camera center on map

View File

@ -23,7 +23,7 @@ endif
$(LIBCORE): $(OBJECTS)
$(eval CURRENT_FILE := $(shell echo $$(($(CURRENT_FILE) + 1))))
$(eval PERCENTAGE := $(shell echo $$(($(CURRENT_FILE) * 100 / $(TOTAL_BUILD_FILES)))))
@echo $(ECHO_OPTION) "[$(PERCENTAGE)%] $(YELLOW)Creating Static Lib $@$(RESET)"
@echo $(ECHO_OPTION) "[$(PERCENTAGE)%] $(YELLOW)Linking Static Lib $@$(RESET)"
$(Q)$(TARGET_HOST_AR) rcs $@ $(OBJECTS)
$(BUILD_DIR)/$(notdir $(CORE_DIR))/%.o: $(CORE_DIR)/%

View File

@ -43,7 +43,7 @@ int destroy_asset(asset_t *asset)
}
// No args
int create_asset_header_def(asset_header_def_t *asset_header_def, va_list args)
int create_asset_header_def(asset_header_def_t *asset_header_def, va_list args __attribute__((unused)))
{
asset_header_def->name = NULL;

View File

@ -499,3 +499,42 @@ int map_display_foreground(void)
return EXIT_SUCCESS;
}
#if DEBUG > 1
int map_display_hitboxes(void)
{
uint32_t left_tile = 0;
if(game.camera.view_rect.x / TILE_SIZE > 0)
left_tile = game.camera.view_rect.x / TILE_SIZE;
uint32_t right_tile = game.map->width;
if((game.camera.view_rect.x + game.camera.view_rect.w) / TILE_SIZE + 1 < (int)game.map->width)
right_tile = (game.camera.view_rect.x + game.camera.view_rect.w) / TILE_SIZE + 1;
uint32_t top_tile = 0;
if(game.camera.view_rect.y / TILE_SIZE > 0)
top_tile = game.camera.view_rect.y / TILE_SIZE;
uint32_t bottom_tile = game.map->height;
if((game.camera.view_rect.y + game.camera.view_rect.h) / TILE_SIZE + 1 < (int)game.map->height)
bottom_tile = (game.camera.view_rect.y + game.camera.view_rect.h) / TILE_SIZE + 1;
for(uint32_t tile_y = top_tile; tile_y < bottom_tile; tile_y++)
for(uint32_t tile_x = left_tile; tile_x < right_tile; tile_x++)
{
if(game.map->hitboxes[tile_y * game.map->width + tile_x] == 1)
{
frect_t draw_frect = {
.x = tile_x * TILE_SIZE,
.y = tile_y * TILE_SIZE,
.w = TILE_SIZE,
.h = TILE_SIZE
};
if(display_draw_frect(&draw_frect, C_RED, 128)) return_failure_int;
}
}
return EXIT_SUCCESS;
}
#endif // DEBUG > 1

View File

@ -41,4 +41,8 @@ int map_display_background(void);
int map_display_foreground(void);
#if DEBUG > 1
int map_display_hitboxes(void);
#endif // DEBUG > 1
#endif // MAP_H

View File

@ -54,9 +54,85 @@ int physics_system_update(component_t *component)
system_data->velocity.x = lerp_time(system_data->velocity.x, system_data->target_velocity.x * system_data->speed, system_data->smoothing_factor, game.delta_time_ms);
system_data->velocity.y = lerp_time(system_data->velocity.y, system_data->target_velocity.y * system_data->speed, system_data->smoothing_factor, game.delta_time_ms);
if(hitbox_component_data->activated)
{
// Resolve entities collisions.
if(linked_list_for_each(&game.entity_manager.entities, action_detect_solve_entities_collision, component)) return EXIT_FAILURE;
// Resolve map collisions
if(game.map)
{
uint16_t left_tile = 0;
if(game.camera.view_rect.x / TILE_SIZE > 0)
left_tile = hitbox_component_data->bounds.x / TILE_SIZE;
uint16_t right_tile = game.map->width;
if((hitbox_component_data->bounds.x + hitbox_component_data->bounds.w) / TILE_SIZE + 1 < game.map->width)
right_tile = (hitbox_component_data->bounds.x + hitbox_component_data->bounds.w) / TILE_SIZE + 1;
uint16_t top_tile = 0;
if(hitbox_component_data->bounds.y / TILE_SIZE > 0)
top_tile = hitbox_component_data->bounds.y / TILE_SIZE;
uint16_t bottom_tile = game.map->height;
if((hitbox_component_data->bounds.y + hitbox_component_data->bounds.h) / TILE_SIZE + 1 < game.map->height)
bottom_tile = (hitbox_component_data->bounds.y + hitbox_component_data->bounds.h) / TILE_SIZE + 1;
for(uint16_t tile_y = top_tile; tile_y < bottom_tile; tile_y++)
for(uint16_t tile_x = left_tile; tile_x < right_tile; tile_x++)
{
if(game.map->hitboxes[tile_y * game.map->width + tile_x] == 1)
{
const frect_t *hitbox_bounds = &hitbox_component_data->bounds;
const frect_t target_hitbox_bounds = {
.x = tile_x * TILE_SIZE,
.y = tile_y * TILE_SIZE,
.w = TILE_SIZE,
.h = TILE_SIZE
};
frect_t intersect;
if(intersect_frect(hitbox_bounds, &target_hitbox_bounds, &intersect))
{
if(intersect.w < intersect.h)
{
const float left_correction = hitbox_bounds->x + hitbox_bounds->w - target_hitbox_bounds.x;
const float right_correction = target_hitbox_bounds.x + target_hitbox_bounds.w - hitbox_bounds->x;
if(left_correction < right_correction)
{
transform_component_data->bounds.x -= left_correction;
if(system_data->velocity.x > 0.0f) system_data->velocity.x = 0.0f;
}
else
{
transform_component_data->bounds.x += right_correction;
if(system_data->velocity.x < 0.0f) system_data->velocity.x = 0.0f;
}
}
else
{
float top_correction = hitbox_bounds->y + hitbox_bounds->h - target_hitbox_bounds.y;
float bottom_correction = target_hitbox_bounds.y + target_hitbox_bounds.h - hitbox_bounds->y;
if(top_correction < bottom_correction)
{
transform_component_data->bounds.y -= top_correction;
if(system_data->velocity.y > 0.0f) system_data->velocity.y = 0.0f;
}
else
{
transform_component_data->bounds.y += bottom_correction;
if(system_data->velocity.y < 0.0f) system_data->velocity.y = 0.0f;
}
}
}
}
}
}
}
transform_component_data->bounds.x += system_data->velocity.x * (float)game.delta_time_ms / 1000.0f;
transform_component_data->bounds.y += system_data->velocity.y * (float)game.delta_time_ms / 1000.0f;

View File

@ -186,6 +186,14 @@ int game_render(void)
return_failure_int;
}
#if DEBUG > 1
if(map_display_hitboxes())
{
game.is_running = false;
return_failure_int;
}
#endif // DEBUG > 1
if(display_update())
{
game.is_running = false;