Compare commits

...

3 Commits

Author SHA1 Message Date
En Yi 9f6c37c1fd Fix bubbling particles issue out-of-water 2024-08-11 15:50:11 +08:00
En Yi 5d1784dad8 Attempt to fix BG scrolling 2024-08-10 17:45:09 +08:00
En Yi 2c908ffd46 Update rendering for editor scene
Internal Changelog:
- Add background
- Update grid and bbox drawing
2024-08-10 17:21:10 +08:00
2 changed files with 202 additions and 176 deletions

View File

@ -160,10 +160,12 @@ static void level_scene_render_func(Scene_t* scene)
#endif #endif
CAirTimer_t* p_air = get_component(p_ent, CAIRTIMER_T); CAirTimer_t* p_air = get_component(p_ent, CAIRTIMER_T);
Vector2 air_pos = {game_rec.x + game_rec.width - 16, game_rec.y + game_rec.height - 16}; Sprite_t* spr = get_sprite(&scene->engine->assets, "p_bigbubble");
Vector2 air_pos = {game_rec.x + game_rec.width - 32, game_rec.y + game_rec.height - 32};
for (uint8_t i = 0; i < p_air->curr_count; i++) for (uint8_t i = 0; i < p_air->curr_count; i++)
{ {
DrawCircleV(air_pos, 16, BLUE); draw_sprite(spr, 0, air_pos, 0, false);
//DrawCircleV(air_pos, 16, BLUE);
air_pos.x -= 32; air_pos.x -= 32;
} }
} }
@ -208,91 +210,18 @@ 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);
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);
DrawTexturePro(*bg,
//(Rectangle){0,0,64,64},
(Rectangle){min.x,0,(tilemap.width+1)*tilemap.tile_size*2, (tilemap.height+1)*tilemap.tile_size*2},
(Rectangle){0,0,(tilemap.width+1)*tilemap.tile_size*2, (tilemap.height+1)*tilemap.tile_size*2},
//(Rectangle){0,0,game_rec.width, game_rec.height},
(Vector2){0,0}, 0.0f, WHITE
);
BeginMode2D(data->camera.cam); BeginMode2D(data->camera.cam);
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;
//if (!tilemap.tiles[i].moveable)
//{
// // Draw water tile
// Color water_colour = ColorAlpha(RED, 0.2);
// DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, water_colour);
//}
uint8_t tile_sprite_idx = tilemap.tiles[i].tile_type + tilemap.tiles[i].rotation;
if (data->tile_sprites[tile_sprite_idx] != NULL)
{
draw_sprite(data->tile_sprites[tile_sprite_idx], 0, (Vector2){x,y}, 0.0f, false);
}
else if (tilemap.tiles[i].tile_type == SOLID_TILE)
{
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)
{
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, MAROON);
}
else if (tilemap.tiles[i].tile_type == LADDER)
{
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, ORANGE);
}
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].wet)
{
#define SURFACE_THICKNESS 4
int up = i - tilemap.width;
unsigned int bot = i + tilemap.width;
int right = i + 1;
int left = i - 1;
int bot_line = y + TILE_SIZE - tilemap.tiles[i].water_level * WATER_BBOX_STEP - SURFACE_THICKNESS / 2;
if (up >= 0 && tilemap.tiles[up].wet)
{
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
)
{
if (i % tilemap.width != 0 && tilemap.tiles[left].wet && (tilemap.tiles[bot].solid == SOLID || tilemap.tiles[bot-1].solid == SOLID))
{
DrawLineEx((Vector2){x, bot_line}, (Vector2){x + TILE_SIZE / 2, bot_line}, SURFACE_THICKNESS, ColorAlpha(BLUE, 0.7));
}
if (right % tilemap.width != 0 && tilemap.tiles[right].wet && (tilemap.tiles[bot].solid == SOLID || tilemap.tiles[bot+1].solid == SOLID))
{
DrawLineEx((Vector2){x + TILE_SIZE / 2, bot_line}, (Vector2){x + TILE_SIZE, bot_line}, SURFACE_THICKNESS, ColorAlpha(BLUE, 0.7));
}
}
}
if (tilemap.tiles[i].max_water_level < MAX_WATER_LEVEL)
{
DrawRectangleLinesEx((Rectangle){x, y, TILE_SIZE, TILE_SIZE}, 2.0, ColorAlpha(BLUE, 0.5));
}
}
}
char buffer[64] = {0}; char buffer[64] = {0};
sc_map_foreach_value(&scene->ent_manager.entities, p_ent) sc_map_foreach_value(&scene->ent_manager.entities, p_ent)
@ -315,6 +244,8 @@ 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)
{ {
@ -427,6 +358,8 @@ 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); CSprite_t* p_cspr = get_component(p_ent, CSPRITE_T);
if (p_cspr != NULL) if (p_cspr != NULL)
{ {
@ -460,6 +393,89 @@ static void render_editor_game_scene(Scene_t* scene)
DrawCircleV(p_ent->position, tilemap.tile_size >> 1, (data->coins.current < data->coins.total)? RED : GREEN); DrawCircleV(p_ent->position, tilemap.tile_size >> 1, (data->coins.current < data->coins.total)? RED : GREEN);
} }
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;
//if (!tilemap.tiles[i].moveable)
//{
// // Draw water tile
// Color water_colour = ColorAlpha(RED, 0.2);
// DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, water_colour);
//}
uint8_t tile_sprite_idx = tilemap.tiles[i].tile_type + tilemap.tiles[i].rotation;
if (data->tile_sprites[tile_sprite_idx] != NULL)
{
draw_sprite(data->tile_sprites[tile_sprite_idx], 0, (Vector2){x,y}, 0.0f, false);
}
else if (tilemap.tiles[i].tile_type == SOLID_TILE)
{
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)
{
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, MAROON);
}
else if (tilemap.tiles[i].tile_type == LADDER)
{
DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, ORANGE);
}
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].wet)
{
#define SURFACE_THICKNESS 4
int up = i - tilemap.width;
unsigned int bot = i + tilemap.width;
int right = i + 1;
int left = i - 1;
int bot_line = y + TILE_SIZE - tilemap.tiles[i].water_level * WATER_BBOX_STEP - SURFACE_THICKNESS / 2;
if (up >= 0 && tilemap.tiles[up].wet)
{
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
)
{
if (i % tilemap.width != 0 && tilemap.tiles[left].wet && (tilemap.tiles[bot].solid == SOLID || tilemap.tiles[bot-1].solid == SOLID))
{
DrawLineEx((Vector2){x, bot_line}, (Vector2){x + TILE_SIZE / 2, bot_line}, SURFACE_THICKNESS, ColorAlpha(BLUE, 0.7));
}
if (right % tilemap.width != 0 && tilemap.tiles[right].wet && (tilemap.tiles[bot].solid == SOLID || tilemap.tiles[bot+1].solid == SOLID))
{
DrawLineEx((Vector2){x + TILE_SIZE / 2, bot_line}, (Vector2){x + TILE_SIZE, bot_line}, SURFACE_THICKNESS, ColorAlpha(BLUE, 0.7));
}
}
}
if (tilemap.tiles[i].max_water_level < MAX_WATER_LEVEL)
{
DrawRectangleLinesEx((Rectangle){x, y, TILE_SIZE, TILE_SIZE}, 2.0, ColorAlpha(BLUE, 0.5));
}
}
}
draw_particle_system(&scene->part_sys); draw_particle_system(&scene->part_sys);
// Draw water tile // Draw water tile
@ -505,15 +521,15 @@ static void render_editor_game_scene(Scene_t* scene)
sprintf(buffer, "%u", sc_map_size_64v(&tilemap.tiles[i].entities_set)); sprintf(buffer, "%u", sc_map_size_64v(&tilemap.tiles[i].entities_set));
if (tilemap.tiles[i].solid > 0) //if (tilemap.tiles[i].solid > 0)
{ {
DrawText(buffer, x, y, 10, WHITE); DrawText(buffer, x, y, 10, WHITE);
} }
else //else
{ //{
// Draw water tile // // Draw water tile
DrawText(buffer, x, y, 10, BLACK); // DrawText(buffer, x, y, 10, BLACK);
} //}
} }
} }
@ -521,12 +537,12 @@ static void render_editor_game_scene(Scene_t* scene)
for (size_t i = min.x; i < max.x; ++i) for (size_t i = min.x; i < max.x; ++i)
{ {
int x = (i+1)*TILE_SIZE; int x = (i+1)*TILE_SIZE;
DrawLine(x, 0, x, tilemap.height * TILE_SIZE, BLACK); DrawLine(x, 0, x, tilemap.height * TILE_SIZE, WHITE);
} }
for (size_t i = min.y; i < max.y;++i) for (size_t i = min.y; i < max.y;++i)
{ {
int y = (i+1)*TILE_SIZE; int y = (i+1)*TILE_SIZE;
DrawLine(0, y, tilemap.width * TILE_SIZE, y, BLACK); DrawLine(0, y, tilemap.width * TILE_SIZE, y, WHITE);
} }
} }
EndMode2D(); EndMode2D();
@ -1043,6 +1059,8 @@ void init_sandbox_scene(LevelScene_t* scene)
scene->data.tile_sprites[SPIKES + TILE_180ROT] = get_sprite(&scene->scene.engine->assets, "u_spikes"); scene->data.tile_sprites[SPIKES + TILE_180ROT] = get_sprite(&scene->scene.engine->assets, "u_spikes");
scene->data.selected_solid_tilemap = 0; scene->data.selected_solid_tilemap = 0;
scene->data.solid_tile_sprites = get_sprite(&scene->scene.engine->assets, SOLID_TILE_SELECTIONS[0]); scene->data.solid_tile_sprites = get_sprite(&scene->scene.engine->assets, SOLID_TILE_SELECTIONS[0]);
Texture2D* tex = get_texture(&scene->scene.engine->assets, "bg_tex");
SetTextureWrap(*tex, TEXTURE_WRAP_REPEAT);
for (size_t i = 0; i < scene->data.tilemap.width; ++i) for (size_t i = 0; i < scene->data.tilemap.width; ++i)
{ {

View File

@ -1847,6 +1847,14 @@ void airtimer_update_system(Scene_t* scene)
{ {
p_air->curr_count = p_air->max_count; p_air->curr_count = p_air->max_count;
p_air->curr_ftimer = p_air->max_ftimer * 2; // Lengthen the first p_air->curr_ftimer = p_air->max_ftimer * 2; // Lengthen the first
CEmitter_t* p_emitter = get_component(p_ent, CEMITTER_T);
if (p_emitter != NULL)
{
if (is_emitter_handle_alive(&scene->part_sys, p_emitter->handle))
{
unload_emitter_handle(&scene->part_sys, p_emitter->handle);
}
}
} }
else else
{ {