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
21e608fb
Commit
21e608fb
authored
6 months ago
by
Frederik
Browse files
Options
Downloads
Patches
Plain Diff
Add checks for attacking allies and debug output for clicking non valid target
parent
b5ffe3d9
Branches
Branches containing commit
No related tags found
2 merge requests
!29
Merge main into box2d to implement physics
,
!20
Level event handler
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/game/Level.cpp
+14
-2
14 additions, 2 deletions
src/game/Level.cpp
src/game/Unit.cpp
+5
-0
5 additions, 0 deletions
src/game/Unit.cpp
src/game/Unit.hpp
+2
-0
2 additions, 0 deletions
src/game/Unit.hpp
with
21 additions
and
2 deletions
src/game/Level.cpp
+
14
−
2
View file @
21e608fb
...
...
@@ -411,9 +411,17 @@ void Level::handleAttackingEvents(Engine& engine, SDL_Event& event)
if
(
event
.
button
.
button
==
SDL_BUTTON_LEFT
)
{
std
::
pair
<
int
,
int
>
tilePos
=
calcTilePos
(
event
.
button
.
x
,
event
.
button
.
y
);
int
targetedUnit
;
if
((
targetedUnit
=
selectUnit
(
tilePos
.
first
,
tilePos
.
second
))
>=
0
)
int
targetedUnit
=
selectUnit
(
tilePos
.
first
,
tilePos
.
second
);
if
(
targetedUnit
>=
0
)
{
if
(
m_units
.
at
(
m_selectedUnit
).
getFaction
()
==
m_units
.
at
(
targetedUnit
).
getFaction
())
{
std
::
cout
<<
"You cannot attack your allies!"
<<
std
::
endl
;
return
;
}
Unit
&
attacking
=
m_units
.
at
(
m_selectedUnit
);
Unit
&
defending
=
m_units
.
at
(
targetedUnit
);
attacking
.
attack
(
defending
);
...
...
@@ -428,6 +436,10 @@ void Level::handleAttackingEvents(Engine& engine, SDL_Event& event)
m_selectedUnit
=
-
1
;
m_state
=
LevelState
::
SELECTING_STATE
;
}
else
{
std
::
cout
<<
"No valid target clicked"
<<
std
::
endl
;
}
}
break
;
default
:
...
...
This diff is collapsed.
Click to expand it.
src/game/Unit.cpp
+
5
−
0
View file @
21e608fb
...
...
@@ -216,4 +216,9 @@ bool Unit::inRange(Unit& enemy)
return
false
;
}
UnitFaction
Unit
::
getFaction
()
{
return
this
->
m_faction
;
}
}
// namespace advanced_wars
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/game/Unit.hpp
+
2
−
0
View file @
21e608fb
...
...
@@ -116,6 +116,8 @@ class Unit
*/
void
on_left_click
(
SDL_Event
event
);
UnitFaction
getFaction
();
private
:
UnitFaction
m_faction
;
UnitId
m_id
;
...
...
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