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
3528a3d6
Commit
3528a3d6
authored
7 months ago
by
Max Cherris
Browse files
Options
Downloads
Patches
Plain Diff
Refactor left_click
Why does the clicked unit dissappear after moving it?
parent
af6c8e06
Branches
Branches containing commit
No related tags found
1 merge request
!15
Merge units into main
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/level.cpp
+2
-4
2 additions, 4 deletions
src/level.cpp
src/unit.cpp
+3
-52
3 additions, 52 deletions
src/unit.cpp
src/unit.hpp
+2
-2
2 additions, 2 deletions
src/unit.hpp
with
7 additions
and
58 deletions
src/level.cpp
+
2
−
4
View file @
3528a3d6
...
...
@@ -113,7 +113,7 @@ void Level::handleEvent(Engine &engine, SDL_Event &event) {
if
(
click_check_left
(
event
.
button
.
x
,
event
.
button
.
y
))
{
if
(
selectedUnit
)
{
selectedUnit
->
on
C
lick
(
event
,
units
);
selectedUnit
->
on
_left_c
lick
(
event
,
units
);
}
if
(
selectedBuilding
)
{
...
...
@@ -146,8 +146,6 @@ void Level::handleEvent(Engine &engine, SDL_Event &event) {
}
else
{
selectedUnit
->
update_position
(
tileX
,
tileY
);
}
...
...
This diff is collapsed.
Click to expand it.
src/unit.cpp
+
3
−
52
View file @
3528a3d6
...
...
@@ -175,60 +175,11 @@ Features:
- show context menu
*/
void
Unit
::
on
C
lick
(
SDL_Event
event
,
std
::
vector
<
Unit
>
&
unitVector
)
void
Unit
::
on
_left_c
lick
(
SDL_Event
event
,
std
::
vector
<
Unit
>
&
unitVector
)
{
Unit
*
defender
=
nullptr
;
Unit
*
attacker
=
nullptr
;
std
::
cout
<<
"Left-button pressed on unit: "
<<
this
->
health
<<
std
::
endl
;
switch
(
event
.
button
.
button
)
{
case
SDL_BUTTON_LEFT
:
// we have to re-initialize the unit.state (probably to idle)
this
->
is_selected
=
true
;
std
::
cout
<<
"I am selected!!"
<<
std
::
endl
;
std
::
cout
<<
"And my position is:"
<<
this
->
x
<<
" "
<<
this
->
y
<<
std
::
endl
;
//make move range calc
break
;
case
SDL_BUTTON_RIGHT
:
this
->
is_targeted
=
true
;
std
::
cout
<<
"I am targeted!!"
<<
std
::
endl
;
std
::
cout
<<
"And my position is:"
<<
this
->
x
<<
" "
<<
this
->
y
<<
std
::
endl
;
for
(
Unit
unit
:
unitVector
)
{
if
(
unit
.
state
==
advanced_wars
::
UnitState
::
UNAVAILABLE
)
{
continue
;
}
if
(
unit
.
is_selected
)
{
attacker
=
&
unit
;
}
if
(
unit
.
is_targeted
)
{
defender
=
&
unit
;
}
}
if
(
attacker
!=
nullptr
&&
defender
!=
nullptr
)
{
//attack(attacker, defender);
std
::
cout
<<
"We are fighting!!"
<<
std
::
endl
;
break
;
}
else
{
std
::
cerr
<<
"Angriff konnte nicht gestartet werden!"
<<
std
::
endl
;
break
;
}
}
}
bool
Unit
::
inRange
(
Unit
*
enemy
)
...
...
This diff is collapsed.
Click to expand it.
src/unit.hpp
+
2
−
2
View file @
3528a3d6
...
...
@@ -112,9 +112,9 @@ public:
/*
This function will be called by an external event-handler, eventually.
Currently, it should be called if a Uni
t is
interacted with and the resulting SDL_EVENT is passed through, and then decided upon
It should star
t
d
is
playing standard unit information, such as UI and move_range
*/
void
on
C
lick
(
SDL_Event
event
,
std
::
vector
<
Unit
>
&
unitVector
);
void
on
_left_c
lick
(
SDL_Event
event
,
std
::
vector
<
Unit
>
&
unitVector
);
private
:
UnitFaction
faction
;
...
...
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