bad problem...
I have a pretty good pattern AI working right now and I just finished up the last part for my last enemy. What the patter code does is it makes the enemy move left or right and then shoot when I want them to. I have been using the same struture (and sometimes code) for all of the other ememies and they have worked fine but this one has a problem. It won''t fire the weapon, I tested to see if it was preforming the drawing function and it is, then I tested to see if it was performing the firing function and it was (well I already knew that because it was playing the firing sound). I double checked that I was doing everything the same way as I was doing it before and I was. So now I am completely clueless why this is happening. Im pretty sure that its in the actual gun''s code not the AI so here is that code (this code is almost the exact same as all my other gun''s code that works find):
void Init_Bosscannon(void)
{
Load_Bitmap_File(&bitmap16bit, "BOSSMSL.BMP";
#if 1
for (int msl=0; msl<MAX_BOSSCANNON; msl++)
{
Create_BOB(&bosscannon[msl],0,0,4,8,2,
BOB_ATTR_VISIBLE / BOB_ATTR_MULTI_FRAME,
DDSCAPS_SYSTEMMEMORY);
for (int frame=0; frame<2; frame++)
Load_Frame_BOB(&bosscannon[msl],&bitmap16bit,frame,frame,0,BITMAP_EXTRACT_MODE_CELL);
Set_Anim_Speed_BOB(&bosscannon[msl],1);
bosscannon[msl].state = BOSSCANNON_STATE_OFF;
}
#endif
#if 0
Create_BOB(&bosscannon[0],0,0,4,8,2,
BOB_ATTR_VISIBLE / BOB_ATTR_MULTI_FRAME,
DDSCAPS_SYSTEMMEMORY);
for (int frame=0; frame<2; frame++)
Load_Frame_BOB(&bosscannon[0],&bitmap16bit,frame,frame,0,BITMAP_EXTRACT_MODE_CELL);
Set_Anim_Speed_BOB(&bosscannon[0],1);
bosscannon[0].state = BOSSCANNON_STATE_OFF;
for (int msl=1; msl<MAX_BOSSCANNON; msl++)
{
memcpy(&bosscannon[msl], &bosscannon[0], sizeof(BOB));
}
#endif
Unload_Bitmap_File(&bitmap16bit);
}
void Delete_Bosscannon(void)
{
for (int index=0; index<MAX_BOSSCANNON; index++)
Destroy_BOB(&bosscannon[index]);
}
void Move_Bosscannon(void)
{
for (int index=0; index<MAX_BOSSCANNON; index++)
{
if (bosscannon[index].state == BOSSCANNON_STATE_ON)
{
Move_BOB(&bosscannon[index]);
if (bosscannon[index].y > 600 )
{
bosscannon[index].state = BOSSCANNON_STATE_OFF;
continue;
}
}
}
for (index=0; index<MAX_BOSSCANNON; index++)
{
if ((bosscannon[index].attr & BOB_ATTR_VISIBLE) && (bosscannon[index].state == BOSSCANNON_STATE_ON)
&& (Collision_BOBS(&ship, &bosscannon[index]) ) )
{
bosscannon[index].state = BOSSCANNON_STATE_OFF;
counter2 = 0;
player_state = PLAYER_STATE_DYING;
}
}
}
void Draw_Bosscannon(void)
{
for (int index=0; index<MAX_BOSSCANNON; index++)
{
if (bosscannon[index].state == BOSSCANNON_STATE_ON)
{
Draw_BOB(&bosscannon[index],lpddsback);
Animate_BOB(&bosscannon[index]);
}
}
}
void Fire_Bosscannon(int x,int y, int vel)
{
if (bosson == 1 // boss2on == 1)
{
for (int index=0; index<MAX_BOSSCANNON; index++)
{
if (bosscannon[index].state == BOSSCANNON_STATE_OFF)
{
bosscannon[index].x = x;
bosscannon[index].y = y;
bosscannon[index].yv = vel;
bosscannon[index].curr_frame = 0;
bosscannon[index].state = BOSSCANNON_STATE_ON;
for (int sound_index=0; sound_index < MAX_FIRE_SOUNDS; sound_index++)
{
if (Status_Sound(fire_ids[sound_index])==0)
{
Play_Sound(fire_ids[sound_index]);
break;
}
}
return;
}
}
}
}
In Game_Init() I execute Init_Bosscannon, in Game_Main() I execute Move_Bosscannon and Draw_Bosscannon, and in Game_Shutdown I execute Delete_Bosscannon. Does anyone see any errors in this code above? If you think that the AI code will help I can post that up too.
Thanx,
ViPeR
The above post is kinda stupid because I just found out that it kinda has to be in the AI code. But if anyone sees an error in the code above let me know. Here is the pattern code:
int pattern_5[] = {OPCB_SHOOT, 0, OPCB_E, 50, OPCB_SHOOT, 0, OPCB_W, 50, OPCB_END,0};
int pattern_6[] = {OPCB_SHOOT, 0, OPCB_E, 50, OPCB_SHOOT, 0, OPCB_W, 50, OPCB_END,0};
int *patterns3[NUM_PATTERNS3] = {pattern_5, pattern_6};
int *curr_pattern3=NULL;
int boss_ip =0,
boss_counter=0,
boss_pattern_index;
Then down in the code a bit is Boss_AI():
void Boss_AI(void)
{
static int opcode3,
operand3;
int index3,
index;
if (state_ready != 0)
{
if (curr_pattern3==NULL)
{
boss_pattern_index = rand()%NUM_PATTERNS3;
curr_pattern3 = patterns3[boss_pattern_index];
boss_ip = 0;
boss_counter = 0;
}
if (--boss_counter <= 0)
{
opcode3 = curr_pattern3[boss_ip++];
operand3 = curr_pattern3[boss_ip++];
switch(opcode3)
{
case OPCB_SHOOT:
{
if (bosson == 1)
{
Set_Vel_BOB(&boss,0,0);
Fire_Bosscannon(boss.x+28-8,boss.y-8,16);
}
if (boss2on == 1)
{
Set_Vel_BOB(&boss2[1],0,0);
Fire_Bosscannon(boss2[1].x+28-8,boss2[1].y-8,16);
}
boss_counter = operand3;
} break;
case OPCB_E:
{
Set_Vel_BOB(&boss,1,0);
Set_Vel_BOB(&boss2[1],6,0);
boss_counter = operand3;
} break;
case OPCB_W:
{
Set_Vel_BOB(&boss,-1,0);
Set_Vel_BOB(&boss2[1],-6,0);
boss_counter = operand3;
} break;
case OPCB_END:
{
Set_Vel_BOB(&boss,0,0);
Set_Vel_BOB(&boss2[1],0,0);
boss_pattern_index = rand()%NUM_PATTERNS3;
curr_pattern3 = patterns3[boss_pattern_index];
boss_ip = 0;
boss_counter = 0;
} break;
default: break;
}
}
}
}
Everything is correctly defined (if it wasn''t it would probably give me a compiler error which I am not getting) and Boss_AI() is executed in the Game_Main() function. I don''t really see the problem is this code at all but if anyone else does let me know.
Thanx,
ViPeR
int pattern_5[] = {OPCB_SHOOT, 0, OPCB_E, 50, OPCB_SHOOT, 0, OPCB_W, 50, OPCB_END,0};
int pattern_6[] = {OPCB_SHOOT, 0, OPCB_E, 50, OPCB_SHOOT, 0, OPCB_W, 50, OPCB_END,0};
int *patterns3[NUM_PATTERNS3] = {pattern_5, pattern_6};
int *curr_pattern3=NULL;
int boss_ip =0,
boss_counter=0,
boss_pattern_index;
Then down in the code a bit is Boss_AI():
void Boss_AI(void)
{
static int opcode3,
operand3;
int index3,
index;
if (state_ready != 0)
{
if (curr_pattern3==NULL)
{
boss_pattern_index = rand()%NUM_PATTERNS3;
curr_pattern3 = patterns3[boss_pattern_index];
boss_ip = 0;
boss_counter = 0;
}
if (--boss_counter <= 0)
{
opcode3 = curr_pattern3[boss_ip++];
operand3 = curr_pattern3[boss_ip++];
switch(opcode3)
{
case OPCB_SHOOT:
{
if (bosson == 1)
{
Set_Vel_BOB(&boss,0,0);
Fire_Bosscannon(boss.x+28-8,boss.y-8,16);
}
if (boss2on == 1)
{
Set_Vel_BOB(&boss2[1],0,0);
Fire_Bosscannon(boss2[1].x+28-8,boss2[1].y-8,16);
}
boss_counter = operand3;
} break;
case OPCB_E:
{
Set_Vel_BOB(&boss,1,0);
Set_Vel_BOB(&boss2[1],6,0);
boss_counter = operand3;
} break;
case OPCB_W:
{
Set_Vel_BOB(&boss,-1,0);
Set_Vel_BOB(&boss2[1],-6,0);
boss_counter = operand3;
} break;
case OPCB_END:
{
Set_Vel_BOB(&boss,0,0);
Set_Vel_BOB(&boss2[1],0,0);
boss_pattern_index = rand()%NUM_PATTERNS3;
curr_pattern3 = patterns3[boss_pattern_index];
boss_ip = 0;
boss_counter = 0;
} break;
default: break;
}
}
}
}
Everything is correctly defined (if it wasn''t it would probably give me a compiler error which I am not getting) and Boss_AI() is executed in the Game_Main() function. I don''t really see the problem is this code at all but if anyone else does let me know.
Thanx,
ViPeR
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement