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
8abe6c39
Commit
8abe6c39
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
define level rules in struct
parent
d2237aa6
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
+13
-13
13 additions, 13 deletions
demo/demo/grid.cpp
demo/include/grid.hpp
+5
-3
5 additions, 3 deletions
demo/include/grid.hpp
with
18 additions
and
16 deletions
demo/demo/grid.cpp
+
13
−
13
View file @
8abe6c39
...
...
@@ -73,7 +73,7 @@ namespace demo {
}
}
static
fggl
::
entity
::
EntityID
build_test_env
(
DemoGrid
*
area
)
{
static
fggl
::
entity
::
EntityID
build_test_env
(
DemoGrid
*
area
,
LevelRules
&
rules
)
{
area
->
clear
();
build_room
(
area
,
{
5
,
5
},
{
4
,
4
});
build_room
(
area
,
{
11
,
5
},
{
1
,
1
});
...
...
@@ -84,7 +84,10 @@ namespace demo {
// set goal
area
->
setFloorAt
(
17
,
5
,
2
);
build_room
(
area
,
{
25
,
5
},
{
3
,
3
});
// level rules
rules
.
startingPower
=
20
;
rules
.
startingPos
=
{
5
,
5
};
rules
.
startingDirection
=
1
;
// player
fggl
::
entity
::
EntityID
player
=
fggl
::
entity
::
INVALID
;
...
...
@@ -93,9 +96,6 @@ namespace demo {
player
=
manager
.
create
();
auto
&
cellPos
=
manager
.
add
<
CellPos
>
(
player
);
auto
&
robotState
=
manager
.
add
<
RobotState
>
(
player
);
cellPos
.
pos
=
{
5
,
5
};
cellPos
.
direction
=
1
;
robotState
.
power
=
32
;
}
return
player
;
...
...
@@ -140,6 +140,7 @@ namespace demo {
btn
->
label
(
"go"
);
btn
->
addCallback
([
=
](){
if
(
!
this
->
m_program
.
playing
)
{
resetPuzzle
();
this
->
m_program
.
m_currInstruction
=
0
;
this
->
m_program
.
playing
=
true
;
}
...
...
@@ -162,7 +163,7 @@ namespace demo {
// create the grid world
m_grid
=
std
::
make_unique
<
DemoGrid
>
(
m_tiles
);
m_player
=
build_test_env
(
m_grid
.
get
());
m_player
=
build_test_env
(
m_grid
.
get
()
,
m_levelRules
);
resetPuzzle
();
}
...
...
@@ -171,7 +172,6 @@ namespace demo {
m_grid
=
nullptr
;
}
constexpr
float
DRAW_SIZE
=
64.0
F
;
constexpr
float
DRAW_HALF
=
DRAW_SIZE
/
2.0
F
;
constexpr
float
WALL_HALF
=
2.5
F
;
...
...
@@ -292,17 +292,17 @@ namespace demo {
}
void
GridScene
::
resetPuzzle
()
{
auto
&
robotPos
=
m_grid
->
entities
().
get
<
CellPos
>
(
m_player
);
auto
&
robotState
=
m_grid
->
entities
().
get
<
RobotState
>
(
m_player
);
// reset instruction panel
m_program
.
playing
=
false
;
m_program
.
m_currInstruction
=
0
;
// reset robot state
robotPos
.
pos
=
{
5
,
5
};
robotPos
.
direction
=
1
;
robotState
.
power
=
32
;
auto
&
robotPos
=
m_grid
->
entities
().
get
<
CellPos
>
(
m_player
);
auto
&
robotState
=
m_grid
->
entities
().
get
<
RobotState
>
(
m_player
);
robotPos
.
pos
=
m_levelRules
.
startingPos
;
robotPos
.
direction
=
m_levelRules
.
startingDirection
;
robotState
.
power
=
m_levelRules
.
startingPower
;
}
void
GridScene
::
checkVictory
()
{
...
...
This diff is collapsed.
Click to expand it.
demo/include/grid.hpp
+
5
−
3
View file @
8abe6c39
...
...
@@ -32,8 +32,10 @@ namespace demo {
constexpr
int
GRID_SIZE
=
255
;
using
DemoGrid
=
fggl
::
entity
::
grid
::
Area2D
<
GRID_SIZE
,
GRID_SIZE
>
;
struct
Sprite
{
struct
LevelRules
{
fggl
::
math
::
vec2i
startingPos
;
uint32_t
startingDirection
;
uint32_t
startingPower
;
};
struct
CellPos
{
...
...
@@ -52,7 +54,6 @@ namespace demo {
struct
RobotState
{
uint32_t
power
=
64
;
};
class
GridScene
:
public
fggl
::
scenes
::
GameBase
{
...
...
@@ -68,6 +69,7 @@ namespace demo {
fggl
::
animation
::
FrameAnimator
m_animator
;
std
::
unique_ptr
<
DemoGrid
>
m_grid
;
fggl
::
gui
::
Container
m_canvas
;
LevelRules
m_levelRules
;
fggl
::
entity
::
EntityID
m_player
=
fggl
::
entity
::
INVALID
;
Program
m_program
;
...
...
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