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
d2237aa6
Commit
d2237aa6
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
add reset system to robot puzzle
parent
9e6f29ea
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/demo/grid.cpp
+27
-1
27 additions, 1 deletion
demo/demo/grid.cpp
demo/include/grid.hpp
+7
-0
7 additions, 0 deletions
demo/include/grid.hpp
with
34 additions
and
1 deletion
demo/demo/grid.cpp
+
27
−
1
View file @
d2237aa6
...
@@ -92,9 +92,12 @@ namespace demo {
...
@@ -92,9 +92,12 @@ namespace demo {
{
{
player
=
manager
.
create
();
player
=
manager
.
create
();
auto
&
cellPos
=
manager
.
add
<
CellPos
>
(
player
);
auto
&
cellPos
=
manager
.
add
<
CellPos
>
(
player
);
auto
&
robotState
=
manager
.
add
<
RobotState
>
(
player
);
cellPos
.
pos
=
{
5
,
5
};
cellPos
.
pos
=
{
5
,
5
};
cellPos
.
direction
=
1
;
cellPos
.
direction
=
1
;
robotState
.
power
=
32
;
}
}
return
player
;
return
player
;
}
}
...
@@ -160,6 +163,8 @@ namespace demo {
...
@@ -160,6 +163,8 @@ namespace demo {
// create the grid world
// create the grid world
m_grid
=
std
::
make_unique
<
DemoGrid
>
(
m_tiles
);
m_grid
=
std
::
make_unique
<
DemoGrid
>
(
m_tiles
);
m_player
=
build_test_env
(
m_grid
.
get
());
m_player
=
build_test_env
(
m_grid
.
get
());
resetPuzzle
();
}
}
void
GridScene
::
deactivate
()
{
void
GridScene
::
deactivate
()
{
...
@@ -267,8 +272,15 @@ namespace demo {
...
@@ -267,8 +272,15 @@ namespace demo {
return
;
return
;
}
}
auto
&
manager
=
m_grid
->
entities
();
if
(
m_program
.
m_currInstruction
<
m_program
.
m_instructions
.
size
()
)
{
if
(
m_program
.
m_currInstruction
<
m_program
.
m_instructions
.
size
()
)
{
auto
&
robotState
=
m_grid
->
entities
().
get
<
RobotState
>
(
m_player
);
if
(
robotState
.
power
==
0
)
{
// a looser is you
resetPuzzle
();
return
;
}
robotState
.
power
--
;
m_program
.
m_instructions
[
m_program
.
m_currInstruction
]();
m_program
.
m_instructions
[
m_program
.
m_currInstruction
]();
m_program
.
m_currInstruction
++
;
m_program
.
m_currInstruction
++
;
}
else
{
}
else
{
...
@@ -279,6 +291,20 @@ namespace demo {
...
@@ -279,6 +291,20 @@ 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
;
}
void
GridScene
::
checkVictory
()
{
void
GridScene
::
checkVictory
()
{
if
(
!
m_program
.
playing
)
{
if
(
!
m_program
.
playing
)
{
auto
&
botPos
=
m_grid
->
entities
().
get
<
CellPos
>
(
m_player
).
pos
;
auto
&
botPos
=
m_grid
->
entities
().
get
<
CellPos
>
(
m_player
).
pos
;
...
...
This diff is collapsed.
Click to expand it.
demo/include/grid.hpp
+
7
−
0
View file @
d2237aa6
...
@@ -50,6 +50,11 @@ namespace demo {
...
@@ -50,6 +50,11 @@ namespace demo {
bool
playing
=
false
;
bool
playing
=
false
;
};
};
struct
RobotState
{
uint32_t
power
=
64
;
};
class
GridScene
:
public
fggl
::
scenes
::
GameBase
{
class
GridScene
:
public
fggl
::
scenes
::
GameBase
{
public:
public:
explicit
GridScene
(
fggl
::
App
&
app
);
explicit
GridScene
(
fggl
::
App
&
app
);
...
@@ -67,6 +72,8 @@ namespace demo {
...
@@ -67,6 +72,8 @@ namespace demo {
fggl
::
entity
::
EntityID
m_player
=
fggl
::
entity
::
INVALID
;
fggl
::
entity
::
EntityID
m_player
=
fggl
::
entity
::
INVALID
;
Program
m_program
;
Program
m_program
;
void
resetPuzzle
();
void
tickPlayer
();
void
tickPlayer
();
void
checkVictory
();
void
checkVictory
();
...
...
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