Skip to content

Commit 8a7f8d4

Browse files
authored
Merge pull request gameprogcpp#10 from chalonverse/master
Chapters 13/14
2 parents 999d6ad + fb04980 commit 8a7f8d4

276 files changed

Lines changed: 263575 additions & 139832 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ Release/
88
*.xccheckout
99
*.stackdump
1010
.vs
11-
Chapter15/Assets/Saved.gplevel
12-
Chapter15/Assets/*.bin
11+
Chapter14/Assets/Saved.gplevel
12+
Chapter14/Assets/*.bin
1313
External/FMOD

‎Chapter10/Assets/RacingCar.gpmesh‎

Lines changed: 0 additions & 46594 deletions
This file was deleted.

‎Chapter10/Assets/RacingCar.png‎

-2.62 MB
Binary file not shown.

‎Chapter11/Assets/RacingCar.gpmesh‎

Lines changed: 0 additions & 46594 deletions
This file was deleted.

‎Chapter11/Assets/RacingCar.png‎

-2.62 MB
Binary file not shown.

‎Chapter11/Game.cpp‎

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ void Game::GenerateOutput()
292292

293293
void Game::LoadData()
294294
{
295-
LoadFont("Assets/Carlito-Regular.ttf");
296295
// Load English text
297296
LoadText("Assets/English.gptext");
298297

@@ -349,7 +348,6 @@ void Game::LoadData()
349348
// UI elements
350349
mHUD = new HUD(this);
351350

352-
353351
// Start music
354352
mMusicEvent = mAudioSystem->PlayEvent("event:/Music");
355353

@@ -455,20 +453,6 @@ void Game::PushUI(UIScreen* screen)
455453
mUIStack.emplace_back(screen);
456454
}
457455

458-
void Game::LoadFont(const std::string& fileName)
459-
{
460-
Font* font = new Font(this);
461-
if (font->Load(fileName))
462-
{
463-
mFonts.emplace(fileName, font);
464-
}
465-
else
466-
{
467-
font->Unload();
468-
delete font;
469-
}
470-
}
471-
472456
Font* Game::GetFont(const std::string& fileName)
473457
{
474458
auto iter = mFonts.find(fileName);
@@ -478,7 +462,18 @@ Font* Game::GetFont(const std::string& fileName)
478462
}
479463
else
480464
{
481-
return nullptr;
465+
Font* font = new Font(this);
466+
if (font->Load(fileName))
467+
{
468+
mFonts.emplace(fileName, font);
469+
}
470+
else
471+
{
472+
font->Unload();
473+
delete font;
474+
font = nullptr;
475+
}
476+
return font;
482477
}
483478
}
484479

‎Chapter11/Game.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class Game
4646
GameState GetState() const { return mGameState; }
4747
void SetState(GameState state) { mGameState = state; }
4848

49-
void LoadFont(const std::string& fileName);
5049
class Font* GetFont(const std::string& fileName);
5150

5251
void LoadText(const std::string& fileName);

‎Chapter11/UIScreen.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ void UIScreen::ProcessInput(const uint8_t* keys)
8181
// Get position of mouse
8282
int x, y;
8383
SDL_GetMouseState(&x, &y);
84-
// Convert to (0,0) center coordinates (assume 1024x768)
84+
// Convert to (0,0) center coordinates
8585
Vector2 mousePos(static_cast<float>(x), static_cast<float>(y));
86-
mousePos.x -= 512.0f;
87-
mousePos.y = 384.0f - mousePos.y;
86+
mousePos.x -= mGame->GetRenderer()->GetScreenWidth() * 0.5f;
87+
mousePos.y = mGame->GetRenderer()->GetScreenHeight() * 0.5f - mousePos.y;
8888

8989
// Highlight any buttons
9090
for (auto b : mButtons)

‎Chapter12/Assets/RacingCar.gpmesh‎

Lines changed: 0 additions & 46594 deletions
This file was deleted.

‎Chapter12/Assets/RacingCar.png‎

-2.62 MB
Binary file not shown.

0 commit comments

Comments
 (0)