diff --git a/src/GameBall/core/actors/common_ball_actor.cpp b/src/GameBall/core/actors/common_ball_actor.cpp index 82d6c37..91a0357 100644 --- a/src/GameBall/core/actors/common_ball_actor.cpp +++ b/src/GameBall/core/actors/common_ball_actor.cpp @@ -3,12 +3,57 @@ #include "GameBall/core/game_ball.h" namespace GameBall::Actors { - +static int count = 1; CommonBallActor::CommonBallActor(GameBall *app) : Actor(app) { entity_ = app->Scene()->CreateEntity( app->AssetManager()->StaticModelFile("models/sphere.obj")); - entity_->SetAlbedoImage( - app->AssetManager()->ImageFile("textures/2k_moon.jpg")); + if (count == 1) + std::cout << "Choose the color of the player ball:"; + else if (count == 2) + std::cout << "Choose the color of the enemy ball:"; + else if (count == 3) + std::cout << "Choose the color of the large ball:"; + else if (count == 4) + std::cout << "Choose the color of the small ball:"; + else + exit(0); + std::string enter; + while (1) { + std::cin >> enter; + if (enter == "white") { + entity_->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_ao_2k.jpg")); + break; + } else if (enter == "orange") { + entity_->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_arm_2k.jpg")); + break; + } else if (enter == "tile") { + entity_->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_disp_2k.jpg")); + break; + } else if (enter == "blue1") { + entity_->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_nor_dx_2k.jpg")); + break; + } else if (enter == "blue2") { + entity_->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_nor_gl_2k.jpg")); + break; + } else if (enter == "grey") { + entity_->SetAlbedoImage(app->AssetManager()->ImageFile("textures/floor_tiles_06_2k/floor_tiles_06_rough_2k.jpg ")); + break; + } else if (enter == "Moon") { + entity_->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/2k_moon.jpg")); + break; + } else { + std::cout<< + "We only have 7 textures, namely blue1, blue2, "<< + "white, orange, tile, grey, and Moon. Please choose again.\n"; + } + } + count++; } CommonBallActor::~CommonBallActor() { diff --git a/src/GameBall/core/game_ball.cpp b/src/GameBall/core/game_ball.cpp index a47b79e..cf00dc4 100644 --- a/src/GameBall/core/game_ball.cpp +++ b/src/GameBall/core/game_ball.cpp @@ -37,17 +37,47 @@ void GameBall::OnInit() { auto primary_player = world->CreatePlayer(); auto enemy_player = world->CreatePlayer(); + auto large_player = world->CreatePlayer(); + auto small_player = world->CreatePlayer(); auto primary_unit = world->CreateUnit( - primary_player->PlayerId(), glm::vec3{0.0f, 1.0f, 0.0f}, 1.0f, 1.0f); + primary_player->PlayerId(), glm::vec3{20.0f, 21.0f, 0.0f}, 1.0f, 1.0f); auto enemy_unit = world->CreateUnit( - enemy_player->PlayerId(), glm::vec3{-5.0f, 1.0f, 0.0f}, 1.0f, 1.0f); + enemy_player->PlayerId(), glm::vec3{0.0f, 21.0f, -20.0f}, 1.0f, 1.0f); + auto large_unit = world->CreateUnit( + large_player->PlayerId(), glm::vec3{-30.0f, 2.0f, 0.0f}, 2.0f, 6.0f); + auto small_unit = world->CreateUnit( + small_player->PlayerId(), glm::vec3{0.0f, 20.7f, 20.0f}, 0.7f, 0.343f); auto primary_obstacle = world->CreateObstacle( - glm::vec3{0.0f, -10.0f, 0.0f}, std::numeric_limits::infinity(), + glm::vec3{0.0f, -40.0f, 0.0f}, std::numeric_limits::infinity(), + false, 80.0f); + auto obstacle2 = world->CreateObstacle( + glm::vec3{20.0f, 10.0f, 0.0f}, std::numeric_limits::infinity(), false, 20.0f); - + auto obstacle3 = world->CreateObstacle( + glm::vec3{0.0f, 10.0f, 20.0f}, std::numeric_limits::infinity(), + false, 20.0f); + auto obstacle4 = world->CreateObstacle( + glm::vec3{0.0f, 10.0f, -20.0f}, std::numeric_limits::infinity(), + false, 20.0f); + auto obstacle5 = world->CreateObstacle( + glm::vec3{-35.0f, 0.75f, 1.5f}, std::numeric_limits::infinity(), + false, 1.5f); + auto obstacle6 = world->CreateObstacle( + glm::vec3{-35.0f, 0.75f, -1.5f}, std::numeric_limits::infinity(), + false, 1.5f); + auto obstacle7 = world->CreateObstacle( + glm::vec3{-35.0f, 3.75f, 0.0f}, std::numeric_limits::infinity(), + false, 4.5f); + auto obstacle8 = world->CreateObstacle( + glm::vec3{15.0f, 15.0f, 15.0f}, std::numeric_limits::infinity(), + false, 10.0f); primary_player_id_ = primary_player->PlayerId(); + large_player_id_ = large_player->PlayerId(); + small_player_id_ = small_player->PlayerId(); primary_player->SetPrimaryUnit(primary_unit->UnitId()); + large_player->SetLargeUnit(large_unit->UnitId()); + small_player->SetSmallUnit(small_unit->UnitId()); VkExtent2D extent = FrameExtent(); float aspect = static_cast(extent.width) / extent.height; diff --git a/src/GameBall/core/game_ball.h b/src/GameBall/core/game_ball.h index 3da4bd6..6d6a25b 100644 --- a/src/GameBall/core/game_ball.h +++ b/src/GameBall/core/game_ball.h @@ -71,6 +71,8 @@ class GameBall : public GameX::Base::Application { uint64_t primary_player_id_{0}; uint64_t primary_player_primary_unit_object_id_{0}; + uint64_t large_player_id_{0}; + uint64_t small_player_id_{0}; bool ignore_next_mouse_move_{true}; diff --git a/src/GameBall/logic/obstacles/block.cpp b/src/GameBall/logic/obstacles/block.cpp index 7107909..5fdb516 100644 --- a/src/GameBall/logic/obstacles/block.cpp +++ b/src/GameBall/logic/obstacles/block.cpp @@ -4,7 +4,7 @@ #include "GameBall/logic/world.h" namespace GameBall::Logic::Obstacles { - +short count=0; Block::Block(World *world, glm::vec3 position, float mass, @@ -22,7 +22,7 @@ Block::Block(World *world, SetMass(mass_); SetSideLength(side_length_); SetMotion(position_, velocity_, orientation_, L_); - cube.elasticity = 0.25f; + cube.elasticity = 0.5f; cube.friction = 0.5f; } @@ -32,12 +32,53 @@ SYNC_ACTOR_FUNC(Block) { actor->SetInertiaTensor(J_); actor->SetGravity(gravity_); actor->SetMotion(position_, velocity_, orientation_, L_); - if (ActorInitialize()) { - actor->Entity()->SetAlbedoImage(app->AssetManager()->ImageFile( + if (ActorInitialize()) + if (count <2) { + std::cout << "Choose a setting:\n"; + char input; + std::cin >> input; + switch (input) { + case '1': + actor->Entity()->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_ao_2k.jpg")); + break; + case '2': + actor->Entity()->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_arm_2k.jpg")); + break; + case '3': + actor->Entity()->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_diff_2k.jpg")); + break; + case '4': + actor->Entity()->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_disp_2k.jpg")); + break; + case '5': + actor->Entity()->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_nor_dx_2k.jpg")); + break; + case '6': + actor->Entity()->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_nor_gl_2k.jpg")); + break; + case '7': + actor->Entity()->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_rough_2k.jpg")); + break; + case '8': + actor->Entity()->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_spec_2k.jpg")); + break; + default: + actor->Entity()->SetAlbedoImage(app->AssetManager()->ImageFile( + "textures/floor_tiles_06_2k/floor_tiles_06_diff_2k.jpg")); + } + count++; + } else + actor->Entity()->SetAlbedoImage(app->AssetManager()->ImageFile( "textures/floor_tiles_06_2k/floor_tiles_06_diff_2k.jpg")); - } -} - + } void Block::SetMass(float mass) { auto physics_world = world_->PhysicsWorld(); auto &cube = physics_world->GetCube(cude_id_); diff --git a/src/GameBall/logic/player.cpp b/src/GameBall/logic/player.cpp index 6668885..44e5327 100644 --- a/src/GameBall/logic/player.cpp +++ b/src/GameBall/logic/player.cpp @@ -20,10 +20,26 @@ uint64_t Player::PrimaryUnitId() const { return primary_unit_id_; } +uint64_t Player::LargeUnitId() const { + return large_unit_id_; +} + +uint64_t Player::SmallUnitId() const { + return small_unit_id_; +} + void Player::SetPrimaryUnit(uint64_t unit_id) { primary_unit_id_ = unit_id; } +void Player::SetLargeUnit(uint64_t unit_id) { + large_unit_id_ = unit_id; +} + +void Player::SetSmallUnit(uint64_t unit_id) { + small_unit_id_ = unit_id; +} + void Player::SetInput(const PlayerInput &input) { input_ = input; } diff --git a/src/GameBall/logic/player.h b/src/GameBall/logic/player.h index ef33e2e..1ed17ff 100644 --- a/src/GameBall/logic/player.h +++ b/src/GameBall/logic/player.h @@ -12,8 +12,16 @@ class Player { uint64_t PrimaryUnitId() const; + uint64_t LargeUnitId() const; + + uint64_t SmallUnitId() const; + void SetPrimaryUnit(uint64_t unit_id); + void SetLargeUnit(uint64_t unit_id); + + void SetSmallUnit(uint64_t unit_id); + void SetInput(const PlayerInput &input); [[nodiscard]] PlayerInput GetPlayerInput() const; @@ -25,6 +33,8 @@ class Player { uint64_t player_id_{}; uint64_t primary_unit_id_{}; + uint64_t large_unit_id_{}; + uint64_t small_unit_id_{}; PlayerInput input_{}; }; diff --git a/src/GameBall/logic/player_input.cpp b/src/GameBall/logic/player_input.cpp index c002a91..4e92424 100644 --- a/src/GameBall/logic/player_input.cpp +++ b/src/GameBall/logic/player_input.cpp @@ -19,6 +19,27 @@ PlayerInput PlayerInputController::GetInput() { auto yaw = pitch_yaw.y; input_.orientation = {glm::sin(glm::radians(yaw)), 0.0f, -glm::cos(glm::radians(yaw))}; + input_.v_jump = (glfwGetKey(window, GLFW_KEY_J) == GLFW_PRESS); + input_.low = (glfwGetKey(window, GLFW_KEY_0) == GLFW_PRESS); + input_.high = (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS); + input_.return_if_too_light = + (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS && + count_chances < 2); // 2 chances of returning to the base + if (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) + R_pressed_now = R_pressed_before = true; + if (glfwGetKey(window, GLFW_KEY_R) == GLFW_RELEASE && R_pressed_before && + R_pressed_now) { + R_pressed_now = false; + count_chances++; + } + input_.halt = (glfwGetKey(window, GLFW_KEY_H) == GLFW_PRESS); + if (glfwGetKey(window, GLFW_KEY_T) == GLFW_PRESS) + T_pressed_now = true; + if (glfwGetKey(window, GLFW_KEY_T) == GLFW_RELEASE && T_pressed_now) + T_pressed_now = !T_pressed_now, T_pressed_before = !T_pressed_before; + input_.restart_halt = T_pressed_before; + input_.end_if_too_heavy = (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS); + input_.end = (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS); auto result = input_; input_ = {}; return result; diff --git a/src/GameBall/logic/player_input.h b/src/GameBall/logic/player_input.h index 98b60c0..7b90a22 100644 --- a/src/GameBall/logic/player_input.h +++ b/src/GameBall/logic/player_input.h @@ -13,6 +13,17 @@ struct PlayerInput { bool move_right{false}; bool brake{false}; glm::vec3 orientation{0.0f, 0.0f, 1.0f}; + bool v_jump{false}; // make the sphere jump if it is on the cube + bool low{false}; // lower the mass by 10% once called + bool high{false}; // increase the mass by 10% at the supply base(0,1,0) + bool return_if_too_light{ + false}; // return to the supply base and recover normal mass if called + bool halt{false}; // Stop the game and the balls will make no response until + // halting ends + bool restart_halt{false}; // Halt by pressing T once, and restart the game by + // pressing T again + bool end_if_too_heavy{false}; // end the game if the ball is too heavy + bool end{false}; // quit immediately }; class PlayerInputController { @@ -23,6 +34,11 @@ class PlayerInputController { private: GameBall *app_; PlayerInput input_{}; + bool R_pressed_before = false; // indicate whether R has been pressed before + bool R_pressed_now = false; // indicate whether R is being pressed + bool T_pressed_before = false; + bool T_pressed_now = false; + int count_chances = 0, count_halt = 0; }; } // namespace GameBall::Logic diff --git a/src/GameBall/logic/units/regular_ball.cpp b/src/GameBall/logic/units/regular_ball.cpp index af1cc95..8bc6e7b 100644 --- a/src/GameBall/logic/units/regular_ball.cpp +++ b/src/GameBall/logic/units/regular_ball.cpp @@ -1,147 +1,262 @@ -#include "GameBall/logic/units/regular_ball.h" - -#include "GameBall/core/game_ball.h" -#include "GameBall/logic/world.h" - -namespace GameBall::Logic::Units { -RegularBall::RegularBall(World *world, - uint64_t player_id, - const glm::vec3 &position, - float radius, - float mass) - : Unit(world, player_id) { - radius_ = radius; - mass_ = mass; - position_ = position; - auto physics_world = world_->PhysicsWorld(); - sphere_id_ = physics_world->CreateSphere(); - auto &sphere = physics_world->GetSphere(sphere_id_); - sphere.position = position_; - sphere.SetRadiusMass(radius_, mass_); - sphere.orientation = orientation_; - sphere.velocity = velocity_; - sphere.angular_velocity = glm::vec3{0.0f}; - sphere.elasticity = 1.0f; - sphere.friction = 10.0f; - sphere.gravity = glm::vec3{0.0f, -9.8f, 0.0f}; -} - -RegularBall::~RegularBall() { - ; -} - -SYNC_ACTOR_FUNC(RegularBall) { - auto physics_world = world_->PhysicsWorld(); - auto &sphere = physics_world->GetSphere(sphere_id_); - actor->SetMass(1.0f); - actor->SetGravity(glm::vec3{0.0f, -9.8f, 0.0f}); - actor->SetTransform(glm::mat3{radius_}); - actor->SetMotion(position_, velocity_, orientation_, augular_momentum_); - actor->SetMomentOfInertia(sphere.inertia[0][0]); -} - -void RegularBall::UpdateTick() { - float delta_time = world_->TickDeltaT(); - 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}; - // } - // } - // } - - sphere.velocity *= std::pow(0.5f, delta_time); - sphere.angular_velocity *= std::pow(0.2f, delta_time); - - position_ = sphere.position; - velocity_ = sphere.velocity; - orientation_ = sphere.orientation; - augular_momentum_ = sphere.inertia * sphere.angular_velocity; -} - -void RegularBall::SetMass(float mass) { - auto physics_world = world_->PhysicsWorld(); - auto &sphere = physics_world->GetSphere(sphere_id_); - sphere.SetRadiusMass(radius_, mass); - mass_ = mass; -} - -void RegularBall::SetGravity(const glm::vec3 &gravity) { - auto physics_world = world_->PhysicsWorld(); - auto &sphere = physics_world->GetSphere(sphere_id_); - sphere.gravity = gravity; -} - -void RegularBall::SetRadius(float radius) { - auto physics_world = world_->PhysicsWorld(); - auto &sphere = physics_world->GetSphere(sphere_id_); - sphere.SetRadiusMass(radius, mass_); - radius_ = radius; -} - -void RegularBall::SetMotion(const glm::vec3 &position, - const glm::vec3 &velocity, - const glm::mat3 &orientation, - const glm::vec3 &angular_momentum) { - auto physics_world = world_->PhysicsWorld(); - auto &sphere = physics_world->GetSphere(sphere_id_); - sphere.position = position; - sphere.velocity = velocity; - sphere.orientation = orientation; - sphere.angular_velocity = sphere.inertia_inv * angular_momentum; - position_ = position; - velocity_ = velocity; - orientation_ = orientation; - augular_momentum_ = angular_momentum; -} - -glm::vec3 RegularBall::Position() const { - return position_; -} - -glm::vec3 RegularBall::Velocity() const { - return velocity_; -} - -glm::mat3 RegularBall::Orientation() const { - return orientation_; -} - -glm::vec3 RegularBall::AngularMomentum() const { - return augular_momentum_; -} - -} // namespace GameBall::Logic::Units +#include "GameBall/logic/units/regular_ball.h" + +#include "GameBall/core/game_ball.h" +#include "GameBall/logic/world.h" + +#include +#include + +namespace GameBall::Logic::Units { +short count_ret = 0, count_fallen=0;//count how many times R is pressed. +//count how many balls have fallen +float Y1=0.0f;//record the position of the enemy spheres +const short number_of_balls = 3; +RegularBall::RegularBall(World *world, + uint64_t player_id, + const glm::vec3 &position, + float radius, + float mass) + : Unit(world, player_id) { + radius_ = radius; + mass_ = mass; + position_ = position; + auto physics_world = world_->PhysicsWorld(); + sphere_id_ = physics_world->CreateSphere(); + auto &sphere = physics_world->GetSphere(sphere_id_); + sphere.position = position_; + sphere.SetRadiusMass(radius_, mass_); + sphere.orientation = orientation_; + sphere.velocity = velocity_; + sphere.angular_velocity = glm::vec3{0.0f}; + sphere.elasticity = 1.0f; + sphere.friction = 10.0f; + sphere.gravity = glm::vec3{0.0f, -9.8f, 0.0f}; +} + +RegularBall::~RegularBall() { + ; +} + +SYNC_ACTOR_FUNC(RegularBall) { + auto physics_world = world_->PhysicsWorld(); + auto &sphere = physics_world->GetSphere(sphere_id_); + actor->SetMass(1.0f); + actor->SetGravity(glm::vec3{0.0f, -9.8f, 0.0f}); + actor->SetTransform(glm::mat3{radius_}); + actor->SetMotion(position_, velocity_, orientation_, augular_momentum_); + actor->SetMomentOfInertia(sphere.inertia[0][0]); +} + +void RegularBall::UpdateTick() { + float delta_time = world_->TickDeltaT(); + 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.restart_halt) { + 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 && std::abs(sphere.velocity.y)>=0.01f) { + sphere.angular_velocity = glm::vec3{0.0f}; + } + + if (input.low) { + sphere.mass *= 0.9f; + } + + if (input.high && std::abs(sphere.position.x) < 5.0f && + std::abs(sphere.position.z) < 5.0f && + std::abs(sphere.position.y - 1.0f) < 0.01f) { + sphere.mass *= 1.1f; + } + if (input.v_jump) { + if (std::abs(sphere.position.y - 1.0f) < 0.01f || + std::abs(sphere.position.y - 21.0f) < + 0.01f || + (std::abs(sphere.position.y - 7.0f) < 0.01f && std :: + abs(sphere.position.z)<2.25f&&std::abs(sphere.position.x+35.0f)<2.25f)) + sphere.velocity.y = 10.0f; + } + if (input.return_if_too_light) { + if (sphere.mass <= 0.50f && count_ret < 2) { + sphere.position.y = 1.00f; + sphere.position.x = 0.00f; + sphere.position.z = 0.00f; + sphere.mass = 1.0f; + } + count_ret++; + } + + if (input.end_if_too_heavy && sphere.mass >= 2.0f) { + world_->RemovePlayer(owner->PrimaryUnitId()); + exit(0); + } + if (input.halt) { + std::cout << "Exit?(Y/n)\n"; + char c; + std::cin >> c; + if (c == 'Y' || c == 'y') { + world_->RemovePlayer(owner->PrimaryUnitId()); + exit(0); // This exit is more stable + } + std::cout << "______________Halting______________\n"; + std::cout << "Please enter a 4-digit password:\n"; + termios oldt; + tcgetattr(STDIN_FILENO, &oldt); + termios newt=oldt; + newt.c_lflag &= ~ECHO; + tcsetattr(STDIN_FILENO, TCSANOW, &newt); + std::string password, enter; + char p; + int length = 4; + for (int i = 0; i < length; i++) + std::cin >> p, password += p; + std::cout << "Successfully memorized password, enter again to " + "restart the game:\n"; + int i; + for (i = 0; i < 3; i++) { + std::cin >> enter; + if (enter == password) { + input.halt = false; + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); + break; + } else if (i < 2) + std::cout << "Enter again:\n"; + } + if (i == 3) { + std::cout << "Sorry, but we have to stop now.\n"; + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); + sleep(5000); // Linux:sleep(5000) + world_->RemovePlayer(owner->PrimaryUnitId()); + exit(0); + } + } + if (input.end) { + world_->RemovePlayer(owner->PrimaryUnitId()); + exit(0); + } + } else { + glm::vec3 zero_v{0.0f}; + sphere.velocity = zero_v; + sphere.angular_velocity *= 0; + } + } + } + sphere.velocity *= std::pow(0.5f, delta_time); + sphere.angular_velocity *= std::pow(0.2f, delta_time); + + position_ = sphere.position; + velocity_ = sphere.velocity; + orientation_ = sphere.orientation; + augular_momentum_ = sphere.inertia * sphere.angular_velocity; + + if (owner) { + if (UnitId() != owner->PrimaryUnitId()) { + Y1 = sphere.position.y; + if (Y1 < -160.0f) { + world_->RemovePlayer(player_id_); + count_fallen++; + } + if (UnitId() == owner->SmallUnitId() && sphere.position.x <= -32.75f && + sphere.position.x >= -37.25f && + std::abs(sphere.position.z) <= 2.25f) { + world_->RemovePlayer(owner->PrimaryUnitId()); + std::cerr << "You have lost the game!"; + sleep(3000); + exit(0); + } + } else if (Y1 > sphere.position.y + 10.0f&&sphere.position.y>0.99f || + sphere.position.y < -160.0f) { + world_->RemovePlayer(owner->PrimaryUnitId()); + std::cerr << "You have lost the game!"; + sleep(3000); + exit(0); + } else if (Y1>0.0f&&count_fallen==number_of_balls) { + world_->RemovePlayer(owner->PrimaryUnitId()); + std::cerr << "$$$$$$@@@@@@You have won the game!@@@@@@$$$$$$"; + sleep(10000); + exit(0); + } + } +} + +void RegularBall::SetMass(float mass) { + auto physics_world = world_->PhysicsWorld(); + auto &sphere = physics_world->GetSphere(sphere_id_); + sphere.SetRadiusMass(radius_, mass); + mass_ = mass; +} + +void RegularBall::SetGravity(const glm::vec3 &gravity) { + auto physics_world = world_->PhysicsWorld(); + auto &sphere = physics_world->GetSphere(sphere_id_); + sphere.gravity = gravity; +} + +void RegularBall::SetRadius(float radius) { + auto physics_world = world_->PhysicsWorld(); + auto &sphere = physics_world->GetSphere(sphere_id_); + sphere.SetRadiusMass(radius, mass_); + radius_ = radius; +} + +void RegularBall::SetMotion(const glm::vec3 &position, + const glm::vec3 &velocity, + const glm::mat3 &orientation, + const glm::vec3 &angular_momentum) { + auto physics_world = world_->PhysicsWorld(); + auto &sphere = physics_world->GetSphere(sphere_id_); + sphere.position = position; + sphere.velocity = velocity; + sphere.orientation = orientation; + sphere.angular_velocity = sphere.inertia_inv * angular_momentum; + position_ = position; + velocity_ = velocity; + orientation_ = orientation; + augular_momentum_ = angular_momentum; +} + +glm::vec3 RegularBall::Position() const { + return position_; +} + +glm::vec3 RegularBall::Velocity() const { + return velocity_; +} + +glm::mat3 RegularBall::Orientation() const { + return orientation_; +} + +glm::vec3 RegularBall::AngularMomentum() const { + return augular_momentum_; +} + +} // namespace GameBall::Logic::Units diff --git a/src/GameX/utils/common.cpp b/src/GameX/utils/common.cpp index ca02f43..b0f99b8 100644 --- a/src/GameX/utils/common.cpp +++ b/src/GameX/utils/common.cpp @@ -1,3 +1,2 @@ #include "GameX/utils/common.h" - namespace GameX::Base {}