Spawn a new food when one was eaten. Initially, there's one food per player spawned.
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
#define MIN_LEVEL_WIDTH 8 // TODO: SS - Move these out of here.
|
#define MIN_LEVEL_WIDTH 8 // TODO: SS - Move these out of here.
|
||||||
#define MIN_LEVEL_HEIGHT 8
|
#define MIN_LEVEL_HEIGHT 8
|
||||||
|
|
||||||
Game_World *game_world_create(uint32_t seed, uint16_t level_width, uint16_t level_height) {
|
Game_World *game_world_create(uint32_t seed, uint8_t amount_of_food_to_spawn_initially, uint16_t level_width, uint16_t level_height) {
|
||||||
assert(level_width >= MIN_LEVEL_WIDTH); // We should probably have failed earlier.
|
assert(level_width >= MIN_LEVEL_WIDTH); // We should probably have failed earlier.
|
||||||
assert(level_height >= MIN_LEVEL_HEIGHT);
|
assert(level_height >= MIN_LEVEL_HEIGHT);
|
||||||
|
|
||||||
@@ -28,8 +28,8 @@ Game_World *game_world_create(uint32_t seed, uint16_t level_width, uint16_t leve
|
|||||||
|
|
||||||
grid_initialize(&w->grid, level_width, level_height);
|
grid_initialize(&w->grid, level_width, level_height);
|
||||||
|
|
||||||
{ // TEMP: SS - Testing ..
|
// Spawn initial food(s).
|
||||||
for(uint16_t i = 0; i < 8; i++) {
|
for(uint16_t i = 0; i < amount_of_food_to_spawn_initially; i++) {
|
||||||
Entity_ID entity_food;
|
Entity_ID entity_food;
|
||||||
|
|
||||||
uint16_t x = 0;
|
uint16_t x = 0;
|
||||||
@@ -43,7 +43,6 @@ Game_World *game_world_create(uint32_t seed, uint16_t level_width, uint16_t leve
|
|||||||
&entity_food
|
&entity_food
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
@@ -270,7 +269,21 @@ void game_world_tick(Game_World *world) {
|
|||||||
e->child = child_entity;
|
e->child = child_entity;
|
||||||
|
|
||||||
{ // Spawn food.
|
{ // Spawn food.
|
||||||
|
uint16_t food_spawn_x = 0;
|
||||||
|
uint16_t food_spawn_y = 0;
|
||||||
|
|
||||||
|
if(!game_world_find_position_to_spawn(world, &food_spawn_x, &food_spawn_y)) {
|
||||||
|
printf("Failed to find a position to spawn food.\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Entity_ID entity_food;
|
||||||
|
assert(game_world_create_entity(
|
||||||
|
world,
|
||||||
|
Entity_Type_Food,
|
||||||
|
food_spawn_x, food_spawn_y,
|
||||||
|
&entity_food
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,10 +308,10 @@ bool game_world_find_position_to_spawn(Game_World *world, uint16_t *out_x, uint1
|
|||||||
assert(out_x != NULL);
|
assert(out_x != NULL);
|
||||||
assert(out_y != NULL);
|
assert(out_y != NULL);
|
||||||
|
|
||||||
uint8_t attempts = MAX_ATTEMPTS_AT_FINDING_POSITION_TO_SPAWN;
|
uint32_t attempts = world->grid.width * world->grid.height;
|
||||||
while(attempts > 0) {
|
while(attempts > 0) {
|
||||||
uint16_t potential_x = random_u32_range(&world->random_generator, 0, (uint32_t) world->grid.width);
|
uint16_t potential_x = random_u32_range(&world->random_generator, 0, (uint32_t) world->grid.width - 1);
|
||||||
uint16_t potential_y = random_u32_range(&world->random_generator, 0, (uint32_t) world->grid.height);
|
uint16_t potential_y = random_u32_range(&world->random_generator, 0, (uint32_t) world->grid.height - 1);
|
||||||
|
|
||||||
Grid_Cell *cell = grid_get_cell(&world->grid, potential_x, potential_y);
|
Grid_Cell *cell = grid_get_cell(&world->grid, potential_x, potential_y);
|
||||||
assert(cell != NULL);
|
assert(cell != NULL);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ typedef struct {
|
|||||||
|
|
||||||
} Game_World;
|
} Game_World;
|
||||||
|
|
||||||
Game_World *game_world_create(uint32_t seed, uint16_t level_width, uint16_t level_height);
|
Game_World *game_world_create(uint32_t seed, uint8_t amount_of_food_to_spawn_initially, uint16_t level_width, uint16_t level_height);
|
||||||
void game_world_destroy(Game_World *world);
|
void game_world_destroy(Game_World *world);
|
||||||
|
|
||||||
bool game_world_create_entity(Game_World *world, Entity_Type type, uint16_t x, uint16_t y, Entity_ID *out_entity_id);
|
bool game_world_create_entity(Game_World *world, Entity_Type type, uint16_t x, uint16_t y, Entity_ID *out_entity_id);
|
||||||
@@ -31,8 +31,6 @@ void game_world_tick(Game_World *world);
|
|||||||
|
|
||||||
Entity *game_world_try_get_entity_by_id(Game_World *world, Entity_ID id);
|
Entity *game_world_try_get_entity_by_id(Game_World *world, Entity_ID id);
|
||||||
|
|
||||||
#define MAX_ATTEMPTS_AT_FINDING_POSITION_TO_SPAWN 8
|
|
||||||
|
|
||||||
bool game_world_find_position_to_spawn(Game_World *world, uint16_t *out_x, uint16_t *out_y);
|
bool game_world_find_position_to_spawn(Game_World *world, uint16_t *out_x, uint16_t *out_y);
|
||||||
Entity_Movement_Direction game_world_choose_initial_move_direction_based_on_coords(Game_World *world, uint16_t x, uint16_t y);
|
Entity_Movement_Direction game_world_choose_initial_move_direction_based_on_coords(Game_World *world, uint16_t x, uint16_t y);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ Simulation_World simulation_create_world(uint32_t seed, bool online, uint8_t max
|
|||||||
|
|
||||||
w.online = online;
|
w.online = online;
|
||||||
|
|
||||||
w.game_world = game_world_create(seed, width, height);
|
uint16_t amount_of_food_to_spawn_initially = max_players; // NOTE: SS - One per player. Might change and/or be customizable.
|
||||||
|
w.game_world = game_world_create(seed, amount_of_food_to_spawn_initially, width, height);
|
||||||
assert(w.game_world != NULL);
|
assert(w.game_world != NULL);
|
||||||
|
|
||||||
w.match_state = Simulation_Match_State_Waiting_To_Start;
|
w.match_state = Simulation_Match_State_Waiting_To_Start;
|
||||||
|
|||||||
10
src/todo.md
10
src/todo.md
@@ -12,14 +12,10 @@
|
|||||||
- Spawn players at a random position.
|
- Spawn players at a random position.
|
||||||
- [x] When initially joining.
|
- [x] When initially joining.
|
||||||
- [ ] When dead and should respawn.
|
- [ ] When dead and should respawn.
|
||||||
- Spawn food every N tick(?)
|
- [x] Spawn a new food when one was eaten.
|
||||||
- [ ] Spawn food at a random position every N tick.
|
|
||||||
- Do we want a "max food on the board" value?
|
|
||||||
- Why?
|
|
||||||
- This can easily be implemented later.
|
|
||||||
- If we have that much food on the board, don't spawn new food.
|
|
||||||
- Otherwise, spawn new food at a random position.
|
|
||||||
- [x] When a player disconnects, all children should recursively be destroyed too. Not just the head.
|
- [x] When a player disconnects, all children should recursively be destroyed too. Not just the head.
|
||||||
|
- [ ] Send networked input.
|
||||||
|
- [ ] Set up session when joining the host.
|
||||||
- [ ] Change player-movement?
|
- [ ] Change player-movement?
|
||||||
- Only inputs needed are RIGHT and LEFT. Turn relative to your head.
|
- Only inputs needed are RIGHT and LEFT. Turn relative to your head.
|
||||||
- Right now we're moving relative to world-up.
|
- Right now we're moving relative to world-up.
|
||||||
|
|||||||
Reference in New Issue
Block a user