PDA

View Full Version : Spawning an EWeapon



Joe123
04-14-2008, 12:58 PM
I don't really know how to work these very well.

What I want to do is spawn an EWeapon, make it look like a deku nut, and have it fly at where Link is.

How'd I go about doing that?

jman2050
04-14-2008, 02:32 PM
eweapon deku_nut = CreateEWeapon(*insert number here*)

deku_nut->Tile = *whatever*
deku_nut->CSet = *whatever*
deku_nut->Dir = DIR_UP or whatever
deku_nut->Step = *whatever*
deku_nut->X = *whatever*
deku_nut->Y = *whatever*

That's pretty much the bare minimum you can do to spawn an eweapon and have it move. From there you can modify variables such as its DeadState (described in zscript.txt), Damage, whether it uses an angle value, etc. Lweapons work in identical fashion.

Joe123
04-14-2008, 02:45 PM
Yah, I got that much, but do I have to use the angle thing to make it fly at Link?

And how would I go about doing that?

jman2050
04-14-2008, 03:00 PM
oh, make it fly towards Link?

That would require your own code to do so. Actually it was impossible until the current build (780) since you need an arctan function. For reference, here's the homing code for the fireball from the ZC source



void weapon::seekLink()
{
angular = true;
angle = atan2(double(LinkY()-y),double(LinkX()-x));
if(angle==-PI || angle==PI) dir=left;
else if(angle==-PI/2) dir=up;
else if(angle==PI/2) dir=down;
else if(angle==0) dir=right;
else if(angle<-PI/2) dir=l_up;
else if(angle<0) dir=r_up;
else if(angle>(PI/2)) dir=l_down;
else dir=r_down;

if (z>LinkZ()) z--;
else if (z<LinkZ()) z++;
}


I don't think the expressions to change dir is needed in your case honestly. Still, this should sum up what you need to do.

Also, note that ZC's arctan function takes the width first, not height.

Joe123
04-14-2008, 03:07 PM
oh ok, thanks =)

Why do you need arctan (what is that by the way?) to work out the angle of a segment though?

Can't you just do it with circle geometry or normal trig?

jman2050
04-14-2008, 03:34 PM
Arc Tangent is literally the inverse of Tangent. i.e. x = Tan(y), y = Arctan(x). When inputting an angle into a tangent function, it returns the slope of the hypotenuse. The Arc Tangent takes the slope of the hypotenuse as its input and returns the angle. Now, normal trig functions work fine and good... provided you actually know the angle of one of the corners of a triangle. In cases where you don't, you have to derive one of them from the slope, which is what Arctan is for.

Note that the actual Arc Tangent function is complex, so trying to implement it yourself is definitely not recommended.

Joe123
04-14-2008, 03:39 PM
Ohhhh!

Inverse tan!

I'm used to calling that 'tan^-1', so the 'arctan' notation confused me.


Of couse you need that to work out the angle, silly me >_<
When I saw 'Tan, Sine and Cosine' in ZScript, I assumed the inverses were already implemented.

jman2050
04-14-2008, 03:49 PM
Ohhhh!

Inverse tan!

I'm used to calling that 'tan^-1', so the 'arctan' notation confused me.


Of couse you need that to work out the angle, silly me >_<
When I saw 'Tan, Sine and Cosine' in ZScript, I assumed the inverses were already implemented.

Heh, I think the problem is that the common notation is somewhat of a misnomer. Using tan^-1 logically to indicate the inverse makes sense, but mathematically tan^-1 already exists in another form, the cotangent (1/(tan^1) if you remember), which isn't the same thing.

Joe123
04-14-2008, 04:07 PM
Yeah, now I come to think of it, my maths tutor had said pretty much just that, 'tan^-1 is actually not a very good name for it, you should call it arctan', but I didn't think of that >_<

I don't recall cotangent though.

Joe123
04-14-2008, 06:10 PM
So how do I use that seeklink void?

EDIT: Oh, is that just an example of how I might do it in a more specific situation?


eweapon dnut = Screen->CreateEWeapon(133);
dnut->OriginalTile = 40940;
dnut->Tile = 40940;
dnut->NumFrames = 4;
dnut->ASpeed = 6;
dnut->Angular = true;
dnut->Angle = atan2(double(LinkY()-y),double(LinkX()-x));
dnut->Step = 5;


Is that good then?


eweapon dnut = CreateEWeapon(133);
dnut->OriginalTile = 40940;
dnut->Tile = 40940;
dnut->NumFrames = 4;
dnut->ASpeed = 6;
dnut->Angular = true;
dnut->Angle = ArcTan(2*(Link->Y-dnut->Y),2*(Link->X-dnut->X));
dnut->Step = 5;

EDIT: or even that?



EDIT: OK, this is strange.
It compiles ok, except I'm getting an error after I exit the compiler =S


Unable to parse instruction 226 from script zscript.z
The error was: Invalid instruction.
The command was (ARCTANd2) (,)

weird.

EDIT: yeah, and the script just does nothing >_<

Gleeok
04-14-2008, 07:52 PM
oh, make it fly towards Link?

That would require your own code to do so. Actually it was impossible until the current build (780) since you need an arctan function. For reference, here's the homing code for the fireball from the ZC source



void weapon::seekLink()
{
angular = true;
angle = atan2(double(LinkY()-y),double(LinkX()-x));
if(angle==-PI || angle==PI) dir=left;
else if(angle==-PI/2) dir=up;
else if(angle==PI/2) dir=down;
else if(angle==0) dir=right;
else if(angle<-PI/2) dir=l_up;
else if(angle<0) dir=r_up;
else if(angle>(PI/2)) dir=l_down;
else dir=r_down;

if (z>LinkZ()) z--;
else if (z<LinkZ()) z++;
}


I don't think the expressions to change dir is needed in your case honestly. Still, this should sum up what you need to do.

Also, note that ZC's arctan function takes the width first, not height.

*Bows down in worship to jman2050*



Alright Joe, I'll take a look at what you're doing there. Don't worry, we'll get this up and running in no time! :D



EDIT: Uh, Joe123, you forgot to set the X,Y values...also try this->X,Y instead of dnut x,y...Otherwise I'm still messing with it.

jman2050
04-14-2008, 10:59 PM
That's a bug. Apparantly after testing the ArcTan function I made a quick little adjustment that screwed things up. For now, what you could do is, after compiling the script, go to allegro.log and copy the ZASM output to a new file, put a space between ARCTANR and d2, then import that directly. Will be fixed in the next beta.

Gleeok
04-14-2008, 11:48 PM
Yeah, I was just about to reply to this saying I think it's a bug in the compiler....

So, would it also be possible to just combine the ZASM line:

ARCTANR d2;


in the zscript itself? I've read somewhere that they can be combined if you're *careful*.

EDIT: The ZASM import doesn't want to parse instruction 1...?

Joe123
04-15-2008, 02:49 AM
Oh, could you compile a new build soon then please Jman?

I tried compiling that ZASM script, but it didn't work.
I don't really know anything about ZASM.

jman2050
04-16-2008, 12:16 PM
Don't include the name of the script in the ZASm file, just the instructions itself :P

Joe123
04-16-2008, 01:31 PM
oh >_<

Oops =P


Well I'll wait for the next build anyway, it's for a script I was writing for someone else, and he'll be able to wait I'm sure.
It's not too pressing.