Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
tutorial: elementary scripts
This time, we will not need custom C++ classes, we will use the scripting system of libgeds to tell which spriteset and tileset to load, and to instanciate an animated character. Demo.cmd is the main script doing all this. It requires a sub-script describing the "state machine" for the animated character "xdad.cmd". Such a sub-script gets its own set of animation and state identifiers, which the root script can later 'import' selectively. At least one state of the sub-script needs to be imported if you want to be able to create new instances of the character. Instantiation is performed through the `gob<instance-id> :state<global-state-id>(<coordinates>) <cast>` line. This will lookup the given state, decide what sort of back-end code is required to process the state machine (in this case a SimpleGob) and creates it, linking it to the given state. As a result, the `Hero` class is no longer required, nor is explicit loading of SpriteSet. Resources are now managed directly by the GameScript class, according to the `spr.<command>` and `bg<layer-id>.<command>` lines of the script. Admittedly, the new character cannot move yet. We will solve this with appropriate state machine rules in upcoming tutorials. The glu logic to manipulate the GameScript is implemented through two 'window' classes(both defined in GameWindow.hpp), one for parsing and running the level (GameWindow), and the other to handle level-to-level transition (LoadingWindow). We can get the script running simply by "switching" to the GameWindow (using Engine::setWindow) once the appropriate FileReader has been created. You will note a few changes regarding the 'background' initialization: - we now have to explictly call `restore()` in the code, because we no longer ask the engine to switch to the MetaWindow. - the GameScript do use the BG2 for its own purpose, and loads tileset there. However, the settings are slightly different from what we did before. The tileset gets loaded at a higher location (address) in video memory. We could initialize `tile = 512`, but we can also tell the hardware to interprete the tile number "3" differently (2 * 256 + 3) by setting the BG_TILE_BASE field of the background layer control register. - this is also temporarily. We'll do more interesting backgrounds using maps created by the Level Editor for DS in an upcoming tutorial.
- Loading branch information
Showing
4 changed files
with
62 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- sh -*- | ||
# simple demo script. With no maps yet, there isn't much to demonstrate ^^" | ||
# | ||
print "loading level1" | ||
bg0.load "../bg.spr" | ||
print "loading sprites" | ||
spr.load "../hero.spr":1 | ||
|
||
print "declaring state machine" | ||
|
||
input "xdad.cmd" | ||
import state 0 | ||
print "creating gobs" | ||
gob0 :state0 (128, 100) h # rightmost | ||
focus=gob0 | ||
print "go!" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
anim1 0 { | ||
spr0 4 | ||
delay 3 | ||
spr0 5 | ||
delay 3 | ||
spr0 6 | ||
delay 3 | ||
spr0 7 | ||
delay 3 | ||
spr0 8 | ||
delay 3 | ||
spr0 9 | ||
delay 3 | ||
spr0 a | ||
delay 3 | ||
spr0 b | ||
delay 3 | ||
loop | ||
} | ||
|
||
state0 :anim1 | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters