Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Level design - fixed buying items + global health + new title #123

Merged
merged 5 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Roche-Engine/Components/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ void Entity::SetComponents()

if (GetType() == "LevelTrigger")
{
for (std::shared_ptr<ProjectileManager>& pManager : m_vecProjectileManagers)
pManager->SetOwner(Projectile::ProjectileOwner::LevelTrigger);
m_levelTrigger = std::make_shared<LevelTrigger>(GetCollider());
}
}
Expand Down
2 changes: 1 addition & 1 deletion Roche-Engine/Components/EntityController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct EntityData
{
std::string name;
std::string texture;
std::string type;
std::string type;
std::vector<float> position;
std::vector<float> scale;
float rotation;
Expand Down
16 changes: 16 additions & 0 deletions Roche-Engine/Components/Health.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,16 @@ void Health::AddToEvent() noexcept
{
EventSystem::Instance()->AddClient( EVENTID::PlayerDamage, this );
EventSystem::Instance()->AddClient( EVENTID::PlayerHeal, this );
EventSystem::Instance()->AddClient(EVENTID::SavePlayerHealth, this);
EventSystem::Instance()->AddClient(EVENTID::GetPlayerHealth, this);
}

void Health::RemoveFromEvent() noexcept
{
EventSystem::Instance()->RemoveClient( EVENTID::PlayerDamage, this );
EventSystem::Instance()->RemoveClient( EVENTID::PlayerHeal, this );
EventSystem::Instance()->RemoveClient(EVENTID::SavePlayerHealth, this);
EventSystem::Instance()->RemoveClient(EVENTID::GetPlayerHealth, this);
}

void Health::HandleEvent( Event* event )
Expand All @@ -113,5 +117,17 @@ void Health::HandleEvent( Event* event )
if ( m_sType == "Player" )
Heal( 1 );
break;
case EVENTID::SavePlayerHealth:
if (m_sType == "Player")
{
EventSystem::Instance()->AddEvent(EVENTID::SetPlayerHealth, &m_fCurrentHealth);
}
break;
case EVENTID::GetPlayerHealth:
if (m_sType == "Player")
{
m_fCurrentHealth = *static_cast<float*>(event->GetData());
}
break;
}
}
5 changes: 5 additions & 0 deletions Roche-Engine/Events/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ enum class EVENTID
PlayDayMusic,
PlayShopMusic,
PlayMainMenuMusic,
SavePlayerHealth,
LoadPlayerHealth,
GetPlayerHealth,
SetPlayerHealth,

// Camera Actions
MoveUp,
Expand Down Expand Up @@ -91,6 +95,7 @@ enum class EVENTID
CurrentGamePhase,
BackToMainMenu,
WinWindow,

// PlayerDeath, // Added below, affects UI as well
// GameRestartEvent, // Added in game events, affects UI as well
SwapGameLevelsWindow,
Expand Down
2 changes: 1 addition & 1 deletion Roche-Engine/Graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void Graphics::EndFrame()
m_pBackBuffer->BindNull( m_pContext.Get() );

