More progress.
This commit is contained in:
@@ -47,6 +47,8 @@ static void state_enter(Presentation_State *state) {
|
||||
|
||||
// TODO: SS - Maybe put the textures in an array and index them using an enum?
|
||||
// These should probably be loaded at start-up instead of here.
|
||||
ctx->texture_shadow_basic = LoadTexture("assets/sprites/spr_shadow_basic.png");
|
||||
assert(IsTextureValid(ctx->texture_shadow_basic));
|
||||
ctx->texture_grass = LoadTexture("assets/sprites/spr_floor_grass.png");
|
||||
assert(IsTextureValid(ctx->texture_grass));
|
||||
ctx->texture_apple = LoadTexture("assets/sprites/spr_food_apple.png");
|
||||
@@ -60,6 +62,8 @@ static void state_enter(Presentation_State *state) {
|
||||
static void state_tick(Presentation_State *state) {
|
||||
Presentation_State_Ingame_Context *ctx = (Presentation_State_Ingame_Context *)state->context;
|
||||
(void)ctx;
|
||||
|
||||
game_session_tick(g_current_session);
|
||||
|
||||
{ // TEMP: SS
|
||||
if(IsKeyPressed(KEY_ESCAPE)) {
|
||||
@@ -74,7 +78,8 @@ static void state_render(Presentation_State *state) {
|
||||
|
||||
ClearBackground((Color) { 240, 236, 226, 255 });
|
||||
|
||||
Game_World *world = g_current_session->simulation_world.game_world;
|
||||
Simulation_World *sim_world = &g_current_session->simulation_world;
|
||||
Game_World *world = sim_world->game_world;
|
||||
Grid *grid = &world->grid;
|
||||
|
||||
uint32_t grid_total_size = grid->width * grid->height;
|
||||
@@ -107,74 +112,99 @@ static void state_render(Presentation_State *state) {
|
||||
uint32_t pres_y = y * GRID_CELL_SIZE;
|
||||
|
||||
Grid_Cell *cell = &grid->cells[i];
|
||||
Entity *entity = &cell->entity;
|
||||
switch(entity->type) {
|
||||
case Entity_Type_None: {
|
||||
break;
|
||||
}
|
||||
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.
|
||||
|
||||
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;
|
||||
if(cell->entity != NULL) {
|
||||
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.
|
||||
|
||||
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 }
|
||||
);
|
||||
|
||||
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() * sin_frequency)) * sin_amplitude,
|
||||
GRID_CELL_SIZE,
|
||||
GRID_CELL_SIZE
|
||||
},
|
||||
origin, // Origin.
|
||||
0, // Rotation.
|
||||
tint // Tint.
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
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;
|
||||
case Entity_Type_Food: {
|
||||
uint32_t flash = ((sin(GetTime() * 8) + 1)/2) * 32;
|
||||
Color tint = (Color) { 255-flash, 255-flash, 255-flash, 255 };
|
||||
|
||||
Vector2 origin = (Vector2) { GRID_CELL_SIZE/2, GRID_CELL_SIZE/2 };
|
||||
|
||||
// Draw shadow.
|
||||
DrawTextureEx(
|
||||
ctx->texture_shadow_basic,
|
||||
(Vector2) { pres_x, pres_y },
|
||||
0.0f,
|
||||
1.0f,
|
||||
(Color) { 0, 0, 0, 32 }
|
||||
);
|
||||
|
||||
DrawTexturePro(
|
||||
ctx->texture_apple,
|
||||
(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() * 12) + 1)/2) * 1,
|
||||
GRID_CELL_SIZE,
|
||||
GRID_CELL_SIZE
|
||||
},
|
||||
origin, // Origin.
|
||||
0, // Rotation.
|
||||
tint // Tint.
|
||||
);
|
||||
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() * sin_frequency)) * sin_amplitude,
|
||||
GRID_CELL_SIZE,
|
||||
GRID_CELL_SIZE
|
||||
},
|
||||
origin, // Origin.
|
||||
0, // Rotation.
|
||||
tint // Tint.
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
case Entity_Type_Food: {
|
||||
uint32_t flash = ((sin(GetTime() * 8) + 1)/2) * 32;
|
||||
Color tint = (Color) { 255-flash, 255-flash, 255-flash, 255 };
|
||||
|
||||
Vector2 origin = (Vector2) { GRID_CELL_SIZE/2, GRID_CELL_SIZE/2 };
|
||||
|
||||
DrawTexturePro(
|
||||
ctx->texture_apple,
|
||||
(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() * 12) + 1)/2) * 1,
|
||||
GRID_CELL_SIZE,
|
||||
GRID_CELL_SIZE
|
||||
},
|
||||
origin, // Origin.
|
||||
0, // Rotation.
|
||||
tint // Tint.
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{ // TEMP: SS - Render match state.
|
||||
char buf[512];
|
||||
snprintf(&buf[0], sizeof(buf), "Match-state: %i. Tick: %lu.", sim_world->match_state, sim_world->tick);
|
||||
|
||||
DrawText(buf, 32, 32, 12, RED);
|
||||
}
|
||||
|
||||
}
|
||||
EndMode2D();
|
||||
}
|
||||
@@ -184,6 +214,7 @@ static void state_exit(Presentation_State *state) {
|
||||
(void)ctx;
|
||||
printf("Exiting ingame\n");
|
||||
|
||||
UnloadTexture(ctx->texture_shadow_basic);
|
||||
UnloadTexture(ctx->texture_grass);
|
||||
UnloadTexture(ctx->texture_apple);
|
||||
UnloadTexture(ctx->texture_snake_head);
|
||||
|
||||
Reference in New Issue
Block a user