Compare commits

..

No commits in common. "963ba341648a0d09c0c1a6cbad17ff2a55394470" and "209f09e307558f0641e7defc97ff802d1648f824" have entirely different histories.

10 changed files with 155 additions and 103 deletions

View File

@ -9,6 +9,9 @@
#include <stdio.h>
#include <unistd.h>
// Maintain own queue to handle key presses
struct sc_queue_32 key_buffer;
Scene_t* scenes[1];
static GameEngine_t engine =
{
@ -20,7 +23,7 @@ static GameEngine_t engine =
int main(void)
{
init_engine(&engine);
sc_queue_init(&key_buffer);
InitWindow(1280, 640, "raylib");
SetTargetFPS(60);
init_memory_pools();
@ -45,7 +48,38 @@ int main(void)
while(true)
{
process_inputs(&engine, &scene.scene);
// This entire key processing relies on the assumption that a pressed key will
// appear in the polling of raylib
unsigned int sz = sc_queue_size(&key_buffer);
// Process any existing pressed key
for (size_t i = 0; i < sz; i++)
{
int button = sc_queue_del_first(&key_buffer);
ActionType_t action = sc_map_get_64(&scene.scene.action_map, button);
if (IsKeyReleased(button))
{
do_action(&scene.scene, action, false);
}
else
{
do_action(&scene.scene, action, true);
sc_queue_add_last(&key_buffer, button);
}
}
// Detect new key presses
while(true)
{
int button = GetKeyPressed();
if (button == 0) break;
ActionType_t action = sc_map_get_64(&scene.scene.action_map, button);
if (!sc_map_found(&scene.scene.action_map)) continue;
do_action(&scene.scene, action, true);
sc_queue_add_last(&key_buffer, button);
}
update_scene(&scene.scene);
update_entity_manager(&scene.scene.ent_manager);
// This is needed to advance time delta
@ -61,7 +95,7 @@ int main(void)
}
free_scene(&scene.scene);
term_level_scene_data(&scene.data);
deinit_engine(&engine);
sc_queue_term(&key_buffer);
term_assets(&engine.assets);
CloseWindow();
}

37
main.c
View File

@ -24,7 +24,7 @@ int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
init_engine(&engine);
sc_queue_init(&key_buffer);
InitWindow(screenWidth, screenHeight, "raylib");
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
init_memory_pools();
@ -62,7 +62,33 @@ int main(void)
// appear in the polling of raylib
Scene_t* curr_scene = engine.scenes[engine.curr_scene];
process_inputs(&engine, curr_scene);
unsigned int sz = sc_queue_size(&key_buffer);
// Process any existing pressed key
for (size_t i = 0; i < sz; i++)
{
int button = sc_queue_del_first(&key_buffer);
ActionType_t action = sc_map_get_64(&curr_scene->action_map, button);
if (IsKeyReleased(button))
{
do_action(curr_scene, action, false);
}
else
{
do_action(curr_scene, action, true);
sc_queue_add_last(&key_buffer, button);
}
}
// Detect new key presses
while(true)
{
int button = GetKeyPressed();
if (button == 0) break;
ActionType_t action = sc_map_get_64(&curr_scene->action_map, button);
if (!sc_map_found(&curr_scene->action_map)) continue;
do_action(curr_scene, action, true);
sc_queue_add_last(&key_buffer, button);
}
update_scene(curr_scene);
update_entity_manager(&curr_scene->ent_manager);
@ -73,16 +99,11 @@ int main(void)
{
sc_queue_clear(&key_buffer);
}
if (curr_scene->state == SCENE_ENDED && engine.curr_scene == 0)
{
break;
}
}
free_sandbox_scene(&sandbox_scene);
free_game_scene(&level_scene);
free_menu_scene(&menu_scene);
deinit_engine(&engine);
sc_queue_term(&key_buffer);
term_assets(&engine.assets);
CloseWindow();
}

View File

