Skip to content

Commit

Permalink
Add exploding star animation to chlcc intro
Browse files Browse the repository at this point in the history
  • Loading branch information
newo-2001 committed Oct 14, 2024
1 parent 6defe2c commit 7ab5c25
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 67 deletions.
30 changes: 20 additions & 10 deletions profiles/chlcc/hud/titlemenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ root.TitleMenu = {
PressToStartAnimDurationOut = 0.5,
PressToStartSprite = "TitleMenuPressToStart",
IntroBackgroundSprite = "TitleMenuIntroBackground",
IntroBouncingStarSprite = "StarLogo",
IntroSmallStarSprite = "TitleMenuIntroSmallStar",
IntroBigStarSprite = "TitleMenuIntroBigStar",
IntroExplodingStarAnimationDuration = 1.5,
IntroExplodingStarAnimationRotationDuration = 0.5,
IntroExplodingStarAnimationDistance = 315,
BackgroundSprite = "TitleMenuBackground",
DelusionADVUnderSprite = "DelusionADVUnder", -- "DelusionADVUnderEnglish" with the TLed assets, "DelusionADVUnder" with the original ones
DelusionADVUnderX = 78, --74 with the TLed assets, 78 with the original ones
Expand Down Expand Up @@ -243,9 +248,14 @@ root.Sprites["TitleMenuIntroBackground"] = {
Bounds = { X = 0, Y = 0, Width = 1280, Height = 720 },
};

root.Sprites["TitleMenuIntroSmallStar"] = {
Sheet = "Title",
Bounds = { X = 1153, Y = 534, Width = 45, Height = 44 },
};

root.Sprites["TitleMenuIntroBigStar"] = {
Sheet = "Title",
Bounds = { X = 1156, Y = 345, Width = 178, Height = 170 }
Bounds = { X = 1156, Y = 345, Width = 178, Height = 170 },
};

root.Sprites["TitleMenuBackground"] = {
Expand Down Expand Up @@ -326,48 +336,48 @@ root.TitleMenu.IntroStarBounceAnimationPath = {
EndPosition = { X = 1152, Y = 576 },
Duration = 0.72,
EasingX = EasingFunction.Linear,
EasingY = EasingFunction.QuadraticIn
EasingY = EasingFunction.QuadraticIn,
},
{
StartPosition = { X = 1152, Y = 576 },
EndPosition = { X = 1050, Y = 504 },
Duration = 0.3,
EasingX = EasingFunction.Linear,
EasingY = EasingFunction.QuadraticOut
EasingY = EasingFunction.QuadraticOut,
},
{
StartPosition = { X = 1050, Y = 504 },
EndPosition = { X = 960, Y = 576 },
Duration = 0.3,
EasingX = EasingFunction.Linear,
EasingY = EasingFunction.QuadraticIn
EasingY = EasingFunction.QuadraticIn,
},
{
StartPosition = { X = 960, Y = 576 },
EndPosition = { X = 870, Y = 504 },
Duration = 0.3,
EasingX = EasingFunction.Linear,
EasingY = EasingFunction.QuadraticOut
EasingY = EasingFunction.QuadraticOut,
},
{
StartPosition = { X = 870, Y = 504 },
EndPosition = { X = 780, Y = 576 },
Duration = 0.3,
EasingX = EasingFunction.Linear,
EasingY = EasingFunction.QuadraticIn
EasingY = EasingFunction.QuadraticIn,
},
{
StartPosition = { X = 780, Y = 576 },
EndPosition = { X = 704, Y = 252 },
Duration = 0.66,
EasingX = EasingFunction.Linear,
EasingY = EasingFunction.QuadraticOut
EasingY = EasingFunction.QuadraticOut,
},
{
StartPosition = { X = 704, Y = 252 },
EndPosition = { X = 640, Y = 360 },
Duration = 0.4,
EasingX = EasingFunction.Linear,
EasingY = EasingFunction.QuadraticIn
}
}
EasingY = EasingFunction.QuadraticIn,
},
};
67 changes: 55 additions & 12 deletions src/games/chlcc/titlemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ void TitleMenu::Hide() {
void TitleMenu::Update(float dt) {
UpdateInput();
IntroStarBounceAnimation.Update(dt);
IntroExplodingStarAnimation.Update(dt);
IntroExplodingStarRotationAnimation.Update(dt);
PressToStartAnimation.Update(dt);
SpinningCircleAnimation.Update(dt);
PrimaryFadeAnimation.Update(dt);
Expand Down Expand Up @@ -380,7 +382,6 @@ void TitleMenu::Render() {
if (ScrWork[SW_MENUCT] < 64) {
switch (ScrWork[SW_TITLEDISPCT]) {
case 0: { // Initial animation
Renderer->DrawSprite(IntroBackgroundSprite, glm::vec2(0.0f));
DrawIntroAnimation();
} break;
case 1: { // Press to start
Expand Down Expand Up @@ -448,20 +449,62 @@ void TitleMenu::Render() {
}

inline void TitleMenu::DrawIntroAnimation() {
if (IntroStarBounceAnimation.State == AS_Stopped &&
IntroStarBounceAnimation.IsOut()) {
IntroStarBounceAnimation.StartOut(true);
} else if (IntroStarBounceAnimation.State == AS_Playing) {
if (IntroStarBounceAnimation.GetCurrentSegmentIndex() == 5 &&
Audio::Channels[Audio::AC_SE0]->State == ACS_Paused) {
Audio::Channels[Audio::AC_SE0]->Resume();
Renderer->DrawSprite(IntroBackgroundSprite, glm::vec2(0.0f));

switch (TitleMenuIntroAnimationState) {
case TitleMenuIntroAnimationState::Out: {
IntroStarBounceAnimation.StartIn();
TitleMenuIntroAnimationState = TitleMenuIntroAnimationState::BouncingStar;
return;
}
case TitleMenuIntroAnimationState::BouncingStar: {
if (IntroStarBounceAnimation.GetCurrentSegmentIndex() == 1 &&
Audio::Channels[Audio::AC_SE0]->State == ACS_Paused) {
Audio::Channels[Audio::AC_SE0]->Resume();
}

glm::vec2 position = IntroStarBounceAnimation.GetPosition() -
IntroBouncingStarSprite.Bounds.Dimensions() / 2.0f;

glm::vec2 starPosition = IntroStarBounceAnimation.GetPosition() -
glm::vec2(StarLogoSprite.Bounds.Width / 2,
StarLogoSprite.Bounds.Height / 2);
Renderer->DrawSprite(StarLogoSprite, position);

Renderer->DrawSprite(StarLogoSprite, starPosition);
if (IntroStarBounceAnimation.IsIn()) {
TitleMenuIntroAnimationState =
TitleMenuIntroAnimationState::ExplodingStar;
IntroExplodingStarAnimation.StartIn();
IntroExplodingStarRotationAnimation.StartIn();
}

return;
}
case TitleMenuIntroAnimationState::ExplodingStar: {
glm::vec2 origin = IntroStarBounceAnimation.GetPosition() -
IntroBouncingStarSprite.Bounds.Dimensions() / 2.0f;
constexpr size_t NUM_STARS = 5;
for (size_t i = 0; i < NUM_STARS; i++) {
float rayAngle = M_PI_2 - M_PI * 2 / NUM_STARS * i;
glm::vec2 directionVector(std::cos(rayAngle), -std::sin(rayAngle));
glm::vec2 displacement = directionVector *
IntroExplodingStarAnimation.Progress *
IntroExplodingStarAnimationDistance;
glm::vec2 position = origin + displacement;

float opacity = 1 - IntroExplodingStarAnimation.Progress;
float angle = M_PI * 2 * IntroExplodingStarRotationAnimation.Progress;
if (i >= 3) angle = -angle;

Renderer->DrawSprite(IntroSmallStarSprite, position,
{1.0f, 1.0f, 1.0f, opacity}, {1.0f, 1.0f}, angle);
}

if (IntroExplodingStarAnimation.IsOut()) {
TitleMenuIntroAnimationState =
TitleMenuIntroAnimationState::FallingStars;
IntroExplodingStarRotationAnimation.State = AS_Stopped;
}

return;
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/games/chlcc/titlemenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Impacto {
namespace UI {
namespace CHLCC {

BETTER_ENUM(TitleMenuIntroAnimationState, int, Out, BouncingStar, ExplodingStar, FallingStars, In)

class TitleMenu : public Menu {
public:
TitleMenu();
Expand All @@ -26,7 +28,10 @@ class TitleMenu : public Menu {
Animation ItemsFadeInAnimation;
Animation SecondaryItemsFadeInAnimation;
Animation SpinningCircleAnimation;

PathAnimation IntroStarBounceAnimation;
Animation IntroExplodingStarAnimation;
Animation IntroExplodingStarRotationAnimation;

void MenuButtonOnClick(Widgets::Button* target);
void SecondaryButtonOnClick(Widgets::Button* target);
Expand Down Expand Up @@ -58,6 +63,9 @@ class TitleMenu : public Menu {
Widgets::Group* SystemItems;
Widgets::CHLCC::TitleButton* Config;
Widgets::CHLCC::TitleButton* SystemSave;

TitleMenuIntroAnimationState TitleMenuIntroAnimationState =
TitleMenuIntroAnimationState::Out;
};

} // namespace CHLCC
Expand Down
3 changes: 2 additions & 1 deletion src/io/physicalfilestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ IoError PhysicalFileStream::Create(std::string const& fileName, Stream** out,
PhysicalFileStream* result = new PhysicalFileStream(fileName, flags);
if (result->ErrorCode != IoError_OK) {
ImpLog(LL_Error, LC_IO, "Failed to open file \"%s\"\n", fileName.c_str());
IoError error = result->ErrorCode;
delete result;
return result->ErrorCode;
return error;
}
if (!result->FileStream) {
ImpLog(LL_Error, LC_IO, "Failed to open file \"%s\", error: \"%s\"\n",
Expand Down
14 changes: 7 additions & 7 deletions src/pathanimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ float Ease(float progress, EasingFunction function) {
switch (function) {
case EasingFunction::Linear: {
return progress;
} break;
}
case EasingFunction::QuadraticIn: {
return progress * progress;
} break;
}
case EasingFunction::QuadraticOut: {
return 1 - (1 - progress) * (1 - progress);
} break;
}
case EasingFunction::CubicIn: {
return progress * progress * progress;
} break;
}
case EasingFunction::CubicOut: {
return 1 - std::powf(1 - progress, 3);

Check failure on line 21 in src/pathanimation.cpp

View workflow job for this annotation

GitHub Actions / linux

‘powf’ is not a member of ‘std’; did you mean ‘pow’?
} break;
}
}
}

Check warning on line 24 in src/pathanimation.cpp

View workflow job for this annotation

GitHub Actions / windows

'Impacto::Ease': not all control paths return a value

PathAnimation::PathAnimation(std::vector<PathSegment> path) : Path(path) {
float totalDuration = 0;
for (PathSegment& segment : path) {
for (const PathSegment& segment : path) {
totalDuration += segment.Duration;
}

Expand Down Expand Up @@ -57,7 +57,7 @@ void PathAnimation::UpdateImpl(float dt) {
float segmentEndProgress = Direction == 1 ? 0 : 1;
size_t segment = Direction == 1 ? 0 : Path.size() - 1;
size_t end = Direction == 1 ? Path.size() : -1;

while (segment != end) {
float segmentStartProgress = segmentEndProgress;
segmentEndProgress += Path[segment].Duration / this->DurationIn * Direction;
Expand Down
2 changes: 1 addition & 1 deletion src/pathanimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ float Ease(float progress, EasingFunction function = EasingFunction::Linear);
struct PathSegment {
glm::vec2 StartPosition;
glm::vec2 EndPosition;
float Duration;
float Duration = 0;
EasingFunction EasingX = EasingFunction::Linear;
EasingFunction EasingY = EasingX;
};
Expand Down
18 changes: 18 additions & 0 deletions src/profile/games/chlcc/titlemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ namespace TitleMenu {

void Configure() {
IntroBackgroundSprite = EnsureGetMemberSprite("IntroBackgroundSprite");
IntroBouncingStarSprite = EnsureGetMemberSprite("IntroBouncingStarSprite");
IntroSmallStarSprite = EnsureGetMemberSprite("IntroSmallStarSprite");
IntroBigStarSprite = EnsureGetMemberSprite("IntroBigStarSprite");
IntroExplodingStarAnimationDuration =
EnsureGetMemberFloat("IntroExplodingStarAnimationDuration");
IntroExplodingStarAnimationRotationDuration =
EnsureGetMemberFloat("IntroExplodingStarAnimationRotationDuration");
IntroExplodingStarAnimationDistance =
EnsureGetMemberFloat("IntroExplodingStarAnimationDistance");
BackgroundSprite = EnsureGetMemberSprite("BackgroundSprite");
DelusionADVUnderSprite = EnsureGetMemberSprite("DelusionADVUnderSprite");
DelusionADVUnderX = EnsureGetMemberFloat("DelusionADVUnderX");
Expand Down Expand Up @@ -142,6 +150,16 @@ void Configure() {
IntroStarBounceAnimationPath,
IntroStarBounceAnimationPath + IntroStarBounceAnimationSegmentCount
));

menu->IntroExplodingStarRotationAnimation.LoopMode = ALM_Loop;
menu->IntroExplodingStarRotationAnimation.DurationIn =
IntroExplodingStarAnimationRotationDuration;
menu->IntroExplodingStarRotationAnimation.DurationOut =
IntroExplodingStarAnimationRotationDuration;

menu->IntroExplodingStarAnimation.DurationIn = IntroExplodingStarAnimationDuration;
menu->IntroExplodingStarAnimation.DurationOut =
IntroExplodingStarAnimationDuration;

UI::TitleMenuPtr = menu;

Expand Down
Loading

0 comments on commit 7ab5c25

Please sign in to comment.