Adding camera and tilemap display.
This commit is contained in:
parent
75a9ceb635
commit
447592a0d8
|
|
@ -1 +1 @@
|
|||
Subproject commit 519ae78ada36b922c64de8d37571db8d0ba0c944
|
||||
Subproject commit 5eb065b1cfeeeeb5be4a386943a8d898af0f6328
|
||||
|
|
@ -44,7 +44,10 @@ inline int sprite_component_draw(const component_t *component)
|
|||
{
|
||||
const sprite_component_data_t *component_data = component->data;
|
||||
|
||||
if(display_draw_texture(component_data->texture, &component_data->src_rect, &component_data->dst_rect, component_data->flip)) return_failure_int;
|
||||
frect_t src_frect;
|
||||
rect_to_frect(&component_data->src_rect, &src_frect);
|
||||
|
||||
if(display_draw_texture(component_data->texture, &src_frect, &component_data->dst_rect, component_data->flip)) return_failure_int;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
41
src/game.c
41
src/game.c
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include "display.h"
|
||||
#include "camera.h"
|
||||
#include "asset_manager.h"
|
||||
#include "event_bus.h"
|
||||
#include "ecs.h"
|
||||
|
|
@ -15,16 +16,23 @@ int game_init(void)
|
|||
game.is_running = false;
|
||||
|
||||
if(display_init()) return_failure_int;
|
||||
camera_init();
|
||||
if(tilemap_display_init()) return_failure_int;
|
||||
event_bus_init();
|
||||
entity_manager_init();
|
||||
if(asset_manager_init()) return_failure_int;
|
||||
|
||||
if(!asset_manager_load_asset("tileset", ASSET_TEXTURE)) return_failure_int;
|
||||
|
||||
asset_t *map_asset = asset_manager_load_asset("dungeon_room_1", ASSET_MAP);
|
||||
if(!map_asset) return_failure_int;
|
||||
|
||||
if(map_load_entities(map_asset->data)) return_failure_int;
|
||||
game.map = map_asset->data;
|
||||
|
||||
if(map_load_entities(game.map)) return_failure_int;
|
||||
|
||||
asset_t *tileset_asset = asset_manager_load_asset("tileset", ASSET_TEXTURE);
|
||||
if(!tileset_asset) return_failure_int;
|
||||
|
||||
game.tilemap_display.tileset = tileset_asset->data;
|
||||
|
||||
/* ======== Player ======== */
|
||||
{
|
||||
|
|
@ -43,6 +51,12 @@ int game_init(void)
|
|||
.w = 32.0f,
|
||||
.h = 32.0f
|
||||
};
|
||||
|
||||
game.camera.tracking_pos = (fvector2d_t *)&transform_component_data->bounds;
|
||||
game.camera.tracking_center_offset = (fvector2d_t) {
|
||||
.x = transform_component_data->bounds.w / 2,
|
||||
.y = transform_component_data->bounds.h / 2
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -128,6 +142,8 @@ int game_update(void)
|
|||
return_failure_int;
|
||||
}
|
||||
|
||||
camera_update();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -139,12 +155,30 @@ int game_render(void)
|
|||
return_failure_int;
|
||||
}
|
||||
|
||||
if(tilemap_display_update())
|
||||
{
|
||||
game.is_running = false;
|
||||
return_failure_int;
|
||||
}
|
||||
|
||||
if(tilemap_display_background())
|
||||
{
|
||||
game.is_running = false;
|
||||
return_failure_int;
|
||||
}
|
||||
|
||||
if(entity_manager_draw())
|
||||
{
|
||||
game.is_running = false;
|
||||
return_failure_int;
|
||||
}
|
||||
|
||||
if(tilemap_display_foreground())
|
||||
{
|
||||
game.is_running = false;
|
||||
return_failure_int;
|
||||
}
|
||||
|
||||
if(display_update())
|
||||
{
|
||||
game.is_running = false;
|
||||
|
|
@ -159,6 +193,7 @@ int game_exit(void)
|
|||
if(asset_manager_exit()) return_failure_int;
|
||||
if(entity_manager_exit()) return_failure_int;
|
||||
if(event_bus_exit()) return_failure_int;
|
||||
tilemap_display_exit();
|
||||
display_exit();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
Loading…
Reference in New Issue