felflame 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.byebug_history +20 -0
- data/.gitignore +17 -0
- data/.inch.yml +11 -0
- data/.rspec +1 -0
- data/.rubocop.yml +13 -0
- data/.yardopts +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +87 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.mdown +410 -0
- data/Rakefile +45 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/codeclimate/export-coverage.rb +16 -0
- data/deprecated/components/00_renderable.rb +19 -0
- data/deprecated/components/01_sprite.rb +57 -0
- data/deprecated/components/02_label.rb +32 -0
- data/deprecated/components/03_player_control.rb +26 -0
- data/deprecated/components/04_map.rb +21 -0
- data/deprecated/components/05_interactable.rb +16 -0
- data/deprecated/components/06_collidable.rb +22 -0
- data/deprecated/components/07_battle.rb +4 -0
- data/deprecated/components/07_indoor.rb +4 -0
- data/deprecated/components/07_overworld.rb +16 -0
- data/deprecated/components/debug_singleton.rb +13 -0
- data/deprecated/helpers/00_tileset.rb +56 -0
- data/deprecated/helpers/01_component.rb +74 -0
- data/deprecated/systems/00_update_levels.rb +34 -0
- data/deprecated/systems/10_player.rb +41 -0
- data/deprecated/systems/99_render.rb +37 -0
- data/docs/CNAME +1 -0
- data/docs/FelFlame.html +317 -0
- data/docs/FelFlame/ComponentManager.html +1627 -0
- data/docs/FelFlame/Components.html +423 -0
- data/docs/FelFlame/Entities.html +1054 -0
- data/docs/FelFlame/Helper.html +142 -0
- data/docs/FelFlame/Helper/ComponentManager.html +1627 -0
- data/docs/FelFlame/Scenes.html +761 -0
- data/docs/FelFlame/Stage.html +598 -0
- data/docs/FelFlame/Systems.html +1541 -0
- data/docs/_index.html +173 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +497 -0
- data/docs/file.README.html +498 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +498 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +475 -0
- data/docs/top-level-namespace.html +137 -0
- data/felflame.gemspec +45 -0
- data/lib/felflame.rb +59 -0
- data/lib/felflame/component_manager.rb +245 -0
- data/lib/felflame/entity_manager.rb +135 -0
- data/lib/felflame/scene_manager.rb +58 -0
- data/lib/felflame/stage_manager.rb +70 -0
- data/lib/felflame/system_manager.rb +213 -0
- data/lib/felflame/version.rb +5 -0
- data/logos/felflame-logo-text.png +0 -0
- data/logos/felflame-logo-text.svg +172 -0
- data/logos/felflame-logo.png +0 -0
- data/logos/felflame-logo.svg +97 -0
- metadata +239 -0
data/docs/file_list.html
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>File List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<div id="content">
|
23
|
+
<div class="fixed_header">
|
24
|
+
<h1 id="full_list_header">File List</h1>
|
25
|
+
<div id="full_list_nav">
|
26
|
+
|
27
|
+
<span><a target="_self" href="class_list.html">
|
28
|
+
Classes
|
29
|
+
</a></span>
|
30
|
+
|
31
|
+
<span><a target="_self" href="method_list.html">
|
32
|
+
Methods
|
33
|
+
</a></span>
|
34
|
+
|
35
|
+
<span><a target="_self" href="file_list.html">
|
36
|
+
Files
|
37
|
+
</a></span>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">Search: <input type="text" /></div>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<ul id="full_list" class="file">
|
45
|
+
|
46
|
+
|
47
|
+
<li id="object_README" class="odd">
|
48
|
+
<div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
|
49
|
+
</li>
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
</ul>
|
54
|
+
</div>
|
55
|
+
</body>
|
56
|
+
</html>
|
data/docs/frames.html
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>Documentation by YARD 0.9.26</title>
|
6
|
+
</head>
|
7
|
+
<script type="text/javascript">
|
8
|
+
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
9
|
+
var name = match ? match[1] : 'index.html';
|
10
|
+
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
11
|
+
window.top.location = name;
|
12
|
+
</script>
|
13
|
+
<noscript>
|
14
|
+
<h1>Oops!</h1>
|
15
|
+
<h2>YARD requires JavaScript!</h2>
|
16
|
+
</noscript>
|
17
|
+
</html>
|
data/docs/index.html
ADDED
@@ -0,0 +1,498 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.26
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="content"><div id='filecontents'><p><img src="https://filestorage.catgirls.rodeo/images/felflame-logo-smaller-text.png" alt="FelFlame"></p>
|
61
|
+
|
62
|
+
<p><a href="https://codeclimate.com/github/realtradam/FelFlame/maintainability"><img src="https://api.codeclimate.com/v1/badges/56d425d9078e98efb74b/maintainability" alt="Maintainability"></a>
|
63
|
+
<a href="https://codeclimate.com/github/realtradam/FelFlame/test_coverage"><img src="https://api.codeclimate.com/v1/badges/56d425d9078e98efb74b/test_coverage" alt="Test Coverage"></a>
|
64
|
+
<a href="http://inch-ci.org/github/realtradam/FelFlame"><img src="http://inch-ci.org/github/realtradam/FelFlame.svg?branch=master" alt="Inline docs"></a>
|
65
|
+
<a href="https://github.com/realtradam/FelFlame/blob/master/LICENSE"><img src="https://img.shields.io/github/license/realtradam/FelFlame?label=license&style=flat" alt="MIT License"></a>
|
66
|
+
<a href="https://ko-fi.com/tradam"><img src="https://img.shields.io/static/v1?message=Buy%20me%20a%20coffee&logo=kofi&labelColor=ff5e5b&color=434B57&logoColor=white&label=%20" alt="Ko-Fi"></a></p>
|
67
|
+
|
68
|
+
<!-- vim-markdown-toc GFM -->
|
69
|
+
|
70
|
+
<ul>
|
71
|
+
<li><a href="#what-is-felflame">What is FelFlame?</a></li>
|
72
|
+
<li><a href="#what-is-ecs">What is ECS?</a>
|
73
|
+
- <a href="#components">Components</a>
|
74
|
+
- <a href="#entities">Entities</a>
|
75
|
+
- <a href="#systems">Systems</a>
|
76
|
+
- <a href="#scenes">Scenes</a>
|
77
|
+
- <a href="#stage">Stage</a></li>
|
78
|
+
<li><a href="#usage">Usage</a>
|
79
|
+
|
80
|
+
<ul>
|
81
|
+
<li><a href="#entities-1">Entities</a>
|
82
|
+
|
83
|
+
<ul>
|
84
|
+
<li><a href="#creation">Creation</a></li>
|
85
|
+
<li><a href="#accessing">Accessing</a></li>
|
86
|
+
<li><a href="#get-id">Get ID</a></li>
|
87
|
+
<li><a href="#adding-and-removing-components">Adding and Removing Components</a></li>
|
88
|
+
<li><a href="#deletion">Deletion</a></li>
|
89
|
+
</ul></li>
|
90
|
+
<li><a href="#components-1">Components</a>
|
91
|
+
|
92
|
+
<ul>
|
93
|
+
<li><a href="#creating-a-component-manager">Creating a Component Manager</a></li>
|
94
|
+
<li><a href="#creating-a-component-from-a-component-manager">Creating a Component from a Component Manager</a></li>
|
95
|
+
<li><a href="#accessing-and-getting-id">Accessing and Getting ID</a></li>
|
96
|
+
<li><a href="#accessing-attributes-and-changing-them">Accessing Attributes and Changing Them</a></li>
|
97
|
+
<li><a href="#deleting-components">Deleting Components</a></li>
|
98
|
+
<li><a href="#iterating-over-components">Iterating over Components</a></li>
|
99
|
+
</ul></li>
|
100
|
+
<li><a href="#systems-1">Systems</a>
|
101
|
+
|
102
|
+
<ul>
|
103
|
+
<li><a href="#creation-1">Creation</a></li>
|
104
|
+
<li><a href="#execution">Execution</a></li>
|
105
|
+
<li><a href="#alternative-execution">Alternative Execution</a></li>
|
106
|
+
<li><a href="#clearing-alternative-executions">Clearing Alternative Executions</a></li>
|
107
|
+
<li><a href="#redefinition">Redefinition</a></li>
|
108
|
+
</ul></li>
|
109
|
+
<li><a href="#scenes-1">Scenes</a>
|
110
|
+
|
111
|
+
<ul>
|
112
|
+
<li><a href="#creation-2">Creation</a></li>
|
113
|
+
<li><a href="#accessing-1">Accessing</a></li>
|
114
|
+
<li><a href="#adding-systems">Adding Systems</a></li>
|
115
|
+
<li><a href="#removing-systems">Removing Systems</a></li>
|
116
|
+
<li><a href="#clearing">Clearing</a></li>
|
117
|
+
<li><a href="#execution-1">Execution</a></li>
|
118
|
+
</ul></li>
|
119
|
+
<li><a href="#stage-1">Stage</a>
|
120
|
+
|
121
|
+
<ul>
|
122
|
+
<li><a href="#adding-scenes">Adding Scenes</a></li>
|
123
|
+
<li><a href="#removing-scenes">Removing Scenes</a></li>
|
124
|
+
<li><a href="#executing">Executing</a></li>
|
125
|
+
</ul></li>
|
126
|
+
<li><a href="#closing-notes">Closing Notes</a></li>
|
127
|
+
</ul></li>
|
128
|
+
<li><a href="#contribution">Contribution</a></li>
|
129
|
+
</ul>
|
130
|
+
|
131
|
+
<!-- vim-markdown-toc -->
|
132
|
+
|
133
|
+
<h1 id="what-is-felflame">What is FelFlame?</h1>
|
134
|
+
|
135
|
+
<p>FelFlame is an ECS framework for developing games in the Ruby language. FelFlame has been designed from the ground up with these three ideas in mind:</p>
|
136
|
+
|
137
|
+
<ol>
|
138
|
+
<li><strong>Engine Agnostic:</strong> FelFlame has been designed to be rendering engine agnostic as long as the target rendering engine is written in Ruby. This means that this framework can be dropped into existing rendering engines such as <a href="http://www.ruby2d.com">Ruby2D</a> or <a href="https://dragonruby.org/toolkit/game">DRGTK</a> with little modifications.</li>
|
139
|
+
<li><strong>Easily Extensible:</strong> FelFlame has been designed such that extensions to its capabilities can be easily added. Extensions such as rendering engine wrappers, premade systems, premade components, etcetera can be easily coded and then distributed as gems.</li>
|
140
|
+
<li><strong>Priciple of (My) Least Astonishment:</strong> I want to develop games using a language and framework I love and makes sense to me, inspired by the <a href="https://en.wikipedia.org/wiki/Ruby_(programming_language)#Philosophy">Philosophy of the creator of Ruby</a>.</li>
|
141
|
+
</ol>
|
142
|
+
|
143
|
+
<h1 id="what-is-ecs">What is ECS?</h1>
|
144
|
+
|
145
|
+
<p>ECS is a software architectural pattern that is used in video game development. Traditionally games were programmed using an object oriented method, while ECS instead attempts to program games using a data oriented method instead.<br>
|
146
|
+
ECS stands for Entity, Component, and System.</p>
|
147
|
+
|
148
|
+
<hr>
|
149
|
+
|
150
|
+
<h3 id="components">Components</h3>
|
151
|
+
|
152
|
+
<p>This is where the data or information of a given "object" is stored. There is no logic or code here. </p>
|
153
|
+
|
154
|
+
<h3 id="entities">Entities</h3>
|
155
|
+
|
156
|
+
<p>Entities will contain one or more Components, but contains no logic or data otherwise</p>
|
157
|
+
|
158
|
+
<h3 id="systems">Systems</h3>
|
159
|
+
|
160
|
+
<p>Systems are where all the logic or code is kept. There is no data stored in here.</p>
|
161
|
+
|
162
|
+
<hr>
|
163
|
+
|
164
|
+
<p>By using this pattern it allows programmers to easily control what an "object" or entity can do and how much data it needs to have. It avoids the issue of inhertance as no inhertance is ever required in this system. If you need a certain entity to have a certain functionality you just add the relevant component to it, and the systems that automatically go over specific components will give your entitiy the desired functionality. </p>
|
165
|
+
|
166
|
+
<p><strong>"But your framework also has <code>Scenes</code> and a <code>Stage</code>, what is that about?"</strong> </p>
|
167
|
+
|
168
|
+
<hr>
|
169
|
+
|
170
|
+
<h3 id="scenes">Scenes</h3>
|
171
|
+
|
172
|
+
<p>Scenes are simply a collection or subset of Systems. This allows for an easy way to activate and deactivate Systems.</p>
|
173
|
+
|
174
|
+
<h3 id="stage">Stage</h3>
|
175
|
+
|
176
|
+
<p>The Stage is Scenes which are activated. This means any Scenes on the Stage are executed each frame, while the rest of the Systems are not.</p>
|
177
|
+
|
178
|
+
<hr>
|
179
|
+
|
180
|
+
<p>If all of this sounds very confusing, don't worry. A video tutorial series is in the works where I will build a game using this framework and explain every step of the way. You can also read some examples and explanations below.</p>
|
181
|
+
|
182
|
+
<h1 id="usage">Usage</h1>
|
183
|
+
|
184
|
+
<h2 id="entities">Entities</h2>
|
185
|
+
|
186
|
+
<h3 id="creation">Creation</h3>
|
187
|
+
|
188
|
+
<p>Entities are essentially "objects" in the game world. To create a new Entity we do the following:</p>
|
189
|
+
|
190
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@entity</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Entities.html" title="FelFlame::Entities (class)">Entities</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="FelFlame/Entities.html#initialize-instance_method" title="FelFlame::Entities#initialize (method)">new</a></span></span>
|
191
|
+
</code></pre>
|
192
|
+
|
193
|
+
<p>or if we want to add (any number of)components to it:</p>
|
194
|
+
|
195
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@entity</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'>Entites</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Components.html" title="FelFlame::Components (class)">Components</a></span></span><span class='op'>::</span><span class='const'>Health</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='comma'>,</span>
|
196
|
+
<span class='ivar'>@component</span><span class='comma'>,</span>
|
197
|
+
<span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Components.html" title="FelFlame::Components (class)">Components</a></span></span><span class='op'>::</span><span class='const'>Armour</span><span class='lbracket'>[</span><span class='int'>7</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
198
|
+
</code></pre>
|
199
|
+
|
200
|
+
<h3 id="accessing">Accessing</h3>
|
201
|
+
|
202
|
+
<p>Once components are created we can access them using their ID like so:</p>
|
203
|
+
|
204
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@entity</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Entities.html" title="FelFlame::Entities (class)">Entities</a></span></span><span class='lbracket'>[</span><span class='int'>2</span><span class='rbracket'>]</span>
|
205
|
+
</code></pre>
|
206
|
+
|
207
|
+
<h3 id="get-id">Get ID</h3>
|
208
|
+
|
209
|
+
<p>Entity ID's are generated starting from 0 and ascending, unless if there is a missing ID because of a deleted
|
210
|
+
entity where a new entity will claim that ID. To get the ID of an Entity:</p>
|
211
|
+
|
212
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@entity</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span>
|
213
|
+
</code></pre>
|
214
|
+
|
215
|
+
<h3 id="adding-and-removing-components">Adding and Removing Components</h3>
|
216
|
+
|
217
|
+
<p>We can still add or remove Components from an Entity after it has been created. Here is how:</p>
|
218
|
+
|
219
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@entity</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span> <span class='ivar'>@component</span>
|
220
|
+
<span class='ivar'>@entity</span><span class='period'>.</span><span class='id identifier rubyid_remove'>remove</span> <span class='ivar'>@component</span>
|
221
|
+
</code></pre>
|
222
|
+
|
223
|
+
<h3 id="deletion">Deletion</h3>
|
224
|
+
|
225
|
+
<p>To have all Components from an Entity removed and the Entity deleted we do the following:</p>
|
226
|
+
|
227
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@entity</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span>
|
228
|
+
</code></pre>
|
229
|
+
|
230
|
+
<h2 id="components">Components</h2>
|
231
|
+
|
232
|
+
<h3 id="creating-a-component-manager">Creating a Component Manager</h3>
|
233
|
+
|
234
|
+
<p>Components are where all the data is stored. The data is stored in variables or accessors in each component.
|
235
|
+
These accessors and their defaults are configured when a component manager is created, like so:</p>
|
236
|
+
|
237
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@component_manager</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Components.html" title="FelFlame::Components (class)">Components</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="FelFlame/Components.html#new-class_method" title="FelFlame::Components.new (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Stats</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='symbol'>:armour</span><span class='comma'>,</span> <span class='label'>hp:</span> <span class='int'>100</span><span class='rparen'>)</span>
|
238
|
+
</code></pre>
|
239
|
+
|
240
|
+
<p>In this example we created a component manager called "Stats".
|
241
|
+
The name given to component managers must follow the same rules for naming constants in ruby for a reason you will shortly see.
|
242
|
+
The parameters following are all creating the attributes we can set.
|
243
|
+
We can set any number of parameters we wish, in this example we define two.
|
244
|
+
The <code>:armour</code> parameter is being created without a default, it will equal to <code>nil</code> when a new component is created, while <code>hp</code> will be equal to 100 when a component is created.
|
245
|
+
When defining attributes symbols should be used.</p>
|
246
|
+
|
247
|
+
<h3 id="creating-a-component-from-a-component-manager">Creating a Component from a Component Manager</h3>
|
248
|
+
|
249
|
+
<p>Now that we have a component manager we can make components from it like so:</p>
|
250
|
+
|
251
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@component</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Components.html" title="FelFlame::Components (class)">Components</a></span></span><span class='op'>::</span><span class='const'>Stats</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
252
|
+
</code></pre>
|
253
|
+
|
254
|
+
<p>Or we can even change the defaults:</p>
|
255
|
+
|
256
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@component</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Components.html" title="FelFlame::Components (class)">Components</a></span></span><span class='op'>::</span><span class='const'>Stats</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>armour:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>steel</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
257
|
+
</code></pre>
|
258
|
+
|
259
|
+
<h3 id="accessing-and-getting-id">Accessing and Getting ID</h3>
|
260
|
+
|
261
|
+
<p>Just like Entities, Components have IDs.
|
262
|
+
These IDs are only unique within the scope of their respective Component Managers.
|
263
|
+
Here is how we can get the ID, as well as how to access a Component from its Component Manager.</p>
|
264
|
+
|
265
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@component</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Components.html" title="FelFlame::Components (class)">Components</a></span></span><span class='op'>::</span><span class='const'>Stats</span><span class='lbracket'>[</span><span class='int'>2</span><span class='rbracket'>]</span>
|
266
|
+
<span class='ivar'>@component</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span> <span class='comment'># => 2
|
267
|
+
</span></code></pre>
|
268
|
+
|
269
|
+
<h3 id="accessing-attributes-and-changing-them">Accessing Attributes and Changing Them</h3>
|
270
|
+
|
271
|
+
<p>There are a few different ways we can read or change the attributes of a component depending on what our needs are.
|
272
|
+
Here are the ways to edit attrubutes, followed by the ways to read them.</p>
|
273
|
+
|
274
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@component</span><span class='period'>.</span><span class='id identifier rubyid_armour'>armour</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Mythril</span><span class='tstring_end'>'</span></span>
|
275
|
+
<span class='ivar'>@component</span><span class='period'>.</span><span class='id identifier rubyid_update_attrs'>update_attrs</span><span class='lparen'>(</span><span class='label'>armour:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Leather</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>hp:</span> <span class='int'>95</span><span class='rparen'>)</span>
|
276
|
+
</code></pre>
|
277
|
+
|
278
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@component</span><span class='period'>.</span><span class='id identifier rubyid_hp'>hp</span> <span class='comment'># => 95
|
279
|
+
</span><span class='ivar'>@component</span><span class='period'>.</span><span class='id identifier rubyid_attrs'>attrs</span> <span class='comment'># => {armour: 'Leather', hp: 95}
|
280
|
+
</span></code></pre>
|
281
|
+
|
282
|
+
<h3 id="deleting-components">Deleting Components</h3>
|
283
|
+
|
284
|
+
<p>Deleting a Component is the same format as deleting an Entity. When a Component is deleted referenced to it such as to entities are automatically cleared.</p>
|
285
|
+
|
286
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@component</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span>
|
287
|
+
</code></pre>
|
288
|
+
|
289
|
+
<h3 id="iterating-over-components">Iterating over Components</h3>
|
290
|
+
|
291
|
+
<p>When you make Systems you will want to be able to iterate over all Components of the same Component Manager(for example iterating over all sprites to render them). Here is how we do that:</p>
|
292
|
+
|
293
|
+
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Components.html" title="FelFlame::Components (class)">Components</a></span></span><span class='op'>::</span><span class='const'>Sprites</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_component'>component</span><span class='op'>|</span>
|
294
|
+
<span class='comment'>#do something with components
|
295
|
+
</span><span class='kw'>end</span>
|
296
|
+
</code></pre>
|
297
|
+
|
298
|
+
<h2 id="systems">Systems</h2>
|
299
|
+
|
300
|
+
<h3 id="creation">Creation</h3>
|
301
|
+
|
302
|
+
<p>We can create Systems like so:</p>
|
303
|
+
|
304
|
+
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="FelFlame/Systems.html#initialize-instance_method" title="FelFlame::Systems#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>name:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Render</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>priority:</span> <span class='int'>2</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
305
|
+
<span class='comment'># Code and Logic
|
306
|
+
</span><span class='kw'>end</span>
|
307
|
+
</code></pre>
|
308
|
+
|
309
|
+
<p>The name we assign is how we can access the System, like so:</p>
|
310
|
+
|
311
|
+
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>Render</span>
|
312
|
+
</code></pre>
|
313
|
+
|
314
|
+
<p>Priority determines the order Systems should be executed, this is used for <code>Scenes</code> and the <code>Stage</code>.
|
315
|
+
The lower the number, the earlier a given System will be executed.
|
316
|
+
E.g priority 1 will go first, priority 2 will go second, etcetera. </p>
|
317
|
+
|
318
|
+
<p>Often we will want to execute some logic on each Component in a given Component Manager so our code might look like this:</p>
|
319
|
+
|
320
|
+
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="FelFlame/Systems.html#initialize-instance_method" title="FelFlame::Systems#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>name:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Render</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>priority:</span> <span class='int'>2</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
321
|
+
<span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Components.html" title="FelFlame::Components (class)">Components</a></span></span><span class='op'>::</span><span class='const'>Sprites</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_component'>component</span><span class='op'>|</span>
|
322
|
+
<span class='comment'># do something with these components
|
323
|
+
</span> <span class='kw'>end</span>
|
324
|
+
<span class='kw'>end</span>
|
325
|
+
</code></pre>
|
326
|
+
|
327
|
+
<h3 id="execution">Execution</h3>
|
328
|
+
|
329
|
+
<p>After we create a System, it won't do anything on its own until we tell it to. Here is how:</p>
|
330
|
+
|
331
|
+
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>Render</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
|
332
|
+
</code></pre>
|
333
|
+
|
334
|
+
<p>Sometimes you might want to manually activate a System, but the more common way to have Systems be triggered is to use Scenes and the Stage or the alternative ways of execution.</p>
|
335
|
+
|
336
|
+
<h3 id="alternative-execution">Alternative Execution</h3>
|
337
|
+
|
338
|
+
<p>Sometimes you want a System to automatically trigger when a special even happens. FelFlame can keep track of when a Component is added, removed, or when an attribute is changed and then execute Systems linked to these events. Here is how to create these links:</p>
|
339
|
+
|
340
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># When this Component is added to an Entity, this System will be called
|
341
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_trigger_when_added'>trigger_when_added</span><span class='lparen'>(</span><span class='ivar'>@component</span><span class='rparen'>)</span>
|
342
|
+
|
343
|
+
<span class='comment'># When this Component is removed from an Entity, this System will be called
|
344
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_trigger_when_removed'>trigger_when_removed</span><span class='lparen'>(</span><span class='ivar'>@component</span><span class='rparen'>)</span>
|
345
|
+
|
346
|
+
<span class='comment'># When this Component's health attribute is changed, this System will be called
|
347
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_trigger_when_is_set'>trigger_when_is_set</span><span class='lparen'>(</span><span class='ivar'>@component</span><span class='comma'>,</span> <span class='symbol'>:health</span><span class='rparen'>)</span>
|
348
|
+
</code></pre>
|
349
|
+
|
350
|
+
<p>If we want these triggers to happen for all Components that belong to specific Component Manager then we can do that instead:</p>
|
351
|
+
|
352
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># When a Component from this Component Manager is added to an Entity, this System will be called
|
353
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_trigger_when_added'>trigger_when_added</span><span class='lparen'>(</span><span class='ivar'>@component_manager</span><span class='rparen'>)</span>
|
354
|
+
|
355
|
+
<span class='comment'># When a Component from this Component Manager is removed from an Entity, this System will be called
|
356
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_trigger_when_removed'>trigger_when_removed</span><span class='lparen'>(</span><span class='ivar'>@component_manager</span><span class='rparen'>)</span>
|
357
|
+
|
358
|
+
<span class='comment'># When this Component's health attribute from this Component Manager is changed, this System will be called
|
359
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_trigger_when_is_set'>trigger_when_is_set</span><span class='lparen'>(</span><span class='ivar'>@component_manager</span><span class='comma'>,</span> <span class='symbol'>:health</span><span class='rparen'>)</span>
|
360
|
+
</code></pre>
|
361
|
+
|
362
|
+
<p>We can create any number of these links between Systems, Components, and Component Manangers as we like, simply call the method again with our other Components and Component Managers</p>
|
363
|
+
|
364
|
+
<h3 id="clearing-alternative-executions">Clearing Alternative Executions</h3>
|
365
|
+
|
366
|
+
<p>If we wish to remove these links that we created, we can do that using the follwing function in any of the following ways:</p>
|
367
|
+
|
368
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># clears ALL triggers with this system
|
369
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_clear_triggers'>clear_triggers</span>
|
370
|
+
|
371
|
+
<span class='comment'># clears ALL triggers with this Component Manager
|
372
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_clear_triggers'>clear_triggers</span><span class='lparen'>(</span><span class='ivar'>@component</span><span class='rparen'>)</span>
|
373
|
+
|
374
|
+
<span class='comment'># clear the 'trigger_when_added' for this Component
|
375
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_clear_triggers'>clear_triggers</span><span class='lparen'>(</span><span class='ivar'>@component</span><span class='comma'>,</span> <span class='symbol'>:added</span><span class='rparen'>)</span>
|
376
|
+
|
377
|
+
<span class='comment'># clear the 'trigger_when_removed' for this Component
|
378
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_clear_triggers'>clear_triggers</span><span class='lparen'>(</span><span class='ivar'>@component</span><span class='comma'>,</span> <span class='symbol'>:removed</span><span class='rparen'>)</span>
|
379
|
+
|
380
|
+
<span class='comment'># clear the 'trigger_when_is_set' for this Component specifically for the health attribute
|
381
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_clear_triggers'>clear_triggers</span><span class='lparen'>(</span><span class='ivar'>@component</span><span class='comma'>,</span> <span class='symbol'>:is_set</span><span class='comma'>,</span> <span class='symbol'>:health</span><span class='rparen'>)</span>
|
382
|
+
</code></pre>
|
383
|
+
|
384
|
+
<p>Likewise we can do the same with Component Managers:</p>
|
385
|
+
|
386
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># clears ALL triggers with this Component
|
387
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_clear_triggers'>clear_triggers</span><span class='lparen'>(</span><span class='ivar'>@component_manager</span><span class='rparen'>)</span>
|
388
|
+
|
389
|
+
<span class='comment'># clear the 'trigger_when_added' for this Component Manager
|
390
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_clear_triggers'>clear_triggers</span><span class='lparen'>(</span><span class='ivar'>@component_manager</span><span class='comma'>,</span> <span class='symbol'>:added</span><span class='rparen'>)</span>
|
391
|
+
|
392
|
+
<span class='comment'># clear the 'trigger_when_removed' for this Component Manager
|
393
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_clear_triggers'>clear_triggers</span><span class='lparen'>(</span><span class='ivar'>@component_manager</span><span class='comma'>,</span> <span class='symbol'>:removed</span><span class='rparen'>)</span>
|
394
|
+
|
395
|
+
<span class='comment'># clear the 'trigger_when_is_set' for this Component Manager specifically for the health attribute
|
396
|
+
</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_clear_triggers'>clear_triggers</span><span class='lparen'>(</span><span class='ivar'>@component_manager</span><span class='comma'>,</span> <span class='symbol'>:is_set</span><span class='comma'>,</span> <span class='symbol'>:health</span><span class='rparen'>)</span>
|
397
|
+
</code></pre>
|
398
|
+
|
399
|
+
<h3 id="redefinition">Redefinition</h3>
|
400
|
+
|
401
|
+
<p>If we wanted to change what code or logic a given System executes, we could do that with:</p>
|
402
|
+
|
403
|
+
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>PassiveRegen</span><span class='period'>.</span><span class='id identifier rubyid_redefine'>redefine</span> <span class='kw'>do</span>
|
404
|
+
<span class='comment'># Some new logic or code
|
405
|
+
</span><span class='kw'>end</span>
|
406
|
+
</code></pre>
|
407
|
+
|
408
|
+
<h2 id="scenes">Scenes</h2>
|
409
|
+
|
410
|
+
<h3 id="creation">Creation</h3>
|
411
|
+
|
412
|
+
<p>Once we have all the core parts of ECS, we will want to organize our Systems. To do this we will use Scenes to group up Systems so they can quickly be enabled or disabled. Note that <a href="#alternative-execution">Alternative Executions</a> will occur even if they are not part of a Scene. Here is how we make a new Scene:</p>
|
413
|
+
|
414
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@scene</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Scenes.html" title="FelFlame::Scenes (class)">Scenes</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="FelFlame/Scenes.html#initialize-instance_method" title="FelFlame::Scenes#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ExampleScene</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
415
|
+
</code></pre>
|
416
|
+
|
417
|
+
<h3 id="accessing">Accessing</h3>
|
418
|
+
|
419
|
+
<p>Just like other classes in FelFlame, the name we gave the Scene is how we access it:</p>
|
420
|
+
|
421
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@scene</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Scenes.html" title="FelFlame::Scenes (class)">Scenes</a></span></span><span class='op'>::</span><span class='const'>ExampleScene</span>
|
422
|
+
</code></pre>
|
423
|
+
|
424
|
+
<h3 id="adding-systems">Adding Systems</h3>
|
425
|
+
|
426
|
+
<p>Adding Systems is simple. We can add as many as we want. In this example we add 3 different systems:</p>
|
427
|
+
|
428
|
+
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Scenes.html" title="FelFlame::Scenes (class)">Scenes</a></span></span><span class='op'>::</span><span class='const'>ExampleScene</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>Render</span><span class='comma'>,</span> <span class='ivar'>@system2</span><span class='comma'>,</span> <span class='ivar'>@system3</span><span class='rparen'>)</span>
|
429
|
+
</code></pre>
|
430
|
+
|
431
|
+
<h3 id="removing-systems">Removing Systems</h3>
|
432
|
+
|
433
|
+
<p>Removing Systems works simularly:</p>
|
434
|
+
|
435
|
+
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Scenes.html" title="FelFlame::Scenes (class)">Scenes</a></span></span><span class='op'>::</span><span class='const'>ExampleScene</span><span class='period'>.</span><span class='id identifier rubyid_remove'>remove</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Systems.html" title="FelFlame::Systems (class)">Systems</a></span></span><span class='op'>::</span><span class='const'>Render</span><span class='comma'>,</span> <span class='ivar'>@system2</span><span class='comma'>,</span> <span class='ivar'>@system3</span><span class='rparen'>)</span>
|
436
|
+
</code></pre>
|
437
|
+
|
438
|
+
<h3 id="clearing">Clearing</h3>
|
439
|
+
|
440
|
+
<p>If you want to remove all Systems from a Scene here is how we do it:</p>
|
441
|
+
|
442
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@scene</span><span class='period'>.</span><span class='id identifier rubyid_clear'>clear</span>
|
443
|
+
</code></pre>
|
444
|
+
|
445
|
+
<h3 id="execution">Execution</h3>
|
446
|
+
|
447
|
+
<p>To execute all Systems within a scene once we can just do:</p>
|
448
|
+
|
449
|
+
<pre class="code ruby"><code class="ruby"><span class='ivar'>@scene</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span>
|
450
|
+
</code></pre>
|
451
|
+
|
452
|
+
<p>The Scene will make sure that the systems are executed in the correct order based on their given priorities</p>
|
453
|
+
|
454
|
+
<h2 id="stage">Stage</h2>
|
455
|
+
|
456
|
+
<h3 id="adding-scenes">Adding Scenes</h3>
|
457
|
+
|
458
|
+
<p>Finally we have the Stage. There is only a single Stage and we do not have to create it as it exists by default. By adding a Scene to the Stage we are saying that the Scene is active. To add a Scene we do the following:</p>
|
459
|
+
|
460
|
+
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Stage.html" title="FelFlame::Stage (class)">Stage</a></span></span><span class='period'>.</span><span class='id identifier rubyid_add'><span class='object_link'><a href="FelFlame/Stage.html#add-class_method" title="FelFlame::Stage.add (method)">add</a></span></span> <span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'>Scene</span><span class='op'>::</span><span class='const'>ExampleScene</span>
|
461
|
+
</code></pre>
|
462
|
+
|
463
|
+
<h3 id="removing-scenes">Removing Scenes</h3>
|
464
|
+
|
465
|
+
<p>Likewise we can remove Scenes:</p>
|
466
|
+
|
467
|
+
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Stage.html" title="FelFlame::Stage (class)">Stage</a></span></span><span class='period'>.</span><span class='id identifier rubyid_remove'><span class='object_link'><a href="FelFlame/Stage.html#remove-class_method" title="FelFlame::Stage.remove (method)">remove</a></span></span> <span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'>Scene</span><span class='op'>::</span><span class='const'>ExampleScene</span>
|
468
|
+
</code></pre>
|
469
|
+
|
470
|
+
<h3 id="executing">Executing</h3>
|
471
|
+
|
472
|
+
<p>On each frame of the game we want to execute the Stage once. When the Stage is executed it is progressing your game 1 frame forward. The Stage will make sure for you that all the Systems from all Scenes added will be executed in the correct order according to their priority. Here is how we do it:</p>
|
473
|
+
|
474
|
+
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="FelFlame.html" title="FelFlame (class)">FelFlame</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FelFlame/Stage.html" title="FelFlame::Stage (class)">Stage</a></span></span><span class='period'>.</span><span class='id identifier rubyid_call'><span class='object_link'><a href="FelFlame/Stage.html#call-class_method" title="FelFlame::Stage.call (method)">call</a></span></span>
|
475
|
+
</code></pre>
|
476
|
+
|
477
|
+
<h2 id="closing-notes">Closing Notes</h2>
|
478
|
+
|
479
|
+
<p>There are some methods I haven't gone over in the overview. If you want to see everything and read in more detail check out the <a href="https://rubydoc.info/github/realtradam/FelFlame/master/frames">Documentation</a>!</p>
|
480
|
+
|
481
|
+
<h1 id="contribution">Contribution</h1>
|
482
|
+
|
483
|
+
<p>Contributors are welcome! I am always looking to impove the capabilities of game development in Ruby. Feel free to open an issue to discuss a proposed changed or fix. To code a change or fix first fork the project. Next write your changes or fixes. Make sure all your changes and fixes are properly documented using Yard(I will not merge if it is not 100% documented) and make sure everything has tests written for it with Rspec(I will also not merge if it does not have 100% test coverage). Once you have your changes made then simply make a pull request. </p>
|
484
|
+
|
485
|
+
<p>If you need help writing documentation or tests feel free to ask! </p>
|
486
|
+
|
487
|
+
<p>If you want to contribute to development with a thanks you can always <a href="https://ko-fi.com/tradam">buy me a coffee ;^)</a></p>
|
488
|
+
</div></div>
|
489
|
+
|
490
|
+
<div id="footer">
|
491
|
+
Generated on Fri Jul 9 01:56:53 2021 by
|
492
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
493
|
+
0.9.26 (ruby-2.7.3).
|
494
|
+
</div>
|
495
|
+
|
496
|
+
</div>
|
497
|
+
</body>
|
498
|
+
</html>
|