Skip to content

Commit

Permalink
Level Selection Transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
vedangjavdekar committed Oct 23, 2023
1 parent 1dd224d commit 1e56084
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Engine/src/Engine/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,12 @@ namespace Engine
{
AddEvent(CreateGridStateChangeEvent(ALT_MODE_NC, EDIT_MODE_OFF));
}
#ifdef BUILD_DEBUG
else
{
Close();
}
#endif
break;
}
default:
Expand Down Expand Up @@ -365,6 +367,9 @@ namespace Engine
m_ActionMap.AddAction(ActionType::ALT_MODE, KEY_LEFT_CONTROL, InteractionType::PRESSED, MappingContext::GAME | MappingContext::EDITOR);
m_ActionMap.AddAction(ActionType::NUMBER_MODE, KEY_LEFT_CONTROL, InteractionType::RELEASED, MappingContext::GAME | MappingContext::EDITOR);

m_ActionMap.AddAction(ActionType::ALT_MODE, KEY_RIGHT_CONTROL, InteractionType::PRESSED, MappingContext::GAME | MappingContext::EDITOR);
m_ActionMap.AddAction(ActionType::NUMBER_MODE, KEY_RIGHT_CONTROL, InteractionType::RELEASED, MappingContext::GAME | MappingContext::EDITOR);

m_ActionMap.AddAction(ActionType::BOARD_RESET, KEY_R, InteractionType::PRESSED, MappingContext::GAME | MappingContext::EDITOR | MappingContext::POST_GAME);
m_ActionMap.AddAction(ActionType::SAVE_LEVEL, KEY_F, InteractionType::PRESSED, MappingContext::EDITOR);

Expand Down
22 changes: 19 additions & 3 deletions Engine/src/Engine/LevelSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ namespace Engine

void LevelSelection::ShowMenu()
{
m_SlideTime = 0.0f;
m_AnimationDirection = 1;
m_IsOpen = true;
Application::Get().AddEvent(Event{ EventType::INPUT_LAYER_OPERATION, {(int)InputLayerOperation::PUSH, (int)MappingContext::LEVEL_SELECTION} });
}
Expand Down Expand Up @@ -157,11 +159,21 @@ namespace Engine

void LevelSelection::Update(const float deltaTime)
{
if (!m_IsOpen)
if (!m_IsOpen && (m_AnimationDirection == 0))
{
return;
}

if (m_AnimationDirection != 0)
{
m_SlideTime += m_AnimationDirection * deltaTime;
if (m_SlideTime < 0.0f || m_SlideTime > Settings.SlideTime)
{
m_SlideTime = Clamp(m_SlideTime, 0.0f, Settings.SlideTime);
m_AnimationDirection = 0;
}
}

if (m_Offset != m_TargetOffset)
{
m_TweenTime += deltaTime;
Expand All @@ -182,16 +194,19 @@ namespace Engine

void LevelSelection::Draw(float widthPercent, float heightPercent, float padding)
{
if (!m_IsOpen)
if (!m_IsOpen && (m_AnimationDirection == 0))
{
return;
}

const float absWidth = widthPercent * GetScreenWidth();
const float absHeight = heightPercent * GetScreenHeight();

const float targetX = 0.5f * (GetScreenWidth() - absWidth);
const float currentX = Lerp(GetScreenWidth(), targetX, Easings::EaseInOutCubic(m_SlideTime / Settings.SlideTime));

Rectangle ClientArea = {
0.5f * (GetScreenWidth() - absWidth),
currentX,
0.5f * (GetScreenHeight() - absHeight),
absWidth,
absHeight
Expand Down Expand Up @@ -259,6 +274,7 @@ namespace Engine
}

m_IsOpen = false;
m_AnimationDirection = -1;
}

bool LevelSelection::IsOpen() const
Expand Down
8 changes: 7 additions & 1 deletion Engine/src/Engine/LevelSelection.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ namespace Engine
{
struct ScrollSettings
{
float SlideTime = 0.5f;

int ItemHeight = 50;
int Separation = 5;
int FontSize = 30;
float ScrollMultiplier = 0.5f;
float ScrollTime = 0.5f;

bool WrapAround = true;

};

struct ItemStyle
Expand Down Expand Up @@ -55,7 +58,7 @@ namespace Engine
ItemStyle SelectedItemStyle{ WHITE, ORANGE };
private:
bool m_IsOpen = false;

std::string m_LoadedLevelName;
std::string m_DirectoryPath;
std::vector<std::string> m_LevelNames;
Expand All @@ -69,5 +72,8 @@ namespace Engine

float m_TargetOffset = 0.0f;
float m_StartOffset = 0.0f;

float m_SlideTime = 0.0f;
int m_AnimationDirection = 0;
};
}
12 changes: 12 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,15 @@ The game is feature complete:
- Adding new levels is as easy as dropping a `*.data` file in the required
format in the `data/` directory
- Game comes with 15 levels right now.

# Ideas to explore further

- Using the github repo as a central level database, and fetching all the levels
at the start of the game.
- Getting the community created content through pull
requests.
- Making this project cross platform:
- Scripts for building on Linux and Mac.
- Removing the `WinMain` from the code.
- Find better solutions Level Selection and how it tries to rename every single
level if one of the in betweens are missing.

0 comments on commit 1e56084

Please sign in to comment.