Removed 'child_index' from entities. It gets figured out in presentation instead.

This commit is contained in:
2025-12-12 18:45:56 +01:00
parent ddeb82fdc8
commit a6d8d7d0c2
3 changed files with 74 additions and 81 deletions

View File

@@ -139,76 +139,87 @@ static void state_render(Presentation_State *state) {
Grid_Cell *cell = &grid->cells[i];
if(cell->entity != NULL) {
Entity *entity = cell->entity;
switch(entity->type) {
case Entity_Type_Snake_Head:
case Entity_Type_Snake_Body: {
case Entity_Type_Snake_Head: {
Color tint = (Color) { 255, 135, 102, 255 }; // TODO: SS - Get tint based on player ID.
Vector2 origin = (Vector2) { GRID_CELL_SIZE/2, GRID_CELL_SIZE/2 };
float sin_frequency = 0.0f;
float sin_amplitude = 0.0f;
Texture2D *texture = NULL;
if(entity->type == Entity_Type_Snake_Head) {
texture = &ctx->texture_snake_head;
}
else {
texture = &ctx->texture_snake_body;
// TODO: SS - If it's a body, check what index it is and use that as an y-offset to make it look cool, like a wave.
sin_frequency = 4.0f;
sin_amplitude = 1.0f;
}
// Draw shadow.
DrawTextureEx(
ctx->texture_shadow_basic,
(Vector2) { pres_x, pres_y },
0.0f,
1.0f,
(Color) { 0, 0, 0, 32 }
);
float rotation = 0.0f;
switch(entity->move_direction){
case Entity_Movement_Direction_None: {
rotation = 0.0f;
break;
Entity *e = entity;
uint16_t i = 0;
while(e != NULL) { // Loop over all the body-parts of the snake, including the head.
float sin_frequency = 0.0f;
float sin_amplitude = 0.0f;
uint32_t pres_x = e->x * GRID_CELL_SIZE;
uint32_t pres_y = e->y * GRID_CELL_SIZE;
Texture2D *texture = NULL;
if(e->type == Entity_Type_Snake_Head) {
texture = &ctx->texture_snake_head;
}
case Entity_Movement_Direction_Up: {
rotation = -90.0f;
break;
else {
texture = &ctx->texture_snake_body;
sin_frequency = 4.0f;
sin_amplitude = 1.0f;
}
case Entity_Movement_Direction_Down: {
rotation = 90.0f;
break;
}
case Entity_Movement_Direction_Right: {
rotation = 0.0f;
break;
}
case Entity_Movement_Direction_Left: {
rotation = 180.0f;
break;
// Draw shadow.
DrawTextureEx(
ctx->texture_shadow_basic,
(Vector2) { pres_x, pres_y },
0.0f,
1.0f,
(Color) { 0, 0, 0, 32 }
);
float rotation = 0.0f;
switch(e->move_direction){
case Entity_Movement_Direction_None: {
rotation = 0.0f;
break;
}
case Entity_Movement_Direction_Up: {
rotation = -90.0f;
break;
}
case Entity_Movement_Direction_Down: {
rotation = 90.0f;
break;
}
case Entity_Movement_Direction_Right: {
rotation = 0.0f;
break;
}
case Entity_Movement_Direction_Left: {
rotation = 180.0f;
break;
}
}
DrawTexturePro(
*texture,
(Rectangle) { // Source.
0, 0, GRID_CELL_SIZE, GRID_CELL_SIZE
},
(Rectangle) { // Destination.
pres_x + origin.x,
pres_y + origin.y + ENTITY_PRESENTATION_Y_OFFSET - (sin((GetTime() + (float)(i) / 4.0) * sin_frequency)) * sin_amplitude,
GRID_CELL_SIZE,
GRID_CELL_SIZE
},
origin, // Origin.
rotation, // Rotation.
tint // Tint.
);
e = game_world_try_get_entity_by_id(world, e->child);
i += 1;
}
DrawTexturePro(
*texture,
(Rectangle) { // Source.
0, 0, GRID_CELL_SIZE, GRID_CELL_SIZE
},
(Rectangle) { // Destination.
pres_x + origin.x,
pres_y + origin.y + ENTITY_PRESENTATION_Y_OFFSET - (sin((GetTime() + (float)(entity->child_index) / 4.0) * sin_frequency)) * sin_amplitude,
GRID_CELL_SIZE,
GRID_CELL_SIZE
},
origin, // Origin.
rotation, // Rotation.
tint // Tint.
);
break;
}
case Entity_Type_Snake_Body: {
break;
}
case Entity_Type_Food: {