diff options
Diffstat (limited to 'src/mrsun.cpp')
-rwxr-xr-x | src/mrsun.cpp | 196 |
1 files changed, 130 insertions, 66 deletions
diff --git a/src/mrsun.cpp b/src/mrsun.cpp index 0b2c798..5c20169 100755 --- a/src/mrsun.cpp +++ b/src/mrsun.cpp @@ -17,10 +17,14 @@ class daMrSun_c : public dEn_c { float yThreshold; float yAccel; Vec swoopTarget; - float slope; u32 timer; float xSpiralOffset; float ySpiralOffset; + float swoopA; + float swoopB; + float swoopC; + float swoopSpeed; + static daMrSun_c *build(); @@ -65,11 +69,20 @@ int daMrSun_c::onCreate() { OSReport("Creating the Mr.Sun Model"); allocator.link(-1, GameHeaps[0], 0, 0x20); - nw4r::g3d::ResFile rf(getResource("bilikyu", "g3d/sun.brres")); - model.setup(rf.GetResMdl("Sun"), &allocator, 0x224, 1, 0); -// SetupTextures_Enemy(&model, 0); - SetupTextures_Map(&model, 0); - + if (this->settings == 0) { // It's a sun + nw4r::g3d::ResFile rf(getResource("bilikyu", "g3d/sun.brres")); + model.setup(rf.GetResMdl("Sun"), &allocator, 0x224, 1, 0); + // SetupTextures_Enemy(&model, 0); + SetupTextures_Map(&model, 0); + } + + else { // It's a moon + nw4r::g3d::ResFile rf(getResource("bilikyu", "g3d/bilikyu.brres")); + model.setup(rf.GetResMdl("bilikyu"), &allocator, 0x224, 1, 0); + // SetupTextures_Enemy(&model, 0); + SetupTextures_Map(&model, 0); + } + allocator.unlink(); OSReport("Setting Mr.Sun's Size to 4.0"); @@ -156,11 +169,19 @@ void daMrSun_c::executeState_Follow() { this->direction = dSprite_c__getXDirectionOfFurthestPlayerRelativeToVEC3(this, this->pos); + float speedDelta; + if (this->settings == 0) { speedDelta = 0.1; } // It's a sun + else { speedDelta = 0.15; } // It's a moon + if (this->direction == 0) { - this->speed.x = this->speed.x + 0.1; + this->speed.x = this->speed.x + speedDelta; + + if (this->speed.x < 0) { this->speed.x = this->speed.x + (speedDelta / 2); } } else { - this->speed.x = this->speed.x - 0.1; + this->speed.x = this->speed.x - speedDelta; + + if (this->speed.x > 0) { this->speed.x = this->speed.x - (speedDelta / 2); } } HandleXSpeed(this); @@ -190,49 +211,51 @@ void daMrSun_c::endState_Follow() { void daMrSun_c::beginState_Swoop() { OSReport("Swooping down from above, Mr.Sun falls down."); - dStageActor_c *Player = GetSpecificPlayerActor(0); - if (Player == 0) { Player = GetSpecificPlayerActor(1); } - if (Player == 0) { Player = GetSpecificPlayerActor(2); } - if (Player == 0) { Player = GetSpecificPlayerActor(3); } - if (Player == 0) { doStateChange(&StateID_Follow); } + // Not enough space to swoop, spit instead. + if (this->swoopTarget.y < (this->pos.y - 50)) { doStateChange(&StateID_Spit); } + if ((this->pos.x - 64) < this->swoopTarget.x < (this->pos.x + 64)) { doStateChange(&StateID_Spit); } + + if (this->settings == 0) { + this->swoopTarget.y = this->swoopTarget.y - 16; + } // It's a sun - this->swoopTarget = Player->pos; - this->swoopTarget.y = this->swoopTarget.y - 24; + else { + this->swoopTarget.y = this->swoopTarget.y - 4; + } // It's a moon + + + float x1, x2, x3, y1, y2, y3; + + x1 = this->pos.x - this->swoopTarget.x; + x2 = 0; + x3 = -x1; + + y1 = this->pos.y - this->swoopTarget.y; + y2 = 0; + y3 = y1; + + float denominator = (x1 - x2) * (x1 - x3) * (x2 - x3); + this->swoopA = (x3 * (y2 - y1) + x2 * (y1 - y3) + x1 * (y3 - y2)) / denominator; + this->swoopB = (x3*x3 * (y1 - y2) + x2*x2 * (y3 - y1) + x1*x1 * (y2 - y3)) / denominator; + this->swoopC = (x2 * x3 * (x2 - x3) * y1 + x3 * x1 * (x3 - x1) * y2 + x1 * x2 * (x1 - x2) * y3) / denominator; - float relativeSunX = this->swoopTarget.x - this->pos.x; - float relativeSunY = this->swoopTarget.y - this->pos.y; + this->swoopSpeed = x3 * 2 / 75; - this->slope = relativeSunY / relativeSunX; } void daMrSun_c::executeState_Swoop() { - - if (this->slope < 0.0) { - this->speed.x = this->speed.x + 0.3; - this->speed.y = this->speed.y - (0.2 * -slope); - } - else if (this->slope > 0.0) { - this->speed.x = this->speed.x - 0.3; - this->speed.y = this->speed.y - (0.2 * slope); - } + // Everything is calculated up top, just need to modify it. - float yDiff; + this->pos.x = this->pos.x + this->swoopSpeed; - if (this->pos.y < this->swoopTarget.y) { - this->speed.x = this->speed.x * 0.2; - this->speed.y = this->speed.y * 0.2; - } - - HandleXSpeed(this); - HandleYSpeed(this); - UpdateObjectPosBasedOnSpeedValues_real(this); + this->pos.y = ( this->swoopA*(this->pos.x - this->swoopTarget.x)*(this->pos.x - this->swoopTarget.x) + this->swoopB*(this->pos.x - this->swoopTarget.x) + this->swoopC ) + this->swoopTarget.y; + + if (this->pos.y > this->Baseline) { doStateChange(&StateID_Follow); } - if (this->pos.y < this->swoopTarget.y) { - if (this->speed.y < 0.1) { doStateChange(&StateID_Follow); } } - } void daMrSun_c::endState_Swoop() { OSReport("Returning to the sky, Mr.Sun flies into the sunset."); + this->speed.y = 0; } @@ -249,14 +272,16 @@ void daMrSun_c::beginState_Spiral() { void daMrSun_c::executeState_Spiral() { float Loops; - float Period; float Magnitude; + float Period; Loops = 6.0; - // Use a period of 0.1 for the moon - Period = 0.075; Magnitude = 11.0; + // Use a period of 0.1 for the moon + if (this->settings == 0) { Period = 0.075; } // It's a sun + else { Period = 0.1; } // It's a moon + this->pos.x = this->xSpiralOffset + Magnitude*((this->SpiralLoop * cos(this->SpiralLoop))); this->pos.y = this->ySpiralOffset + Magnitude*((this->SpiralLoop * sin(this->SpiralLoop))); @@ -285,17 +310,36 @@ void daMrSun_c::executeState_Spit() { float neg = -1.0; if (this->direction == 0) { neg = 1.0; } - dStageActor_c *spawner = CreateActor(106, 0, this->pos, 0, 0); - spawner->speed.x = 6.0 * neg; - spawner->speed.y = -2.5; + + if (this->settings == 0) { + dStageActor_c *spawner = CreateActor(106, 0, this->pos, 0, 0); + spawner->speed.x = 6.0 * neg; + spawner->speed.y = -2.5; + + spawner = CreateActor(106, 0, this->pos, 0, 0); + spawner->speed.x = 0.0 * neg; + spawner->speed.y = -6.0; - spawner = CreateActor(106, 0, this->pos, 0, 0); - spawner->speed.x = 0.0 * neg; - spawner->speed.y = -6.0; - - spawner = CreateActor(106, 0, this->pos, 0, 0); - spawner->speed.x = 3.5 * neg; - spawner->speed.y = -6.0; + spawner = CreateActor(106, 0, this->pos, 0, 0); + spawner->speed.x = 3.5 * neg; + spawner->speed.y = -6.0; + } // It's a sun + + + else { + dStageActor_c *spawner = CreateActor(118, 0, this->pos, 0, 0); + spawner->speed.x = 6.0 * neg; + spawner->speed.y = -2.5; + + spawner = CreateActor(118, 0, this->pos, 0, 0); + spawner->speed.x = 0.0 * neg; + spawner->speed.y = -6.0; + + spawner = CreateActor(118, 0, this->pos, 0, 0); + spawner->speed.x = 3.5 * neg; + spawner->speed.y = -6.0; + } // It's a moon + } this->timer = this->timer + 1; @@ -330,8 +374,8 @@ void daMrSun_c::executeState_Spin() { if (this->timer < 60) { rotBonus = this->timer; } else { rotBonus = 120 - this->timer; } - this->rot.x = this->rot.x + (50 * rotBonus); - this->rot.y = this->rot.y + (50 * rotBonus); +// this->rot.x = this->rot.x + (50 * rotBonus); + this->rot.z = this->rot.z + (50 * rotBonus); int randomBall; randomBall = GenerateRandomNumber(6); @@ -368,14 +412,22 @@ void daMrSun_c::executeState_Spin() { ylaunch = -7.5; } - dStageActor_c *spawner = CreateActor(106, 0, this->pos, 0, 0); - spawner->speed.x = xlaunch; - spawner->speed.y = ylaunch; + if (this->settings == 0) { + dStageActor_c *spawner = CreateActor(106, 0, this->pos, 0, 0); + spawner->speed.x = xlaunch; + spawner->speed.y = ylaunch; + } // It's a sun + + else { + dStageActor_c *spawner = CreateActor(118, 0, this->pos, 0, 0); + spawner->speed.x = xlaunch; + spawner->speed.y = ylaunch; + } // It's a moon } if (this->timer > 120) { - this->rot.x = this->rot.x / 2; - this->rot.y = this->rot.y / 2; +// this->rot.x = this->rot.x / 2; +// this->rot.y = this->rot.y / 2; this->doStateChange(&StateID_Follow); } } @@ -401,21 +453,33 @@ void daMrSun_c::beginState_Wait() { this->rot.x = 11000; this->rot.y = 0; // this->rot.z = 11000; + + dStageActor_c *Player = GetSpecificPlayerActor(0); + if (Player == 0) { Player = GetSpecificPlayerActor(1); } + if (Player == 0) { Player = GetSpecificPlayerActor(2); } + if (Player == 0) { Player = GetSpecificPlayerActor(3); } + if (Player == 0) { doStateChange(&StateID_Follow); } + + this->swoopTarget = Player->pos; } void daMrSun_c::executeState_Wait() { int Choice; - - if (this->timer > 20) { + int TimerMax; + + if (this->settings == 0) { TimerMax = 20; } // It's a sun + else { TimerMax = 15; } // It's a moon + + if (this->timer > TimerMax) { // doStateChange(&StateID_Spit); - Choice = GenerateRandomNumber(1); + Choice = GenerateRandomNumber(6); OSReport("Choice: %d", Choice); - if (Choice == 0) { doStateChange(&StateID_Swoop); } -// else if (Choice == 1) { doStateChange(&StateID_Spin); } -// else if (Choice == 2) { doStateChange(&StateID_Swoop); } -// else if (Choice == 3) { doStateChange(&StateID_Spiral); } + if (Choice == 0) { doStateChange(&StateID_Spit); } + else if (Choice == 1) { doStateChange(&StateID_Spin); } + else if (Choice == 2) { doStateChange(&StateID_Spiral); } + else { doStateChange(&StateID_Swoop); } } |