From 82a9161028b88e75c24789269bba7fc04a18e56f Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 16 Apr 2023 19:49:16 -0500 Subject: [PATCH] SHOOTME2 is now a thing instead of being ISHOOT (AI will be for a different enemy) --- Faceball2030/Editor.h | 2 ++ Faceball2030/assets/map/map1.map | 4 ++-- Faceball2030/main.cpp | 38 +++++++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Faceball2030/Editor.h b/Faceball2030/Editor.h index f80de93..d5e988c 100644 --- a/Faceball2030/Editor.h +++ b/Faceball2030/Editor.h @@ -11,7 +11,9 @@ enum EnemyID { EXIT, START, SHOOTME, + SHOOTME2, ISHOOT, + ISHOOT2, SONAR, COIN = 56, POWERUP_ARMOR = 57, diff --git a/Faceball2030/assets/map/map1.map b/Faceball2030/assets/map/map1.map index d8fb2c4..4ece5d2 100644 --- a/Faceball2030/assets/map/map1.map +++ b/Faceball2030/assets/map/map1.map @@ -3,13 +3,13 @@ 32777 32778 8202 -8200 +8728 24584 8204 40965 57753 24584 -8192 +25104 8192 16788 8197 diff --git a/Faceball2030/main.cpp b/Faceball2030/main.cpp index 0654b55..b4bce21 100644 --- a/Faceball2030/main.cpp +++ b/Faceball2030/main.cpp @@ -93,7 +93,7 @@ void FaceBall::InitializeEnemyData() { enemyData[EXIT] = { "EXIT",undefined,GREEN }; enemyData[START] = { "SPAWN POSITION",undefined,{128,64,0} }; enemyData[SHOOTME] = { "SHOOTME",enemy_ShootMe,YELLOW,1,1,PI / 8,2,1 }; - enemyData[ISHOOT] = { "ISHOOT",enemy_IShoot,YELLOW,1,1,PI / 6,2,1,0.4f }; + enemyData[SHOOTME2] = { "SHOOTME2",enemy_IShoot,YELLOW,1,1,PI / 6,2,1,0.5f }; enemyData[SONAR] = { "Sonar",enemy_Sonar,RED,5,1,PI / 8,2,1 }; enemyData[COIN] = { "Coin",undefined,BLUE }; enemyData[POWERUP_ARMOR] = { "Armor",undefined,{96,0,96} }; @@ -1532,12 +1532,38 @@ void FaceBall::RunEnemyAI(Enemy& e,float fElapsedTime,int myIndex) { case SHOOTME: { e.rot += 0.5 * fElapsedTime; }break; - case ISHOOT: { + case SHOOTME2: { switch (e.GetPhase()) { case Phase::DEFAULT: { - vf2d movementVec = {std::cosf(e.rot) * dat.movSpd * fElapsedTime,std::sinf(e.rot) * dat.movSpd * fElapsedTime }; - if (-1==CheckEnemyCollision({ movementVec.x,0,movementVec.y },{e.pos.x,e.pos.z},e.radius,myIndex)&& - !CheckCollision({movementVec.x,0,movementVec.y},{e.pos.x,e.pos.z}, e.radius)) { + vf2d movementVec = { std::cosf(e.rot) * dat.movSpd * fElapsedTime,std::sinf(e.rot) * dat.movSpd * fElapsedTime }; + if (-1 == CheckEnemyCollision({ movementVec.x,0,movementVec.y }, { e.pos.x,e.pos.z }, e.radius, myIndex) && + !CheckCollision({ movementVec.x,0,movementVec.y }, { e.pos.x,e.pos.z }, e.radius)) { + e.pos.x += movementVec.x; + e.pos.z += movementVec.y; + } + else { + e.SetPhase(Phase::TURNING); + e.turnAmt = PI; + } + }break; + case Phase::TURNING: { + if (e.turnAmt > 0) { + float rotAmt = std::min(e.turnAmt, dat.rotSpd * fElapsedTime); + e.turnAmt -= rotAmt; + e.rot += rotAmt; + if (e.turnAmt <= 0) { + e.SetPhase(Phase::DEFAULT); + } + } + }break; + } + }break; + case ISHOOT2: { + switch (e.GetPhase()) { + case Phase::DEFAULT: { + vf2d movementVec = { std::cosf(e.rot) * dat.movSpd * fElapsedTime,std::sinf(e.rot) * dat.movSpd * fElapsedTime }; + if (-1 == CheckEnemyCollision({ movementVec.x,0,movementVec.y }, { e.pos.x,e.pos.z }, e.radius, myIndex) && + !CheckCollision({ movementVec.x,0,movementVec.y }, { e.pos.x,e.pos.z }, e.radius)) { e.pos.x += movementVec.x; e.pos.z += movementVec.y; if (e.CanShoot()) { @@ -1551,7 +1577,7 @@ void FaceBall::RunEnemyAI(Enemy& e,float fElapsedTime,int myIndex) { }break; case Phase::TURNING: { if (e.turnAmt > 0) { - float rotAmt = std::min(e.turnAmt,dat.rotSpd * fElapsedTime); + float rotAmt = std::min(e.turnAmt, dat.rotSpd * fElapsedTime); e.turnAmt -= rotAmt; e.rot += rotAmt; if (e.turnAmt <= 0) {