@ -5,6 +5,8 @@
#include <stdio.h>
#include <unistd.h>
// Maintain own queue to handle key presses
struct sc_queue_32 key_buffer;
Scene_t* scenes[1];
static GameEngine_t engine =
@ -17,7 +19,7 @@ static GameEngine_t engine =
int main(void)
{
init_engine(&engine);
sc_queue_init(&key_buffer);
InitWindow(1280, 640, "raylib");
SetTargetFPS(60);
init_memory_pools();
@ -45,7 +47,34 @@ int main(void)
// This entire key processing relies on the assumption that a pressed key will
// appear in the polling of raylib
process_inputs(&engine, &scene.scene);
unsigned int sz = sc_queue_size(&key_buffer);
// Process any existing pressed key
for (size_t i = 0; i < sz; i++)
{
int button = sc_queue_del_first(&key_buffer);
ActionType_t action = sc_map_get_64(&scene.scene.action_map, button);
if (IsKeyReleased(button))
{
do_action(&scene.scene, action, false);
}
else
{
do_action(&scene.scene, action, true);
sc_queue_add_last(&key_buffer, button);
}
}
// Detect new key presses
while(true)
{
int button = GetKeyPressed();
if (button == 0) break;
ActionType_t action = sc_map_get_64(&scene.scene.action_map, button);
if (!sc_map_found(&scene.scene.action_map)) continue;
do_action(&scene.scene, action, true);
sc_queue_add_last(&key_buffer, button);
}
update_scene(&scene.scene);
update_entity_manager(&scene.scene.ent_manager);
@ -54,7 +83,7 @@ int main(void)
if (WindowShouldClose()) break;
}
free_sandbox_scene(&scene);
deinit_engine(&engine);
sc_queue_term(&key_buffer);
term_assets(&engine.assets);
CloseWindow();
}

View File

@ -163,7 +163,6 @@ typedef struct _CWaterRunner {
int32_t fill_idx;
int16_t fill_range[2];
uint8_t movement_delay;
int8_t movement_speed;
int16_t counter;
}CWaterRunner_t;

View File

