Advertisement
ReaperZX7

Danmakufu ph3, Final code form, Homing Player Shot

Jan 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.05 KB | None | 0 0
  1. //remember to set these global variables for easy adjustment
  2. let SHOT_HOMING = /*how strong the homing on the shots should be*/
  3. let SHOT_MAX_HOMING_DIST = /*the shot will home in on enemies within this distance*/
  4.  
  5. //you also need this function
  6. function angleTo(obj,dest) {
  7.     let dir = atan2(ObjMove_GetY(dest)-ObjMove_GetY(obj),ObjMove_GetX(dest)-ObjMove_GetX(obj));
  8.     return dir;
  9. }
  10.  
  11. //whenever you need to fire a homing shot just use this section
  12. let bullet = CreatePlayerShotA1(input desired values);
  13. shotCommands(bullet);
  14. //----------------------------
  15.  
  16. //insert this somewhere else, probably near the bottom
  17. task shotCommands(obj) {
  18.     //A:
  19.     while (!Obj_IsDeleted(obj)) {
  20.         //1:
  21.         let enemyMatrix = GetIntersectionRegistedEnemyID;
  22.         //2:
  23.         let homingBool = false;
  24.         //3:
  25.         if (length(enemyMatrix) > 0) {
  26.             //3.1:
  27.             let targetDist = SHOT_MAX_HOMING_DIST;
  28.             //3.2:
  29.             let targetID = 0;
  30.            
  31.             //3.3:
  32.             ascent (i in 0..length(enemyMatrix)) {
  33.                 //3.3.1:
  34.                 if (GetObjectDistance(obj,enemy[i]) < targetDist) {
  35.                     //3.3.1.1:
  36.                     targetDist = GetObjectDistance(obj,enemy[i]);
  37.                     //3.3.1.2:
  38.                     targetID = enemyMatrix[i];
  39.                     //3.3.1.3:
  40.                     homingBool = true;
  41.                 }
  42.             }
  43.             //3.4:
  44.             if (homingBool == true) {
  45.                 //3.4.1:
  46.                 let shotAngle = ObjMove_GetAngle(obj);
  47.                     //3.4.1.1:
  48.                     while (shotAngle >= 360) {
  49.                         shotAngle -= 360;
  50.                     }
  51.                     while (shotAngle < 0) {
  52.                         shotAngle += 360;
  53.                     }
  54.                 //3.4.2:
  55.                 let targetAngle = angleTo(obj,target);
  56.                     //3.4.2.1:
  57.                     while (targetAngle >= 360) {
  58.                         targetAngle -= 360;
  59.                     }
  60.                     while (targetAngle < 0) {
  61.                         targetAngle += 360;
  62.                     }
  63.                
  64.                 //3.4.3:
  65.                 let targetAngleN = targetAngle-180;
  66.                     //3.4.3.1:
  67.                     while (targetAngleN >= 360) {
  68.                         targetAngleN -= 360;
  69.                     }
  70.                     while (targetAngleN < 0) {
  71.                         targetAngleN += 360;
  72.                     }
  73.                
  74.                 //3.4.4:
  75.                 if (targetAngle > 180) {
  76.                     //3.4.4.1:
  77.                     if (shotAngle < (targetAngle - SHOT_HOMING) && shotAngle > targetAngleN) {
  78.                         //3.4.4.1.1:
  79.                         ObjMove_SetAngle(obj,shotAngle+SHOT_HOMING);
  80.                     }
  81.                     //3.4.4.2:
  82.                     if (shotAngle > (targetAngle + SHOT_HOMING) || shotAngle < targetAngleN) {
  83.                         //3.4.4.2.1:
  84.                         ObjMove_SetAngle(obj,shotAngle-SHOT_HOMING);
  85.                     }
  86.                     //3.4.4.3:
  87.                     if (shotAngle >= (targetAngle - SHOT_HOMING) && shotAngle <= (targetAngle + SHOT_HOMING)) {
  88.                         //3.4.4.3.1:
  89.                         ObjMove_SetAngle(obj,targetAngle);
  90.                     }
  91.                 }
  92.                 //3.4.5:
  93.                 if (targetAngle < 180) {
  94.                     //3.4.5.1:
  95.                     if (shotAngle > targetAngleN || shotAngle < (targetAngle + SHOT_HOMING)) {
  96.                         //3.4.5.1.1:
  97.                         ObjMove_SetAngle(obj,shotAngle+SHOT_HOMING);
  98.                     }
  99.                     //3.4.5.2:
  100.                     if (shotAngle < targetAngleN && shotAngle > (targetAngle - SHOT_HOMING)) {
  101.                         //3.4.5.2.1:
  102.                         ObjMove_SetAngle(obj,shotAngle-SHOT_HOMING);
  103.                     }
  104.                     //3.4.5.3:
  105.                     if (shotAngle >= (targetAngle - SHOT_HOMING) && shotAngle <= (targetAngle + SHOT_HOMING)) {
  106.                         //3.4.5.3.1:
  107.                         ObjMove_SetAngle(obj,targetAngle);
  108.                     }
  109.                 }
  110.             }
  111.         }
  112.         //4:
  113.         yield;
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement