Compare commits
5 Commits
34b60fb699
...
67e0e7dc08
Author | SHA1 | Date |
---|---|---|
|
67e0e7dc08 | |
|
f3defcf656 | |
|
ee65e3c974 | |
|
e24bb382f9 | |
|
04d928c97f |
269
CMakeLists.txt
269
CMakeLists.txt
|
@ -2,18 +2,26 @@ set(PROJECT_NAME HATPC_remake)
|
|||
set(CMAKE_C_COMPILER clang)
|
||||
set(CMAKE_C_FLAGS "-Wall -Wextra")
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
project(${PROJECT_NAME} C CXX)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(RAYLIB_DIR /usr/local/lib CACHE FILEPATH "directory to Raylib")
|
||||
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)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_WEB")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s MIN_WEBGL_VERSION=2 -s MAX_WEBGL_VERSION=2 -s TOTAL_MEMORY=16777216 -s TOTAL_STACK=1048576 --preload-file ./res ")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_WEB")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s MIN_WEBGL_VERSION=2 -s MAX_WEBGL_VERSION=2 -s TOTAL_MEMORY=16777216 -s TOTAL_STACK=1048576 --preload-file ./res ")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
|
||||
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||
endif ()
|
||||
|
||||
if (${CMAKE_BUILD_TYPE} STREQUAL tile16)
|
||||
|
@ -24,210 +32,71 @@ set(GAME_LIBS
|
|||
lib_scenes
|
||||
)
|
||||
|
||||
if (${RUN_PROFILER})
|
||||
set(GAME_LIBS
|
||||
lib_scenes
|
||||
pthread
|
||||
dl
|
||||
)
|
||||
endif()
|
||||
|
||||
add_subdirectory(engine)
|
||||
add_subdirectory(scenes)
|
||||
if (NOT EMSCRIPTEN)
|
||||
add_subdirectory(res)
|
||||
endif ()
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.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
|
||||
macro(add_target_exe name)
|
||||
add_executable(${name}
|
||||
${name}.c
|
||||
tracy/public/TracyClient.cpp
|
||||
)
|
||||
target_compile_definitions(sandbox_trace
|
||||
PUBLIC
|
||||
TRACY_ENABLE
|
||||
TRACY_ON_DEMAND
|
||||
)
|
||||
target_include_directories(sandbox_trace
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
PUBLIC
|
||||
tracy/public/
|
||||
)
|
||||
)
|
||||
target_include_directories(${name}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
PUBLIC
|
||||
tracy/public/
|
||||
)
|
||||
if (RUN_PROFILER)
|
||||
target_compile_definitions(${name}
|
||||
PUBLIC
|
||||
TRACY_ENABLE
|
||||
TRACY_ON_DEMAND
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(sandbox_trace
|
||||
PUBLIC
|
||||
lib_scenes_trace
|
||||
pthread
|
||||
dl
|
||||
)
|
||||
|
||||
add_executable(scene_test
|
||||
scene_test.c
|
||||
)
|
||||
|
||||
target_include_directories(scene_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
if (NOT EMSCRIPTEN)
|
||||
if (INCLUDE_ASAN)
|
||||
target_compile_options(${name} PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(${name} PRIVATE -fsanitize=address -gdwarf-4)
|
||||
endif ()
|
||||
if (EXPORT_MMAP)
|
||||
target_link_options(${name} PRIVATE -Xlinker -Map=scene_test.map)
|
||||
endif()
|
||||
endif ()
|
||||
target_link_libraries(${name}
|
||||
PUBLIC
|
||||
${GAME_LIBS}
|
||||
)
|
||||
endmacro()
|
||||
|
||||
add_target_exe(main)
|
||||
add_target_exe(level_test)
|
||||
add_target_exe(scene_test)
|
||||
|
||||
if (NOT EMSCRIPTEN)
|
||||
target_compile_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
endif ()
|
||||
target_link_libraries(scene_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
|
||||
if (NOT EMSCRIPTEN)
|
||||
|
||||
add_executable(EntManager_test
|
||||
entManager_test.c
|
||||
)
|
||||
target_compile_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_include_directories(EntManager_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_libraries(EntManager_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
|
||||
add_executable(scene_test_mem
|
||||
scene_test.c
|
||||
)
|
||||
target_include_directories(scene_test_mem
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_options(scene_test_mem PRIVATE -Xlinker -Map=scene_test.map)
|
||||
|
||||
target_link_libraries(scene_test_mem
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
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)
|
||||
find_package(cmocka 1.1.0 REQUIRED)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
if (BUILD_EXTRAS AND NOT RUN_PROFILER)
|
||||
add_target_exe(entManager_test)
|
||||
add_target_exe(water_test)
|
||||
add_target_exe(level_load_test)
|
||||
add_target_exe(menu_test)
|
||||
add_target_exe(assets_test)
|
||||
add_target_exe(particle_test)
|
||||
add_target_exe(scene_man_test)
|
||||
add_target_exe(level_select_test)
|
||||
endif()
|
||||
if (BUILD_TESTING)
|
||||
find_package(cmocka 1.1.0 REQUIRED)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -32,6 +32,7 @@ add_library(lib_engine OBJECT
|
|||
collisions.c
|
||||
mempool.c
|
||||
entManager.c
|
||||
render_queue.c
|
||||
)
|
||||
target_link_libraries(lib_engine
|
||||
PUBLIC
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef __COLLISION_FUNCS_H
|
||||
#define __COLLISION_FUNCS_H
|
||||
#include "EC.h"
|
||||
#include "render_queue.h"
|
||||
|
||||
typedef enum SolidType
|
||||
{
|
||||
|
@ -42,6 +43,7 @@ typedef struct TileGrid
|
|||
unsigned int max_tiles;
|
||||
unsigned int tile_size;
|
||||
Tile_t* tiles;
|
||||
RenderInfoNode* render_nodes;
|
||||
}TileGrid_t;
|
||||
|
||||
typedef struct TileArea {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "sc/heap/sc_heap.h"
|
||||
#include "assets.h"
|
||||
#include "particle_sys.h"
|
||||
#include "render_queue.h"
|
||||
|
||||
typedef struct Scene Scene_t;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
// if memory used too high
|
||||
#define MAX_SCENES_TO_RENDER 8
|
||||
#define MAX_RENDER_LAYERS 4
|
||||
#define MAX_RENDERMANAGER_DEPTH 4
|
||||
#define MAX_ENTITIES 2047
|
||||
#define MAX_TEXTURES 16
|
||||
#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
|
19
level_test.c
19
level_test.c
|
@ -7,6 +7,8 @@
|
|||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tracy/TracyC.h"
|
||||
#define N_SCENES 1
|
||||
|
||||
Scene_t *scenes[N_SCENES];
|
||||
|
@ -30,13 +32,8 @@ int main(int argc, char** argv)
|
|||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
init_engine(&engine, (Vector2){screenWidth, screenHeight});
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
#ifndef NDEBUG
|
||||
load_from_infofile("res/assets.info.raw", &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);
|
||||
|
||||
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;
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
TracyCFrameMark;
|
||||
// This entire key processing relies on the assumption that a pressed key will
|
||||
// appear in the polling of raylib
|
||||
Scene_t* curr_scene = engine.scenes[engine.curr_scene];
|
||||
|
@ -106,11 +104,16 @@ int main(int argc, char** argv)
|
|||
float frame_time = GetFrameTime();
|
||||
float delta_time = fminf(frame_time, DT);
|
||||
|
||||
update_scene(curr_scene, delta_time);
|
||||
update_entity_manager(&curr_scene->ent_manager);
|
||||
{
|
||||
TracyCZoneN(ctx, "Update", true)
|
||||
update_scene(curr_scene, delta_time);
|
||||
update_entity_manager(&curr_scene->ent_manager);
|
||||
update_sfx_list(&engine);
|
||||
TracyCZoneEnd(ctx)
|
||||
}
|
||||
|
||||
// This is needed to advance time delta
|
||||
render_scene(curr_scene);
|
||||
update_sfx_list(&engine);
|
||||
|
||||
if (curr_scene->state != 0)
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
!CMakeLists.txt
|
||||
!ldtk_repacker.py
|
||||
!pack_ldtk.sh
|
||||
!pack_resources.sh
|
||||
!test_assets.info
|
||||
!testLevels.lvldata.zst
|
||||
!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
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/../tracy/public/
|
||||
)
|
||||
|
||||
if (${RUN_PROFILER})
|
||||
target_compile_definitions(lib_scenes
|
||||
PUBLIC
|
||||
TRACY_ENABLE
|
||||
TRACY_ON_DEMAND
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(lib_scenes
|
||||
PUBLIC
|
||||
lib_engine
|
||||
)
|
||||
|
||||
add_library(lib_scenes_trace STATIC
|
||||
assets_loader.c
|
||||
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
|
||||
TRACY_ENABLE
|
||||
TRACY_ON_DEMAND
|
||||
)
|
||||
target_include_directories(lib_scenes_trace
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/../tracy/public/
|
||||
)
|
||||
target_link_libraries(lib_scenes_trace
|
||||
PUBLIC
|
||||
lib_engine
|
||||
)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "EC.h"
|
||||
#include "render_queue.h"
|
||||
#include "particle_sys.h" // includes assets
|
||||
|
||||
enum ComponentEnum {
|
||||
|
@ -145,19 +146,17 @@ typedef struct _SpriteRenderInfo
|
|||
} SpriteRenderInfo_t;
|
||||
|
||||
typedef struct _CSprite_t {
|
||||
RenderInfoNode node;
|
||||
SpriteRenderInfo_t* sprites;
|
||||
sprite_transition_func_t transition_func;
|
||||
unsigned int current_idx;
|
||||
bool flip_x;
|
||||
bool flip_y;
|
||||
bool pause;
|
||||
int current_frame;
|
||||
float fractional;
|
||||
float rotation; // Degree
|
||||
float rotation_speed; // Degree / s
|
||||
int elapsed;
|
||||
Vector2 offset;
|
||||
Color colour;
|
||||
uint8_t depth;
|
||||
bool pause;
|
||||
} CSprite_t;
|
||||
|
||||
typedef struct _CMoveable_t {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// Constants to be used in game
|
||||
#ifndef __CONSTANTS_H
|
||||
#define __CONSTANTS_H
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef TILE16_SIZE
|
||||
#define TILE_SIZE 32
|
||||
#define DEFAULT_MAP_WIDTH 48
|
||||
|
@ -47,4 +49,11 @@
|
|||
#define WATER_BBOX_STEP (TILE_SIZE / MAX_WATER_LEVEL)
|
||||
|
||||
#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
|
||||
|
|
|
@ -58,13 +58,6 @@ static Vector2 urchin_click_pos = {0,0};
|
|||
#define SELECTION_LAYER 0
|
||||
#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
|
||||
static const char* SOLID_TILE_SELECTIONS[N_SOLID_TILESETS] = {
|
||||
"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.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");
|
||||
BeginTextureMode(scene->layers.render_layers[GAME_LAYER].layer_tex);
|
||||
ClearBackground(WHITE);
|
||||
|
@ -342,58 +387,23 @@ 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};
|
||||
sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
|
||||
if (data->show_grid)
|
||||
{
|
||||
if (p_ent->m_tag == LEVEL_END_TAG) continue;
|
||||
|
||||
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
||||
|
||||
// Entity culling
|
||||
Vector2 box_size = {0};
|
||||
if (p_bbox != NULL) box_size = p_bbox->size;
|
||||
if (
|
||||
p_ent->position.x + box_size.x < min.x * tilemap.tile_size
|
||||
|| p_ent->position.x > max.x * tilemap.tile_size
|
||||
|| p_ent->position.y + box_size.y < min.y * tilemap.tile_size
|
||||
|| p_ent->position.y > max.y * tilemap.tile_size
|
||||
) continue;
|
||||
|
||||
if (data->show_grid)
|
||||
sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
|
||||
{
|
||||
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
||||
|
||||
// Entity culling
|
||||
Vector2 box_size = {0};
|
||||
if (p_bbox != NULL) box_size = p_bbox->size;
|
||||
if (
|
||||
p_ent->position.x + box_size.x < min.x * tilemap.tile_size
|
||||
|| p_ent->position.x > max.x * tilemap.tile_size
|
||||
|| p_ent->position.y + box_size.y < min.y * tilemap.tile_size
|
||||
|| p_ent->position.y > max.y * tilemap.tile_size
|
||||
) continue;
|
||||
|
||||
Color colour;
|
||||
switch(p_ent->m_tag)
|
||||
{
|
||||
|
@ -418,6 +428,21 @@ static void render_editor_game_scene(Scene_t* scene)
|
|||
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_ent->m_tag == BOULDER_ENT_TAG)
|
||||
|
@ -508,35 +533,10 @@ static void render_editor_game_scene(Scene_t* scene)
|
|||
DrawRectangleLinesEx(rec, 1.5, PURPLE);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
execute_render(&data->render_manager);
|
||||
|
||||
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
||||
{
|
||||
for (int tile_x = min.x; tile_x < max.x; tile_x++)
|
||||
|
@ -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)
|
||||
{
|
||||
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);
|
||||
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.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 "game_systems.h"
|
||||
#include "water_flow.h"
|
||||
|
@ -9,12 +11,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
static Tile_t all_tiles[MAX_N_TILES] = {0};
|
||||
static const uint8_t CONNECTIVITY_TILE_MAPPING[16] = {
|
||||
0,3,15,14,
|
||||
1,2,12,13,
|
||||
7,6,11,10,
|
||||
4,5,8 ,9 ,
|
||||
};
|
||||
static RenderInfoNode all_tile_rendernodes[MAX_N_TILES] = {0};
|
||||
|
||||
#define GAME_LAYER 0
|
||||
#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)
|
||||
{
|
||||
TracyCZoneN(ctx, "GameRender", true)
|
||||
// This function will render the game scene outside of the intended draw function
|
||||
// Just for clarity and separation of logic
|
||||
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.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");
|
||||
BeginTextureMode(scene->layers.render_layers[GAME_LAYER].layer_tex);
|
||||
ClearBackground(WHITE);
|
||||
|
@ -174,6 +246,7 @@ static void render_regular_game_scene(Scene_t* scene)
|
|||
|
||||
BeginMode2D(data->camera.cam);
|
||||
|
||||
#ifdef ENABLE_RENDER_FALLBACK
|
||||
for (int tile_y = min.y; tile_y < max.y; tile_y++)
|
||||
{
|
||||
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 (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
|
||||
if (data->tile_sprites[tilemap.tiles[i].tile_type] == NULL)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (p_ent->m_tag == LEVEL_END_TAG) continue;
|
||||
|
||||
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
||||
|
||||
// Entity culling
|
||||
|
@ -246,34 +278,8 @@ static void render_regular_game_scene(Scene_t* scene)
|
|||
|| p_ent->position.y > max.y * tilemap.tile_size
|
||||
) continue;
|
||||
|
||||
// Render Sprite only
|
||||
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;
|
||||
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;
|
||||
}
|
||||
if (p_cspr != NULL) continue;
|
||||
|
||||
// Continue here only if no sprite
|
||||
Color colour;
|
||||
|
@ -293,6 +299,12 @@ static void render_regular_game_scene(Scene_t* scene)
|
|||
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_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_x = min.x; tile_x < max.x; tile_x++)
|
||||
|
@ -369,31 +380,46 @@ static void render_regular_game_scene(Scene_t* scene)
|
|||
if (tilemap.tiles[i].tile_type != LADDER)
|
||||
{
|
||||
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);
|
||||
if (data->solid_tile_sprites == NULL) {
|
||||
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, BLACK);
|
||||
}
|
||||
}
|
||||
else if (tilemap.tiles[i].tile_type == SOLID_TILE)
|
||||
else if (data->tile_sprites[tile_sprite_idx] == NULL)
|
||||
{
|
||||
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)
|
||||
{
|
||||
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, MAROON);
|
||||
}
|
||||
else if (tilemap.tiles[i].tile_type == SPIKES)
|
||||
{
|
||||
DrawRectangle(
|
||||
x + tilemap.tiles[i].offset.x, y + tilemap.tiles[i].offset.y,
|
||||
tilemap.tiles[i].size.x, tilemap.tiles[i].size.y, RED
|
||||
);
|
||||
if (tilemap.tiles[i].tile_type == ONEWAY_TILE)
|
||||
{
|
||||
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, MAROON);
|
||||
}
|
||||
else if (tilemap.tiles[i].tile_type == SPIKES)
|
||||
{
|
||||
DrawRectangle(
|
||||
x + tilemap.tiles[i].offset.x, y + tilemap.tiles[i].offset.y,
|
||||
tilemap.tiles[i].size.x, tilemap.tiles[i].size.y, RED
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#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)
|
||||
{
|
||||
#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));
|
||||
}
|
||||
|
||||
|
||||
if (
|
||||
bot <= tilemap.n_tiles
|
||||
&& 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//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;
|
||||
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();
|
||||
EndTextureMode();
|
||||
TracyCZoneEnd(ctx)
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
scene->data.tilemap.tiles = all_tiles;
|
||||
scene->data.tilemap.render_nodes = all_tile_rendernodes;
|
||||
init_level_scene_data(
|
||||
&scene->data, MAX_N_TILES, all_tiles,
|
||||
(Rectangle){
|
||||
|
@ -512,6 +509,16 @@ void init_game_scene(LevelScene_t* scene)
|
|||
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_RUNNING] = NULL;
|
||||
scene->data.sm.state_functions[LEVEL_STATE_DEAD] = NULL;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#include "assets_tag.h"
|
||||
#ifdef TRACY_ENABLE
|
||||
#include "tracy/TracyC.h"
|
||||
#endif
|
||||
|
||||
#include "game_systems.h"
|
||||
|
||||
|
@ -781,9 +779,7 @@ void spike_collision_system(Scene_t* scene)
|
|||
|
||||
void tile_collision_system(Scene_t* scene)
|
||||
{
|
||||
#ifdef TRACY_ENABLE
|
||||
TracyCZoneN(ctx, "TileCol", true)
|
||||
#endif
|
||||
static bool checked_entities[MAX_COMP_POOL_SIZE] = {0};
|
||||
|
||||
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)
|
||||
#endif
|
||||
}
|
||||
|
||||
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;
|
||||
CSprite_t* p_cspr = get_component(p_other_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);
|
||||
|
|
|
@ -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);
|
||||
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);
|
||||
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);
|
||||
p_cspr->sprites = item_sprite_map;
|
||||
p_cspr->current_idx = 19;
|
||||
p_cspr->node.scale = (Vector2){1, 1};
|
||||
p_cspr->node.colour = WHITE;
|
||||
p_cspr->depth = 2;
|
||||
|
||||
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);
|
||||
p_cspr->sprites = item_sprite_map;
|
||||
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};
|
||||
const int HITBOX_LONG_SIDE = 10;
|
||||
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);
|
||||
p_cspr->sprites = item_sprite_map;
|
||||
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);
|
||||
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);
|
||||
p_cspr->sprites = item_sprite_map;
|
||||
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);
|
||||
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);
|
||||
p_cspr->sprites = item_sprite_map;
|
||||
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);
|
||||
|
||||
|
@ -298,6 +314,9 @@ Entity_t* create_chest(EntityManager_t* ent_manager)
|
|||
CSprite_t* p_cspr = add_component(p_chest, CSPRITE_T);
|
||||
p_cspr->sprites = item_sprite_map;
|
||||
p_cspr->current_idx = 18;
|
||||
p_cspr->node.scale = (Vector2){1, 1};
|
||||
p_cspr->node.colour = WHITE;
|
||||
p_cspr->depth = 2;
|
||||
|
||||
|
||||
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);
|
||||
p_cspr->sprites = item_sprite_map;
|
||||
p_cspr->current_idx = 20;
|
||||
p_cspr->node.scale = (Vector2){1, 1};
|
||||
p_cspr->node.colour = WHITE;
|
||||
|
||||
add_component(p_flag, CTILECOORD_COMP_T);
|
||||
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);
|
||||
CPlayerState_t* p_plr = get_component(ent, CPLAYERSTATE_T);
|
||||
|
||||
if (p_ctrans->velocity.x > 0) p_spr->flip_x = true;
|
||||
else if (p_ctrans->velocity.x < 0) p_spr->flip_x = false;
|
||||
if (p_ctrans->velocity.x > 0) {
|
||||
p_spr->node.flip |= 1;
|
||||
}
|
||||
else if (p_ctrans->velocity.x < 0)
|
||||
{
|
||||
p_spr->node.flip &= ~1;
|
||||
}
|
||||
|
||||
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);
|
||||
p_cspr->sprites = player_sprite_map;
|
||||
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);
|
||||
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);
|
||||
p_cspr->sprites = player_sprite_map;
|
||||
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);
|
||||
|
||||
|
@ -160,6 +171,9 @@ Entity_t* create_player_finish(EntityManager_t* ent_manager)
|
|||
p_cspr->sprites = player_sprite_map;
|
||||
p_cspr->current_idx = SPR_PLAYER_ENTER;
|
||||
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);
|
||||
p_clifetimer->life_time = 0.9f;
|
||||
|
|
|
@ -75,6 +75,7 @@ typedef struct LevelSceneData {
|
|||
bool show_grid;
|
||||
Vector2 player_spawn;
|
||||
LevelSceneStateMachine_t sm;
|
||||
RenderManager render_manager;
|
||||
}LevelSceneData_t;
|
||||
|
||||
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)
|
||||
{
|
||||
init_render_manager(&data->render_manager);
|
||||
|
||||
data->game_rec = view_zone;
|
||||
memset(&data->camera, 0, sizeof(LevelCamera_t));
|
||||
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;
|
||||
|
||||
memset(&data->sm, 0, sizeof(data->sm));
|
||||
|
||||
}
|
||||
|
||||
void term_level_scene_data(LevelSceneData_t* data)
|
||||
|
@ -128,8 +131,16 @@ bool load_level_tilemap(LevelScene_t* scene, unsigned int level_num)
|
|||
scene->data.tilemap.tiles[i].offset = (Vector2){0, 0};
|
||||
scene->data.tilemap.tiles[i].size = (Vector2){TILE_SIZE, TILE_SIZE};
|
||||
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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
// 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++)
|
||||
{
|
||||
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;
|
||||
|
|
|
@ -110,7 +110,7 @@ static void level_scene_render_func(Scene_t* scene)
|
|||
if (spr.sprite != NULL)
|
||||
{
|
||||
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