|  | @@ -88,19 +88,33 @@ void PlayingState::update(GameStateManager& gsm, std::chrono::milliseconds const
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |    auto const direction = new_direction_.value_or(direction_);
 |  |    auto const direction = new_direction_.value_or(direction_);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +  auto const MAX_X = static_cast<float>(CELLS_X-1);
 | 
											
												
													
														|  | 
 |  | +  auto const MAX_Y = static_cast<float>(CELLS_Y-1);
 | 
											
												
													
														|  |    SDL_FPoint new_head = head_;
 |  |    SDL_FPoint new_head = head_;
 | 
											
												
													
														|  |    switch (direction) {
 |  |    switch (direction) {
 | 
											
												
													
														|  |    case Direction::Up:
 |  |    case Direction::Up:
 | 
											
												
													
														|  |      new_head.y -= distance;
 |  |      new_head.y -= distance;
 | 
											
												
													
														|  | 
 |  | +    if (new_head.y<0.0f && !deadly_wall_) {
 | 
											
												
													
														|  | 
 |  | +      new_head.y += MAX_Y;
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |      break;
 |  |      break;
 | 
											
												
													
														|  |    case Direction::Down:
 |  |    case Direction::Down:
 | 
											
												
													
														|  |      new_head.y += distance;
 |  |      new_head.y += distance;
 | 
											
												
													
														|  | 
 |  | +    if (new_head.y>=MAX_Y && !deadly_wall_) {
 | 
											
												
													
														|  | 
 |  | +      new_head.y -= MAX_Y;
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |      break;
 |  |      break;
 | 
											
												
													
														|  |    case Direction::Left:
 |  |    case Direction::Left:
 | 
											
												
													
														|  |      new_head.x -= distance;
 |  |      new_head.x -= distance;
 | 
											
												
													
														|  | 
 |  | +    if (new_head.x<0.0f && !deadly_wall_) {
 | 
											
												
													
														|  | 
 |  | +      new_head.x += MAX_X;
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |      break;
 |  |      break;
 | 
											
												
													
														|  |    case Direction::Right:
 |  |    case Direction::Right:
 | 
											
												
													
														|  |      new_head.x += distance;
 |  |      new_head.x += distance;
 | 
											
												
													
														|  | 
 |  | +    if (new_head.x>=MAX_X && !deadly_wall_) {
 | 
											
												
													
														|  | 
 |  | +      new_head.x -= MAX_X;
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |      break;
 |  |      break;
 | 
											
												
													
														|  |    }
 |  |    }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -112,6 +126,11 @@ void PlayingState::update(GameStateManager& gsm, std::chrono::milliseconds const
 | 
											
												
													
														|  |        new_direction_.reset();
 |  |        new_direction_.reset();
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +    if (detect_death(new_pos)) {
 | 
											
												
													
														|  | 
 |  | +      HighScoreManager::instance().set_new_score(length_);
 | 
											
												
													
														|  | 
 |  | +      gsm.replace_state(GameStates::GameOver);
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |      if (new_pos==target_) {
 |  |      if (new_pos==target_) {
 | 
											
												
													
														|  |        ++length_;
 |  |        ++length_;
 | 
											
												
													
														|  |        speed_ = std::min(MAX_SPEED, speed_*ACCELERATION);
 |  |        speed_ = std::min(MAX_SPEED, speed_*ACCELERATION);
 | 
											
										
											
												
													
														|  | @@ -122,11 +141,6 @@ void PlayingState::update(GameStateManager& gsm, std::chrono::milliseconds const
 | 
											
												
													
														|  |        }
 |  |        }
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    if (detect_death(new_pos)) {
 |  | 
 | 
											
												
													
														|  | -      HighScoreManager::instance().set_new_score(length_);
 |  | 
 | 
											
												
													
														|  | -      gsm.replace_state(GameStates::GameOver);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |      tail_.push_front(old_pos);
 |  |      tail_.push_front(old_pos);
 | 
											
												
													
														|  |      if (tail_.size()+1>length_)
 |  |      if (tail_.size()+1>length_)
 | 
											
												
													
														|  |        tail_.pop_back();
 |  |        tail_.pop_back();
 | 
											
										
											
												
													
														|  | @@ -151,7 +165,8 @@ void PlayingState::handle_direction_change()
 | 
											
												
													
														|  |      else if (keyboard[SDL_SCANCODE_DOWN] || keyboard[SDL_SCANCODE_S]) {
 |  |      else if (keyboard[SDL_SCANCODE_DOWN] || keyboard[SDL_SCANCODE_S]) {
 | 
											
												
													
														|  |        new_direction_ = Direction::Down;
 |  |        new_direction_ = Direction::Down;
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | -  } else {
 |  | 
 | 
											
												
													
														|  | 
 |  | +  }
 | 
											
												
													
														|  | 
 |  | +  else {
 | 
											
												
													
														|  |      if (keyboard[SDL_SCANCODE_LEFT] || keyboard[SDL_SCANCODE_A]) {
 |  |      if (keyboard[SDL_SCANCODE_LEFT] || keyboard[SDL_SCANCODE_A]) {
 | 
											
												
													
														|  |        new_direction_ = Direction::Left;
 |  |        new_direction_ = Direction::Left;
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
										
											
												
													
														|  | @@ -190,7 +205,10 @@ void PlayingState::render_ui(SDLRenderer& renderer, SDL_Rect const& playing_fiel
 | 
											
												
													
														|  |    SDL_RenderCopy(renderer, text, nullptr, &render_quad);
 |  |    SDL_RenderCopy(renderer, text, nullptr, &render_quad);
 | 
											
												
													
														|  |    SDL_DestroyTexture(text);
 |  |    SDL_DestroyTexture(text);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -  SDL_SetRenderDrawColor(renderer, 249, 95, 0, SDL_ALPHA_OPAQUE);
 |  | 
 | 
											
												
													
														|  | 
 |  | +  if (deadly_wall_)
 | 
											
												
													
														|  | 
 |  | +    SDL_SetRenderDrawColor(renderer, 249, 95, 0, SDL_ALPHA_OPAQUE);
 | 
											
												
													
														|  | 
 |  | +  else
 | 
											
												
													
														|  | 
 |  | +    SDL_SetRenderDrawColor(renderer, 255, 204, 0, SDL_ALPHA_OPAQUE);
 | 
											
												
													
														|  |    SDL_RenderDrawRect(renderer, &playing_field);
 |  |    SDL_RenderDrawRect(renderer, &playing_field);
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -204,6 +222,7 @@ bool PlayingState::place_target()
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |    }
 |  |    }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +  field.erase(::head_position(head_));
 | 
											
												
													
														|  |    for (auto const& particle: tail_) {
 |  |    for (auto const& particle: tail_) {
 | 
											
												
													
														|  |      field.erase(particle);
 |  |      field.erase(particle);
 | 
											
												
													
														|  |    }
 |  |    }
 | 
											
										
											
												
													
														|  | @@ -216,6 +235,7 @@ bool PlayingState::place_target()
 | 
											
												
													
														|  |    std::ranges::sample(field, std::back_inserter(result), 1, generator_);
 |  |    std::ranges::sample(field, std::back_inserter(result), 1, generator_);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |    target_ = result[0];
 |  |    target_ = result[0];
 | 
											
												
													
														|  | 
 |  | +  deadly_wall_ = distribution_deadly_wall(generator_)!=0;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |    return true;
 |  |    return true;
 | 
											
												
													
														|  |  }
 |  |  }
 |