Difference between revisions of "Modules/game pawn/Usage"

From MSX Game Library

< Modules‎ | game pawn

(Define pawn's sprites)
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
=== Define pawn's sprites ===
 
=== Define pawn's sprites ===
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 offset of the layer relative to the Pawn position, the pattern number offset from the pattern number defined in the animation, the sprite color and a special flag for display.
  
 
'''Example:'''
 
'''Example:'''
Line 16: Line 16:
 
'''Example:'''
 
'''Example:'''
 
Push animation with function to trigger ‎<syntaxhighlight lang="C">
 
Push animation with function to trigger ‎<syntaxhighlight lang="C">
const Game_Frame g_FramePunch[] =
+
const Game_Frame g_FramesPunch[] =
 
{
 
{
 
{ 0, 4, NULL}, // Display pattern 0 for 4 render cycles
 
{ 0, 4, NULL}, // Display pattern 0 for 4 render cycles
Line 31: Line 31:
 
'''Examples:''' ‎<syntaxhighlight lang="c">
 
'''Examples:''' ‎<syntaxhighlight lang="c">
 
const Game_Action g_AnimActions[] =
 
const Game_Action g_AnimActions[] =
{ //  Frames        Number                  Loop? Interrupt?
+
{ //  Frames        Number                  Loop? Interrupt?
{ g_FramesIdle, numberof(g_FramesIdle), TRUE, TRUE },
+
{ g_FramesIdle, numberof(g_FramesIdle), TRUE, TRUE },
{ g_FramesMove, numberof(g_FramesMove), TRUE, TRUE },
+
{ g_FramesMove, numberof(g_FramesMove), TRUE, TRUE },
{ g_FramesJump, numberof(g_FramesJump), TRUE, TRUE },
+
{ g_FramesJump, numberof(g_FramesJump), TRUE, TRUE },
{ g_FramesFall, numberof(g_FramesFall), TRUE, TRUE },
+
{ g_FramesPunch, numberof(g_FramesFall), FALSE, FALSE }, // Play once, can't be interrupted
 
};‎</syntaxhighlight>
 
};‎</syntaxhighlight>

Revision as of 23:38, 18 April 2024

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 offset of the layer relative to the Pawn position, 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. Create a structure for each animation. You have to provide a complete list of all action that the pawn can do.

Example:

Push animation with function to trigger ‎
const Game_Frame g_FramesPunch[] =
{
	{ 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 actions

An action is defined in the Game_Action structure and include a animation plus some parameters like the looping of the animation or a flag to determine if the action can be interrupted.

Examples:
const Game_Action g_AnimActions[] =
{ //  Frames        Number                  Loop?  Interrupt?
	{ g_FramesIdle,  numberof(g_FramesIdle), TRUE,  TRUE },
	{ g_FramesMove,  numberof(g_FramesMove), TRUE,  TRUE },
	{ g_FramesJump,  numberof(g_FramesJump), TRUE,  TRUE },
	{ g_FramesPunch, numberof(g_FramesFall), FALSE, FALSE }, // Play once, can't be interrupted
};‎