Compare commits

...

3 Commits

Author SHA1 Message Date
En Yi ededdb488b Fix off-by-one error in one-way tile check 2024-05-13 21:51:52 +08:00
En Yi 8765500606 Add button to toggle solid tilemap 2024-05-11 15:53:39 +08:00
En Yi 7b4af0b513 Add tilemap rendering from sprite
Internal Changelog:
- Add a mapping from connectivity to tile to render
- Add new field for static tilemap sprite
2024-05-09 21:07:15 +08:00
5 changed files with 38 additions and 9 deletions

View File

@ -1,5 +1,6 @@
#ifndef __ACTIONS_H
#define __ACTIONS_H
// TODO: These are game specific, so should move out of engine
typedef enum ActionType
{
ACTION_UP=0,
@ -21,5 +22,6 @@ typedef enum ActionType
ACTION_TOGGLE_TIMESLOW,
ACTION_SPAWN_TILE,
ACTION_REMOVE_TILE,
ACTION_SWITCH_TILESET,
}ActionType_t;
#endif // __ACTIONS_H

View File

@ -101,7 +101,7 @@ static inline bool add_a_sprite(Assets_t* assets, const SpriteInfo_t* spr_info,
// Cannot be zero
spr->frame_count = 1;
}
spr->frame_per_row = spr_info->frame_count;
spr->frame_per_row = spr_info->frame_per_row;
spr->speed = spr_info->speed;
return true;
}

View File

@ -44,6 +44,19 @@ static bool crate_activation = false;
#define GAME_LAYER 0
#define SELECTION_LAYER 1
#define CONTROL_LAYER 2
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"
};
static char* get_spawn_selection_string(enum EntitySpawnSelection sel)
{
switch(sel)
@ -221,7 +234,12 @@ static void render_editor_game_scene(Scene_t* scene)
}
else if (tilemap.tiles[i].tile_type == SOLID_TILE)
{
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
);
//sprintf(buffer, "%u", tilemap.tiles[i].connectivity);
//DrawText(buffer, x + tilemap.tile_size / 2, y + tilemap.tile_size / 2, 12, WHITE);
}
else if (tilemap.tiles[i].tile_type == ONEWAY_TILE)
{
@ -479,11 +497,6 @@ static void render_editor_game_scene(Scene_t* scene)
// Draw water tile
DrawText(buffer, x, y, 10, BLACK);
}
if (tilemap.tiles[i].solid == SOLID)
{
sprintf(buffer, "%u", tilemap.tiles[i].connectivity);
DrawText(buffer, x + tilemap.tile_size / 2, y + tilemap.tile_size / 2, 12, WHITE);
}
}
}
@ -978,6 +991,15 @@ static void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
update_entity_manager(&scene->ent_manager);
default:
break;
case ACTION_SWITCH_TILESET:
if (!pressed)
{
data->selected_solid_tilemap++;
if (data->selected_solid_tilemap >= N_SOLID_TILESETS) data->selected_solid_tilemap = 0;
data->solid_tile_sprites = get_sprite(&scene->engine->assets, SOLID_TILE_SELECTIONS[data->selected_solid_tilemap]);
}
break;
}
}
}
@ -1002,6 +1024,8 @@ void init_sandbox_scene(LevelScene_t* scene)
scene->data.tile_sprites[SPIKES + TILE_90CWROT] = get_sprite(&scene->scene.engine->assets, "l_spikes");
scene->data.tile_sprites[SPIKES + TILE_90CCWROT] = get_sprite(&scene->scene.engine->assets, "r_spikes");
scene->data.tile_sprites[SPIKES + TILE_180ROT] = get_sprite(&scene->scene.engine->assets, "u_spikes");
scene->data.selected_solid_tilemap = 0;
scene->data.solid_tile_sprites = get_sprite(&scene->scene.engine->assets, SOLID_TILE_SELECTIONS[0]);
for (size_t i = 0; i < scene->data.tilemap.width; ++i)
{
@ -1262,6 +1286,7 @@ void init_sandbox_scene(LevelScene_t* scene)
sc_map_put_64(&scene->scene.action_map, KEY_L, ACTION_EXIT);
sc_map_put_64(&scene->scene.action_map, KEY_R, ACTION_RESTART);
sc_map_put_64(&scene->scene.action_map, KEY_B, ACTION_TOGGLE_GRID);
sc_map_put_64(&scene->scene.action_map, KEY_Z, ACTION_SWITCH_TILESET);
sc_map_put_64(&scene->scene.action_map, KEY_V, ACTION_SET_SPAWNPOINT);
sc_map_put_64(&scene->scene.action_map, KEY_U, ACTION_TOGGLE_TIMESLOW);
sc_map_put_64(&scene->scene.action_map, MOUSE_LEFT_BUTTON, ACTION_SPAWN_TILE);

View File

@ -118,8 +118,8 @@ static bool check_collision_and_move(
{
// One way collision is a bit special
if (
p_ct->prev_position.y + p_bbox->size.y - 1 < other_pos->y
&& ent->position.y + p_bbox->size.y - 1 >= other_pos->y
p_ct->prev_position.y + p_bbox->size.y < other_pos->y
&& ent->position.y + p_bbox->size.y >= other_pos->y
)
{
offset.y = other_pos->y - (ent->position.y + p_bbox->size.y);

View File

@ -44,6 +44,8 @@ typedef struct LevelSceneData {
Rectangle game_rec;
LevelCamera_t camera;
Sprite_t* tile_sprites[MAX_TILE_SPRITES];
Sprite_t* solid_tile_sprites;
uint8_t selected_solid_tilemap;
LevelPack_t* level_pack;
unsigned int current_level;
CoinCounter_t coins;