// Present frame
HRESULT hr = m_pSwapChain->GetSwapChain()->Present( 1u, NULL );
HRESULT hr = m_pSwapChain->GetSwapChain()->Present( 0u, NULL );
if ( FAILED( hr ) )
{
hr == DXGI_ERROR_DEVICE_REMOVED ?
Expand Down
4 changes: 4 additions & 0 deletions Roche-Engine/Input/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ void Input::UpdateKeyboard( const float dt )

if ( m_keyboard.KeyIsPressed( 'K' ) )
EventSystem::Instance()->AddEvent( EVENTID::PlayerHeal );
if (m_keyboard.KeyIsPressed('H'))
{
EventSystem::Instance()->AddEvent(EVENTID::ChangePhase);
}
#endif

if ( keycode == VK_ESCAPE )
Expand Down
9 changes: 9 additions & 0 deletions Roche-Engine/Levels/GameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ GameManager::~GameManager()
EventSystem::Instance()->RemoveClient(EVENTID::PlayDayMusic, this);
EventSystem::Instance()->RemoveClient(EVENTID::PlayShopMusic, this);
EventSystem::Instance()->RemoveClient(EVENTID::PlayMainMenuMusic, this);
EventSystem::Instance()->RemoveClient(EVENTID::SetPlayerHealth, this);
EventSystem::Instance()->RemoveClient(EVENTID::LoadPlayerHealth, this);
EventSystem::Instance()->RemoveClient(EVENTID::UpdateBrightness, this);
EventSystem::Instance()->RemoveClient(EVENTID::UpdateBrightness_Day, this);
}
Expand Down Expand Up @@ -94,6 +96,11 @@ void GameManager::HandleEvent(Event* event)
case EVENTID::PlayMainMenuMusic:
AudioEngine::GetInstance()->PlayAudio("MusicMenu", "MainMenuMusic", MUSIC);
break;
case EVENTID::SetPlayerHealth:
m_fSaveCurrentHealth = *static_cast<float*>(event->GetData());
break;
case EVENTID::LoadPlayerHealth:
EventSystem::Instance()->AddEvent(EVENTID::GetPlayerHealth,&m_fSaveCurrentHealth);
case EVENTID::UpdateBrightness:
kyle-robinson marked this conversation as resolved.
Show resolved Hide resolved
UpdateBrightness();
break;
Expand All @@ -117,6 +124,8 @@ void GameManager::AddToEvent() noexcept
EventSystem::Instance()->AddClient(EVENTID::PlayDayMusic, this);
EventSystem::Instance()->AddClient(EVENTID::PlayShopMusic, this);
EventSystem::Instance()->AddClient(EVENTID::PlayMainMenuMusic, this);
EventSystem::Instance()->AddClient(EVENTID::SetPlayerHealth, this);
EventSystem::Instance()->AddClient(EVENTID::LoadPlayerHealth, this);
EventSystem::Instance()->AddClient(EVENTID::UpdateBrightness, this);
EventSystem::Instance()->AddClient(EVENTID::UpdateBrightness_Day, this);
}
Expand Down
2 changes: 2 additions & 0 deletions Roche-Engine/Levels/GameManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class GameManager : public Listener
float* m_fRedOverlay = new float;
float* m_fGreenOverlay = new float;
float* m_fBlueOverlay = new float;

float m_fSaveCurrentHealth;
};

#endif // !GAMEMANAGER_H
44 changes: 21 additions & 23 deletions Roche-Engine/Objects/ShopItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,21 @@ ShopItem::~ShopItem()

void ShopItem::PlayerInRange(Collider& collider)
{
if(collider.EntityType() == "Player")
{
m_bCollisionCheck = true;

if (m_bInputCheck)
{
if (m_itemName == "HealthPotion")
{
EventSystem::Instance()->AddEvent(EVENTID::BuyPotion);
}
else
{
std::pair<std::string, int>* item = new std::pair<std::string, int>();
item->first = m_itemName;
item->second = 1;
EventSystem::Instance()->AddEvent(EVENTID::UpdateSeed, item);
}
}

m_bInputCheck = false;
}
m_bCollisionCheck = true;
}

void ShopItem::PlayerOutRange(Collider& collider)
{
m_bCollisionCheck = false;
}


