Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cpp-project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Maul
cpp-project
Commits
44f27529
Commit
44f27529
authored
5 months ago
by
Frederik
Browse files
Options
Downloads
Patches
Plain Diff
Add display for players money
parent
dcbb784f
No related branches found
No related tags found
1 merge request
!56
Add display for players money
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/game/level/Level.cpp
+2
-0
2 additions, 0 deletions
src/game/level/Level.cpp
src/game/player/Player.cpp
+38
-0
38 additions, 0 deletions
src/game/player/Player.cpp
src/game/player/Player.hpp
+2
-0
2 additions, 0 deletions
src/game/player/Player.hpp
with
42 additions
and
0 deletions
src/game/level/Level.cpp
+
2
−
0
View file @
44f27529
...
@@ -429,6 +429,8 @@ void Level::render(Engine& engine)
...
@@ -429,6 +429,8 @@ void Level::render(Engine& engine)
m_recruitingMenu
.
render
(
engine
);
m_recruitingMenu
.
render
(
engine
);
}
}
m_turnQ
.
front
().
renderMoney
(
engine
,
RENDERING_SCALE
);
if
(
m_showUnitInfoMenu
)
if
(
m_showUnitInfoMenu
)
{
{
m_unitInfoMenu
.
render
(
engine
);
m_unitInfoMenu
.
render
(
engine
);
...
...
This diff is collapsed.
Click to expand it.
src/game/player/Player.cpp
+
38
−
0
View file @
44f27529
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
*/
*/
#include
"Player.hpp"
#include
"Player.hpp"
#include
<SDL_ttf.h>
#include
<iostream>
#include
<iostream>
namespace
advanced_wars
namespace
advanced_wars
...
@@ -107,4 +108,41 @@ void Player::spendMoney(int toSpend)
...
@@ -107,4 +108,41 @@ void Player::spendMoney(int toSpend)
{
{
m_money
-=
toSpend
;
m_money
-=
toSpend
;
}
}
void
Player
::
renderMoney
(
Engine
&
engine
,
int
scale
)
{
if
(
TTF_Init
()
==
-
1
)
{
return
;
}
TTF_Font
*
font
=
TTF_OpenFont
(
"res/ARCADECLASSIC.TTF"
,
16
);
SDL_Rect
backdrop
=
{
0
,
0
,
75
*
scale
,
40
*
scale
};
SDL_Rect
textRect
=
{
4
*
scale
,
3
*
scale
,
70
*
scale
,
35
*
scale
};
SDL_Rect
outline
=
{
0
,
0
,
77
*
scale
,
42
*
scale
};
SDL_SetRenderDrawBlendMode
(
engine
.
renderer
(),
SDL_BlendMode
::
SDL_BLENDMODE_BLEND
);
SDL_SetRenderDrawColor
(
engine
.
renderer
(),
255
,
255
,
255
,
200
);
SDL_RenderFillRect
(
engine
.
renderer
(),
&
outline
);
SDL_SetRenderDrawColor
(
engine
.
renderer
(),
75
,
87
,
219
,
200
);
SDL_RenderFillRect
(
engine
.
renderer
(),
&
backdrop
);
std
::
string
money
=
std
::
to_string
(
m_money
);
SDL_Surface
*
textSurface
=
TTF_RenderUTF8_Solid
(
font
,
money
.
c_str
(),
{
200
,
200
,
0
,
200
});
SDL_Texture
*
textTexture
=
SDL_CreateTextureFromSurface
(
engine
.
renderer
(),
textSurface
);
SDL_RenderCopy
(
engine
.
renderer
(),
textTexture
,
NULL
,
&
textRect
);
SDL_FreeSurface
(
textSurface
);
SDL_DestroyTexture
(
textTexture
);
TTF_CloseFont
(
font
);
TTF_Quit
();
}
}
// namespace advanced_wars
}
// namespace advanced_wars
This diff is collapsed.
Click to expand it.
src/game/player/Player.hpp
+
2
−
0
View file @
44f27529
...
@@ -62,6 +62,8 @@ class Player
...
@@ -62,6 +62,8 @@ class Player
*/
*/
void
spendMoney
(
int
toSpend
);
void
spendMoney
(
int
toSpend
);
void
renderMoney
(
Engine
&
engine
,
int
scale
);
private:
private:
int
m_money
;
// The players current amound of money
int
m_money
;
// The players current amound of money
bool
m_alive
;
// Signals if the player is alive or not
bool
m_alive
;
// Signals if the player is alive or not
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment