///////////////////////
/// THE DALEKS ///
/// NPC Script ///
/// For ZC 2.55 ///
/// v0.2 ///
/// 7th March, 2019 ///
///////////////////////
npc script Dalek
{
const int LASER_LAYER = 3;
const int LASER_COLOUR = 0x04;
const int LASER_OPACITY = 128;
const int ANGLE_VISION = 60;
const int SHOT_STEP = 120;
const int COODOWN = 150;
const int WTYPE = EW_SCRIPT1;
const int SHOT_SFX = 70;
void run (int angleOfVision, int shotStep, int shotCooldownTime, int weaponType, int shotSFX)
{
//Get attributes
angleOfVision = (this->InitD[0] > 0 ) ? this->InitD[0] : ANGLE_VISION;
shotStep = (this->InitD[1]] > 0 ) ? this->InitD[1]] : SHOT_STEP;
shotCooldownTime = (this->InitD[2] > 0 ) ? this->InitD[2] : COODOWN;
weaponType = (ghost->InitD[3] > 0 ) ? ghost->InitD[3] : WTYPE;
shotSFX = (ghost->InitD[4] > 0 ) ? ghost->InitD[4]: SHOT_SFX;
int shotCooldown = shotCooldownTime;
int laserStartX;
int laserStartY;
eweapon beam;
while(this->isValid())
{
//Shooting
if ( shotCooldown > 0 )
--shotCooldown;
//Only one beam at a time
else if ( !beam->isValid() )
{
//Check angle to Link against angle of vision
//int angleToLink = Angle(CenterX(this), CenterY(this), CenterLinkX(), CenterLinkY());
//int facingAngle = Dir4Angle(this->Dir);
//int difference = Abs(angleToLink - facingAngle);
//int difference = Abs((Angle(CenterX(this), CenterY(this), CenterLinkX(), CenterLinkY())) - (Dir4Angle(this->Dir)));
//If Link is within this angle
//if ( difference <= angleOfVision/2 )
if ( (Abs((Angle(CenterX(this), CenterY(this), CenterLinkX(), CenterLinkY())) - (Dir4Angle(this->Dir)))) <= angleOfVision/2 )
{
shotCooldown = shotCooldownTime; //can reduce down by reading InitD again -Z
laserStartX = CenterX(this);
laserStartY = CenterY(this);
beam = Screen->CreateEWeapon(weaponType);
beam->X = laserStartX;
beam->Y = laserStartY;
beam->Angular = true;
beam->Angle = ArcTan(Link->X-beam->X, Link->Y-beam->X);
beam->Step = shotStep;
beam->Damage = this->WeaponDamage;
Audio->PlaySound(shotSFX);
beam->DrawXOffset = 999; //Draw off-screen
}
}
//Draw laser beam
if ( beam->isValid() )
{
Screen->Line(LASER_LAYER, laserStartX, laserStartY, CenterX(beam), CenterY(beam), LASER_COLOUR, 1, 0, 0, 0, LASER_OPACITY);
}
Waitframe();
}
}
}
Comments