Difference between revisions of "Modules/game pawn"
From MSX Game Library
< Modules
(→Define pawn's animations) |
|||
Line 15: | Line 15: | ||
The visual of a pawn is defined by one or more sprite layers. The <tt>Game_Sprite</tt> structure allows to define the parameters of each layer : The X/Y position of the layer relative to the Pawn, the pattern number offset from the pattern number defined in the animation, the sprite color and a special flag for display. | The visual of a pawn is defined by one or more sprite layers. The <tt>Game_Sprite</tt> structure allows to define the parameters of each layer : The X/Y position of the layer relative to the Pawn, the pattern number offset from the pattern number defined in the animation, the sprite color and a special flag for display. | ||
− | ''' | + | '''Example:''' |
− | + | A two color sprite (2 layer): <syntaxhighlight lang="C"> | |
const Game_Sprite g_SpriteLayers[] = | const Game_Sprite g_SpriteLayers[] = | ||
{ | { | ||
{ 0, 0, 0, COLOR_WHITE, 0 }, // Sprite position offset: 0,0. Pattern offset: 0. Color: White. No special flag | { 0, 0, 0, COLOR_WHITE, 0 }, // Sprite position offset: 0,0. Pattern offset: 0. Color: White. No special flag | ||
+ | { 0, -8, 4, COLOR_GRAY, 0 }, // Sprite position offset: 0,-8. Pattern offset: 4. Color: Gray. No special flag | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | === Define pawn's animations === | |
− | const | + | Each animation is defined by a list of Game_Frame structures that determine : The pattern number of the animation frame, the duration of the frame in number of display cycles, and a function to call when the character reach a given frame of the animation. |
+ | |||
+ | '''Example:''' | ||
+ | Push animation with function to trigger <syntaxhighlight lang="C"> | ||
+ | const Game_Frame g_FramePunch[] = | ||
{ | { | ||
− | { 0, | + | { 0, 4, null }, // Display pattern 0 for 4 render cycles |
− | { | + | { 8, 4, null }, |
+ | { 8, 1, DoPunch }, // call function DoPunch() when Pawn is displaying this frame | ||
+ | { 16, 4, null }, | ||
+ | { 24, 4, null }, | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== Define pawn's animations === | === Define pawn's animations === | ||
Line 56: | Line 55: | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
== Annexe == | == Annexe == | ||
* See also : Sample program {{SAMPLE|s_game}} | * See also : Sample program {{SAMPLE|s_game}} |
Revision as of 13:41, 18 February 2022
The game_pawn module handle character animation, rendering, collision and physics.
This module offer several structures the user can use to configure a pawn (a player, an enemy or any moving object) for rendering (multi-layers and flip/flap) and movement.
Contents
Dependencies
Settings
- GAMEPAWN_USE_PHYSICS: Include collision and physics handling functions.
Usage
Define pawn's sprites
The visual of a pawn is defined by one or more sprite layers. The Game_Sprite structure allows to define the parameters of each layer : The X/Y position of the layer relative to the Pawn, the pattern number offset from the pattern number defined in the animation, the sprite color and a special flag for display.
Example:
A two color sprite (2 layer): const Game_Sprite g_SpriteLayers[] = { { 0, 0, 0, COLOR_WHITE, 0 }, // Sprite position offset: 0,0. Pattern offset: 0. Color: White. No special flag { 0, -8, 4, COLOR_GRAY, 0 }, // Sprite position offset: 0,-8. Pattern offset: 4. Color: Gray. No special flag };
Define pawn's animations
Each animation is defined by a list of Game_Frame structures that determine : The pattern number of the animation frame, the duration of the frame in number of display cycles, and a function to call when the character reach a given frame of the animation.
Example:
Push animation with function to trigger const Game_Frame g_FramePunch[] = { { 0, 4, null }, // Display pattern 0 for 4 render cycles { 8, 4, null }, { 8, 1, DoPunch }, // call function DoPunch() when Pawn is displaying this frame { 16, 4, null }, { 24, 4, null }, };
Define pawn's animations
Each animation is defined by a list of Game_Frame structures that determine : The pattern number of the animation frame, the duration of the frame in number of display cycles, and a function to call when the character reach a given frame of the animation.
Examples:
Push animation with function to trigger const Game_Frame g_FramePunch[] = { { 0, 4, null }, // Display pattern 0 for 4 render cycles { 8, 4, null }, { 8, 1, DoPunch }, // call function DoPunch() when Pawn is displaying this frame { 16, 4, null }, { 24, 4, null }, };
Annexe
- See also : Sample program s_game