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
70b3c323
Commit
70b3c323
authored
5 months ago
by
Max Cherris
Browse files
Options
Downloads
Patches
Plain Diff
Add building selection
parent
4b69d0a8
No related branches found
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
+34
-1
34 additions, 1 deletion
src/level.cpp
src/level.hpp
+3
-0
3 additions, 0 deletions
src/level.hpp
src/unit.cpp
+15
-0
15 additions, 0 deletions
src/unit.cpp
with
52 additions
and
1 deletion
src/level.cpp
+
34
−
1
View file @
70b3c323
...
...
@@ -29,6 +29,16 @@ bool Level::clickCheck(int mouseX, int mouseY) {
int
tileX
=
mouseX
/
(
16
*
RENDERING_SCALE
);
int
tileY
=
mouseY
/
(
16
*
RENDERING_SCALE
);
if
(
selectUnit
(
tileX
,
tileY
))
return
true
;
if
(
selectBuilding
(
tileX
,
tileY
))
return
true
;
std
::
cout
<<
"Neither building nor unit clicked"
<<
std
::
endl
;
return
false
;
}
bool
Level
::
selectUnit
(
int
tileX
,
int
tileY
)
{
for
(
auto
&
unit
:
units
)
{
if
(
unit
.
x
==
tileX
&&
unit
.
y
==
tileY
)
{
...
...
@@ -37,8 +47,23 @@ bool Level::clickCheck(int mouseX, int mouseY) {
return
true
;
}
}
selectedUnit
=
nullptr
;
return
false
;
}
bool
Level
::
selectBuilding
(
int
tileX
,
int
tileY
)
{
for
(
auto
&
building
:
buildings
)
{
if
(
building
.
x
==
tileX
&&
building
.
y
==
tileY
)
{
//std::cout << "X:" << unit.x << "Y:" << unit.y << std::endl;
selectedBuilding
=
&
building
;
return
true
;
}
}
selectedBuilding
=
nullptr
;
return
false
;
}
void
Level
::
handleEvent
(
Engine
&
engine
,
SDL_Event
&
event
)
{
...
...
@@ -50,8 +75,16 @@ void Level::handleEvent(Engine &engine, SDL_Event &event) {
{
case
SDL_MOUSEBUTTONDOWN
:
if
(
clickCheck
(
event
.
button
.
x
,
event
.
button
.
y
))
{
if
(
selectedUnit
)
{
selectedUnit
->
onClick
(
event
,
units
);
}
if
(
selectedBuilding
)
{
//building stuff
}
}
break
;
default
:
...
...
This diff is collapsed.
Click to expand it.
src/level.hpp
+
3
−
0
View file @
70b3c323
...
...
@@ -34,6 +34,9 @@ private:
std
::
vector
<
Unit
>
units
;
std
::
vector
<
Effect
>
effects
;
Unit
*
selectedUnit
;
Building
*
selectedBuilding
;
bool
selectUnit
(
int
tileX
,
int
tileY
);
bool
selectBuilding
(
int
tileX
,
int
tileY
);
bool
clickCheck
(
int
mouseX
,
int
mouseY
);
};
...
...
This diff is collapsed.
Click to expand it.
src/unit.cpp
+
15
−
0
View file @
70b3c323
...
...
@@ -106,6 +106,19 @@ namespace advanced_wars
this
->
y
=
posY
;
}
/*
Features:
//select unit
- show context menu
- show move range
- MAYBE show valid targets
//deselect unit
//attack unit
- show context menu
*/
void
Unit
::
onClick
(
SDL_Event
event
,
std
::
vector
<
Unit
>
&
unitVector
)
{
...
...
@@ -129,6 +142,8 @@ namespace advanced_wars
};
}
*/
//make move range calc
break
;
case
SDL_BUTTON_RIGHT
:
...
...
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