Position Player::GetNextPosition(double dt) const { const double speed = 7; const Position pos = GetPosition(); const Direction dir = GetDirection(); return Position(pos.x + dir.x() * dt * speed, pos.y + dir.y() * dt * speed); }
static double signed_distance_on_direction( const Point &point0, const Point &point1, const Direction &direction) { return ((point1.x() - point0.x()) * direction.x() + (point1.y() - point0.y()) * direction.y()); }
void Snake::game_loop() { update_positions(); intersect(); render(); if (finished()) { gameover(); return; } Timers::oneshot( std::chrono::milliseconds(_head_dir.x() == 0 ? 120 : 70), [this](auto) { this->game_loop(); } ); }