Compare commits
5 Commits
34b60fb699
...
67e0e7dc08
Author | SHA1 | Date |
---|---|---|
|
67e0e7dc08 | |
|
f3defcf656 | |
|
ee65e3c974 | |
|
e24bb382f9 | |
|
04d928c97f |
229
CMakeLists.txt
229
CMakeLists.txt
|
@ -2,10 +2,18 @@ set(PROJECT_NAME HATPC_remake)
|
||||||
set(CMAKE_C_COMPILER clang)
|
set(CMAKE_C_COMPILER clang)
|
||||||
set(CMAKE_C_FLAGS "-Wall -Wextra")
|
set(CMAKE_C_FLAGS "-Wall -Wextra")
|
||||||
cmake_minimum_required(VERSION 3.22.1)
|
cmake_minimum_required(VERSION 3.22.1)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
project(${PROJECT_NAME} C CXX)
|
project(${PROJECT_NAME} C CXX)
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
set(RAYLIB_DIR /usr/local/lib CACHE FILEPATH "directory to Raylib")
|
set(RAYLIB_DIR /usr/local/lib CACHE FILEPATH "directory to Raylib")
|
||||||
set(LIBZSTD_DIR /usr/local/lib CACHE FILEPATH "directory to zstd")
|
set(LIBZSTD_DIR /usr/local/lib CACHE FILEPATH "directory to zstd")
|
||||||
|
option(RUN_PROFILER OFF)
|
||||||
|
option(INCLUDE_ASAN ON)
|
||||||
|
option(EXPORT_MMAP OFF)
|
||||||
|
option(BUILD_EXTRAS OFF)
|
||||||
|
|
||||||
|
# If you want to use Heaptrack to profile the memory
|
||||||
|
# Do not compile in ASAN
|
||||||
|
|
||||||
if (EMSCRIPTEN)
|
if (EMSCRIPTEN)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||||
|
@ -24,208 +32,69 @@ set(GAME_LIBS
|
||||||
lib_scenes
|
lib_scenes
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (${RUN_PROFILER})
|
||||||
|
set(GAME_LIBS
|
||||||
|
lib_scenes
|
||||||
|
pthread
|
||||||
|
dl
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_subdirectory(engine)
|
add_subdirectory(engine)
|
||||||
add_subdirectory(scenes)
|
add_subdirectory(scenes)
|
||||||
if (NOT EMSCRIPTEN)
|
if (NOT EMSCRIPTEN)
|
||||||
add_subdirectory(res)
|
add_subdirectory(res)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
macro(add_target_exe name)
|
||||||
main.c
|
add_executable(${name}
|
||||||
)
|
${name}.c
|
||||||
|
|
||||||
# Use Heaptrack to profile the main application
|
|
||||||
# Do not compile in ASAN
|
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME}
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
add_executable(level_player
|
|
||||||
level_test.c
|
|
||||||
)
|
|
||||||
|
|
||||||
# Use Heaptrack to profile the main application
|
|
||||||
# Do not compile in ASAN
|
|
||||||
|
|
||||||
target_include_directories(level_player
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(level_player
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(sandbox_trace
|
|
||||||
scene_test.c
|
|
||||||
tracy/public/TracyClient.cpp
|
tracy/public/TracyClient.cpp
|
||||||
)
|
)
|
||||||
target_compile_definitions(sandbox_trace
|
target_include_directories(${name}
|
||||||
PUBLIC
|
|
||||||
TRACY_ENABLE
|
|
||||||
TRACY_ON_DEMAND
|
|
||||||
)
|
|
||||||
target_include_directories(sandbox_trace
|
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
tracy/public/
|
tracy/public/
|
||||||
)
|
)
|
||||||
|
if (RUN_PROFILER)
|
||||||
target_link_libraries(sandbox_trace
|
target_compile_definitions(${name}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
lib_scenes_trace
|
TRACY_ENABLE
|
||||||
pthread
|
TRACY_ON_DEMAND
|
||||||
dl
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(scene_test
|
|
||||||
scene_test.c
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(scene_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if (NOT EMSCRIPTEN)
|
|
||||||
target_compile_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(scene_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if (NOT EMSCRIPTEN)
|
if (NOT EMSCRIPTEN)
|
||||||
|
if (INCLUDE_ASAN)
|
||||||
add_executable(EntManager_test
|
target_compile_options(${name} PRIVATE -fsanitize=address -gdwarf-4)
|
||||||
entManager_test.c
|
target_link_options(${name} PRIVATE -fsanitize=address -gdwarf-4)
|
||||||
)
|
endif ()
|
||||||
target_compile_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
if (EXPORT_MMAP)
|
||||||
target_link_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
target_link_options(${name} PRIVATE -Xlinker -Map=scene_test.map)
|
||||||
target_include_directories(EntManager_test
|
endif()
|
||||||
PRIVATE
|
endif ()
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
target_link_libraries(${name}
|
||||||
)
|
PUBLIC
|
||||||
target_link_libraries(EntManager_test
|
|
||||||
${GAME_LIBS}
|
${GAME_LIBS}
|
||||||
)
|
)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
add_target_exe(main)
|
||||||
|
add_target_exe(level_test)
|
||||||
|
add_target_exe(scene_test)
|
||||||
|
|
||||||
add_executable(scene_test_mem
|
if (NOT EMSCRIPTEN)
|
||||||
scene_test.c
|
if (BUILD_EXTRAS AND NOT RUN_PROFILER)
|
||||||
)
|
add_target_exe(entManager_test)
|
||||||
target_include_directories(scene_test_mem
|
add_target_exe(water_test)
|
||||||
PRIVATE
|
add_target_exe(level_load_test)
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
add_target_exe(menu_test)
|
||||||
)
|
add_target_exe(assets_test)
|
||||||
target_link_options(scene_test_mem PRIVATE -Xlinker -Map=scene_test.map)
|
add_target_exe(particle_test)
|
||||||
|
add_target_exe(scene_man_test)
|
||||||
target_link_libraries(scene_test_mem
|
add_target_exe(level_select_test)
|
||||||
${GAME_LIBS}
|
endif()
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(water_test
|
|
||||||
water_test.c
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(water_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_link_libraries(water_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
target_compile_options(water_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(water_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
|
|
||||||
add_executable(level_load_test
|
|
||||||
level_load_test.c
|
|
||||||
)
|
|
||||||
target_include_directories(level_load_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_link_libraries(level_load_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
target_compile_options(level_load_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(level_load_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
|
|
||||||
add_executable(menu_test
|
|
||||||
menu_test.c
|
|
||||||
)
|
|
||||||
target_include_directories(menu_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_compile_options(menu_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(menu_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_libraries(menu_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(assets_test
|
|
||||||
assets_test.c
|
|
||||||
)
|
|
||||||
target_include_directories(assets_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_compile_options(assets_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(assets_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_libraries(assets_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(particle_test
|
|
||||||
particle_test.c
|
|
||||||
)
|
|
||||||
target_include_directories(particle_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_compile_options(particle_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(particle_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_libraries(particle_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(scene_man_test
|
|
||||||
scene_man_test.c
|
|
||||||
)
|
|
||||||
target_include_directories(scene_man_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_compile_options(scene_man_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(scene_man_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_libraries(scene_man_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
add_executable(level_select_test
|
|
||||||
level_select_test.c
|
|
||||||
)
|
|
||||||
target_include_directories(level_select_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_compile_options(level_select_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(level_select_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_libraries(level_select_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
if (BUILD_TESTING)
|
if (BUILD_TESTING)
|
||||||
find_package(cmocka 1.1.0 REQUIRED)
|
find_package(cmocka 1.1.0 REQUIRED)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
|
|
@ -32,6 +32,7 @@ add_library(lib_engine OBJECT
|
||||||
collisions.c
|
collisions.c
|
||||||
mempool.c
|
mempool.c
|
||||||
entManager.c
|
entManager.c
|
||||||
|
render_queue.c
|
||||||
)
|
)
|
||||||
target_link_libraries(lib_engine
|
target_link_libraries(lib_engine
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef __COLLISION_FUNCS_H
|
#ifndef __COLLISION_FUNCS_H
|
||||||
#define __COLLISION_FUNCS_H
|
#define __COLLISION_FUNCS_H
|
||||||
#include "EC.h"
|
#include "EC.h"
|
||||||
|
#include "render_queue.h"
|
||||||
|
|
||||||
typedef enum SolidType
|
typedef enum SolidType
|
||||||
{
|
{
|
||||||
|
@ -42,6 +43,7 @@ typedef struct TileGrid
|
||||||
unsigned int max_tiles;
|
unsigned int max_tiles;
|
||||||
unsigned int tile_size;
|
unsigned int tile_size;
|
||||||
Tile_t* tiles;
|
Tile_t* tiles;
|
||||||
|
RenderInfoNode* render_nodes;
|
||||||
}TileGrid_t;
|
}TileGrid_t;
|
||||||
|
|
||||||
typedef struct TileArea {
|
typedef struct TileArea {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "sc/heap/sc_heap.h"
|
#include "sc/heap/sc_heap.h"
|
||||||
#include "assets.h"
|
#include "assets.h"
|
||||||
#include "particle_sys.h"
|
#include "particle_sys.h"
|
||||||
|
#include "render_queue.h"
|
||||||
|
|
||||||
typedef struct Scene Scene_t;
|
typedef struct Scene Scene_t;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
// if memory used too high
|
// if memory used too high
|
||||||
#define MAX_SCENES_TO_RENDER 8
|
#define MAX_SCENES_TO_RENDER 8
|
||||||
#define MAX_RENDER_LAYERS 4
|
#define MAX_RENDER_LAYERS 4
|
||||||
|
#define MAX_RENDERMANAGER_DEPTH 4
|
||||||
#define MAX_ENTITIES 2047
|
#define MAX_ENTITIES 2047
|
||||||
#define MAX_TEXTURES 16
|
#define MAX_TEXTURES 16
|
||||||
#define MAX_SPRITES 127
|
#define MAX_SPRITES 127
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
#include "render_queue.h"
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
void init_render_manager(RenderManager *manager)
|
||||||
|
{
|
||||||
|
memset(manager, 0, sizeof(*manager));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool add_render_node(RenderManager *manager, RenderInfoNode *node, uint8_t layer_num)
|
||||||
|
{
|
||||||
|
if (node->next != NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (node->spr == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
layer_num = (layer_num >= MAX_RENDERMANAGER_DEPTH) ? MAX_RENDERMANAGER_DEPTH - 1 : layer_num;
|
||||||
|
|
||||||
|
node->next = manager->layers[layer_num];
|
||||||
|
manager->layers[layer_num] = node;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void execute_render(RenderManager *manager) {
|
||||||
|
for (uint8_t depth = 0; depth < MAX_RENDERMANAGER_DEPTH; ++depth)
|
||||||
|
{
|
||||||
|
RenderInfoNode* curr = manager->layers[depth];
|
||||||
|
while (curr != NULL)
|
||||||
|
{
|
||||||
|
draw_sprite_pro(
|
||||||
|
curr->spr, curr->frame_num, curr->pos,
|
||||||
|
curr->rotation, curr->flip, curr->scale,
|
||||||
|
curr->colour
|
||||||
|
);
|
||||||
|
RenderInfoNode* next = curr->next;
|
||||||
|
curr->next = NULL;
|
||||||
|
curr = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reset_render_manager(manager);
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef RENDER_QUEUE_H
|
||||||
|
#define RENDER_QUEUE_H
|
||||||
|
#include "assets.h"
|
||||||
|
#include "engine_conf.h"
|
||||||
|
|
||||||
|
typedef struct RenderInfoNode RenderInfoNode;
|
||||||
|
struct RenderInfoNode {
|
||||||
|
// Intrusive Linked-list Node
|
||||||
|
RenderInfoNode* next;
|
||||||
|
|
||||||
|
Sprite_t* spr;
|
||||||
|
Vector2 pos;
|
||||||
|
int frame_num;
|
||||||
|
float rotation;
|
||||||
|
Vector2 scale;
|
||||||
|
Color colour;
|
||||||
|
uint8_t flip;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct RenderManager {
|
||||||
|
RenderInfoNode* layers[MAX_RENDERMANAGER_DEPTH];
|
||||||
|
} RenderManager;
|
||||||
|
|
||||||
|
void init_render_manager(RenderManager* manager);
|
||||||
|
#define reset_render_manager init_render_manager
|
||||||
|
|
||||||
|
bool add_render_node(RenderManager* manager, RenderInfoNode* node, uint8_t layer_num);
|
||||||
|
void execute_render(RenderManager* manager);
|
||||||
|
#endif
|
15
level_test.c
15
level_test.c
|
@ -7,6 +7,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tracy/TracyC.h"
|
||||||
#define N_SCENES 1
|
#define N_SCENES 1
|
||||||
|
|
||||||
Scene_t *scenes[N_SCENES];
|
Scene_t *scenes[N_SCENES];
|
||||||
|
@ -30,13 +32,8 @@ int main(int argc, char** argv)
|
||||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||||
init_engine(&engine, (Vector2){screenWidth, screenHeight});
|
init_engine(&engine, (Vector2){screenWidth, screenHeight});
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
#ifndef NDEBUG
|
|
||||||
load_from_infofile("res/assets.info.raw", &engine.assets);
|
load_from_infofile("res/assets.info.raw", &engine.assets);
|
||||||
init_player_creation("res/player_spr.info", &engine.assets);
|
init_player_creation("res/player_spr.info", &engine.assets);
|
||||||
#else
|
|
||||||
load_from_rres("res/myresources.rres", &engine.assets);
|
|
||||||
init_player_creation_rres("res/myresources.rres", "player_spr.info", &engine.assets);
|
|
||||||
#endif
|
|
||||||
init_item_creation(&engine.assets);
|
init_item_creation(&engine.assets);
|
||||||
|
|
||||||
load_sfx(&engine, "snd_jump", PLAYER_JMP_SFX);
|
load_sfx(&engine, "snd_jump", PLAYER_JMP_SFX);
|
||||||
|
@ -91,6 +88,7 @@ int main(int argc, char** argv)
|
||||||
const float DT = 1.0f/60.0f;
|
const float DT = 1.0f/60.0f;
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
|
TracyCFrameMark;
|
||||||
// This entire key processing relies on the assumption that a pressed key will
|
// This entire key processing relies on the assumption that a pressed key will
|
||||||
// appear in the polling of raylib
|
// appear in the polling of raylib
|
||||||
Scene_t* curr_scene = engine.scenes[engine.curr_scene];
|
Scene_t* curr_scene = engine.scenes[engine.curr_scene];
|
||||||
|
@ -106,11 +104,16 @@ int main(int argc, char** argv)
|
||||||
float frame_time = GetFrameTime();
|
float frame_time = GetFrameTime();
|
||||||
float delta_time = fminf(frame_time, DT);
|
float delta_time = fminf(frame_time, DT);
|
||||||
|
|
||||||
|
{
|
||||||
|
TracyCZoneN(ctx, "Update", true)
|
||||||
update_scene(curr_scene, delta_time);
|
update_scene(curr_scene, delta_time);
|
||||||
update_entity_manager(&curr_scene->ent_manager);
|
update_entity_manager(&curr_scene->ent_manager);
|
||||||
|
update_sfx_list(&engine);
|
||||||
|
TracyCZoneEnd(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
// This is needed to advance time delta
|
// This is needed to advance time delta
|
||||||
render_scene(curr_scene);
|
render_scene(curr_scene);
|
||||||
update_sfx_list(&engine);
|
|
||||||
|
|
||||||
if (curr_scene->state != 0)
|
if (curr_scene->state != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
!CMakeLists.txt
|
!CMakeLists.txt
|
||||||
!ldtk_repacker.py
|
!ldtk_repacker.py
|
||||||
!pack_ldtk.sh
|
!pack_ldtk.sh
|
||||||
|
!pack_resources.sh
|
||||||
!test_assets.info
|
!test_assets.info
|
||||||
!testLevels.lvldata.zst
|
!testLevels.lvldata.zst
|
||||||
!rres_packer.c
|
!rres_packer.c
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
sed 's|res/||g' assets.info.raw > assets.info
|
||||||
|
./rres_packer
|
||||||
|
mv ../web/res/myresources.rres ../web/res/myresources.rres.old
|
||||||
|
cp ./myresources.rres ../web/res/
|
|
@ -15,37 +15,18 @@ add_library(lib_scenes STATIC
|
||||||
target_include_directories(lib_scenes
|
target_include_directories(lib_scenes
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
)
|
${CMAKE_CURRENT_LIST_DIR}/../tracy/public/
|
||||||
target_link_libraries(lib_scenes
|
|
||||||
PUBLIC
|
|
||||||
lib_engine
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(lib_scenes_trace STATIC
|
if (${RUN_PROFILER})
|
||||||
assets_loader.c
|
target_compile_definitions(lib_scenes
|
||||||
player_ent.c
|
|
||||||
items_ent.c
|
|
||||||
water_flow.c
|
|
||||||
editor_scene.c
|
|
||||||
menu_scene.c
|
|
||||||
level_select_scene.c
|
|
||||||
game_scene.c
|
|
||||||
game_systems.c
|
|
||||||
scene_systems.c
|
|
||||||
camera_systems.c
|
|
||||||
engine_impl.c
|
|
||||||
)
|
|
||||||
target_compile_definitions(lib_scenes_trace
|
|
||||||
PUBLIC
|
PUBLIC
|
||||||
TRACY_ENABLE
|
TRACY_ENABLE
|
||||||
TRACY_ON_DEMAND
|
TRACY_ON_DEMAND
|
||||||
)
|
)
|
||||||
target_include_directories(lib_scenes_trace
|
endif()
|
||||||
PUBLIC
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
target_link_libraries(lib_scenes
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../tracy/public/
|
|
||||||
)
|
|
||||||
target_link_libraries(lib_scenes_trace
|
|
||||||
PUBLIC
|
PUBLIC
|
||||||
lib_engine
|
lib_engine
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "EC.h"
|
#include "EC.h"
|
||||||
|
#include "render_queue.h"
|
||||||
#include "particle_sys.h" // includes assets
|
#include "particle_sys.h" // includes assets
|
||||||
|
|
||||||
enum ComponentEnum {
|
enum ComponentEnum {
|
||||||
|
@ -145,19 +146,17 @@ typedef struct _SpriteRenderInfo
|
||||||
} SpriteRenderInfo_t;
|
} SpriteRenderInfo_t;
|
||||||
|
|
||||||
typedef struct _CSprite_t {
|
typedef struct _CSprite_t {
|
||||||
|
RenderInfoNode node;
|
||||||
SpriteRenderInfo_t* sprites;
|
SpriteRenderInfo_t* sprites;
|
||||||
sprite_transition_func_t transition_func;
|
sprite_transition_func_t transition_func;
|
||||||
unsigned int current_idx;
|
unsigned int current_idx;
|
||||||
bool flip_x;
|
|
||||||
bool flip_y;
|
|
||||||
bool pause;
|
|
||||||
int current_frame;
|
int current_frame;
|
||||||
float fractional;
|
float fractional;
|
||||||
float rotation; // Degree
|
|
||||||
float rotation_speed; // Degree / s
|
float rotation_speed; // Degree / s
|
||||||
int elapsed;
|
int elapsed;
|
||||||
Vector2 offset;
|
Vector2 offset;
|
||||||
Color colour;
|
uint8_t depth;
|
||||||
|
bool pause;
|
||||||
} CSprite_t;
|
} CSprite_t;
|
||||||
|
|
||||||
typedef struct _CMoveable_t {
|
typedef struct _CMoveable_t {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Constants to be used in game
|
// Constants to be used in game
|
||||||
#ifndef __CONSTANTS_H
|
#ifndef __CONSTANTS_H
|
||||||
#define __CONSTANTS_H
|
#define __CONSTANTS_H
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef TILE16_SIZE
|
#ifndef TILE16_SIZE
|
||||||
#define TILE_SIZE 32
|
#define TILE_SIZE 32
|
||||||
#define DEFAULT_MAP_WIDTH 48
|
#define DEFAULT_MAP_WIDTH 48
|
||||||
|
@ -47,4 +49,11 @@
|
||||||
#define WATER_BBOX_STEP (TILE_SIZE / MAX_WATER_LEVEL)
|
#define WATER_BBOX_STEP (TILE_SIZE / MAX_WATER_LEVEL)
|
||||||
|
|
||||||
#define MAX_LEVEL_NUM 50
|
#define MAX_LEVEL_NUM 50
|
||||||
|
|
||||||
|
static const uint8_t CONNECTIVITY_TILE_MAPPING[16] = {
|
||||||
|
0,3,15,14,
|
||||||
|
1,2,12,13,
|
||||||
|
7,6,11,10,
|
||||||
|
4,5,8 ,9 ,
|
||||||
|
};
|
||||||
#endif // __CONSTANTS_H
|
#endif // __CONSTANTS_H
|
||||||
|
|
|
@ -58,13 +58,6 @@ static Vector2 urchin_click_pos = {0,0};
|
||||||
#define SELECTION_LAYER 0
|
#define SELECTION_LAYER 0
|
||||||
#define CONTROL_LAYER 1
|
#define CONTROL_LAYER 1
|
||||||
|
|
||||||
static const uint8_t CONNECTIVITY_TILE_MAPPING[16] = {
|
|
||||||
0,3,15,14,
|
|
||||||
1,2,12,13,
|
|
||||||
7,6,11,10,
|
|
||||||
4,5,8 ,9 ,
|
|
||||||
};
|
|
||||||
|
|
||||||
#define N_SOLID_TILESETS 3
|
#define N_SOLID_TILESETS 3
|
||||||
static const char* SOLID_TILE_SELECTIONS[N_SOLID_TILESETS] = {
|
static const char* SOLID_TILE_SELECTIONS[N_SOLID_TILESETS] = {
|
||||||
"stile0", "stile1", "stile2"
|
"stile0", "stile1", "stile2"
|
||||||
|
@ -302,6 +295,58 @@ static void render_editor_game_scene(Scene_t* scene)
|
||||||
max.x = (int)fmin(tilemap.width, max.x + 1);
|
max.x = (int)fmin(tilemap.width, max.x + 1);
|
||||||
max.y = (int)fmin(tilemap.height, max.y + 1);
|
max.y = (int)fmin(tilemap.height, max.y + 1);
|
||||||
|
|
||||||
|
// Queue Sprite rendering
|
||||||
|
sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
|
||||||
|
{
|
||||||
|
if (!p_ent->m_alive) continue;
|
||||||
|
|
||||||
|
CSprite_t* p_cspr = get_component(p_ent, CSPRITE_T);
|
||||||
|
if (p_cspr == NULL) continue;
|
||||||
|
|
||||||
|
const SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
||||||
|
if (spr.sprite == NULL) continue;
|
||||||
|
|
||||||
|
Vector2 pos = p_ent->position;
|
||||||
|
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
||||||
|
if (p_bbox != NULL)
|
||||||
|
{
|
||||||
|
pos = Vector2Add(
|
||||||
|
pos,
|
||||||
|
get_anchor_offset(p_bbox->size, spr.dest_anchor, p_cspr->node.flip & 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
pos = Vector2Subtract(
|
||||||
|
pos,
|
||||||
|
get_anchor_offset(spr.sprite->frame_size, spr.src_anchor, p_cspr->node.flip & 1)
|
||||||
|
);
|
||||||
|
|
||||||
|
Vector2 offset = spr.offset;
|
||||||
|
if (p_cspr->node.flip & 1) offset.x *= -1;
|
||||||
|
|
||||||
|
pos = Vector2Add(pos, offset);
|
||||||
|
// Entity culling
|
||||||
|
if (
|
||||||
|
pos.x + spr.sprite->frame_size.x < min.x * tilemap.tile_size
|
||||||
|
|| pos.x > max.x * tilemap.tile_size
|
||||||
|
|| pos.y + spr.sprite->frame_size.y < min.y * tilemap.tile_size
|
||||||
|
|| pos.y > max.y * tilemap.tile_size
|
||||||
|
)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_ent->m_tag == LEVEL_END_TAG)
|
||||||
|
{
|
||||||
|
p_cspr->current_frame = 2 * data->selected_solid_tilemap + (
|
||||||
|
(data->coins.current < data->coins.total) ? 0 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
p_cspr->node.spr = spr.sprite;
|
||||||
|
p_cspr->node.frame_num = p_cspr->current_frame;
|
||||||
|
p_cspr->node.pos = pos;
|
||||||
|
add_render_node(&data->render_manager, &p_cspr->node, p_cspr->depth);
|
||||||
|
}
|
||||||
|
|
||||||
Texture2D* bg = get_texture(&scene->engine->assets, "bg_tex");
|
Texture2D* bg = get_texture(&scene->engine->assets, "bg_tex");
|
||||||
BeginTextureMode(scene->layers.render_layers[GAME_LAYER].layer_tex);
|
BeginTextureMode(scene->layers.render_layers[GAME_LAYER].layer_tex);
|
||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
|
@ -342,44 +387,11 @@ static void render_editor_game_scene(Scene_t* scene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_map_foreach_value(&scene->ent_manager.entities_map[LEVEL_END_TAG], p_ent)
|
|
||||||
{
|
|
||||||
CSprite_t* p_cspr = get_component(p_ent, CSPRITE_T);
|
|
||||||
if (p_cspr != NULL)
|
|
||||||
{
|
|
||||||
const SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
|
||||||
if (spr.sprite != NULL)
|
|
||||||
{
|
|
||||||
Vector2 pos = p_ent->position;
|
|
||||||
pos = Vector2Subtract(
|
|
||||||
pos,
|
|
||||||
get_anchor_offset(spr.sprite->frame_size, spr.src_anchor, p_cspr->flip_x)
|
|
||||||
);
|
|
||||||
|
|
||||||
Vector2 offset = spr.offset;
|
|
||||||
if (p_cspr->flip_x) offset.x *= -1;
|
|
||||||
|
|
||||||
pos = Vector2Add(pos, offset);
|
|
||||||
draw_sprite(
|
|
||||||
spr.sprite,
|
|
||||||
2 * data->selected_solid_tilemap + (
|
|
||||||
(data->coins.current < data->coins.total) ? 0 : 1
|
|
||||||
),
|
|
||||||
pos, 0.0f, p_cspr->flip_x
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DrawCircleV(p_ent->position, tilemap.tile_size >> 1, (data->coins.current < data->coins.total)? RED : GREEN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char buffer[64] = {0};
|
char buffer[64] = {0};
|
||||||
|
if (data->show_grid)
|
||||||
|
{
|
||||||
sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
|
sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
|
||||||
{
|
{
|
||||||
if (p_ent->m_tag == LEVEL_END_TAG) continue;
|
|
||||||
|
|
||||||
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
||||||
|
|
||||||
// Entity culling
|
// Entity culling
|
||||||
|
@ -392,8 +404,6 @@ static void render_editor_game_scene(Scene_t* scene)
|
||||||
|| p_ent->position.y > max.y * tilemap.tile_size
|
|| p_ent->position.y > max.y * tilemap.tile_size
|
||||||
) continue;
|
) continue;
|
||||||
|
|
||||||
if (data->show_grid)
|
|
||||||
{
|
|
||||||
Color colour;
|
Color colour;
|
||||||
switch(p_ent->m_tag)
|
switch(p_ent->m_tag)
|
||||||
{
|
{
|
||||||
|
@ -418,6 +428,21 @@ static void render_editor_game_scene(Scene_t* scene)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_ent->m_tag == LEVEL_END_TAG)
|
||||||
|
{
|
||||||
|
DrawCircleV(p_ent->position, tilemap.tile_size >> 1, (data->coins.current < data->coins.total)? RED : GREEN);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_ent->m_tag == DYNMEM_ENT_TAG)
|
||||||
|
{
|
||||||
|
CWaterRunner_t* p_runner = get_component(p_ent, CWATERRUNNER_T);
|
||||||
|
|
||||||
|
unsigned int x = ((p_runner->current_tile) % tilemap.width) * tilemap.tile_size;
|
||||||
|
unsigned int y = ((p_runner->current_tile) / tilemap.width) * tilemap.tile_size;
|
||||||
|
DrawCircle(x+16, y+16, 8, ColorAlpha(BLUE, 0.6));
|
||||||
|
}
|
||||||
|
|
||||||
if (p_bbox != NULL)
|
if (p_bbox != NULL)
|
||||||
{
|
{
|
||||||
if (p_ent->m_tag == BOULDER_ENT_TAG)
|
if (p_ent->m_tag == BOULDER_ENT_TAG)
|
||||||
|
@ -508,34 +533,9 @@ static void render_editor_game_scene(Scene_t* scene)
|
||||||
DrawRectangleLinesEx(rec, 1.5, PURPLE);
|
DrawRectangleLinesEx(rec, 1.5, PURPLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CSprite_t* p_cspr = get_component(p_ent, CSPRITE_T);
|
execute_render(&data->render_manager);
|
||||||
if (p_cspr != NULL)
|
|
||||||
{
|
|
||||||
const SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
|
||||||
if (spr.sprite != NULL)
|
|
||||||
{
|
|
||||||
Vector2 pos = p_ent->position;
|
|
||||||
if (p_bbox != NULL)
|
|
||||||
{
|
|
||||||
pos = Vector2Add(
|
|
||||||
pos,
|
|
||||||
get_anchor_offset(p_bbox->size, spr.dest_anchor, p_cspr->flip_x)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
pos = Vector2Subtract(
|
|
||||||
pos,
|
|
||||||
get_anchor_offset(spr.sprite->frame_size, spr.src_anchor, p_cspr->flip_x)
|
|
||||||
);
|
|
||||||
|
|
||||||
Vector2 offset = spr.offset;
|
|
||||||
if (p_cspr->flip_x) offset.x *= -1;
|
|
||||||
|
|
||||||
pos = Vector2Add(pos, offset);
|
|
||||||
draw_sprite(spr.sprite, p_cspr->current_frame, pos, 0.0f, p_cspr->flip_x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
||||||
{
|
{
|
||||||
|
@ -636,16 +636,6 @@ static void render_editor_game_scene(Scene_t* scene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_map_foreach_value(&scene->ent_manager.entities_map[DYNMEM_ENT_TAG], p_ent)
|
|
||||||
{
|
|
||||||
CWaterRunner_t* p_runner = get_component(p_ent, CWATERRUNNER_T);
|
|
||||||
|
|
||||||
unsigned int x = ((p_runner->current_tile) % tilemap.width) * tilemap.tile_size;
|
|
||||||
unsigned int y = ((p_runner->current_tile) / tilemap.width) * tilemap.tile_size;
|
|
||||||
DrawCircle(x+16, y+16, 8, ColorAlpha(BLUE, 0.6));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (data->show_grid)
|
if (data->show_grid)
|
||||||
{
|
{
|
||||||
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
||||||
|
@ -1321,7 +1311,7 @@ void init_sandbox_scene(LevelScene_t* scene)
|
||||||
{
|
{
|
||||||
Entity_t* p_player = create_player(&scene->scene.ent_manager);
|
Entity_t* p_player = create_player(&scene->scene.ent_manager);
|
||||||
CSprite_t* p_cspr = get_component(p_player, CSPRITE_T);
|
CSprite_t* p_cspr = get_component(p_player, CSPRITE_T);
|
||||||
p_cspr->flip_x = true;
|
p_cspr->node.flip |= 1;
|
||||||
|
|
||||||
p_player->position.x = 100;
|
p_player->position.x = 100;
|
||||||
p_player->position.y = (scene->data.tilemap.height - 1) * scene->data.tilemap.tile_size - PLAYER_HEIGHT;
|
p_player->position.y = (scene->data.tilemap.height - 1) * scene->data.tilemap.tile_size - PLAYER_HEIGHT;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#include "tracy/TracyC.h"
|
||||||
|
|
||||||
#include "scene_impl.h"
|
#include "scene_impl.h"
|
||||||
#include "game_systems.h"
|
#include "game_systems.h"
|
||||||
#include "water_flow.h"
|
#include "water_flow.h"
|
||||||
|
@ -9,12 +11,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static Tile_t all_tiles[MAX_N_TILES] = {0};
|
static Tile_t all_tiles[MAX_N_TILES] = {0};
|
||||||
static const uint8_t CONNECTIVITY_TILE_MAPPING[16] = {
|
static RenderInfoNode all_tile_rendernodes[MAX_N_TILES] = {0};
|
||||||
0,3,15,14,
|
|
||||||
1,2,12,13,
|
|
||||||
7,6,11,10,
|
|
||||||
4,5,8 ,9 ,
|
|
||||||
};
|
|
||||||
|
|
||||||
#define GAME_LAYER 0
|
#define GAME_LAYER 0
|
||||||
#define CONTROL_LAYER 1
|
#define CONTROL_LAYER 1
|
||||||
|
@ -140,6 +137,7 @@ static void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
|
||||||
|
|
||||||
static void render_regular_game_scene(Scene_t* scene)
|
static void render_regular_game_scene(Scene_t* scene)
|
||||||
{
|
{
|
||||||
|
TracyCZoneN(ctx, "GameRender", true)
|
||||||
// This function will render the game scene outside of the intended draw function
|
// This function will render the game scene outside of the intended draw function
|
||||||
// Just for clarity and separation of logic
|
// Just for clarity and separation of logic
|
||||||
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
||||||
|
@ -161,6 +159,80 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
max.x = (int)fmin(tilemap.width, max.x + 1);
|
max.x = (int)fmin(tilemap.width, max.x + 1);
|
||||||
max.y = (int)fmin(tilemap.height, max.y + 1);
|
max.y = (int)fmin(tilemap.height, max.y + 1);
|
||||||
|
|
||||||
|
// Queue TileMap rendering
|
||||||
|
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
||||||
|
{
|
||||||
|
for (int tile_x = min.x; tile_x < max.x; tile_x++)
|
||||||
|
{
|
||||||
|
|
||||||
|
int i = tile_x + tile_y * tilemap.width;
|
||||||
|
// Tile render nodes is static on load and is not dynamically updated.
|
||||||
|
// We exploit the fact that all tiles can only change into an empty
|
||||||
|
// tile.
|
||||||
|
// This won't work if a tile can change into something else
|
||||||
|
if (tilemap.tiles[i].tile_type == EMPTY_TILE) continue;
|
||||||
|
|
||||||
|
uint8_t depth = 2;
|
||||||
|
if (tilemap.tiles[i].tile_type == LADDER)
|
||||||
|
{
|
||||||
|
depth = 0;
|
||||||
|
}
|
||||||
|
add_render_node(&data->render_manager, all_tile_rendernodes + i, depth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Queue Sprite rendering
|
||||||
|
sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
|
||||||
|
{
|
||||||
|
if (!p_ent->m_alive) continue;
|
||||||
|
|
||||||
|
CSprite_t* p_cspr = get_component(p_ent, CSPRITE_T);
|
||||||
|
if (p_cspr == NULL) continue;
|
||||||
|
|
||||||
|
const SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
||||||
|
if (spr.sprite == NULL) continue;
|
||||||
|
|
||||||
|
Vector2 pos = p_ent->position;
|
||||||
|
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
||||||
|
if (p_bbox != NULL)
|
||||||
|
{
|
||||||
|
pos = Vector2Add(
|
||||||
|
pos,
|
||||||
|
get_anchor_offset(p_bbox->size, spr.dest_anchor, p_cspr->node.flip & 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
pos = Vector2Subtract(
|
||||||
|
pos,
|
||||||
|
get_anchor_offset(spr.sprite->frame_size, spr.src_anchor, p_cspr->node.flip & 1)
|
||||||
|
);
|
||||||
|
|
||||||
|
Vector2 offset = spr.offset;
|
||||||
|
if (p_cspr->node.flip & 1) offset.x *= -1;
|
||||||
|
|
||||||
|
pos = Vector2Add(pos, offset);
|
||||||
|
// Entity culling
|
||||||
|
if (
|
||||||
|
pos.x + spr.sprite->frame_size.x < min.x * tilemap.tile_size
|
||||||
|
|| pos.x > max.x * tilemap.tile_size
|
||||||
|
|| pos.y + spr.sprite->frame_size.y < min.y * tilemap.tile_size
|
||||||
|
|| pos.y > max.y * tilemap.tile_size
|
||||||
|
)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_ent->m_tag == LEVEL_END_TAG)
|
||||||
|
{
|
||||||
|
p_cspr->current_frame = 2 * data->selected_solid_tilemap + (
|
||||||
|
(data->coins.current < data->coins.total) ? 0 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
p_cspr->node.spr = spr.sprite;
|
||||||
|
p_cspr->node.frame_num = p_cspr->current_frame;
|
||||||
|
p_cspr->node.pos = pos;
|
||||||
|
add_render_node(&data->render_manager, &p_cspr->node, p_cspr->depth);
|
||||||
|
}
|
||||||
|
|
||||||
Texture2D* bg = get_texture(&scene->engine->assets, "bg_tex");
|
Texture2D* bg = get_texture(&scene->engine->assets, "bg_tex");
|
||||||
BeginTextureMode(scene->layers.render_layers[GAME_LAYER].layer_tex);
|
BeginTextureMode(scene->layers.render_layers[GAME_LAYER].layer_tex);
|
||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
|
@ -174,6 +246,7 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
|
|
||||||
BeginMode2D(data->camera.cam);
|
BeginMode2D(data->camera.cam);
|
||||||
|
|
||||||
|
#ifdef ENABLE_RENDER_FALLBACK
|
||||||
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
||||||
{
|
{
|
||||||
for (int tile_x = min.x; tile_x < max.x; tile_x++)
|
for (int tile_x = min.x; tile_x < max.x; tile_x++)
|
||||||
|
@ -184,56 +257,15 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
|
|
||||||
if (tilemap.tiles[i].tile_type == LADDER)
|
if (tilemap.tiles[i].tile_type == LADDER)
|
||||||
{
|
{
|
||||||
if (data->tile_sprites[tilemap.tiles[i].tile_type] != NULL)
|
if (data->tile_sprites[tilemap.tiles[i].tile_type] == NULL)
|
||||||
{
|
|
||||||
draw_sprite(data->tile_sprites[tilemap.tiles[i].tile_type], 0, (Vector2){x,y}, 0.0f, false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, ORANGE);
|
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, ORANGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_map_foreach_value(&scene->ent_manager.entities_map[LEVEL_END_TAG], p_ent)
|
|
||||||
{
|
|
||||||
// There is only a few exits, can may be get away without culling
|
|
||||||
CSprite_t* p_cspr = get_component(p_ent, CSPRITE_T);
|
|
||||||
if (p_cspr != NULL)
|
|
||||||
{
|
|
||||||
const SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
|
||||||
if (spr.sprite != NULL)
|
|
||||||
{
|
|
||||||
Vector2 pos = p_ent->position;
|
|
||||||
pos = Vector2Subtract(
|
|
||||||
pos,
|
|
||||||
get_anchor_offset(spr.sprite->frame_size, spr.src_anchor, p_cspr->flip_x)
|
|
||||||
);
|
|
||||||
|
|
||||||
Vector2 offset = spr.offset;
|
|
||||||
if (p_cspr->flip_x) offset.x *= -1;
|
|
||||||
|
|
||||||
pos = Vector2Add(pos, offset);
|
|
||||||
draw_sprite(
|
|
||||||
spr.sprite,
|
|
||||||
2 * data->selected_solid_tilemap + (
|
|
||||||
(data->coins.current < data->coins.total) ? 0 : 1
|
|
||||||
),
|
|
||||||
pos, 0.0f, p_cspr->flip_x
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DrawCircleV(p_ent->position, tilemap.tile_size >> 1, (data->coins.current < data->coins.total)? RED : GREEN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
|
sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
|
||||||
{
|
{
|
||||||
if (p_ent->m_tag == LEVEL_END_TAG) continue;
|
|
||||||
|
|
||||||
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
||||||
|
|
||||||
// Entity culling
|
// Entity culling
|
||||||
|
@ -246,34 +278,8 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
|| p_ent->position.y > max.y * tilemap.tile_size
|
|| p_ent->position.y > max.y * tilemap.tile_size
|
||||||
) continue;
|
) continue;
|
||||||
|
|
||||||
// Render Sprite only
|
|
||||||
CSprite_t* p_cspr = get_component(p_ent, CSPRITE_T);
|
CSprite_t* p_cspr = get_component(p_ent, CSPRITE_T);
|
||||||
if (p_cspr != NULL)
|
if (p_cspr != NULL) continue;
|
||||||
{
|
|
||||||
const SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
|
||||||
if (spr.sprite != NULL)
|
|
||||||
{
|
|
||||||
Vector2 pos = p_ent->position;
|
|
||||||
if (p_bbox != NULL)
|
|
||||||
{
|
|
||||||
pos = Vector2Add(
|
|
||||||
pos,
|
|
||||||
get_anchor_offset(p_bbox->size, spr.dest_anchor, p_cspr->flip_x)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
pos = Vector2Subtract(
|
|
||||||
pos,
|
|
||||||
get_anchor_offset(spr.sprite->frame_size, spr.src_anchor, p_cspr->flip_x)
|
|
||||||
);
|
|
||||||
|
|
||||||
Vector2 offset = spr.offset;
|
|
||||||
if (p_cspr->flip_x) offset.x *= -1;
|
|
||||||
|
|
||||||
pos = Vector2Add(pos, offset);
|
|
||||||
draw_sprite(spr.sprite, p_cspr->current_frame, pos, 0.0f, p_cspr->flip_x);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Continue here only if no sprite
|
// Continue here only if no sprite
|
||||||
Color colour;
|
Color colour;
|
||||||
|
@ -293,6 +299,12 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_ent->m_tag == LEVEL_END_TAG)
|
||||||
|
{
|
||||||
|
DrawCircleV(p_ent->position, tilemap.tile_size >> 1, (data->coins.current < data->coins.total)? RED : GREEN);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (p_bbox != NULL)
|
if (p_bbox != NULL)
|
||||||
{
|
{
|
||||||
if (p_ent->m_tag == BOULDER_ENT_TAG)
|
if (p_ent->m_tag == BOULDER_ENT_TAG)
|
||||||
|
@ -357,7 +369,6 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
||||||
{
|
{
|
||||||
for (int tile_x = min.x; tile_x < max.x; tile_x++)
|
for (int tile_x = min.x; tile_x < max.x; tile_x++)
|
||||||
|
@ -369,20 +380,15 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
if (tilemap.tiles[i].tile_type != LADDER)
|
if (tilemap.tiles[i].tile_type != LADDER)
|
||||||
{
|
{
|
||||||
uint8_t tile_sprite_idx = tilemap.tiles[i].tile_type + tilemap.tiles[i].rotation;
|
uint8_t tile_sprite_idx = tilemap.tiles[i].tile_type + tilemap.tiles[i].rotation;
|
||||||
if (data->tile_sprites[tile_sprite_idx] != NULL)
|
if (tilemap.tiles[i].tile_type == SOLID_TILE)
|
||||||
{
|
|
||||||
draw_sprite(data->tile_sprites[tile_sprite_idx], 0, (Vector2){x,y}, 0.0f, false);
|
|
||||||
}
|
|
||||||
else if (tilemap.tiles[i].tile_type == SOLID_TILE)
|
|
||||||
{
|
{
|
||||||
|
if (data->solid_tile_sprites == NULL) {
|
||||||
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, BLACK);
|
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, BLACK);
|
||||||
draw_sprite(
|
|
||||||
data->solid_tile_sprites,
|
|
||||||
CONNECTIVITY_TILE_MAPPING[tilemap.tiles[i].connectivity],
|
|
||||||
(Vector2){x,y}, 0.0f, false
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else if (tilemap.tiles[i].tile_type == ONEWAY_TILE)
|
}
|
||||||
|
else if (data->tile_sprites[tile_sprite_idx] == NULL)
|
||||||
|
{
|
||||||
|
if (tilemap.tiles[i].tile_type == ONEWAY_TILE)
|
||||||
{
|
{
|
||||||
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, MAROON);
|
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, MAROON);
|
||||||
}
|
}
|
||||||
|
@ -394,6 +400,26 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif //ENABLE_RENDER_FALLBACK
|
||||||
|
|
||||||
|
execute_render(&data->render_manager);
|
||||||
|
|
||||||
|
// Particle effect will always be in front of everything except water
|
||||||
|
draw_particle_system(&scene->part_sys);
|
||||||
|
|
||||||
|
// Render water
|
||||||
|
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
||||||
|
{
|
||||||
|
for (int tile_x = min.x; tile_x < max.x; tile_x++)
|
||||||
|
{
|
||||||
|
int i = tile_x + tile_y * tilemap.width;
|
||||||
|
int x = tile_x * TILE_SIZE;
|
||||||
|
int y = tile_y * TILE_SIZE;
|
||||||
|
|
||||||
|
// Draw water flow
|
||||||
if (tilemap.tiles[i].wet)
|
if (tilemap.tiles[i].wet)
|
||||||
{
|
{
|
||||||
#define SURFACE_THICKNESS 4
|
#define SURFACE_THICKNESS 4
|
||||||
|
@ -407,7 +433,6 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
DrawLineEx((Vector2){x + TILE_SIZE / 2, y}, (Vector2){x + TILE_SIZE / 2, y + TILE_SIZE - tilemap.tiles[i].water_level * WATER_BBOX_STEP}, SURFACE_THICKNESS, ColorAlpha(BLUE, 0.7));
|
DrawLineEx((Vector2){x + TILE_SIZE / 2, y}, (Vector2){x + TILE_SIZE / 2, y + TILE_SIZE - tilemap.tiles[i].water_level * WATER_BBOX_STEP}, SURFACE_THICKNESS, ColorAlpha(BLUE, 0.7));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
bot <= tilemap.n_tiles
|
bot <= tilemap.n_tiles
|
||||||
&& tilemap.tiles[i].water_level == 0
|
&& tilemap.tiles[i].water_level == 0
|
||||||
|
@ -428,28 +453,6 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
DrawRectangleLinesEx((Rectangle){x, y, TILE_SIZE, TILE_SIZE}, 2.0, ColorAlpha(BLUE, 0.5));
|
DrawRectangleLinesEx((Rectangle){x, y, TILE_SIZE, TILE_SIZE}, 2.0, ColorAlpha(BLUE, 0.5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//sc_map_foreach_value(&scene->ent_manager.entities_map[DYNMEM_ENT_TAG], p_ent)
|
|
||||||
//{
|
|
||||||
// CWaterRunner_t* p_runner = get_component(p_ent, CWATERRUNNER_T);
|
|
||||||
|
|
||||||
// unsigned int x = ((p_runner->current_tile) % tilemap.width) * tilemap.tile_size;
|
|
||||||
// unsigned int y = ((p_runner->current_tile) / tilemap.width) * tilemap.tile_size;
|
|
||||||
// DrawCircle(x+16, y+16, 8, ColorAlpha(BLUE, 0.6));
|
|
||||||
//}
|
|
||||||
draw_particle_system(&scene->part_sys);
|
|
||||||
|
|
||||||
// Draw water tile
|
|
||||||
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
|
||||||
{
|
|
||||||
for (int tile_x = min.x; tile_x < max.x; tile_x++)
|
|
||||||
{
|
|
||||||
int i = tile_x + tile_y * tilemap.width;
|
|
||||||
int x = tile_x * TILE_SIZE;
|
|
||||||
int y = tile_y * TILE_SIZE;
|
|
||||||
|
|
||||||
uint32_t water_height = tilemap.tiles[i].water_level * WATER_BBOX_STEP;
|
uint32_t water_height = tilemap.tiles[i].water_level * WATER_BBOX_STEP;
|
||||||
Color water_colour = ColorAlpha(BLUE, 0.5);
|
Color water_colour = ColorAlpha(BLUE, 0.5);
|
||||||
|
@ -462,16 +465,9 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//// Draw Border (remove later)
|
|
||||||
//DrawLine(0, 0, 0, tilemap.height * tilemap.tile_size, BLACK);
|
|
||||||
//DrawLine(0, 0, tilemap.width * TILE_SIZE, 0, BLACK);
|
|
||||||
//int val = (tilemap.width) * tilemap.tile_size;
|
|
||||||
//DrawLine(val, 0, val, tilemap.height * tilemap.tile_size, BLACK);
|
|
||||||
//val = (tilemap.height) * tilemap.tile_size;
|
|
||||||
//DrawLine(0, val, tilemap.width * TILE_SIZE, val, BLACK);
|
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
TracyCZoneEnd(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void at_level_start(Scene_t* scene)
|
static void at_level_start(Scene_t* scene)
|
||||||
|
@ -505,6 +501,7 @@ void init_game_scene(LevelScene_t* scene)
|
||||||
init_entity_tag_map(&scene->scene.ent_manager, DYNMEM_ENT_TAG, 16);
|
init_entity_tag_map(&scene->scene.ent_manager, DYNMEM_ENT_TAG, 16);
|
||||||
|
|
||||||
scene->data.tilemap.tiles = all_tiles;
|
scene->data.tilemap.tiles = all_tiles;
|
||||||
|
scene->data.tilemap.render_nodes = all_tile_rendernodes;
|
||||||
init_level_scene_data(
|
init_level_scene_data(
|
||||||
&scene->data, MAX_N_TILES, all_tiles,
|
&scene->data, MAX_N_TILES, all_tiles,
|
||||||
(Rectangle){
|
(Rectangle){
|
||||||
|
@ -512,6 +509,16 @@ void init_game_scene(LevelScene_t* scene)
|
||||||
VIEWABLE_MAP_WIDTH*TILE_SIZE, VIEWABLE_MAP_HEIGHT*TILE_SIZE
|
VIEWABLE_MAP_WIDTH*TILE_SIZE, VIEWABLE_MAP_HEIGHT*TILE_SIZE
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
for (size_t i = 0; i < MAX_N_TILES; i++)
|
||||||
|
{
|
||||||
|
memset(all_tile_rendernodes + i, 0, sizeof(RenderInfoNode));
|
||||||
|
all_tile_rendernodes[i].pos = (Vector2){
|
||||||
|
(i % scene->data.tilemap.width) * TILE_SIZE,
|
||||||
|
(i / scene->data.tilemap.width) * TILE_SIZE,
|
||||||
|
};
|
||||||
|
all_tile_rendernodes[i].scale = (Vector2){1,1};
|
||||||
|
all_tile_rendernodes[i].colour = WHITE;
|
||||||
|
}
|
||||||
scene->data.sm.state_functions[LEVEL_STATE_STARTING] = at_level_start;
|
scene->data.sm.state_functions[LEVEL_STATE_STARTING] = at_level_start;
|
||||||
scene->data.sm.state_functions[LEVEL_STATE_RUNNING] = NULL;
|
scene->data.sm.state_functions[LEVEL_STATE_RUNNING] = NULL;
|
||||||
scene->data.sm.state_functions[LEVEL_STATE_DEAD] = NULL;
|
scene->data.sm.state_functions[LEVEL_STATE_DEAD] = NULL;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#include "assets_tag.h"
|
#include "assets_tag.h"
|
||||||
#ifdef TRACY_ENABLE
|
|
||||||
#include "tracy/TracyC.h"
|
#include "tracy/TracyC.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "game_systems.h"
|
#include "game_systems.h"
|
||||||
|
|
||||||
|
@ -781,9 +779,7 @@ void spike_collision_system(Scene_t* scene)
|
||||||
|
|
||||||
void tile_collision_system(Scene_t* scene)
|
void tile_collision_system(Scene_t* scene)
|
||||||
{
|
{
|
||||||
#ifdef TRACY_ENABLE
|
|
||||||
TracyCZoneN(ctx, "TileCol", true)
|
TracyCZoneN(ctx, "TileCol", true)
|
||||||
#endif
|
|
||||||
static bool checked_entities[MAX_COMP_POOL_SIZE] = {0};
|
static bool checked_entities[MAX_COMP_POOL_SIZE] = {0};
|
||||||
|
|
||||||
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
||||||
|
@ -924,9 +920,7 @@ void tile_collision_system(Scene_t* scene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TRACY_ENABLE
|
|
||||||
TracyCZoneEnd(ctx)
|
TracyCZoneEnd(ctx)
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void friction_coefficient_update_system(Scene_t* scene)
|
void friction_coefficient_update_system(Scene_t* scene)
|
||||||
|
@ -2155,7 +2149,7 @@ void level_end_detection_system(Scene_t* scene)
|
||||||
ent->position.y += tilemap.tile_size >> 1;
|
ent->position.y += tilemap.tile_size >> 1;
|
||||||
CSprite_t* p_cspr = get_component(p_other_ent, CSPRITE_T);
|
CSprite_t* p_cspr = get_component(p_other_ent, CSPRITE_T);
|
||||||
CSprite_t* new_cspr = get_component(ent, CSPRITE_T);
|
CSprite_t* new_cspr = get_component(ent, CSPRITE_T);
|
||||||
new_cspr->flip_x = p_cspr->flip_x;
|
new_cspr->node.flip = p_cspr->node.flip;
|
||||||
|
|
||||||
}
|
}
|
||||||
destroy_entity(scene, &lvl_scene->data.tilemap, p_other_ent);
|
destroy_entity(scene, &lvl_scene->data.tilemap, p_other_ent);
|
||||||
|
|
|
@ -74,6 +74,9 @@ Entity_t* create_crate(EntityManager_t* ent_manager, bool metal, ContainerItem_t
|
||||||
|
|
||||||
CSprite_t* p_cspr = add_component(p_crate, CSPRITE_T);
|
CSprite_t* p_cspr = add_component(p_crate, CSPRITE_T);
|
||||||
p_cspr->sprites = item_sprite_map;
|
p_cspr->sprites = item_sprite_map;
|
||||||
|
p_cspr->node.scale = (Vector2){1, 1};
|
||||||
|
p_cspr->node.colour = WHITE;
|
||||||
|
|
||||||
{
|
{
|
||||||
CContainer_t* p_container = add_component(p_crate, CCONTAINER_T);
|
CContainer_t* p_container = add_component(p_crate, CCONTAINER_T);
|
||||||
p_container->material = metal? METAL_CONTAINER : WOODEN_CONTAINER;
|
p_container->material = metal? METAL_CONTAINER : WOODEN_CONTAINER;
|
||||||
|
@ -122,6 +125,9 @@ Entity_t* create_boulder(EntityManager_t* ent_manager)
|
||||||
CSprite_t* p_cspr = add_component(p_boulder, CSPRITE_T);
|
CSprite_t* p_cspr = add_component(p_boulder, CSPRITE_T);
|
||||||
p_cspr->sprites = item_sprite_map;
|
p_cspr->sprites = item_sprite_map;
|
||||||
p_cspr->current_idx = 19;
|
p_cspr->current_idx = 19;
|
||||||
|
p_cspr->node.scale = (Vector2){1, 1};
|
||||||
|
p_cspr->node.colour = WHITE;
|
||||||
|
p_cspr->depth = 2;
|
||||||
|
|
||||||
return p_boulder;
|
return p_boulder;
|
||||||
}
|
}
|
||||||
|
@ -145,6 +151,8 @@ Entity_t* create_arrow(EntityManager_t* ent_manager, uint8_t dir)
|
||||||
CSprite_t* p_cspr = add_component(p_arrow, CSPRITE_T);
|
CSprite_t* p_cspr = add_component(p_arrow, CSPRITE_T);
|
||||||
p_cspr->sprites = item_sprite_map;
|
p_cspr->sprites = item_sprite_map;
|
||||||
p_cspr->current_idx = 2;
|
p_cspr->current_idx = 2;
|
||||||
|
p_cspr->node.scale = (Vector2){1, 1};
|
||||||
|
p_cspr->node.colour = WHITE;
|
||||||
//p_hitbox->boxes[0] = (Rectangle){TILE_SIZE - 5, TILE_SIZE / 2 - 5, 5, 5};
|
//p_hitbox->boxes[0] = (Rectangle){TILE_SIZE - 5, TILE_SIZE / 2 - 5, 5, 5};
|
||||||
const int HITBOX_LONG_SIDE = 10;
|
const int HITBOX_LONG_SIDE = 10;
|
||||||
const int HITBOX_SHORT_SIDE = 4;
|
const int HITBOX_SHORT_SIDE = 4;
|
||||||
|
@ -197,6 +205,8 @@ Entity_t* create_bomb(EntityManager_t* ent_manager, Vector2 launch_dir)
|
||||||
CSprite_t* p_cspr = add_component(p_bomb, CSPRITE_T);
|
CSprite_t* p_cspr = add_component(p_bomb, CSPRITE_T);
|
||||||
p_cspr->sprites = item_sprite_map;
|
p_cspr->sprites = item_sprite_map;
|
||||||
p_cspr->current_idx = 6;
|
p_cspr->current_idx = 6;
|
||||||
|
p_cspr->node.scale = (Vector2){1, 1};
|
||||||
|
p_cspr->node.colour = WHITE;
|
||||||
|
|
||||||
CTransform_t* p_ctransform = add_component(p_bomb, CTRANSFORM_COMP_T);
|
CTransform_t* p_ctransform = add_component(p_bomb, CTRANSFORM_COMP_T);
|
||||||
p_ctransform->active = true;
|
p_ctransform->active = true;
|
||||||
|
@ -230,6 +240,9 @@ Entity_t* create_explosion(EntityManager_t* ent_manager)
|
||||||
CSprite_t* p_cspr = add_component(p_explosion, CSPRITE_T);
|
CSprite_t* p_cspr = add_component(p_explosion, CSPRITE_T);
|
||||||
p_cspr->sprites = item_sprite_map;
|
p_cspr->sprites = item_sprite_map;
|
||||||
p_cspr->current_idx = 17;
|
p_cspr->current_idx = 17;
|
||||||
|
p_cspr->node.scale = (Vector2){1, 1};
|
||||||
|
p_cspr->node.colour = WHITE;
|
||||||
|
p_cspr->depth = 3;
|
||||||
|
|
||||||
CLifeTimer_t* p_clifetimer = add_component(p_explosion, CLIFETIMER_T);
|
CLifeTimer_t* p_clifetimer = add_component(p_explosion, CLIFETIMER_T);
|
||||||
p_clifetimer->life_time = 0.05f;
|
p_clifetimer->life_time = 0.05f;
|
||||||
|
@ -269,6 +282,9 @@ Entity_t* create_urchin(EntityManager_t* ent_manager)
|
||||||
CSprite_t* p_cspr = add_component(p_urchin, CSPRITE_T);
|
CSprite_t* p_cspr = add_component(p_urchin, CSPRITE_T);
|
||||||
p_cspr->sprites = item_sprite_map;
|
p_cspr->sprites = item_sprite_map;
|
||||||
p_cspr->current_idx = 21;
|
p_cspr->current_idx = 21;
|
||||||
|
p_cspr->node.scale = (Vector2){1, 1};
|
||||||
|
p_cspr->node.colour = WHITE;
|
||||||
|
p_cspr->depth = 2;
|
||||||
|
|
||||||
add_component(p_urchin, CSQUISHABLE_T);
|
add_component(p_urchin, CSQUISHABLE_T);
|
||||||
|
|
||||||
|
@ -298,6 +314,9 @@ Entity_t* create_chest(EntityManager_t* ent_manager)
|
||||||
CSprite_t* p_cspr = add_component(p_chest, CSPRITE_T);
|
CSprite_t* p_cspr = add_component(p_chest, CSPRITE_T);
|
||||||
p_cspr->sprites = item_sprite_map;
|
p_cspr->sprites = item_sprite_map;
|
||||||
p_cspr->current_idx = 18;
|
p_cspr->current_idx = 18;
|
||||||
|
p_cspr->node.scale = (Vector2){1, 1};
|
||||||
|
p_cspr->node.colour = WHITE;
|
||||||
|
p_cspr->depth = 2;
|
||||||
|
|
||||||
|
|
||||||
return p_chest;
|
return p_chest;
|
||||||
|
@ -311,6 +330,8 @@ Entity_t* create_level_end(EntityManager_t* ent_manager)
|
||||||
CSprite_t* p_cspr = add_component(p_flag, CSPRITE_T);
|
CSprite_t* p_cspr = add_component(p_flag, CSPRITE_T);
|
||||||
p_cspr->sprites = item_sprite_map;
|
p_cspr->sprites = item_sprite_map;
|
||||||
p_cspr->current_idx = 20;
|
p_cspr->current_idx = 20;
|
||||||
|
p_cspr->node.scale = (Vector2){1, 1};
|
||||||
|
p_cspr->node.colour = WHITE;
|
||||||
|
|
||||||
add_component(p_flag, CTILECOORD_COMP_T);
|
add_component(p_flag, CTILECOORD_COMP_T);
|
||||||
return p_flag;
|
return p_flag;
|
||||||
|
|
|
@ -30,8 +30,13 @@ static unsigned int player_sprite_transition_func(Entity_t* ent)
|
||||||
CSprite_t* p_spr = get_component(ent, CSPRITE_T);
|
CSprite_t* p_spr = get_component(ent, CSPRITE_T);
|
||||||
CPlayerState_t* p_plr = get_component(ent, CPLAYERSTATE_T);
|
CPlayerState_t* p_plr = get_component(ent, CPLAYERSTATE_T);
|
||||||
|
|
||||||
if (p_ctrans->velocity.x > 0) p_spr->flip_x = true;
|
if (p_ctrans->velocity.x > 0) {
|
||||||
else if (p_ctrans->velocity.x < 0) p_spr->flip_x = false;
|
p_spr->node.flip |= 1;
|
||||||
|
}
|
||||||
|
else if (p_ctrans->velocity.x < 0)
|
||||||
|
{
|
||||||
|
p_spr->node.flip &= ~1;
|
||||||
|
}
|
||||||
|
|
||||||
p_spr->pause = false;
|
p_spr->pause = false;
|
||||||
|
|
||||||
|
@ -111,6 +116,9 @@ Entity_t* create_player(EntityManager_t* ent_manager)
|
||||||
CSprite_t* p_cspr = add_component(p_ent, CSPRITE_T);
|
CSprite_t* p_cspr = add_component(p_ent, CSPRITE_T);
|
||||||
p_cspr->sprites = player_sprite_map;
|
p_cspr->sprites = player_sprite_map;
|
||||||
p_cspr->transition_func = &player_sprite_transition_func;
|
p_cspr->transition_func = &player_sprite_transition_func;
|
||||||
|
p_cspr->node.colour = WHITE;
|
||||||
|
p_cspr->node.scale = (Vector2){1, 1};
|
||||||
|
p_cspr->depth = 1;
|
||||||
|
|
||||||
CEmitter_t* p_emitter = add_component(p_ent, CEMITTER_T);
|
CEmitter_t* p_emitter = add_component(p_ent, CEMITTER_T);
|
||||||
p_emitter->offset = (Vector2){7,0};
|
p_emitter->offset = (Vector2){7,0};
|
||||||
|
@ -133,6 +141,9 @@ Entity_t* create_dead_player(EntityManager_t* ent_manager)
|
||||||
CSprite_t* p_cspr = add_component(p_ent, CSPRITE_T);
|
CSprite_t* p_cspr = add_component(p_ent, CSPRITE_T);
|
||||||
p_cspr->sprites = player_sprite_map;
|
p_cspr->sprites = player_sprite_map;
|
||||||
p_cspr->current_idx = SPR_PLAYER_DEAD;
|
p_cspr->current_idx = SPR_PLAYER_DEAD;
|
||||||
|
p_cspr->node.colour = WHITE;
|
||||||
|
p_cspr->node.scale = (Vector2){1, 1};
|
||||||
|
p_cspr->depth = 3;
|
||||||
|
|
||||||
add_component(p_ent, CMOVEMENTSTATE_T);
|
add_component(p_ent, CMOVEMENTSTATE_T);
|
||||||
|
|
||||||
|
@ -160,6 +171,9 @@ Entity_t* create_player_finish(EntityManager_t* ent_manager)
|
||||||
p_cspr->sprites = player_sprite_map;
|
p_cspr->sprites = player_sprite_map;
|
||||||
p_cspr->current_idx = SPR_PLAYER_ENTER;
|
p_cspr->current_idx = SPR_PLAYER_ENTER;
|
||||||
p_cspr->transition_func = &player_finish_transition_func;
|
p_cspr->transition_func = &player_finish_transition_func;
|
||||||
|
p_cspr->node.colour = WHITE;
|
||||||
|
p_cspr->node.scale = (Vector2){1, 1};
|
||||||
|
p_cspr->depth = 1;
|
||||||
|
|
||||||
CLifeTimer_t* p_clifetimer = add_component(p_ent, CLIFETIMER_T);
|
CLifeTimer_t* p_clifetimer = add_component(p_ent, CLIFETIMER_T);
|
||||||
p_clifetimer->life_time = 0.9f;
|
p_clifetimer->life_time = 0.9f;
|
||||||
|
|
|
@ -75,6 +75,7 @@ typedef struct LevelSceneData {
|
||||||
bool show_grid;
|
bool show_grid;
|
||||||
Vector2 player_spawn;
|
Vector2 player_spawn;
|
||||||
LevelSceneStateMachine_t sm;
|
LevelSceneStateMachine_t sm;
|
||||||
|
RenderManager render_manager;
|
||||||
}LevelSceneData_t;
|
}LevelSceneData_t;
|
||||||
|
|
||||||
static inline void change_level_state(LevelSceneData_t* data, LevelSceneState_t state)
|
static inline void change_level_state(LevelSceneData_t* data, LevelSceneState_t state)
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
void init_level_scene_data(LevelSceneData_t* data, uint32_t max_tiles, Tile_t* tiles, Rectangle view_zone)
|
void init_level_scene_data(LevelSceneData_t* data, uint32_t max_tiles, Tile_t* tiles, Rectangle view_zone)
|
||||||
{
|
{
|
||||||
|
init_render_manager(&data->render_manager);
|
||||||
|
|
||||||
data->game_rec = view_zone;
|
data->game_rec = view_zone;
|
||||||
memset(&data->camera, 0, sizeof(LevelCamera_t));
|
memset(&data->camera, 0, sizeof(LevelCamera_t));
|
||||||
data->camera.cam.rotation = 0.0f;
|
data->camera.cam.rotation = 0.0f;
|
||||||
|
@ -45,6 +47,7 @@ void init_level_scene_data(LevelSceneData_t* data, uint32_t max_tiles, Tile_t* t
|
||||||
data->show_grid = false;
|
data->show_grid = false;
|
||||||
|
|
||||||
memset(&data->sm, 0, sizeof(data->sm));
|
memset(&data->sm, 0, sizeof(data->sm));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void term_level_scene_data(LevelSceneData_t* data)
|
void term_level_scene_data(LevelSceneData_t* data)
|
||||||
|
@ -129,7 +132,15 @@ bool load_level_tilemap(LevelScene_t* scene, unsigned int level_num)
|
||||||
scene->data.tilemap.tiles[i].size = (Vector2){TILE_SIZE, TILE_SIZE};
|
scene->data.tilemap.tiles[i].size = (Vector2){TILE_SIZE, TILE_SIZE};
|
||||||
scene->data.tilemap.tiles[i].def = 0;
|
scene->data.tilemap.tiles[i].def = 0;
|
||||||
|
|
||||||
if (lvl_map.tiles[i].tile_type == 1)
|
memset(scene->data.tilemap.render_nodes + i, 0, sizeof(RenderInfoNode));
|
||||||
|
scene->data.tilemap.render_nodes[i].pos = (Vector2){
|
||||||
|
(i % scene->data.tilemap.width) * TILE_SIZE,
|
||||||
|
(i / scene->data.tilemap.width) * TILE_SIZE,
|
||||||
|
};
|
||||||
|
scene->data.tilemap.render_nodes[i].scale = (Vector2){1,1};
|
||||||
|
scene->data.tilemap.render_nodes[i].colour = WHITE;
|
||||||
|
|
||||||
|
if (lvl_map.tiles[i].tile_type == SOLID_TILE)
|
||||||
{
|
{
|
||||||
change_a_tile(&scene->data.tilemap, i, SOLID_TILE);
|
change_a_tile(&scene->data.tilemap, i, SOLID_TILE);
|
||||||
}
|
}
|
||||||
|
@ -144,7 +155,8 @@ bool load_level_tilemap(LevelScene_t* scene, unsigned int level_num)
|
||||||
scene->data.tilemap.tiles[i].wet = scene->data.tilemap.tiles[i].water_level > 0;
|
scene->data.tilemap.tiles[i].wet = scene->data.tilemap.tiles[i].water_level > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Two pass
|
|
||||||
|
// Two pass, because some tile depends on the solidity of the tiles
|
||||||
for (size_t i = 0; i < scene->data.tilemap.n_tiles;i++)
|
for (size_t i = 0; i < scene->data.tilemap.n_tiles;i++)
|
||||||
{
|
{
|
||||||
if (lvl_map.tiles[i].tile_type >= 8 && lvl_map.tiles[i].tile_type < 20)
|
if (lvl_map.tiles[i].tile_type >= 8 && lvl_map.tiles[i].tile_type < 20)
|
||||||
|
@ -247,6 +259,24 @@ bool load_level_tilemap(LevelScene_t* scene, unsigned int level_num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This only works for static loading.
|
||||||
|
// If a tilemap change change to some other arbitrary tile.
|
||||||
|
// Then this should be done while changing a tile.
|
||||||
|
if (lvl_map.tiles[i].tile_type == SOLID_TILE)
|
||||||
|
{
|
||||||
|
scene->data.tilemap.render_nodes[i].spr = scene->data.solid_tile_sprites;
|
||||||
|
scene->data.tilemap.render_nodes[i].frame_num = CONNECTIVITY_TILE_MAPPING[
|
||||||
|
scene->data.tilemap.tiles[i].connectivity
|
||||||
|
];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uint8_t tile_sprite_idx = scene->data.tilemap.tiles[i].tile_type + scene->data.tilemap.tiles[i].rotation;
|
||||||
|
scene->data.tilemap.render_nodes[i].spr = scene->data.tile_sprites[
|
||||||
|
tile_sprite_idx
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -110,7 +110,7 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
if (spr.sprite != NULL)
|
if (spr.sprite != NULL)
|
||||||
{
|
{
|
||||||
Vector2 pos = Vector2Add(p_ent->position, spr.offset);
|
Vector2 pos = Vector2Add(p_ent->position, spr.offset);
|
||||||
draw_sprite(spr.sprite, p_cspr->current_frame, pos, 0.0f, p_cspr->flip_x);
|
draw_sprite(spr.sprite, p_cspr->current_frame, pos, 0.0f, p_cspr->node.flip & 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue