Removed 'child_index' from entities. It gets figured out in presentation instead.
This commit is contained in:
@@ -139,23 +139,27 @@ static void state_render(Presentation_State *state) {
|
|||||||
Grid_Cell *cell = &grid->cells[i];
|
Grid_Cell *cell = &grid->cells[i];
|
||||||
if(cell->entity != NULL) {
|
if(cell->entity != NULL) {
|
||||||
Entity *entity = cell->entity;
|
Entity *entity = cell->entity;
|
||||||
switch(entity->type) {
|
|
||||||
case Entity_Type_Snake_Head:
|
|
||||||
case Entity_Type_Snake_Body: {
|
|
||||||
Color tint = (Color) { 255, 135, 102, 255 }; // TODO: SS - Get tint based on player ID.
|
|
||||||
|
|
||||||
|
switch(entity->type) {
|
||||||
|
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 };
|
Vector2 origin = (Vector2) { GRID_CELL_SIZE/2, GRID_CELL_SIZE/2 };
|
||||||
|
|
||||||
|
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_frequency = 0.0f;
|
||||||
float sin_amplitude = 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;
|
Texture2D *texture = NULL;
|
||||||
if(entity->type == Entity_Type_Snake_Head) {
|
if(e->type == Entity_Type_Snake_Head) {
|
||||||
texture = &ctx->texture_snake_head;
|
texture = &ctx->texture_snake_head;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
texture = &ctx->texture_snake_body;
|
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_frequency = 4.0f;
|
||||||
sin_amplitude = 1.0f;
|
sin_amplitude = 1.0f;
|
||||||
}
|
}
|
||||||
@@ -170,7 +174,7 @@ static void state_render(Presentation_State *state) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
float rotation = 0.0f;
|
float rotation = 0.0f;
|
||||||
switch(entity->move_direction){
|
switch(e->move_direction){
|
||||||
case Entity_Movement_Direction_None: {
|
case Entity_Movement_Direction_None: {
|
||||||
rotation = 0.0f;
|
rotation = 0.0f;
|
||||||
break;
|
break;
|
||||||
@@ -200,7 +204,7 @@ static void state_render(Presentation_State *state) {
|
|||||||
},
|
},
|
||||||
(Rectangle) { // Destination.
|
(Rectangle) { // Destination.
|
||||||
pres_x + origin.x,
|
pres_x + origin.x,
|
||||||
pres_y + origin.y + ENTITY_PRESENTATION_Y_OFFSET - (sin((GetTime() + (float)(entity->child_index) / 4.0) * sin_frequency)) * sin_amplitude,
|
pres_y + origin.y + ENTITY_PRESENTATION_Y_OFFSET - (sin((GetTime() + (float)(i) / 4.0) * sin_frequency)) * sin_amplitude,
|
||||||
GRID_CELL_SIZE,
|
GRID_CELL_SIZE,
|
||||||
GRID_CELL_SIZE
|
GRID_CELL_SIZE
|
||||||
},
|
},
|
||||||
@@ -209,6 +213,13 @@ static void state_render(Presentation_State *state) {
|
|||||||
tint // Tint.
|
tint // Tint.
|
||||||
);
|
);
|
||||||
|
|
||||||
|
e = game_world_try_get_entity_by_id(world, e->child);
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Entity_Type_Snake_Body: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Entity_Type_Food: {
|
case Entity_Type_Food: {
|
||||||
|
|||||||
@@ -36,10 +36,8 @@ typedef struct {
|
|||||||
uint16_t prev_y;
|
uint16_t prev_y;
|
||||||
|
|
||||||
Entity_Movement_Direction move_direction;
|
Entity_Movement_Direction move_direction;
|
||||||
Entity_Movement_Direction prev_move_direction;
|
|
||||||
|
|
||||||
Entity_ID child;
|
Entity_ID child;
|
||||||
uint16_t child_index; // Primarily used when presenting the body-parts.
|
|
||||||
|
|
||||||
// TODO: SS - Color/tint?
|
// TODO: SS - Color/tint?
|
||||||
} Entity;
|
} Entity;
|
||||||
|
|||||||
@@ -122,7 +122,6 @@ void simulation_world_tick(Simulation_World *simulation_world) {
|
|||||||
simulation_world->match_state = Simulation_Match_State_Ended;
|
simulation_world->match_state = Simulation_Match_State_Ended;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Game_World *gw = simulation_world->game_world;
|
Game_World *gw = simulation_world->game_world;
|
||||||
|
|
||||||
// Loop over all players in the simulation.
|
// Loop over all players in the simulation.
|
||||||
@@ -200,15 +199,7 @@ void simulation_world_tick(Simulation_World *simulation_world) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Move entities.
|
{ // Move entity
|
||||||
// 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;
|
|
||||||
// }
|
|
||||||
|
|
||||||
int16_t dx = 0;
|
int16_t dx = 0;
|
||||||
int16_t dy = 0;
|
int16_t dy = 0;
|
||||||
|
|
||||||
@@ -234,8 +225,6 @@ void simulation_world_tick(Simulation_World *simulation_world) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entity->prev_move_direction = entity->move_direction;
|
|
||||||
|
|
||||||
if(dx != 0 || dy != 0) {
|
if(dx != 0 || dy != 0) {
|
||||||
// Try moving.
|
// Try moving.
|
||||||
|
|
||||||
@@ -317,7 +306,6 @@ void simulation_world_tick(Simulation_World *simulation_world) {
|
|||||||
child_index += 1;
|
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;
|
Entity_ID child_entity = INVALID_ENTITY_ID;
|
||||||
assert(game_world_create_entity(
|
assert(game_world_create_entity(
|
||||||
gw,
|
gw,
|
||||||
@@ -329,10 +317,6 @@ void simulation_world_tick(Simulation_World *simulation_world) {
|
|||||||
|
|
||||||
assert(e->child == INVALID_ENTITY_ID);
|
assert(e->child == INVALID_ENTITY_ID);
|
||||||
e->child = child_entity;
|
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