diff --git a/BANG.mp3 b/BANG.mp3 new file mode 100644 index 0000000..79a428b Binary files /dev/null and b/BANG.mp3 differ diff --git a/src/GameBall/logic/units/regular_ball.cpp b/src/GameBall/logic/units/regular_ball.cpp index af1cc95..7164719 100644 --- a/src/GameBall/logic/units/regular_ball.cpp +++ b/src/GameBall/logic/units/regular_ball.cpp @@ -45,43 +45,43 @@ void RegularBall::UpdateTick() { auto physics_world = world_->PhysicsWorld(); auto &sphere = physics_world->GetSphere(sphere_id_); - // auto owner = world_->GetPlayer(player_id_); - // if (owner) { - // if (UnitId() == owner->PrimaryUnitId()) { - // auto input = owner->TakePlayerInput(); - // - // glm::vec3 forward = glm::normalize(glm::vec3{input.orientation}); - // glm::vec3 right = - // glm::normalize(glm::cross(forward, glm::vec3{0.0f, 1.0f, 0.0f})); - // - // glm::vec3 moving_direction{}; - // - // float angular_acceleration = glm::radians(2880.0f); - // - // if (input.move_forward) { - // moving_direction -= right; - // } - // if (input.move_backward) { - // moving_direction += right; - // } - // if (input.move_left) { - // moving_direction -= forward; - // } - // if (input.move_right) { - // moving_direction += forward; - // } - // - // if (glm::length(moving_direction) > 0.0f) { - // moving_direction = glm::normalize(moving_direction); - // sphere.angular_velocity += - // moving_direction * angular_acceleration * delta_time; - // } - // - // if (input.brake) { - // sphere.angular_velocity = glm::vec3{0.0f}; - // } - // } - // } + auto owner = world_->GetPlayer(player_id_); + if (owner) { + if (UnitId() == owner->PrimaryUnitId()) { + auto input = owner->TakePlayerInput(); + + glm::vec3 forward = glm::normalize(glm::vec3{input.orientation}); + glm::vec3 right = + glm::normalize(glm::cross(forward, glm::vec3{0.0f, 1.0f, 0.0f})); + + glm::vec3 moving_direction{}; + + float angular_acceleration = glm::radians(2880.0f); + + if (input.move_forward) { + moving_direction -= right; + } + if (input.move_backward) { + moving_direction += right; + } + if (input.move_left) { + moving_direction -= forward; + } + if (input.move_right) { + moving_direction += forward; + } + + if (glm::length(moving_direction) > 0.0f) { + moving_direction = glm::normalize(moving_direction); + sphere.angular_velocity += + moving_direction * angular_acceleration * delta_time; + } + + if (input.brake) { + sphere.angular_velocity = glm::vec3{0.0f}; + } + } + } sphere.velocity *= std::pow(0.5f, delta_time); sphere.angular_velocity *= std::pow(0.2f, delta_time); diff --git a/src/GameX/physics/collision.cpp b/src/GameX/physics/collision.cpp index 27de48d..8f67647 100644 --- a/src/GameX/physics/collision.cpp +++ b/src/GameX/physics/collision.cpp @@ -68,7 +68,7 @@ bool DetectCollision(const Sphere &sphere, return true; } -bool SolveCollision(RigidBody &body1, +uint64_t SolveCollision(RigidBody &body1, RigidBody &body2, const Collision &collision) { // std::cout << "Solve Collision..." << std::endl; @@ -103,8 +103,9 @@ bool SolveCollision(RigidBody &body1, body2.velocity + glm::cross(body2.angular_velocity, r2) - body1.velocity - glm::cross(body1.angular_velocity, r1); float velocity_along_normal = glm::dot(relative_velocity, collision.normal); + uint64_t addscore=10000*velocity_along_normal; if (velocity_along_normal > -0.0001f) { - return false; + return 0; } glm::mat3 inverse_inertia1 = @@ -165,7 +166,7 @@ bool SolveCollision(RigidBody &body1, inverse_inertia2 * glm::cross(r2, friction_impulse); } - return true; + return addscore; } } // namespace GameX::Physics diff --git a/src/GameX/physics/collision.h b/src/GameX/physics/collision.h index 2a515b6..d5920b3 100644 --- a/src/GameX/physics/collision.h +++ b/src/GameX/physics/collision.h @@ -19,7 +19,7 @@ bool DetectCollision(const Sphere &sphere, const Cube &cube, Collision &collision); -bool SolveCollision(RigidBody &body1, +uint64_t SolveCollision(RigidBody &body1, RigidBody &body2, const Collision &collision); diff --git a/src/GameX/physics/world.cpp b/src/GameX/physics/world.cpp index 6a68a67..bbee415 100644 --- a/src/GameX/physics/world.cpp +++ b/src/GameX/physics/world.cpp @@ -72,8 +72,10 @@ void World::SolveCollisions() { do { collision_found = false; for (auto &pair : collision_pairs) { - if (SolveCollision(*std::get<0>(pair), *std::get<1>(pair), - std::get<2>(pair))) { + uint64_t k = SolveCollision(*std::get<0>(pair), *std::get<1>(pair), + std::get<2>(pair)); + score_ += k; + if(k!=0){ collision_found = true; } } @@ -88,4 +90,7 @@ void World::ApplyGravity(float delta_time) { cube.second.velocity += cube.second.gravity * delta_time; } } +void World::GetScore(){ + printf("%lu",score_); +} } // namespace GameX::Physics diff --git a/src/GameX/physics/world.h b/src/GameX/physics/world.h index fe902b1..aac3ebb 100644 --- a/src/GameX/physics/world.h +++ b/src/GameX/physics/world.h @@ -23,10 +23,12 @@ class World { void ApplyGravity(float delta_time); + void GetScore(); private: std::map spheres_; uint64_t next_sphere_id_{1}; std::map cubes_; uint64_t next_cube_id_{1}; + uint64_t score_=0; }; } // namespace GameX::Physics