i am using the WGPFD book.
there is this function>
void Fire_Plasma(int x,int y, int vel)
{
// this function fires a plasma pulse at the given starting
// position and velocity, of course, one must be free for
// this to work
// scan for a pulse that is available
for (int index=0; index<MAX_PLASMA; index++)
{
// is this one available
// test if plasma pulse is in flight
if (plasma[index].state == PLASMA_STATE_OFF)
{
// start this one up
plasma[index].x = x;
plasma[index].y = y;
plasma[index].yv = -vel;
plasma[index].curr_frame = 0;
plasma[index].state = PLASMA_STATE_ON;
// later
return;
} // end if
} // end for
} // end Fire_Plasma
i am kinda confused to what actualli happen, that is, which states r being triggered...heres my understanding...see if find any stuff i misunderstood...
"Initially, the plasma state is "off".
and we have #define PLASMA_STATE_OFF 0
#define PLASMA_STATE_ON 1
When spacebar is pressed, Fire_Plasma() starts.
If index is 0, plasma[0].state is checked to see if it is in "off" state.
It is in "off" state, so now plasma[0].state is switched "on".
now in Init_Plasma()"
void Init_Plasma(void)
{
// this function initializes and loads all the plasma
// weapon pulses
// load the plasma imagery
Load_Bitmap_File(&bitmap8bit, "PLASMA8.BMP");
#if 1
// now create and load each plasma pulse
for (int pulse=0; pulse<MAX_PLASMA; pulse++)
{
// create the bob to hold pulse
Create_BOB(&plasma[pulse],0,0,16,24,6,
BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_FRAME,
DDSCAPS_SYSTEMMEMORY);
// load animation frames
for (int frame=0; frame<6; frame++)
Load_Frame_BOB(&plasma[pulse],&bitmap8bit,frame,frame,0,BITMAP_EXTRACT_MODE_CELL);
// set animation rate
Set_Anim_Speed_BOB(&plasma[pulse],1);
// set state to off
plasma[pulse].state = PLASMA_STATE_OFF;
} // end for pulse
#endif
#if 0
// create the first bob
Create_BOB(&plasma[0],0,0,16,24,6,
BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_FRAME,
DDSCAPS_SYSTEMMEMORY);
// load animation frames
for (int frame=0; frame<6; frame++)
Load_Frame_BOB(&plasma[0],&bitmap8bit,frame,frame,0,BITMAP_EXTRACT_MODE_CELL);
// set animation rate
Set_Anim_Speed_BOB(&plasma[0],1);
// set state to off
plasma[0].state = PLASMA_STATE_OFF;
for (int pulse=1; pulse<MAX_PLASMA; pulse++)
{
memcpy(&plasma[pulse], &plasma[0], sizeof(BOB));
} // end for pulse
#endif
// unload data infile
Unload_Bitmap_File(&bitmap8bit);
} // end Init_Plasma
"so now [#if 1] from the Init_Plasma() starts, plasma[0].state
will be switched "off". If MAX_PLASMA is 8, and all plasma[0-7]
undergone [#if 1], and then their states are switched "off" towards the end of [#if 1].
If the spacebar is always pressed, i assume that Fire_Plasma()
continue to occur."
But why do we need [#if 0] in Init_Plasma()?
Does it mean that the next set of 8 plasma pulses will be continued to fire by undergoing [#if 0], since the PLASMA_STATE_OFF is now in effect? (since Fire_Plasma() will set the attributes globally)