void ShopItem::HandleEvent(Event* event)
{
switch (event->GetEventID())
{
case EVENTID::BuySeed:
if(m_bCollisionCheck)
m_bInputCheck = true;
BuyItem();
break;
default:
break;
Expand All @@ -67,6 +47,24 @@ void ShopItem::AddToEvent() noexcept
EventSystem::Instance()->AddClient(EVENTID::BuySeed, this);
}

void ShopItem::BuyItem()
{
if (m_bCollisionCheck)
{
if (m_itemName == "HealthPotion")
{
EventSystem::Instance()->AddEvent(EVENTID::BuyPotion);
}
else
{
std::pair<std::string, int>* item = new std::pair<std::string, int>();
item->first = m_itemName;
item->second = 1;
EventSystem::Instance()->AddEvent(EVENTID::UpdateSeed, item);
}
}
}

void ShopItem::FilterName(std::string name)
{
if (name.contains("Carrot"))
Expand Down
2 changes: 1 addition & 1 deletion Roche-Engine/Objects/ShopItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class ShopItem : public Listener
private:
std::string m_itemName;

bool m_bInputCheck = false;
bool m_bCollisionCheck = false;

// Inherited via Listener
virtual void HandleEvent(Event* event) override;
void AddToEvent() noexcept;

void BuyItem();
void FilterName(std::string name);

int m_iCoins;
Expand Down
6 changes: 3 additions & 3 deletions Roche-Engine/Resources/Entity/Entity_Game.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,11 @@
"bColliderEnabled": true,
"bColliderInteractDecoration": false,
"bColliderInteractEnemy": false,
"bColliderInteractEnemyProjectile": true,
"bColliderInteractEnemyProjectile": false,
"bColliderInteractPlayer": true,
"bColliderInteractPlayerProjectile": true,
"bColliderInteractPlayerProjectile": false,
"bColliderStatic": true,
"bColliderTrigger": true,
"bColliderTrigger": false,
"bProjectileBullet": true,
"bProjectilePattern": true,
"behaviour": "None",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Roche-Engine/Resources/Textures/UI/Title/Title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 27 additions & 12 deletions Roche-Engine/Resources/UI/Screens/Menu_Widgets.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
860.0
],
"type": "Image",
"zindex": 0
"zindex": 1
},
{
"action": "Title Card",
"hide": false,
"name": "Title Card",
"position": [
673.0,
5.0
600.0,
0.0
],
"scale": [
600.0,
600.0
700.0,
700.0
],
"type": "Image",
"zindex": 1
"zindex": 2
},
{
"action": "Link",
Expand All @@ -42,7 +42,7 @@
120.0
],
"type": "Button",
"zindex": 2
"zindex": 3
},
{
"action": "Start",
Expand All @@ -57,7 +57,7 @@
250.0
],
"type": "Button",
"zindex": 3
"zindex": 4
},
{
"action": "Settings",
Expand All @@ -72,7 +72,7 @@
250.0
],
"type": "Button",
"zindex": 4
"zindex": 5
},
{
"action": "Close",
Expand All @@ -87,7 +87,7 @@
250.0
],
"type": "Button",
"zindex": 5
"zindex": 6
},
{
"action": "Credits",
Expand All @@ -102,7 +102,7 @@
120.0
],
"type": "Button",
"zindex": 6
"zindex": 7
},
{
"action": "Leaderboard",
Expand All @@ -117,6 +117,21 @@
250.0
],
"type": "Button",
"zindex": 7
"zindex": 8
},
{
"action": "Backdrop",
"hide": false,
"name": "Backdrop",
"position": [
0.0,
0.0
],
"scale": [
1920.0,
1080.0
],
"type": "Image",
"zindex": 0
}
]
7 changes: 6 additions & 1 deletion Roche-Engine/UI/UIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,26 @@ void UIManager::HandleEvent(Event* event)
case EVENTID::SwapGameLevels:
{
HideAllUI();
// get PLAYER HEALTH
EventSystem::Instance()->AddEvent(EVENTID::SavePlayerHealth);
if (m_sCurrentLevel == *m_vLevelNames[GAME]) {

EventSystem::Instance()->AddEvent(EVENTID::GameLevelChangeEvent, m_vLevelNames[SHOP]);
EventSystem::Instance()->AddEvent(EVENTID::PlayShopMusic);
EventSystem::Instance()->AddEvent(EVENTID::FadeFromBlack);
m_sCurrentLevel = *m_vLevelNames[SHOP];
ShowUI("HUD_Shop");
}
else {

EventSystem::Instance()->AddEvent(EVENTID::GameLevelChangeEvent, m_vLevelNames[GAME]);
EventSystem::Instance()->AddEvent(EVENTID::PlayDayMusic);
EventSystem::Instance()->AddEvent(EVENTID::FadeFromBlack);
m_sCurrentLevel = *m_vLevelNames[GAME];
ShowUI("HUD_Day");
}

//set
EventSystem::Instance()->AddEvent(EVENTID::LoadPlayerHealth);
}
break;
case EVENTID::CloseUIPopUp:
Expand Down
4 changes: 4 additions & 0 deletions Roche-Engine/UI/UIScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,10 @@ void UIScreen::Update( const float dt )
{
m_vWidgets[i]->GetImageWidget()->Resolve("", Colors::AntiqueWhite, "Resources\\Textures\\UI\\Title\\Title.png");
}
if (m_vWidgets[i]->GetAction() == "Backdrop")
{
m_vWidgets[i]->GetImageWidget()->Resolve("", Colors::AntiqueWhite, "Resources\\Textures\\UI\\Backdrop\\Main menu backdrop.png");
}
if ( m_vWidgets[i]->GetAction() == "" )
{
m_vWidgets[i]->GetImageWidget()->Resolve( "", Colors::AntiqueWhite, "Resources\\Textures\\UI\\Board\\Board.png" );
Expand Down