Original Post
ok I'm still working on my 2d sidescrolling game but I've got problems with the boss' AI script. Everything about movement works fine but his attack is the problem. What I'm trying to do is have him randomly shoot a fireball at the player's current location at the time of firing. I figured out an algorhytm for calculating the position and having it literally "warp" to that spot but I want it to slowly move there at a steady speed like 3 pixels per frame for example and I just can't get it to work. AT ALL. I've tried every variation of multiplying, dividing, adding, subtraction and I can't get anything to work. Any ideas? here's the code for that portion: [Edited by - Shenjoku on September 5, 2006 8:45:43 PM]
//enemies current declared variables
bossA.x=100;
bossA.y=100;
bossA.width=45;
bossA.height=40;
bossA.curframe=1;
bossA.lastframe=3;
bossA.animdelay=3;
bossA.animcount=0;
bossA.movex=3;
bossA.movey=3;
...
if(GotLocation!=true)
{
curPlayerx=player.x;
curPlayery=player.y;
GotLocation=true;
}
dist=GetDistance(curPlayerx,curPlayery,bossA.x,bossA.y);
if(dist>0 && curPlayerx>bossA.x)
{
bossA.x+=curPlayerx + bossA.x;
bossA.y+=curPlayery + bossA.y;
}
else if(dist>0 && curPlayerx<bossA.x)
{
bossA.x-=bossA.x - curPlayerx;
bossA.y+=curPlayery + bossA.y;
}
if(bossA.x+bossA.width>=curPlayerx && bossA.x<=curPlayerx+player.width)
{
bossA.animdelay=4;
bossA.width=75;
bossA.height=80;
enemyAttack_image->Release();
enemyAttack_image=LoadTexture("explosion.bmp",D3DCOLOR_XRGB(0,255,0));
bossA.lastframe=7;
if(bossA.curframe==7)
{
enemyAttack_image->Release();
enemyAttack_image=LoadTexture("BLANK.bmp",D3DCOLOR_XRGB(0,255,0));
}
}
//function for gauging distance needed for attacks in the BOSSAI()
int GetDistance(int playerx,int playery,int enemyx,int enemyy)
{
int distance;
distance = sqrt(pow((playerx-enemyx),2)+pow((playery-enemyy),2));
return distance;
}