Compare commits
4 Commits
bafb32501f
...
e9d9ffff20
Author | SHA1 | Date |
---|---|---|
|
e9d9ffff20 | |
|
3580209f71 | |
|
7b3685b792 | |
|
ee4313adbb |
|
@ -11,17 +11,11 @@ if (${CMAKE_BUILD_TYPE} STREQUAL tile16)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(GAME_LIBS
|
set(GAME_LIBS
|
||||||
lib_EC
|
|
||||||
lib_scenes
|
lib_scenes
|
||||||
sc_queue
|
|
||||||
sc_map
|
|
||||||
sc_array
|
|
||||||
raylib
|
|
||||||
m
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
add_subdirectory(engine)
|
add_subdirectory(scenes)
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
main.c
|
main.c
|
||||||
)
|
)
|
||||||
|
@ -29,11 +23,6 @@ add_executable(${PROJECT_NAME}
|
||||||
target_include_directories(${PROJECT_NAME}
|
target_include_directories(${PROJECT_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
${RAYLIB_DIR}/include
|
|
||||||
)
|
|
||||||
target_link_directories(${PROJECT_NAME}
|
|
||||||
PRIVATE
|
|
||||||
${RAYLIB_DIR}/lib
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
@ -48,17 +37,9 @@ target_link_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||||
target_include_directories(EntManager_test
|
target_include_directories(EntManager_test
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
${RAYLIB_DIR}/include
|
|
||||||
)
|
|
||||||
target_link_directories(EntManager_test
|
|
||||||
PRIVATE
|
|
||||||
${RAYLIB_DIR}/lib
|
|
||||||
)
|
)
|
||||||
target_link_libraries(EntManager_test
|
target_link_libraries(EntManager_test
|
||||||
lib_EC
|
${GAME_LIBS}
|
||||||
lib_scenes
|
|
||||||
sc_queue
|
|
||||||
sc_map
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(scene_test
|
add_executable(scene_test
|
||||||
|
@ -68,17 +49,11 @@ add_executable(scene_test
|
||||||
target_include_directories(scene_test
|
target_include_directories(scene_test
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
${RAYLIB_DIR}/include
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
target_compile_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||||
target_link_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
target_link_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||||
|
|
||||||
target_link_directories(scene_test
|
|
||||||
PRIVATE
|
|
||||||
${RAYLIB_DIR}/lib
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(scene_test
|
target_link_libraries(scene_test
|
||||||
${GAME_LIBS}
|
${GAME_LIBS}
|
||||||
)
|
)
|
||||||
|
@ -89,13 +64,9 @@ add_executable(scene_test_mem
|
||||||
target_include_directories(scene_test_mem
|
target_include_directories(scene_test_mem
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
${RAYLIB_DIR}/include
|
|
||||||
)
|
)
|
||||||
target_link_options(scene_test_mem PRIVATE -Xlinker -Map=scene_test.map)
|
target_link_options(scene_test_mem PRIVATE -Xlinker -Map=scene_test.map)
|
||||||
target_link_directories(scene_test_mem
|
|
||||||
PRIVATE
|
|
||||||
${RAYLIB_DIR}/lib
|
|
||||||
)
|
|
||||||
target_link_libraries(scene_test_mem
|
target_link_libraries(scene_test_mem
|
||||||
${GAME_LIBS}
|
${GAME_LIBS}
|
||||||
)
|
)
|
||||||
|
@ -106,14 +77,9 @@ add_executable(menu_test
|
||||||
target_include_directories(menu_test
|
target_include_directories(menu_test
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
${RAYLIB_DIR}/include
|
|
||||||
)
|
)
|
||||||
target_compile_options(menu_test PRIVATE -fsanitize=address -gdwarf-4)
|
target_compile_options(menu_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||||
target_link_options(menu_test PRIVATE -fsanitize=address -gdwarf-4)
|
target_link_options(menu_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||||
target_link_directories(menu_test
|
|
||||||
PRIVATE
|
|
||||||
${RAYLIB_DIR}/lib
|
|
||||||
)
|
|
||||||
target_link_libraries(menu_test
|
target_link_libraries(menu_test
|
||||||
${GAME_LIBS}
|
${GAME_LIBS}
|
||||||
)
|
)
|
||||||
|
@ -124,14 +90,9 @@ add_executable(assets_test
|
||||||
target_include_directories(assets_test
|
target_include_directories(assets_test
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
${RAYLIB_DIR}/include
|
|
||||||
)
|
)
|
||||||
target_compile_options(assets_test PRIVATE -fsanitize=address -gdwarf-4)
|
target_compile_options(assets_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||||
target_link_options(assets_test PRIVATE -fsanitize=address -gdwarf-4)
|
target_link_options(assets_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||||
target_link_directories(assets_test
|
|
||||||
PRIVATE
|
|
||||||
${RAYLIB_DIR}/lib
|
|
||||||
)
|
|
||||||
target_link_libraries(assets_test
|
target_link_libraries(assets_test
|
||||||
${GAME_LIBS}
|
${GAME_LIBS}
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#include "assets_maps.h"
|
|
||||||
|
|
||||||
|
|
||||||
const char* const player_sprite_map[N_PLAYER_SPRITES] = {
|
|
||||||
"plr_stand",
|
|
||||||
"plr_run",
|
|
||||||
};
|
|
|
@ -1,13 +0,0 @@
|
||||||
#ifndef __ASSETS_MAPS_H
|
|
||||||
#define __ASSETS_MAPS_H
|
|
||||||
|
|
||||||
#define N_PLAYER_SPRITES 2
|
|
||||||
enum PlayerSpriteEnum
|
|
||||||
{
|
|
||||||
SPR_PLAYER_STAND = 0,
|
|
||||||
SPR_PLAYER_RUN
|
|
||||||
};
|
|
||||||
|
|
||||||
extern const char* const player_sprite_map[N_PLAYER_SPRITES];
|
|
||||||
|
|
||||||
#endif // __ASSETS_MAPS_H
|
|
10
scene_test.c
10
scene_test.c
|
@ -23,16 +23,16 @@ int main(void)
|
||||||
init_memory_pools();
|
init_memory_pools();
|
||||||
|
|
||||||
init_assets(&engine.assets);
|
init_assets(&engine.assets);
|
||||||
Texture2D* tex = add_texture(&engine.assets, "plr_tex", "res/test_tex.png");
|
Texture2D* tex = add_texture(&engine.assets, "plr_tex", "res/bunny_stand.png");
|
||||||
Sprite_t* spr = add_sprite(&engine.assets, "plr_stand", tex);
|
Sprite_t* spr = add_sprite(&engine.assets, "plr_stand", tex);
|
||||||
spr->origin = (Vector2){0, 0};
|
spr->origin = (Vector2){0, 0};
|
||||||
spr->frame_size = (Vector2){32, 32};
|
spr->frame_size = (Vector2){32, 64};
|
||||||
|
|
||||||
spr = add_sprite(&engine.assets, "plr_run", tex);
|
spr = add_sprite(&engine.assets, "plr_run", tex);
|
||||||
spr->frame_count = 4;
|
spr->frame_count = 1;
|
||||||
spr->origin = (Vector2){0, 0};
|
spr->origin = (Vector2){0, 0};
|
||||||
spr->frame_size = (Vector2){32, 32};
|
spr->frame_size = (Vector2){32, 64};
|
||||||
spr->speed = 15;
|
spr->speed = 30;
|
||||||
|
|
||||||
LevelScene_t scene;
|
LevelScene_t scene;
|
||||||
scene.scene.engine = &engine;
|
scene.scene.engine = &engine;
|
||||||
|
|
|
@ -1,21 +1,16 @@
|
||||||
add_subdirectory(EC)
|
add_subdirectory(engine)
|
||||||
add_library(lib_scenes STATIC
|
add_library(lib_scenes STATIC
|
||||||
engine.c
|
player_ent.c
|
||||||
assets.c
|
items_ent.c
|
||||||
assets_maps.c
|
|
||||||
editor_scene.c
|
editor_scene.c
|
||||||
menu_scene.c
|
menu_scene.c
|
||||||
game_systems.c
|
game_systems.c
|
||||||
AABB.c
|
|
||||||
gui.c
|
|
||||||
)
|
)
|
||||||
target_include_directories(lib_scenes
|
target_include_directories(lib_scenes
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
${RAYLIB_DIR}/include
|
|
||||||
)
|
)
|
||||||
target_link_libraries(lib_scenes
|
target_link_libraries(lib_scenes
|
||||||
PRIVATE
|
PUBLIC
|
||||||
lib_EC
|
lib_engine
|
||||||
raylib
|
|
||||||
)
|
)
|
|
@ -4,7 +4,7 @@
|
||||||
#ifndef TILE16_SIZE
|
#ifndef TILE16_SIZE
|
||||||
#define TILE_SIZE 32
|
#define TILE_SIZE 32
|
||||||
#define DEFAULT_MAP_WIDTH 48
|
#define DEFAULT_MAP_WIDTH 48
|
||||||
#define DEFAULT_MAP_HEIGHT 16
|
#define DEFAULT_MAP_HEIGHT 22
|
||||||
#define VIEWABLE_MAP_WIDTH 32
|
#define VIEWABLE_MAP_WIDTH 32
|
||||||
#define VIEWABLE_MAP_HEIGHT 16
|
#define VIEWABLE_MAP_HEIGHT 16
|
||||||
#else
|
#else
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#ifndef TILE16_SIZE
|
#ifndef TILE16_SIZE
|
||||||
#define PLAYER_WIDTH 30
|
#define PLAYER_WIDTH 30
|
||||||
#define PLAYER_HEIGHT 55
|
#define PLAYER_HEIGHT 42
|
||||||
#define PLAYER_C_WIDTH 30
|
#define PLAYER_C_WIDTH 30
|
||||||
#define PLAYER_C_HEIGHT 30
|
#define PLAYER_C_HEIGHT 30
|
||||||
#else
|
#else
|
|
@ -1,7 +1,7 @@
|
||||||
#include "scene_impl.h"
|
#include "scene_impl.h"
|
||||||
#include "game_systems.h"
|
#include "game_systems.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "assets_maps.h"
|
#include "ent_impl.h"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -40,7 +40,7 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
Entity_t* p_ent;
|
Entity_t* p_ent;
|
||||||
|
|
||||||
BeginTextureMode(data->game_viewport);
|
BeginTextureMode(data->game_viewport);
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(WHITE);
|
||||||
BeginMode2D(data->cam);
|
BeginMode2D(data->cam);
|
||||||
for (size_t i = 0; i < tilemap.n_tiles; ++i)
|
for (size_t i = 0; i < tilemap.n_tiles; ++i)
|
||||||
{
|
{
|
||||||
|
@ -203,57 +203,11 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
static void spawn_crate(Scene_t* scene, unsigned int tile_idx, bool metal)
|
static void spawn_crate(Scene_t* scene, unsigned int tile_idx, bool metal)
|
||||||
{
|
{
|
||||||
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
||||||
Entity_t* p_crate = add_entity(&scene->ent_manager, CRATES_ENT_TAG);
|
Entity_t* p_crate = create_crate(&scene->ent_manager, &scene->engine->assets, metal);
|
||||||
CBBox_t* p_bbox = add_component(&scene->ent_manager, p_crate, CBBOX_COMP_T);
|
|
||||||
|
|
||||||
set_bbox(p_bbox, TILE_SIZE, TILE_SIZE);
|
CTransform_t* p_ctransform = get_component(&scene->ent_manager, p_crate, CTRANSFORM_COMP_T);
|
||||||
p_bbox->solid = true;
|
|
||||||
p_bbox->fragile = !metal;
|
|
||||||
|
|
||||||
CTransform_t* p_ctransform = add_component(&scene->ent_manager, p_crate, CTRANSFORM_COMP_T);
|
|
||||||
p_ctransform->position.x = (tile_idx % data->tilemap.width) * TILE_SIZE;
|
p_ctransform->position.x = (tile_idx % data->tilemap.width) * TILE_SIZE;
|
||||||
p_ctransform->position.y = (tile_idx / data->tilemap.width) * TILE_SIZE;
|
p_ctransform->position.y = (tile_idx / data->tilemap.width) * TILE_SIZE;
|
||||||
add_component(&scene->ent_manager, p_crate, CMOVEMENTSTATE_T);
|
|
||||||
add_component(&scene->ent_manager, p_crate, CTILECOORD_COMP_T);
|
|
||||||
CHurtbox_t* p_hurtbox = add_component(&scene->ent_manager, p_crate, CHURTBOX_T);
|
|
||||||
p_hurtbox->size = p_bbox->size;
|
|
||||||
p_hurtbox->fragile = !metal;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void spawn_player(Scene_t* scene)
|
|
||||||
{
|
|
||||||
Entity_t* p_ent = add_entity(&scene->ent_manager, PLAYER_ENT_TAG);
|
|
||||||
CBBox_t* p_bbox = add_component(&scene->ent_manager, p_ent, CBBOX_COMP_T);
|
|
||||||
|
|
||||||
set_bbox(p_bbox, PLAYER_WIDTH, PLAYER_HEIGHT);
|
|
||||||
add_component(&scene->ent_manager, p_ent, CTRANSFORM_COMP_T);
|
|
||||||
|
|
||||||
CJump_t* p_cjump = add_component(&scene->ent_manager, p_ent, CJUMP_COMP_T);
|
|
||||||
p_cjump->jump_speed = 680;
|
|
||||||
p_cjump->jumps = 1;
|
|
||||||
p_cjump->max_jumps = 1;
|
|
||||||
p_cjump->jump_ready = true;
|
|
||||||
add_component(&scene->ent_manager, p_ent, CPLAYERSTATE_T);
|
|
||||||
add_component(&scene->ent_manager, p_ent, CTILECOORD_COMP_T);
|
|
||||||
add_component(&scene->ent_manager, p_ent, CMOVEMENTSTATE_T);
|
|
||||||
CHitBoxes_t* p_hitbox = add_component(&scene->ent_manager, p_ent, CHITBOXES_T);
|
|
||||||
p_hitbox->n_boxes = 2;
|
|
||||||
p_hitbox->boxes[0] = (Rectangle) {
|
|
||||||
.x = 0,
|
|
||||||
.y = -1,
|
|
||||||
.width = p_bbox->size.x - 1,
|
|
||||||
.height = p_bbox->size.y + 2,
|
|
||||||
};
|
|
||||||
p_hitbox->boxes[1] = (Rectangle) {
|
|
||||||
.x = -1,
|
|
||||||
.y = 0,
|
|
||||||
.width = p_bbox->size.x + 2,
|
|
||||||
.height = p_bbox->size.y - 1,
|
|
||||||
};
|
|
||||||
CSprite_t* p_cspr = add_component(&scene->ent_manager, p_ent, CSPRITE_T);
|
|
||||||
p_cspr->sprite = get_sprite(&scene->engine->assets, "plr_stand");
|
|
||||||
p_cspr->sprites_map = player_sprite_map;
|
|
||||||
p_cspr->transition_func = &player_sprite_transition_func;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void toggle_block_system(Scene_t* scene)
|
static void toggle_block_system(Scene_t* scene)
|
||||||
|
@ -422,7 +376,8 @@ void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
|
||||||
|
|
||||||
void init_level_scene(LevelScene_t* scene)
|
void init_level_scene(LevelScene_t* scene)
|
||||||
{
|
{
|
||||||
init_scene(&scene->scene, LEVEL_SCENE, &level_scene_render_func, &level_do_action);
|
//init_scene(&scene->scene, LEVEL_SCENE, &level_scene_render_func, &level_do_action);
|
||||||
|
init_scene(&scene->scene, &level_scene_render_func, &level_do_action);
|
||||||
|
|
||||||
init_level_scene_data(&scene->data);
|
init_level_scene_data(&scene->data);
|
||||||
// insert level scene systems
|
// insert level scene systems
|
||||||
|
@ -471,7 +426,7 @@ void init_level_scene(LevelScene_t* scene)
|
||||||
all_tiles[tile_idx].tile_type = SOLID_TILE; // for testing
|
all_tiles[tile_idx].tile_type = SOLID_TILE; // for testing
|
||||||
}
|
}
|
||||||
|
|
||||||
spawn_player(&scene->scene);
|
create_player(&scene->scene.ent_manager, &scene->scene.engine->assets);
|
||||||
update_entity_manager(&scene->scene.ent_manager);
|
update_entity_manager(&scene->scene.ent_manager);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
add_subdirectory(EC)
|
||||||
|
add_library(lib_engine STATIC
|
||||||
|
assets.c
|
||||||
|
AABB.c
|
||||||
|
gui.c
|
||||||
|
engine.c
|
||||||
|
)
|
||||||
|
target_include_directories(lib_engine
|
||||||
|
PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
||||||
|
target_link_libraries(lib_engine
|
||||||
|
PUBLIC
|
||||||
|
lib_EC
|
||||||
|
)
|
|
@ -8,7 +8,16 @@ target_include_directories(lib_EC
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
${RAYLIB_DIR}/include
|
${RAYLIB_DIR}/include
|
||||||
)
|
)
|
||||||
target_link_libraries(lib_EC
|
|
||||||
PRIVATE
|
target_link_directories(lib_EC
|
||||||
raylib
|
PUBLIC
|
||||||
|
${RAYLIB_DIR}/lib
|
||||||
|
)
|
||||||
|
target_link_libraries(lib_EC
|
||||||
|
PUBLIC
|
||||||
|
raylib
|
||||||
|
sc_queue
|
||||||
|
sc_map
|
||||||
|
sc_array
|
||||||
|
m
|
||||||
)
|
)
|
|
@ -7,13 +7,14 @@ void change_scene(GameEngine_t* engine, unsigned int idx)
|
||||||
engine->scenes[engine->curr_scene]->state = SCENE_PLAYING;
|
engine->scenes[engine->curr_scene]->state = SCENE_PLAYING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_scene(Scene_t* scene, SceneType_t scene_type, system_func_t render_func, action_func_t action_func)
|
//void init_scene(Scene_t* scene, SceneType_t scene_type, system_func_t render_func, action_func_t action_func)
|
||||||
|
void init_scene(Scene_t* scene, system_func_t render_func, action_func_t action_func)
|
||||||
{
|
{
|
||||||
sc_map_init_64(&scene->action_map, 32, 0);
|
sc_map_init_64(&scene->action_map, 32, 0);
|
||||||
sc_array_init(&scene->systems);
|
sc_array_init(&scene->systems);
|
||||||
init_entity_manager(&scene->ent_manager);
|
init_entity_manager(&scene->ent_manager);
|
||||||
|
|
||||||
scene->scene_type = scene_type;
|
//scene->scene_type = scene_type;
|
||||||
scene->render_function = render_func;
|
scene->render_function = render_func;
|
||||||
scene->action_function = action_func;
|
scene->action_function = action_func;
|
||||||
scene->state = SCENE_ENDED;
|
scene->state = SCENE_ENDED;
|
|
@ -15,10 +15,10 @@ typedef struct GameEngine {
|
||||||
} GameEngine_t;
|
} GameEngine_t;
|
||||||
void change_scene(GameEngine_t* engine, unsigned int idx);
|
void change_scene(GameEngine_t* engine, unsigned int idx);
|
||||||
|
|
||||||
typedef enum SceneType {
|
//typedef enum SceneType {
|
||||||
LEVEL_SCENE = 0,
|
// LEVEL_SCENE = 0,
|
||||||
MENU_SCENE,
|
// MENU_SCENE,
|
||||||
}SceneType_t;
|
//}SceneType_t;
|
||||||
|
|
||||||
typedef enum SceneState {
|
typedef enum SceneState {
|
||||||
SCENE_PLAYING = 0,
|
SCENE_PLAYING = 0,
|
||||||
|
@ -36,7 +36,7 @@ struct Scene {
|
||||||
system_func_t render_function;
|
system_func_t render_function;
|
||||||
action_func_t action_function;
|
action_func_t action_function;
|
||||||
EntityManager_t ent_manager;
|
EntityManager_t ent_manager;
|
||||||
SceneType_t scene_type;
|
//SceneType_t scene_type;
|
||||||
SceneState_t state;
|
SceneState_t state;
|
||||||
GameEngine_t *engine;
|
GameEngine_t *engine;
|
||||||
};
|
};
|
||||||
|
@ -46,7 +46,8 @@ extern void update_scene(Scene_t* scene);
|
||||||
extern void render_scene(Scene_t* scene);
|
extern void render_scene(Scene_t* scene);
|
||||||
extern void do_action(Scene_t* scene, ActionType_t action, bool pressed);
|
extern void do_action(Scene_t* scene, ActionType_t action, bool pressed);
|
||||||
|
|
||||||
void init_scene(Scene_t* scene, SceneType_t scene_type, system_func_t render_func, action_func_t action_func);
|
//void init_scene(Scene_t* scene, SceneType_t scene_type, system_func_t render_func, action_func_t action_func);
|
||||||
|
void init_scene(Scene_t* scene, system_func_t render_func, action_func_t action_func);
|
||||||
void free_scene(Scene_t* scene);
|
void free_scene(Scene_t* scene);
|
||||||
|
|
||||||
#endif // __ENGINE_H
|
#endif // __ENGINE_H
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef __ENT_IMPL_H
|
||||||
|
#define __ENT_IMPL_H
|
||||||
|
#include "entManager.h"
|
||||||
|
#include "assets.h"
|
||||||
|
|
||||||
|
Entity_t* create_player(EntityManager_t* ent_manager, Assets_t* assets);
|
||||||
|
Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool metal);
|
||||||
|
|
||||||
|
#endif // __ENT_IMPL_H
|
|
@ -1,7 +1,6 @@
|
||||||
#include "game_systems.h"
|
#include "game_systems.h"
|
||||||
#include "AABB.h"
|
#include "AABB.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "assets_maps.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static const Vector2 TILE_SZ = {TILE_SIZE, TILE_SIZE};
|
static const Vector2 TILE_SZ = {TILE_SIZE, TILE_SIZE};
|
||||||
|
@ -1134,8 +1133,3 @@ void term_level_scene_data(LevelSceneData_t* data)
|
||||||
//sc_map_term_32(&data->collision_events);
|
//sc_map_term_32(&data->collision_events);
|
||||||
UnloadRenderTexture(data->game_viewport); // Unload render texture
|
UnloadRenderTexture(data->game_viewport); // Unload render texture
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int player_sprite_transition_func(Entity_t* ent)
|
|
||||||
{
|
|
||||||
return SPR_PLAYER_RUN;
|
|
||||||
}
|
|
|
@ -16,6 +16,4 @@ void update_tilemap_system(Scene_t* scene);
|
||||||
void hitbox_update_system(Scene_t* scene);
|
void hitbox_update_system(Scene_t* scene);
|
||||||
void sprite_animation_system(Scene_t* scene);
|
void sprite_animation_system(Scene_t* scene);
|
||||||
void camera_update_system(Scene_t* scene);
|
void camera_update_system(Scene_t* scene);
|
||||||
|
|
||||||
unsigned int player_sprite_transition_func(Entity_t* ent);
|
|
||||||
#endif // __GAME_SYSTEMS_H
|
#endif // __GAME_SYSTEMS_H
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include "ent_impl.h"
|
||||||
|
#include "constants.h"
|
||||||
|
|
||||||
|
Entity_t* create_crate(EntityManager_t* ent_manager, Assets_t* assets, bool metal)
|
||||||
|
{
|
||||||
|
Entity_t* p_crate = add_entity(ent_manager, CRATES_ENT_TAG);
|
||||||
|
CBBox_t* p_bbox = add_component(ent_manager, p_crate, CBBOX_COMP_T);
|
||||||
|
|
||||||
|
set_bbox(p_bbox, TILE_SIZE, TILE_SIZE);
|
||||||
|
p_bbox->solid = true;
|
||||||
|
p_bbox->fragile = !metal;
|
||||||
|
|
||||||
|
add_component(ent_manager, p_crate, CTRANSFORM_COMP_T);
|
||||||
|
add_component(ent_manager, p_crate, CMOVEMENTSTATE_T);
|
||||||
|
add_component(ent_manager, p_crate, CTILECOORD_COMP_T);
|
||||||
|
CHurtbox_t* p_hurtbox = add_component(ent_manager, p_crate, CHURTBOX_T);
|
||||||
|
p_hurtbox->size = p_bbox->size;
|
||||||
|
p_hurtbox->fragile = !metal;
|
||||||
|
return p_crate;
|
||||||
|
}
|
|
@ -118,7 +118,8 @@ static void gui_loop(Scene_t* scene)
|
||||||
|
|
||||||
void init_menu_scene(MenuScene_t* scene)
|
void init_menu_scene(MenuScene_t* scene)
|
||||||
{
|
{
|
||||||
init_scene(&scene->scene, MENU_SCENE, &menu_scene_render_func, &menu_do_action);
|
//init_scene(&scene->scene, MENU_SCENE, &menu_scene_render_func, &menu_do_action);
|
||||||
|
init_scene(&scene->scene, &menu_scene_render_func, &menu_do_action);
|
||||||
|
|
||||||
sc_array_add(&scene->scene.systems, &gui_loop);
|
sc_array_add(&scene->scene.systems, &gui_loop);
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
#include "ent_impl.h"
|
||||||
|
#include "constants.h"
|
||||||
|
|
||||||
|
#define N_PLAYER_SPRITES 2
|
||||||
|
enum PlayerSpriteEnum
|
||||||
|
{
|
||||||
|
SPR_PLAYER_STAND = 0,
|
||||||
|
SPR_PLAYER_RUN
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char* const player_sprite_map[N_PLAYER_SPRITES] = {
|
||||||
|
"plr_stand",
|
||||||
|
"plr_run",
|
||||||
|
};
|
||||||
|
|
||||||
|
static unsigned int player_sprite_transition_func(Entity_t* ent)
|
||||||
|
{
|
||||||
|
return SPR_PLAYER_RUN;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity_t* create_player(EntityManager_t* ent_manager, Assets_t* assets)
|
||||||
|
{
|
||||||
|
Entity_t* p_ent = add_entity(ent_manager, PLAYER_ENT_TAG);
|
||||||
|
CBBox_t* p_bbox = add_component(ent_manager, p_ent, CBBOX_COMP_T);
|
||||||
|
|
||||||
|
set_bbox(p_bbox, PLAYER_WIDTH, PLAYER_HEIGHT);
|
||||||
|
add_component(ent_manager, p_ent, CTRANSFORM_COMP_T);
|
||||||
|
|
||||||
|
CJump_t* p_cjump = add_component(ent_manager, p_ent, CJUMP_COMP_T);
|
||||||
|
p_cjump->jump_speed = 680;
|
||||||
|
p_cjump->jumps = 1;
|
||||||
|
p_cjump->max_jumps = 1;
|
||||||
|
p_cjump->jump_ready = true;
|
||||||
|
add_component(ent_manager, p_ent, CPLAYERSTATE_T);
|
||||||
|
add_component(ent_manager, p_ent, CTILECOORD_COMP_T);
|
||||||
|
add_component(ent_manager, p_ent, CMOVEMENTSTATE_T);
|
||||||
|
CHitBoxes_t* p_hitbox = add_component(ent_manager, p_ent, CHITBOXES_T);
|
||||||
|
p_hitbox->n_boxes = 2;
|
||||||
|
p_hitbox->boxes[0] = (Rectangle) {
|
||||||
|
.x = 0,
|
||||||
|
.y = -1,
|
||||||
|
.width = p_bbox->size.x - 1,
|
||||||
|
.height = p_bbox->size.y + 2,
|
||||||
|
};
|
||||||
|
p_hitbox->boxes[1] = (Rectangle) {
|
||||||
|
.x = -1,
|
||||||
|
.y = 0,
|
||||||
|
.width = p_bbox->size.x + 2,
|
||||||
|
.height = p_bbox->size.y - 1,
|
||||||
|
};
|
||||||
|
CSprite_t* p_cspr = add_component(ent_manager, p_ent, CSPRITE_T);
|
||||||
|
p_cspr->sprite = get_sprite(assets, "plr_stand");
|
||||||
|
p_cspr->offset = (Vector2){0, -20};
|
||||||
|
p_cspr->sprites_map = player_sprite_map;
|
||||||
|
p_cspr->transition_func = &player_sprite_transition_func;
|
||||||
|
|
||||||
|
return p_ent;
|
||||||
|
}
|
Loading…
Reference in New Issue