PDA

View Full Version : Laser Beamos script



beefster09
01-20-2007, 07:06 PM
Instead of a stream of fireballs, it draws a line and a beam end. But I've run across a few problems. The beamos won't start his laser jet. Also note the commented Line function. I can't figure out how to get it through the compiler, so I commented it out.

Anyway:

//-----Scripts for Beamos-----
// When you are close enough, the beamos shoots
// a laser at you. It draws a line representing
// a laser shot from the beamos's eye. A damage
// combo represents the tip of the laser.
//----------------------------

import "std.zh"

//-----BeamosEye-----
// This half determines when the beam should be fired
//
// D0 = The radius of the beamos's sight
// D1 = The delay (in frames) waited before firing (I'd recommend 20)
//-------------------

ffc script BeamosEye{

void run(float radius, int maxdelay){

int currentdelay = 0; // delay waited
bool delaystart = false; // flag for start of delay
float xdist; // used to find how close Link is
float ydist; // same
float hdist; // distance between Link and Eye

Screen->D[0] = 0; // link's xy position
Screen->D[1] = 0; // tells whether link is close enough
Screen->D[2] = this->X + ((this->Y/100)/100) + 8.0008; // xy of eye

while(true){

xdist = this->X - Link->X;
ydist = this->Y - Link->Y;
hdist = Sqrt(Pow(xdist, 2) + Pow(ydist, 2));
// ^Distance formula^

if((hdist <= radius) && (!delaystart)){

Trace(9);
Screen->D[0] = Link->X + ((Link->Y/100)/100);
delaystart = true;
currentdelay = 0;

} //end if

if((hdist > radius) && (Screen->D[1] == 1) || (delaystart)){

Screen->D[1] = 0;
delaystart = false;

} //end if

if(delaystart){

currentdelay += 1;

} //end if

if(currentdelay == maxdelay){

Screen->D[1] = 1;

} //end if

Waitframe();

} //end while

} //end void

} //end ffc script

//--------Beam-------
// This half draws the beam and follows Link
//
// D0 = Speed of the travelling beam
// D1 = Color of the beam
// D2 = Combo to be changed to when active
//-------------------

ffc script Beam{

void run(float speed, float beamcolor, int activecombo){

int passivecombo = this->Data; // combo for inactive beam
bool active = false; // flag determining whether this is active
float xdist; // xdelta of target
float ydist; // ydelta of target
float xratio; // ratio between xdelta and ydelta
float yratio; // same
float hratio; // hypotenuse ratio
float tempxy; // xy of Beam

while(true){

// activation device
if((Screen->D[1] == 1) && (!active)){

this->X = Floor(Screen->D[0]);
this->X = Ceiling(Screen->D[0]) * 100 * 100;
active = true;
this->Data = activecombo;

} //end if

// moving device / line draw-er
if(active){

xratio = 1;
yratio = 1;

xdist = Link->X - this->X;
ydist = Link->Y - this->Y;
if(xdist > ydist){

xratio = xdist / ydist;

} // end if
if(xdist <= ydist){

yratio = ydist / xdist;

} // end if

hratio = Sqrt(Pow(xratio, 2) + Pow(yratio, 2));
xratio = xratio / hratio;
xratio = xratio * speed;
yratio = yratio / hratio;
yratio = yratio * speed;

this->Vx = xratio;
this->Vy = yratio;

tempxy = this->X + ((this->Y/100)/100) + 8.0008;

//Line(tempxy, beamcolor, Screen->D[2], 3, 1, false, 0, 0, 0);

} //end if

// deactivation device
if((Screen->D[1] == 0) && (active)){

this->Vx = 0;
this->Vy = 0;
this->X = 0;
this->Y = 0;
active = false;
this->Data = passivecombo;

} //end if

Waitframe();

} //end while

} //end void

} //end ffc script

What am I doing wrong?

Mario's Hat
01-20-2007, 07:43 PM
Duh! Lazers always need to be charged before firin' them.

beefster09
01-20-2007, 08:09 PM
You're not funny. And It does do that. It takes a user-defined amount of time to actually start to shoot. That's what delaystart, currentdelay, and maxdelay are for.

I bet you didn't even look at the code!

Mario's Hat
01-20-2007, 11:22 PM
I wish. It's machine code.

http://encyclopediadramatica.com/index.php/Machine_Code



Nah, really I didn't. I just saw the perfect opportunity for making a reference to chargin' lazers, firin' lazers and shoopin' whoops.

'twas simply for the lulz, no harm meant.

beefster09
01-21-2007, 12:36 AM
You're not helpful though!

Revfan9
01-21-2007, 01:10 AM
Mario's Hat, please stop spamming. You are not helping.

Beefster, I don't understand Zscript much, but I don't see any code that "Generates" the laser by changing the FFC's combo and I also don't see anything that makes the laser stay there until it hits link, makes it damage link, or makes the beam go away after it hits Link.

beefster09
01-21-2007, 04:06 PM
The combo itself is what is supposed to damage link. The laser keeps firing until Link is out of range. It does change the combo, that's what this->Data is for.

Grayswandir
01-21-2007, 04:32 PM
// activation device
if((Screen->D[1] == 1) && (!active)){

this->X = Floor(Screen->D[0]);
this->X = Ceiling(Screen->D[0]) * 100 * 100;
active = true;
this->Data = activecombo;

} //end if
You have two this->X 's, so the first one doesn't do anything.


Screen->D[2] = this->X + ((this->Y/100)/100) + 8.0008; // xy of eye

Screen->D[0] = Link->X + ((Link->Y/100)/100);


Also, could you explain the whole xy caculation? And why Screen->D[0] doesn't have the +8.0008 attached to the end?

beefster09
01-22-2007, 10:30 AM
XD didn't notice the two x thing.
The xy thing is used to have easier calculation between scripts, and it makes it possible to pass parameters into the Line function, Unfortunately, I couldn't get the function to work.
The xy is basically X on the left side of the decimal and Y on the right 4 decimal places out. The 8.0008 is so that the xy is at the center. 16*16 -> 8*8

beefster09
01-30-2007, 06:42 PM
Umm... I still need help. Don't forget about me.