@ -1,46 +1,5 @@
#include "engine.h"
void init_engine(GameEngine_t* engine)
{
sc_queue_init(&engine->key_buffer);
}
void deinit_engine(GameEngine_t* engine)
{
sc_queue_term(&engine->key_buffer);
}
void process_inputs(GameEngine_t* engine, Scene_t* scene)
{
unsigned int sz = sc_queue_size(&engine->key_buffer);
// Process any existing pressed key
for (size_t i = 0; i < sz; i++)
{
int button = sc_queue_del_first(&engine->key_buffer);
ActionType_t action = sc_map_get_64(&scene->action_map, button);
if (IsKeyReleased(button))
{
do_action(scene, action, false);
}
else
{
do_action(scene, action, true);
sc_queue_add_last(&engine->key_buffer, button);
}
}
// Detect new key presses
while(true)
{
int button = GetKeyPressed();
if (button == 0) break;
ActionType_t action = sc_map_get_64(&scene->action_map, button);
if (!sc_map_found(&scene->action_map)) continue;
do_action(scene, action, true);
sc_queue_add_last(&engine->key_buffer, button);
}
}
void change_scene(GameEngine_t* engine, unsigned int idx)
{
engine->scenes[engine->curr_scene]->state = SCENE_ENDED;

View File

@ -12,8 +12,6 @@ typedef struct GameEngine {
unsigned int max_scenes;
unsigned int curr_scene;
Assets_t assets;
// Maintain own queue to handle key presses
struct sc_queue_32 key_buffer;
} GameEngine_t;
void change_scene(GameEngine_t* engine, unsigned int idx);
@ -43,10 +41,6 @@ struct Scene {
GameEngine_t *engine;
};
void init_engine(GameEngine_t* engine);
void deinit_engine(GameEngine_t* engine);
void process_inputs(GameEngine_t* engine, Scene_t* scene);
// Inline functions, for convenience
extern void update_scene(Scene_t* scene);
extern void render_scene(Scene_t* scene);

View File

@ -199,6 +199,8 @@ static Vector2 shift_bbox(Vector2 bbox, Vector2 new_bbox, AnchorPoint_t anchor)
void player_respawn_system(Scene_t* scene)
{
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
TileGrid_t tilemap = data->tilemap;
Entity_t* p_player;
// Cannot create player while looping though the players
// So have to create outside of the loop
@ -900,12 +902,12 @@ void moveable_update_system(Scene_t* scene)
// Intentional. Want this check even after a gridmove to allow gridmove after that
if (!p_moveable->gridmove)
{
//if (p_ctransform->prev_velocity.y <= 0 && p_ctransform->prev_position.x == p_ctransform->position.x) continue;
if (p_ctransform->prev_velocity.y <= 0 && p_ctransform->prev_position.x == p_ctransform->position.x) continue;
TileGrid_t tilemap = (CONTAINER_OF(scene, LevelScene_t, scene)->data).tilemap;
Vector2 point_to_check = {
.x = p_ctransform->position.x + p_bbox->half_size.x,
.y = p_ctransform->position.y + p_bbox->size.y + 1
.y = p_ctransform->position.y + p_bbox->size.y + 5 // 5 is arbitrary, just to make sure there's a little gap
};
int tile_x = point_to_check.x / TILE_SIZE;
int tile_y = point_to_check.y / TILE_SIZE;

View File

@ -18,20 +18,17 @@ static void menu_scene_render_func(Scene_t* scene)
static void exec_component_function(Scene_t* scene, int sel)
{
switch(sel)
{
case 0:
change_scene(scene->engine, 1);
break;
case 1:
change_scene(scene->engine, 2);
break;
case 3:
scene->state = SCENE_ENDED;
break;
default:
break;
}
switch(sel)
{
case 0:
change_scene(scene->engine, 1);
break;
case 1:
change_scene(scene->engine, 2);
break;
default:
break;
}
}
static void menu_do_action(Scene_t* scene, ActionType_t action, bool pressed)

View File

@ -23,7 +23,6 @@ Entity_t* create_water_runner(EntityManager_t* ent_manager, int32_t width, int32
p_crunner->bfs_tilemap.height = height;
p_crunner->bfs_tilemap.len = total;
p_crunner->movement_delay = 5;
p_crunner->movement_speed = 6;
sc_queue_init(&p_crunner->bfs_queue);
p_crunner->visited = calloc(total, sizeof(bool));
@ -218,29 +217,16 @@ void update_water_runner_system(Scene_t* scene)
p_crunner->counter--;
if (p_crunner->counter == 0)
{
int8_t move_left = p_crunner->movement_speed;
while (move_left)
p_crunner->current_tile = p_crunner->bfs_tilemap.tilemap[p_crunner->current_tile].to;
CTransform_t* p_ct = get_component(ent, CTRANSFORM_COMP_T);
p_ct->position.x = (p_crunner->current_tile % tilemap.width) * tilemap.tile_size;
p_ct->position.y = (p_crunner->current_tile / tilemap.width) * tilemap.tile_size;
tilemap.tiles[p_crunner->current_tile].wet = true;
if (p_crunner->current_tile == p_crunner->target_tile)
{
p_crunner->current_tile = p_crunner->bfs_tilemap.tilemap[p_crunner->current_tile].to;
CTransform_t* p_ct = get_component(ent, CTRANSFORM_COMP_T);
p_ct->position.x = (p_crunner->current_tile % tilemap.width) * tilemap.tile_size;
p_ct->position.y = (p_crunner->current_tile / tilemap.width) * tilemap.tile_size;
Tile_t* tile = tilemap.tiles + p_crunner->current_tile;
tile->wet = true;
move_left--;
if (tile->water_level != tile->max_water_level)
{
move_left--;
}
if (p_crunner->current_tile == p_crunner->target_tile)
{
p_crunner->state = REACHABILITY_SEARCH;
break;
}
p_crunner->counter = p_crunner->movement_delay;
p_crunner->state = REACHABILITY_SEARCH;
}
p_crunner->counter = p_crunner->movement_delay;
}
break;
case REACHABILITY_SEARCH:

View File

@ -407,7 +407,7 @@ static void player_simple_movement_system(Scene_t* scene)
int main(void)
{
init_engine(&engine);
sc_queue_init(&key_buffer);
InitWindow(1280, 640, "raylib");
SetTargetFPS(60);
init_memory_pools();
@ -457,7 +457,38 @@ int main(void)
while(true)
{
process_inputs(&engine, &scene.scene);
// This entire key processing relies on the assumption that a pressed key will
// appear in the polling of raylib
unsigned int sz = sc_queue_size(&key_buffer);
// Process any existing pressed key
for (size_t i = 0; i < sz; i++)
{
int button = sc_queue_del_first(&key_buffer);
ActionType_t action = sc_map_get_64(&scene.scene.action_map, button);
if (IsKeyReleased(button))
{
do_action(&scene.scene, action, false);
}
else
{
do_action(&scene.scene, action, true);
sc_queue_add_last(&key_buffer, button);
}
}
// Detect new key presses
while(true)
{
int button = GetKeyPressed();
if (button == 0) break;
ActionType_t action = sc_map_get_64(&scene.scene.action_map, button);
if (!sc_map_found(&scene.scene.action_map)) continue;
do_action(&scene.scene, action, true);
sc_queue_add_last(&key_buffer, button);
}
update_scene(&scene.scene);
update_entity_manager(&scene.scene.ent_manager);
// This is needed to advance time delta
@ -473,7 +504,7 @@ int main(void)
}
free_scene(&scene.scene);
term_level_scene_data(&scene.data);
deinit_engine(&engine);
sc_queue_term(&key_buffer);
term_assets(&engine.assets);
CloseWindow();
}