Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Game Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Game Development
Game Library
Commits
1cf8f72e
Commit
1cf8f72e
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
shield the grid against out of bounds
parent
5deaeaaf
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
demo/include/grid.hpp
+5
-1
5 additions, 1 deletion
demo/include/grid.hpp
include/fggl/entity/gridworld/zone.hpp
+27
-5
27 additions, 5 deletions
include/fggl/entity/gridworld/zone.hpp
with
32 additions
and
6 deletions
demo/include/grid.hpp
+
5
−
1
View file @
1cf8f72e
...
...
@@ -91,7 +91,11 @@ namespace demo {
}
else
if
(
cell
.
direction
==
3
)
{
moveDir
.
x
=
-
1
;
}
cell
.
pos
+=
moveDir
;
if
(
m_grid
->
canMove
(
cell
.
pos
,
moveDir
)
)
{
cell
.
pos
+=
moveDir
;
}
}
inline
void
rotate
(
bool
clockwise
)
{
...
...
This diff is collapsed.
Click to expand it.
include/fggl/entity/gridworld/zone.hpp
+
27
−
5
View file @
1cf8f72e
...
...
@@ -98,6 +98,11 @@ namespace fggl::entity::grid {
clear
();
}
inline
bool
inBounds
(
GridPos
pos
)
const
{
return
0
<=
pos
.
x
&&
pos
.
x
<=
width
&&
0
<=
pos
.
y
&&
pos
.
y
<=
height
;
}
void
clear
()
{
WallState
noWall
;
...
...
@@ -135,7 +140,10 @@ namespace fggl::entity::grid {
}
inline
bool
canMove
(
GridPos
pos
)
const
{
return
m_tiles
.
m_floors
[
m_floors
.
getCell
(
pos
)]
!=
0
;
if
(
!
inBounds
(
pos
)
)
{
return
false
;
}
return
m_tiles
.
m_floors
[
m_floors
.
get
(
pos
)].
moveCost
!=
FloorTile
::
IMPOSSIBLE
;
}
inline
bool
canMove
(
GridPos
pos
,
math
::
vec2i
dir
)
const
{
...
...
@@ -143,11 +151,25 @@ namespace fggl::entity::grid {
}
inline
bool
blocked
(
GridPos
pos
,
math
::
vec2i
dir
)
const
{
if
(
dir
.
x
==
-
1
||
dir
.
y
==
-
1
)
{
return
m_walls
.
getCell
(
pos
)
!=
0
;
}
else
{
m_walls
.
getCell
(
pos
+
dir
)
!=
0
;
auto
targetPos
=
pos
;
if
(
dir
.
x
==
1
||
dir
.
y
==
1
)
{
targetPos
=
pos
+
dir
;
}
if
(
!
inBounds
(
targetPos
)
)
{
return
true
;
}
auto
&
wallObj
=
m_walls
.
get
(
targetPos
);
if
(
dir
.
y
!=
0
)
{
return
wallObj
.
north
!=
0
;
}
if
(
dir
.
x
!=
0
)
{
return
wallObj
.
west
!=
0
;
}
return
true
;
}
EntityManager
&
entities
()
{
...
...
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