Skip to content

Commit 071c1e7

Browse files
committed
update of the docs
1 parent d1eabd1 commit 071c1e7

File tree

6 files changed

+142
-5
lines changed

6 files changed

+142
-5
lines changed

01-beginner/code/sokoban01.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <algorithm>
12
#include <vector>
23

34
#include <gf/Array2D.h>
@@ -9,8 +10,12 @@
910
#include <gf/Vector.h>
1011
#include <gf/Window.h>
1112

13+
// tag::ns[]
1214
namespace skb {
1315

16+
// end::ns[]
17+
18+
// tag::data[]
1419
const char LevelData[] = {
1520
" #####"
1621
"###@ .#"
@@ -23,10 +28,17 @@ namespace skb {
2328

2429
constexpr gf::Vector2i LevelSize = gf::vec(7, 7);
2530

31+
// end::data[]
32+
33+
// tag::hero[]
2634
struct Hero {
2735
gf::Vector2i position;
2836
};
2937

38+
// end::hero[]
39+
40+
41+
// tag::make_hero[]
3042
Hero makeHero(gf::Span<const char> data, gf::Vector2i size) {
3143
Hero hero = { gf::vec(0, 0) };
3244
gf::Vector2i position = gf::vec(0, 0);
@@ -47,6 +59,8 @@ namespace skb {
4759
return hero;
4860
}
4961

62+
// end::make_hero[]
63+
5064
struct Boxes {
5165
std::vector<gf::Vector2i> positions;
5266

@@ -124,6 +138,8 @@ namespace skb {
124138
case '#':
125139
level.blocks(position) = Block::Wall;
126140
break;
141+
case '\0':
142+
break;
127143
default:
128144
assert(false);
129145
break;
@@ -140,7 +156,9 @@ namespace skb {
140156
return level;
141157
}
142158

159+
// tag::ns[]
143160
}
161+
// end::ns[]
144162

145163

146164
int main() {
@@ -193,6 +211,12 @@ int main() {
193211
if (level.blocks(behind) != skb::Wall && !boxes.hasBox(behind)) {
194212
hero.position = target;
195213
boxes.changeBox(target, behind);
214+
215+
if (std::all_of(boxes.positions.begin(), boxes.positions.end(), [&level](gf::Vector2i coordinates) {
216+
return level.blocks(coordinates) == skb::Block::Goal;
217+
})) {
218+
return 0;
219+
}
196220
}
197221
} else {
198222
hero.position = target;

advanced.adoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,12 @@ v0.1
44
:toc:
55
:homepage: https://gamedevframework.github.io/
66
:stem: latexmath
7-
:source-highlighter: coderay
7+
:source-highlighter: rouge
88
:xrefstyle: full
9+
10+
Things to talk about:
11+
12+
- `gf::Scene`
13+
- `gf::SceneManager`
14+
- `gf::Segue`
15+

analysis.adoc

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,39 @@ v0.1
44
:toc:
55
:homepage: https://gamedevframework.github.io/
66
:stem: latexmath
7-
:source-highlighter: coderay
7+
:source-highlighter: rouge
88
:xrefstyle: full
9+
10+
We analyse Sokoban in an agnostic way, not depending on the underlying technology. This analysis will be the base for the three parts of the tutorial.
11+
12+
13+
== Rules of Sokoban
14+
15+
https://en.wikipedia.org/wiki/Sokoban[Sokoban] is a puzzle game. The goal for the player is to push boxes on their places in a room. The player can only push the boxes, and can only push one at a time.
16+
17+
18+
== Entities in Sokoban
19+
20+
There are three main entities in Sokoban: the level, the hero and the boxes.
21+
22+
=== Level
23+
24+
The level is a 2D array representing the room. Each cell in the array can be either a wall, a goal or a (non-goal) floor. The locations of the hero and the boxes are not coded in this entity because it would had some complexities. The level has a single attribute:
25+
26+
- `blocks` that is a 2D array of block properties (`Wall`, `Goal` or `Floor`)
27+
28+
=== Hero
29+
30+
The hero has a single attribute:
31+
32+
- `position` that indicates its position in the room.
33+
34+
=== Boxes
35+
36+
Boxes, like the hero, are represented by their position in the room. Hence the structure for the boxes has a single attribute too:
37+
38+
- `positions` that is an array of positions in the room, one for each box.
39+
40+
== Graphics for Sokoban
41+
42+
The goal of this tutorial is not to teach graphics. So we will use the excellent graphics from https://kenney.nl/[Kenney.nl] and especially the https://kenney.nl/assets/sokoban[assets for sokoban].

beginner.adoc

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,67 @@ v0.1
44
:toc:
55
:homepage: https://gamedevframework.github.io/
66
:stem: latexmath
7-
:source-highlighter: coderay
7+
:source-highlighter: rouge
88
:xrefstyle: full
9+
10+
This tutorial is a step-by-step construction of Sokoban with Gamedev Framework. In this beginner tutorial, we will understand the basics of game development and use the minimal features of Gamedev Framework.
11+
12+
13+
== Project Setup
14+
15+
.Structure of the project
16+
* `/`: root directory of the project
17+
** `/code/`: directory for the source code
18+
*** `sokoban01.cc`: the single file for this tutorial
19+
** `/CMakeLists.txt`: the build instructions
20+
21+
22+
.Minimal source code
23+
[source,c++]
24+
----
25+
include::01-beginner/code/template01.cc[]
26+
----
27+
28+
29+
.The associated `CMakeLists.txt`
30+
[source,cmake]
31+
----
32+
include::01-beginner/CMakeLists.txt[]
33+
----
34+
35+
== Development
36+
37+
=== Namespace
38+
39+
.Namespace
40+
[source,c++]
41+
----
42+
include::01-beginner/code/sokoban01.cc[tag=ns]
43+
----
44+
45+
=== Data
46+
47+
.Data
48+
[source,c++]
49+
----
50+
include::01-beginner/code/sokoban01.cc[tags=data;ns]
51+
----
52+
53+
=== Structures
54+
55+
.Hero
56+
[source,c++]
57+
----
58+
include::01-beginner/code/sokoban01.cc[tags=hero;ns]
59+
----
60+
61+
62+
=== Structures Instanciation
63+
64+
.Hero Instanciation
65+
[source,c++]
66+
----
67+
include::01-beginner/code/sokoban01.cc[tags=make_hero;ns]
68+
----
69+
70+

index.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ v0.1
44
:toc:
55
:homepage: https://gamedevframework.github.io/
66
:stem: latexmath
7-
:source-highlighter: coderay
7+
:source-highlighter: rouge
88
:xrefstyle: full
99

10+
Welcome in the tutorial for Gamedev Framework. In this tutorial, we are going to learn how to create a game with Gamedev Framework. The game is https://en.wikipedia.org/wiki/Sokoban[Sokoban].
11+
1012
== Journey
1113

1214
- link:analysis.html[Analysis of the game]

intermediate.adoc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,13 @@ v0.1
44
:toc:
55
:homepage: https://gamedevframework.github.io/
66
:stem: latexmath
7-
:source-highlighter: coderay
7+
:source-highlighter: rouge
88
:xrefstyle: full
9+
10+
Things to talk about:
11+
12+
- `gf::View`
13+
- `gf::Action`
14+
- `gf::ResourceManager`
15+
16+

0 commit comments

Comments
 (0)