Skip to content

Commit

Permalink
fix segfault, change caption, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
szymor committed Apr 8, 2023
1 parent 9c3919c commit bd25ced
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ As the name suggests, it is yet another implementation of a popular Snake game.
## to do
- music and sounds,
- custom level support,
- multiple snakes (one for player, others for AI).
- animations?
26 changes: 8 additions & 18 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,11 @@ void room_init(struct Room *room)
room->walls = NULL;
room->obstacles_num = 0;
room->obstacles = NULL;
for (int i = 0; i < SNAKE_NUM; ++i)
{
snake_init(&room->snake[i]);
room->snake[i].alive = false;
}

switch (menu_options[MO_LEVELTYPE])
{
Expand All @@ -1036,7 +1041,7 @@ void room_init(struct Room *room)
room->cg_cartesian.upper_left = (struct Vec2D){ .x = 0, .y = 0};
room->cg_cartesian.bottom_right = (struct Vec2D){ .x = SCREEN_WIDTH, .y = SCREEN_HEIGHT};

snake_init(&room->snake[0]);
room->snake[0].alive = true;
snake_add_segments(&room->snake[0], START_LEN - 1);
camera_prepare(&room->snake[0], CM_FIXED);

Expand Down Expand Up @@ -1069,11 +1074,6 @@ void room_init(struct Room *room)
// other snakes
if (rand() % 8 == 0)
{
for (int i = 1; i < SNAKE_NUM; ++i)
{
snake_init(&room->snake[i]);
room->snake[i].alive = false;
}
for (int i = 1; i < SNAKE_NUM; ++i)
{
bool valid = generate_safe_position(room, &pos,
Expand Down Expand Up @@ -1129,19 +1129,14 @@ void room_init(struct Room *room)
}

// snake initialization
snake_init(&room->snake[0]);
room->snake[0].alive = true;
room->snake[0].pieces[0] = (struct Vec2D){ .x = 0, .y = -room->cg_polar.radius / 2 - HEAD_RADIUS - 1 };
snake_add_segments(&room->snake[0], START_LEN - 1);
camera_prepare(&room->snake[0], CM_TRACKING);

// other snakes
if (rand() % 8 == 0)
{
for (int i = 1; i < SNAKE_NUM; ++i)
{
snake_init(&room->snake[i]);
room->snake[i].alive = false;
}
for (int i = 1; i < SNAKE_NUM; ++i)
{
bool valid = generate_safe_position(room, &pos,
Expand Down Expand Up @@ -1215,19 +1210,14 @@ void room_init(struct Room *room)
}

// snake initialization
snake_init(&room->snake[0]);
room->snake[0].alive = true;
room->snake[0].pieces[0] = (struct Vec2D){ .x = 15, .y = -radius / 3 };
snake_add_segments(&room->snake[0], START_LEN - 1);
camera_prepare(&room->snake[0], CM_TPP_DELAYED);

// other snakes
if (rand() % 8 == 0)
{
for (int i = 1; i < SNAKE_NUM; ++i)
{
snake_init(&room->snake[i]);
room->snake[i].alive = false;
}
for (int i = 1; i < SNAKE_NUM; ++i)
{
bool valid = generate_safe_position(room, &pos,
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main(int argc, char *argv[])
#endif
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, vflags);
SDL_CHECK(screen == NULL);
SDL_WM_SetCaption("Final Snake alpha", NULL);
SDL_WM_SetCaption("Final Snake", NULL);
SDL_ShowCursor(SDL_DISABLE);

int img_flags = IMG_INIT_PNG;
Expand Down

0 comments on commit bd25ced

Please sign in to comment.