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
Onuralp SEZER
Game Library
Commits
65aec1b5
Commit
65aec1b5
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
more work on grid-based environments
parent
89f75b27
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
demo/demo/grid.cpp
+43
-5
43 additions, 5 deletions
demo/demo/grid.cpp
include/fggl/entity/gridworld/zone.hpp
+33
-2
33 additions, 2 deletions
include/fggl/entity/gridworld/zone.hpp
with
76 additions
and
7 deletions
demo/demo/grid.cpp
+
43
−
5
View file @
65aec1b5
...
...
@@ -29,7 +29,25 @@ namespace demo {
fggl
::
debug
::
log
(
fggl
::
debug
::
Level
::
info
,
"GridScene::activate()"
);
// create the grid world
fggl
::
entity
::
grid
::
FloorTile
empty
{
fggl
::
entity
::
grid
::
FloorTile
::
IMPOSSIBLE
,
fggl
::
gfx
::
colours
::
BLACK
};
fggl
::
entity
::
grid
::
FloorTile
ground
{
1
,
fggl
::
gfx
::
colours
::
GREEN
};
m_tiles
.
m_floors
.
push_back
(
empty
);
m_tiles
.
m_floors
.
push_back
(
ground
);
fggl
::
entity
::
grid
::
WallTile
noWall
{};
m_tiles
.
m_walls
.
push_back
(
noWall
);
m_grid
=
std
::
make_unique
<
fggl
::
entity
::
grid
::
Area2D
<
255
,
255
>>
(
m_tiles
);
// create a small area to use
for
(
int
i
=
3
;
i
<
20
;
++
i
)
{
auto
&
walls
=
m_grid
->
wallAt
(
i
,
3
,
true
);
for
(
int
j
=
3
;
j
<
20
;
++
j
)
{
m_grid
->
setFloorAt
(
i
,
j
,
1
);
}
}
}
void
GridScene
::
deactivate
()
{
...
...
@@ -44,12 +62,9 @@ namespace demo {
for
(
int
i
=
0
;
i
<=
31
;
++
i
)
{
for
(
int
j
=
0
;
j
<=
31
;
++
j
)
{
auto
&
cell
=
grid
.
floorAt
(
i
,
j
);
fggl
::
math
::
vec2
drawPos
{
i
*
DRAW_SIZE
,
j
*
DRAW_SIZE
};
float
x
=
i
*
DRAW_SIZE
;
float
y
=
j
*
DRAW_SIZE
;
auto
colour
=
(
i
+
j
)
%
2
==
0
?
fggl
::
gfx
::
colours
::
WHITE
:
fggl
::
gfx
::
colours
::
BLACK
;
fggl
::
gfx
::
Path2D
tileGfx
=
fggl
::
gfx
::
make_rect
({
x
,
y
},
{
DRAW_HALF
,
DRAW_HALF
},
colour
);
fggl
::
gfx
::
Path2D
tileGfx
=
fggl
::
gfx
::
make_rect
(
drawPos
,
{
DRAW_HALF
,
DRAW_HALF
},
cell
.
colour
);
paint
.
fill
(
tileGfx
);
}
}
...
...
@@ -68,6 +83,12 @@ namespace demo {
paint
.
fill
(
hexTest
);
}
// draw with edges
for
(
int
sides
=
3
;
sides
<=
25
;
++
sides
)
{
auto
hexTest
=
fggl
::
gfx
::
make_shape
(
fggl
::
math
::
vec2
{
sides
,
6
}
*
DRAW_SIZE
,
DRAW_HALF
,
sides
,
{
1.0
F
-
(
sides
/
25.0
F
),
0.0
f
,
sides
/
25.0
f
});
paint
.
stroke
(
hexTest
);
}
// draw test arcs
for
(
int
sides
=
0
;
sides
<
12
;
++
sides
)
{
float
endAngle
=
progress
*
(
M_PI
*
2
);
...
...
@@ -79,6 +100,23 @@ namespace demo {
paint
.
fill
(
hexTest
);
}
// draw sweep
for
(
int
sides
=
2
;
sides
<=
25
;
++
sides
){
float
angle
=
progress
*
(
M_PI
*
2
);
float
sliceSize
=
1
/
(
float
)
sides
*
(
M_PI
*
2
);
float
startAngle
=
angle
;
float
endAngle
=
startAngle
+
sliceSize
;
auto
hexTest
=
fggl
::
gfx
::
make_arc
(
fggl
::
math
::
vec2
{
sides
+
3
,
8
}
*
DRAW_SIZE
,
DRAW_HALF
,
startAngle
,
endAngle
,
fggl
::
gfx
::
colours
::
CYAN
);
paint
.
fill
(
hexTest
);
}
progress
+=
0.01
F
;
if
(
progress
>
1.0
F
)
{
progress
=
0.0
F
;
...
...
This diff is collapsed.
Click to expand it.
include/fggl/entity/gridworld/zone.hpp
+
33
−
2
View file @
65aec1b5
...
...
@@ -39,6 +39,10 @@ namespace fggl::entity::grid {
return
m_cells
[
getCellIndex
(
pos
)];
}
inline
void
set
(
math
::
vec2i
pos
,
T
value
)
{
m_cells
[
getCellIndex
(
pos
)]
=
value
;
}
inline
bool
inBounds
(
math
::
vec2i
pos
)
const
{
return
0
<=
pos
.
x
&&
pos
.
x
<=
size
.
x
&&
0
<=
pos
.
y
&&
pos
.
y
<=
size
.
y
;
...
...
@@ -58,10 +62,21 @@ namespace fggl::entity::grid {
struct
FloorTile
{
constexpr
static
uint8_t
IMPOSSIBLE
=
0
;
uint8_t
moveCost
=
IMPOSSIBLE
;
math
::
vec3
colour
;
};
struct
WallTile
{
};
struct
WallState
{
uint32_t
wallNorth
;
uint32_t
wallWest
;
};
struct
TileSet
{
std
::
vector
<
FloorTile
>
m_floors
;
std
::
vector
<
WallTile
>
m_walls
;
};
/**
...
...
@@ -76,7 +91,23 @@ namespace fggl::entity::grid {
inline
explicit
Area2D
(
TileSet
&
tiles
)
:
m_tiles
(
tiles
)
{}
inline
FloorTile
&
floorAt
(
uint32_t
x
,
uint32_t
y
)
{
return
m_tiles
.
m_floors
[
m_floors
.
at
({
x
,
y
})
];
return
m_tiles
.
m_floors
.
at
(
m_floors
.
at
({
x
,
y
})
);
}
inline
void
setFloorAt
(
uint32_t
x
,
uint32_t
y
,
uint32_t
floor
)
{
m_floors
.
set
({
x
,
y
},
floor
);
}
inline
WallTile
&
wallAt
(
uint32_t
x
,
uint32_t
y
,
bool
north
)
{
if
(
north
)
{
return
m_tiles
.
m_walls
.
at
(
m_walls
.
at
({
x
,
y
}).
wallNorth
);
}
else
{
return
m_tiles
.
m_walls
.
at
(
m_walls
.
at
({
x
,
y
}).
wallWest
);
}
}
inline
void
setWallAt
(
uint32_t
x
,
uint32_t
y
,
uint32_t
wall
)
{
m_walls
.
set
({
x
,
y
},
wall
);
}
inline
bool
canMove
(
math
::
vec2i
pos
)
const
{
...
...
@@ -99,7 +130,7 @@ namespace fggl::entity::grid {
private
:
TileSet
&
m_tiles
;
Grid
<
uint32_t
,
width
,
height
>
m_floors
;
Grid
<
uint32_t
,
width
+
1
,
height
+
1
>
m_walls
;
Grid
<
WallState
,
width
+
1
,
height
+
1
>
m_walls
;
};
}
// namespace fggl::entity::gridworld
...
...
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