You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Sprites modes 8x8 and 8x16](#sprites-modes-8x8-and-8x16)
37
34
-[Sprite animations](#sprite-animations)
38
35
-[Collisions sprite vs sprite and sprite vs background](#collisions)
39
-
- Almost transparent, bank management, now using bankpack
40
-
- Fonts
41
-
- Music support using [gbt-player](https://github.com/AntonioND/gbt-player) or [hUGETracker](https://github.com/SuperDisk/hUGETracker)
42
-
- Sound Effects
36
+
-[Auto Banking](#auto-banking)
37
+
-[Fonts](#fonts)
38
+
-[Music](#music)
39
+
- Sound Effects
40
+
- Game Boy Color
43
41
44
42
### Easy makefile support
45
43
@@ -224,7 +222,7 @@ The Sprite field **anim_frame** contains the animation index if there is an anim
224
222
225
223
### Collisions
226
224
227
-
All sprites have a rectangle collider that will be used to check collisions. By default it will be defined by metasprites width and height but you can adjust it on the sprite .meta file
225
+
All sprites have a rectangle collider that will be used to check collisions. By default it will be defined by the metasprites dimensions but you can adjust it on the sprite .meta file
228
226
```
229
227
-px 2 -py 0 -pw 12 -ph 19
230
228
```
@@ -234,8 +232,103 @@ This rectangle will remain constant when the sprite is flipped
234
232
235
233
#### Sprite vs Background
236
234
235
+
First you need to declare an array (terminated in 0) indicating which tiles are considered collidables
236
+
```C
237
+
UINT8 collision_tiles[] = {1, 2, 3, 4, 8, 10, 0}; //In this case tiles 1, 2, 3, 4, 8 an 10 will be considered collidables
238
+
```
239
+
240
+
Then you need to pass this array when you Init the scroll (you can have several arrays depending on the tileset you use)
241
+
```C
242
+
InitScroll(BANK(map), &map, collision_tiles, 0);
243
+
```
244
+
245
+
And now, instead of directly modify the X and Y coordinates of your Sprite, you need to call TranslateSprite
246
+
```C
247
+
TranslateSprite(THIS, -1, 0); //Move the current sprite 1 pixel to the left checking collisions with the background
248
+
```
249
+
If the Sprite collides then it won't advance and TranslateSprite will return the collision tile (so you can check if there are spikes or other stuff)
250
+
251
+
You can also declare an array of collision tiles that will be only checked when the Sprite is moving downwards. This is very useful for platform games where the character can jump into a platform from below
252
+
253
+

254
+
237
255
#### Sprite vs Sprite
238
256
257
+
To check if two sprites are colliding call the function CheckCollision in "Sprite.h"
258
+
```C
259
+
if(CheckCollision(THIS, other_sprite))
260
+
{
261
+
//Sprites are colliding!
262
+
}
263
+
```
264
+
265
+
### Auto Banking
266
+
267
+
ZGB uses [bankpack](https://bbbbbr.github.io/gbdk-2020/docs/api/docs_toolchain.html#autotoc_md79) so you don't need to worry about where to place your code or resources. Just make sure that:
268
+
- **_#include "Banks/SetAutoBank.h"_** is added at the beggining of your States and Sprites
269
+
- If you need to call an sprite function from another sprite, declare it **BANKED**
270
+
```C
271
+
void HitMe(); //WRONG!!
272
+
void HitMe() BANKED; //RIGHT!
273
+
```
274
+
- If you receive this error after making a build:
275
+
```C
276
+
**2>EXEC : error : size of the buffer is too small**_
277
+
```
278
+
279
+
You need to increment N_BANKS (must be a power of two: 2, 4, 8, 16...) in your makefile
280
+
- Check the png created in the Debug/Release folder of your build to get an overview of your banks usage. For a more detailed information you can use [RomUsage](https://github.com/bbbbbr/romusage)
281
+
282
+
### Fonts
283
+
284
+
Fonts in ZGB are gbr files of **45** tiles, with uppercase characters **_A-Z 0-9 !'()-.:?_** The ZGB-Template already comes with a default font that you can customize
285
+
286
+
In order to print some texts in your game
287
+
1. Import the font using
288
+
```C
289
+
#include "Print.h"
290
+
IMPORT_TILES(<font filename>);
291
+
```
292
+
2. Init the font in the START function of your State by calling
293
+
```C
294
+
INIT_FONT(font, PRINT_BKG); //PRINT_BKG to draw on the background or PRINT_WIN to draw on the Window
295
+
```
296
+
3. Print some text using
297
+
```C
298
+
PRINT(0, 0, "Hello World"); //print Hello World on 0, 0
299
+
```
300
+
301
+
You can also use **Printf** to draw some vars with %d %i &u and %s
302
+
303
+
You can change the target (background or window) with the var **print_target**
304
+
305
+
### Music
306
+
307
+
You can select witch music drive to use [gbt-player](https://github.com/AntonioND/gbt-player) or [hUGETracker](https://github.com/SuperDisk/hUGETracker) in the Makefile
308
+
```
309
+
# Music player: HUGETRACKER(default) or GBT_PLAYER
310
+
MUSIC_PLAYER = GBT_PLAYER
311
+
```
312
+
313
+
To play some music in your game
314
+
- Place the .mod or .uge files in the res/music folder
315
+
- Import the music with
316
+
```C
317
+
DECLARE_MUSIC(<music_filename>)
318
+
```
319
+
- Play it with
320
+
```C
321
+
PlayMusic(<music_filename>, LOOP)
322
+
```
323
+
- And Stop it with
324
+
```C
325
+
StopMusic(<music_filename>, LOOP)
326
+
```
327
+
328
+
### Sound Effects
329
+
330
+
### Game Boy Color
331
+
239
332
## License
240
333
241
334
Released under the [MIT license](https://opensource.org/licenses/MIT)
0 commit comments