fixed bug in fight ship

This commit is contained in:
VisualGMQ 2022-02-17 18:48:32 +08:00
parent 1d7a4618f5
commit 0fa67e86c0
5 changed files with 14 additions and 14 deletions

View File

@ -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 @@
胜利条件:
全灭其他所有阵营获得胜利

View File

@ -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&);

View File

@ -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);
}

View File

@ -62,9 +62,9 @@ void FightShipAI(Entity* self) {
auto shipDir = Rotate(Point{0, -1}, self->Get<FightShipCmpt>()->degree);
auto cross = Cross(shipDir, ndir);
if (cross > 0) {
TurnRight(*ship);
TurnRight(*self->Use<MotionCmpt>(), *ship);
} else {
TurnLeft(*ship);
TurnLeft(*self->Use<MotionCmpt>(), *ship);
}
if (abs(Cross(Normalize(motion->speed), Normalize(dir))) < std::sin(Radians(10))) {
if (ship->weapon2->bulletAmount > 0 && Random(1.0f, 100.0f) < 5) {

View File

@ -13,10 +13,10 @@ void FightShipController::Update(float dt) {
auto motionCmpt = entity_->Use<MotionCmpt>();
auto ship = entity_->Use<FightShipCmpt>();
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<MoveCmpt>();
if (IsLeftPressing()) {