Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F624652
DraggingSystem.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
DraggingSystem.cpp
View Options
//
// Created by Ido Mozes on 09/07/2019.
//
#include
"DraggingSystem.h"
void
DraggingSystem::update
(
Entities
*
layers
,
GameData
&
gameData
)
{
if
(
!
gameData
.
isDragging
)
return
;
int
mouseX
,
mouseY
;
SDL_GetMouseState
(
&
mouseX
,
&
mouseY
);
mouseX
=
int
(
mouseX
/
gameData
.
mapScale
);
mouseY
=
int
(
mouseY
/
gameData
.
mapScale
);
for
(
int
i
=
0
;
i
<
N_LAYERS
;
++
i
)
{
for
(
auto
&
entity
:
layers
[
i
])
{
if
(
auto
components
=
entity
->
getComponents
<
Draggable
,
Visibility
>
())
{
auto
[
draggable
,
visibility
]
=
components
.
value
();
visibility
.
setPosition
(
mouseX
-
int
(
visibility
.
getDstRect
()
->
w
/
2.0
),
mouseY
-
int
(
visibility
.
getDstRect
()
->
h
/
2.0
));
bool
freePosition
=
true
;
if
(
mouseX
>=
SIDEBAR_WIDTH
+
MAP_WIDTH
or
mouseX
<
SIDEBAR_WIDTH
)
freePosition
=
true
;
else
for
(
int
x
=
std
::
max
(
mouseX
-
SIDEBAR_WIDTH
-
4
,
0
);
x
<
std
::
min
(
mouseX
-
SIDEBAR_WIDTH
+
5
,
MAP_WIDTH
-
1
);
++
x
)
{
for
(
int
y
=
std
::
max
(
mouseY
-
4
,
0
);
y
<
std
::
min
(
mouseY
+
5
,
MAP_HEIGHT
-
1
);
++
y
)
{
if
(
gameData
.
mapData
[
x
][
y
]
==
OBSTACLE
or
gameData
.
mapData
[
x
][
y
]
==
TOWER
)
{
freePosition
=
false
;
goto
setIsPlaceable
;
}
}
}
setIsPlaceable
:
draggable
.
isPlaceable
=
freePosition
;
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sat, Nov 14, 10:35 PM (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
135875
Default Alt Text
DraggingSystem.cpp (1 KB)
Attached To
Mode
R74 BloonsTD
Attached
Detach File
Event Timeline