Removed 'child_index' from entities. It gets figured out in presentation instead.
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -36,10 +36,8 @@ typedef struct {
|
||||
uint16_t prev_y;
|
||||
|
||||
Entity_Movement_Direction move_direction;
|
||||
Entity_Movement_Direction prev_move_direction;
|
||||
|
||||
Entity_ID child;
|
||||
uint16_t child_index; // Primarily used when presenting the body-parts.
|
||||
|
||||
// TODO: SS - Color/tint?
|
||||
} Entity;
|
||||
|
||||
@@ -122,7 +122,6 @@ void simulation_world_tick(Simulation_World *simulation_world) {
|
||||
simulation_world->match_state = Simulation_Match_State_Ended;
|
||||
}
|
||||
else {
|
||||
|
||||
Game_World *gw = simulation_world->game_world;
|
||||
|
||||
// Loop over all players in the simulation.
|
||||
@@ -200,15 +199,7 @@ void simulation_world_tick(Simulation_World *simulation_world) {
|
||||
}
|
||||
}
|
||||
|
||||
{ // Move entities.
|
||||
// Entity *entity_to_follow = entity;
|
||||
// if(entity->parent != INVALID_ENTITY_ID) {
|
||||
// entity_to_follow = game_world_try_get_entity_by_id(gw, entity->parent);
|
||||
// assert(entity_to_follow != NULL);
|
||||
|
||||
// entity->move_direction = entity_to_follow->prev_move_direction;
|
||||
// }
|
||||
|
||||
{ // Move entity
|
||||
int16_t dx = 0;
|
||||
int16_t dy = 0;
|
||||
|
||||
@@ -233,8 +224,6 @@ void simulation_world_tick(Simulation_World *simulation_world) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
entity->prev_move_direction = entity->move_direction;
|
||||
|
||||
if(dx != 0 || dy != 0) {
|
||||
// Try moving.
|
||||
@@ -317,7 +306,6 @@ void simulation_world_tick(Simulation_World *simulation_world) {
|
||||
child_index += 1;
|
||||
}
|
||||
|
||||
// TODO: SS - Spawn the entity and make it a child of the snake's last child.
|
||||
Entity_ID child_entity = INVALID_ENTITY_ID;
|
||||
assert(game_world_create_entity(
|
||||
gw,
|
||||
@@ -329,10 +317,6 @@ void simulation_world_tick(Simulation_World *simulation_world) {
|
||||
|
||||
assert(e->child == INVALID_ENTITY_ID);
|
||||
e->child = child_entity;
|
||||
|
||||
Entity *child = game_world_try_get_entity_by_id(gw, child_entity);
|
||||
assert(child != NULL);
|
||||
child->child_index = child_index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user