Advertisement
ZoriaRPG

Dalek Script (Original)

Mar 7th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.13 KB | None | 0 0
  1. ///////////////////////
  2. ////  THE DALEKS  /////
  3. ///////////////////////
  4.  
  5.  
  6. //Type: Walking Enemy
  7. //Weapon: NONE
  8. //Death Attrib 1: Angle of vision
  9. //Death Attrib 2: Shot step speed
  10. //Death Attrib 3: Cooldown between shots
  11. //Extra Shots: Type of weapon to use; determines if it gets blocked by walls or different shields (see the EW_ section of std_constants.zh)
  12. //Touch Effects: NONE
  13. //Effect Strength: Shot SFX
  14. //Misc Attrib 11: First of 4 walking combos (up, down, left, right), or -1 to use enemy editor sprite
  15. //Misc Attrib 12: Number of FFC script slot with this script
  16. //"Shielded in ___" flags will work
  17. ffc script walkingLaserShooter{
  18. void run ( int enemyID ){
  19.   npc ghost = Ghost_InitAutoGhost(this, enemyID);
  20.   Ghost_SetFlag(GHF_NORMAL);
  21.   Ghost_SetFlag(GHF_4WAY);
  22.  
  23.   //Get attributes
  24.   int angleOfVision = ghost->Attributes[2];
  25.   int shotStep = ghost->Attributes[3];
  26.   int shotCooldownTime = ghost->Attributes[4];
  27.   int weaponType = ghost->Attributes[5];
  28.   //Attributes[4] is a drop-down box
  29.   int shotSFX = ghost->Attributes[7];
  30.  
  31.   int shotCooldown = shotCooldownTime;
  32.   int turnTimer = ghost->Rate * 10;
  33.   int laserStartX;
  34.   int laserStartY;
  35.  
  36.   eweapon beam;
  37.  
  38.   while(Ghost_HP > 0){
  39.    //Shooting
  40.    if ( shotCooldown > 0 )
  41.         shotCooldown--;
  42.    //Only one beam at a time
  43.    else if ( !beam->isValid() ){
  44.         //Check angle to Link against angle of vision
  45.         int angleToLink = Angle(CenterX(ghost), CenterY(ghost), CenterLinkX(), CenterLinkY());
  46.         int facingAngle = Dir4ToDeg(Ghost_Dir);
  47.         int difference = Abs(angleToLink - facingAngle);
  48.    
  49.         //If Link is within this angle
  50.         if ( difference <= angleOfVision/2 ){
  51.          shotCooldown = shotCooldownTime;
  52.        
  53.          laserStartX = CenterX(ghost);
  54.          laserStartY = CenterY(ghost);
  55.          beam = FireAimedEWeapon(weaponType, laserStartX, laserStartY, 0, shotStep, ghost->WeaponDamage, 0, shotSFX, 0);
  56.          beam->DrawXOffset = 999; //Draw off-screen
  57.         }
  58.    }
  59.  
  60.    //Draw laser beam
  61.    if ( beam->isValid() ){
  62.         Screen->Line(3, laserStartX, laserStartY, CenterX(beam), CenterY(beam), WLS_LASERCOLOR, 1, 0, 0, 0, WLS_LASEROPACITY);
  63.    }
  64.  
  65.    //Change direction
  66.    turnTimer--;
  67.    if ( ghost->Step > 0 && turnTimer <= 0 ){
  68.         //Home in on Link
  69.         if ( ghost->Homing > Rand(256) ){
  70.          int angle = RadianAngle(ghost->X, ghost->Y, Link->X, Link->Y);
  71.          Ghost_Dir = RadianAngleDir4(angle);
  72.          turnTimer = ghost->Rate * 10; //Reset turn timer
  73.         }
  74.         //Otherwise pick random direction
  75.         else{
  76.          Ghost_Dir = Rand(4); //Pick a random direction
  77.          if ( CanWalk(Ghost_X, Ghost_Y, Ghost_Dir, 10, false) ) //If it can move there,
  78.           turnTimer = Rand(ghost->Rate * 10); //Reset turn timer (otherwise try it next frame)
  79.         }
  80.    }
  81.  
  82.    Ghost_Move(Ghost_Dir, ghost->Step/100, ghost->Rate);
  83.    Ghost_Waitframe(this, ghost, true, true);
  84.   }
  85. }
  86. }
  87. int Dir4ToDeg(int dir){
  88. if ( dir == DIR_RIGHT )
  89.   return 0;
  90. if ( dir == DIR_DOWN )
  91.   return 90;
  92. if ( dir == DIR_LEFT )
  93.   return 180;
  94. if ( dir == DIR_UP )
  95.   return -90;
  96. return -1;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement