From 0fa67e86c0d48668d0c000cf4037117b9857abc3 Mon Sep 17 00:00:00 2001 From: VisualGMQ <2142587070@qq.com> Date: Thu, 17 Feb 2022 18:48:32 +0800 Subject: [PATCH] fixed bug in fight ship --- HowToPlay.md | 5 ++--- include/game/action.hpp | 4 ++-- src/game/action.cpp | 8 ++++++-- src/game/ai.cpp | 4 ++-- src/game/controllers/fightship_controller.cpp | 7 ++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/HowToPlay.md b/HowToPlay.md index 72c900d..e0bdb23 100644 --- a/HowToPlay.md +++ b/HowToPlay.md @@ -1,8 +1,9 @@ +在命令行中运行`SpaceWar`即可(确保`assets`文件夹在同一目录下) + ![welcome](./snapshot/welcome.png) 开始界面,上方按钮进入游戏,下方按钮退出游戏 - ![select-ship](./snapshot/select_ship.png) 选择飞船和配置阵营界面。左边选择你的飞船(目前只有两架),右边可以配置阵营: @@ -17,7 +18,6 @@ 战斗机和防御机的起始数量是随机的(总数为Plane Number)。 - ![gaming](./snapshot/gaming.png) 游戏界面。 @@ -39,4 +39,3 @@ 胜利条件: 全灭其他所有阵营获得胜利 - diff --git a/include/game/action.hpp b/include/game/action.hpp index ec0e6f3..db2146f 100644 --- a/include/game/action.hpp +++ b/include/game/action.hpp @@ -12,5 +12,5 @@ void MoveUp(MotionCmpt& motion); void MoveDown(MotionCmpt& motion); void SpeedUp(MotionCmpt& motion, FightShipCmpt& ship); void SpeedDown(MotionCmpt& motion, FightShipCmpt& ship); -void TurnLeft(FightShipCmpt& motion); -void TurnRight(FightShipCmpt& motion); +void TurnLeft(MotionCmpt&, FightShipCmpt&); +void TurnRight(MotionCmpt&, FightShipCmpt&); diff --git a/src/game/action.cpp b/src/game/action.cpp index 62f8dd0..a3632dc 100644 --- a/src/game/action.cpp +++ b/src/game/action.cpp @@ -57,10 +57,14 @@ void SpeedDown(MotionCmpt& motion, FightShipCmpt& ship) { ship.degree); } -void TurnLeft(FightShipCmpt& ship) { +void TurnLeft(MotionCmpt& motion, FightShipCmpt& ship) { ship.degree -= FightShipRotationDegree; + motion.speed = Rotate(Point{0, -1} * Len(motion.speed), + ship.degree); } -void TurnRight(FightShipCmpt& ship) { +void TurnRight(MotionCmpt& motion, FightShipCmpt& ship) { ship.degree += FightShipRotationDegree; + motion.speed = Rotate(Point{0, -1} * Len(motion.speed), + ship.degree); } diff --git a/src/game/ai.cpp b/src/game/ai.cpp index fab779d..19a9eb2 100644 --- a/src/game/ai.cpp +++ b/src/game/ai.cpp @@ -62,9 +62,9 @@ void FightShipAI(Entity* self) { auto shipDir = Rotate(Point{0, -1}, self->Get()->degree); auto cross = Cross(shipDir, ndir); if (cross > 0) { - TurnRight(*ship); + TurnRight(*self->Use(), *ship); } else { - TurnLeft(*ship); + TurnLeft(*self->Use(), *ship); } if (abs(Cross(Normalize(motion->speed), Normalize(dir))) < std::sin(Radians(10))) { if (ship->weapon2->bulletAmount > 0 && Random(1.0f, 100.0f) < 5) { diff --git a/src/game/controllers/fightship_controller.cpp b/src/game/controllers/fightship_controller.cpp index cb92dab..ee2023e 100644 --- a/src/game/controllers/fightship_controller.cpp +++ b/src/game/controllers/fightship_controller.cpp @@ -13,10 +13,10 @@ void FightShipController::Update(float dt) { auto motionCmpt = entity_->Use(); auto ship = entity_->Use(); if (IsKeyPressing(GLFW_KEY_A)) { - TurnLeft(*ship); + TurnLeft(*motionCmpt, *ship); } if (IsKeyPressing(GLFW_KEY_D)) { - TurnRight(*ship); + TurnRight(*motionCmpt, *ship); } if (IsKeyPressing(GLFW_KEY_S)) { SpeedDown(*motionCmpt, *ship); @@ -25,9 +25,6 @@ void FightShipController::Update(float dt) { SpeedUp(*motionCmpt, *ship); } - motionCmpt->speed = Rotate(Point{0, -1} * Len(motionCmpt->speed), - ship->degree); - auto moveCmpt = entity_->Get(); if (IsLeftPressing()) {