PDA

View Full Version : Homing Projectile



Joe123
05-06-2008, 07:46 PM
Well, not really homing, just 'flies at Link' as opposed to 'flies in a straight line'.
A bit (well, a lot) like the fireshooter enemy.


void homingprojectile(int x, int y, int tile, int dmg, int spd){
//Generate and set up projectile
eweapon w = Screen->CreateEWeapon(31);
w->Tile = tile;
w->X = x; w->Y = y;
w->Step = spd;
w->Damage = dmg;
//Shoot projectile at Link
w->Angular = true;
int angle = ArcTan((Link->X-x),(Link->Y-y));
w->Angle = angle;
if(angle==-PI || angle==PI) w->Dir=2;
else if(angle==-PI/2) w->Dir=0;
else if(angle==PI/2) w->Dir=1;
else if(angle==0) w->Dir=3;
else if(angle<-PI/2) w->Dir=4;
else if(angle<0) w->Dir=5;
else if(angle>(PI/2)) w->Dir=6;
else w->Dir=7;
}

D0: X coordinate of projectile
D1: Y coordinate of projectile
D2: tile for projectile to use (it'll need a bit more modification to make animated ones, but not a lot)
D3: damage for projectile to deal
D4: speed of projectile

Thanks Jman.

The_Amaster
05-06-2008, 07:48 PM
Sweet. So using this.
In case I missed it, is there a specific direction projectile firer around also?

Joe123
05-06-2008, 07:51 PM
Well, that's not very difficult and it's a bit more specific.
This is meant to be reasonably general, cause it's not the most simple bit of code for a seemingly easy function.

A specific direction projectile is just something like

eweapon w = Screen->CreateEWeapon(31);
w->Step = 3;
w->Dir = 2;
That'll create a blank projectile and shoot it off to the left.

If you want a projectile that shoots off at a specific angle that's not going to be so easy, but I could modifiy the void I just made to do that I suppose.

The_Amaster
05-06-2008, 07:54 PM
Nah, that should be fine.

And you mentioned animating earlier?
Only if it's not a big deal.

Joe123
05-06-2008, 07:57 PM
void homingprojectile(int x, int y, int tile, int cset, int dmg, int spd, int num, int fspd){
eweapon w = Screen->CreateEWeapon(31);
w->Tile = tile; w->OriginalTile = tile;
w->CSet = cset;
w->NumFrames = num; w->ASpeed = fspd;
w->X = x; w->Y = y;
w->Step = spd;
w->Damage = dmg;
w->Angular = true;
int angle = ArcTan((Link->X-x),(Link->Y-y));
w->Angle = angle;
if(angle==-PI || angle==PI) w->Dir=2;
else if(angle==-PI/2) w->Dir=0;
else if(angle==PI/2) w->Dir=1;
else if(angle==0) w->Dir=3;
else if(angle<-PI/2) w->Dir=4;
else if(angle<0) w->Dir=5;
else if(angle>(PI/2)) w->Dir=6;
else w->Dir=7;
}

D0: X coordinate of projectile
D1: Y coordinate of projectile
D2: tile for projectile to use (it'll need a bit more modification to make animated ones, but not a lot)
D3: cset
D4: damage for projectile to deal
D5: speed of projectile
D6: number of animation frames
D7: speed of animation

The_Amaster
05-06-2008, 08:28 PM
Ah, cool, thanks.

AgentLym
05-06-2008, 09:20 PM
Thanks, Joe! I'll (hopefully) be able to use this!

Master Maniac
05-06-2008, 10:05 PM
hey, agent lym! finally registered here at AGN, eh?

Gleeok
05-07-2008, 01:14 AM
Haha, man you must've really wanted to post this before me. :p Not that I mind, it saves me the trouble. Good work. Quick question for you though; If you've already set the sprites angle, then why go through the trouble of trying to find and set it's dir also?

Joe123
05-07-2008, 03:00 AM
Ah.
Well, initially, I didn't bother setting the Dir, but when Jman told me how to do it, he copied the source code for the fireshooter enemy into his post, and it was in there.
If you don't set up the Dir for the projectile, it doesn't interact with Link's shield properly.

Russ
05-07-2008, 10:59 AM
This seems pretty useful. I'll probably find a way to incorparate it into my quest before the day is done.

Joe123
05-11-2008, 09:21 AM
And just for fun...


ffc script flamethrower{
void run(int t,int c,int d,int n,int f,int a){
if(a==0) a=1;
if(d==0) d=4;
Waitframes(4);
npc e = Screen->LoadNPC(a);
while(e->isValid()){
homingprojectile(e->X,e->Y,t,c,d,2,n,f);
Waitframe();
}
}
}


D0: tile for projectile to use
D1: cset
D2: damage (default 1 heart)
D3: number of frames of animation of projectile
D4: speed of animation
D5: enemy to put flamethrower attack onto (default 1)




Only problem being that the fireballs are blocked even by the small shield.
Any way I can stop that?




Oh, and obviously it won't work without the homingprojectile void in the same script.
I also added a 'CSet' parameter into the void.
Just an oversight on the earlier version.