Advertisement
ShaunJS

PlayerStateHook()

Oct 16th, 2019
1,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. hSpeed = 0;
  2. vSpeed = 0;
  3.  
  4. //If just arriving in this state
  5. if (sprite_index != sPlayerHook)
  6. {
  7.     hook = 0;
  8.     hookX = 0;
  9.     hookY = 0;
  10.     hookStatus = HOOKSTATUS.EXTENDING;
  11.     hookedEntity = noone;
  12.    
  13.     ///Update sprite
  14.     sprite_index = sPlayerHook;
  15.     image_index = floor(((direction div 45) + 1) * 0.5);
  16.     image_speed = 0;
  17. }
  18.  
  19. //Extend/Retract hook:
  20. var _speedHookTemp = speedHook;
  21. if (hookStatus != HOOKSTATUS.EXTENDING) _speedHookTemp *= -1;
  22. hook += _speedHookTemp;
  23. switch (image_index)
  24. {
  25.     case 0: hookX = hook; break;
  26.     case 1: hookY = -hook; break;
  27.     case 2: hookX = -hook; break;
  28.     case 3: hookY = hook; break;
  29. }
  30.  
  31. //Hookshot state machine
  32. switch (hookStatus)
  33. {
  34.     case HOOKSTATUS.EXTENDING:
  35.     {
  36.         //Finish Extending
  37.         if (hook >= distanceHook) hookStatus = HOOKSTATUS.MISSED;
  38.    
  39.         //Check for hit
  40.         var _hookHit = collision_circle(x+hookX,y+hookY,4,pEntity,false,true);
  41.         if (_hookHit != noone)
  42.         {
  43.             //Act depending on what is hit:
  44.             switch (_hookHit.entityHookable)
  45.             {
  46.                 default: //Not hookable entity
  47.                 {
  48.                     //... else potentially harm enemy
  49.                     if (object_is_ancestor(_hookHit.object_index,pEnemy))
  50.                     {
  51.                         HurtEnemy(_hookHit,1,id,5);
  52.                         hookStatus = HOOKSTATUS.MISSED;
  53.                     }
  54.                     else
  55.                     {
  56.                         if (_hookHit.entityHitScript != -1)
  57.                         {
  58.                             with (_hookHit) script_execute(entityHitScript);
  59.                             hookStatus = HOOKSTATUS.MISSED;
  60.                         }
  61.                     }
  62.                 }break;
  63.                 case 1:
  64.                 {
  65.                     hookStatus = HOOKSTATUS.PULLTOPLAYER;
  66.                     hookedEntity = _hookHit;
  67.                 }break;
  68.                 case 2:
  69.                 {
  70.                     hookStatus = HOOKSTATUS.PULLTOENTITY;
  71.                     hookedEntity = _hookHit;   
  72.                 }break;
  73.             }
  74.         }
  75.     }break;
  76.    
  77.     //Pull the entity towards the hooked player
  78.     case HOOKSTATUS.PULLTOPLAYER:
  79.     {
  80.         //Update distance/direction extended
  81.         with (hookedEntity)
  82.         {
  83.             x = other.x + other.hookX;
  84.             y = other.y + other.hookY;
  85.         }
  86.     }break;
  87.    
  88.     //Pull the PLAYER towards the hooked entity
  89.     case HOOKSTATUS.PULLTOENTITY:
  90.     {
  91.         switch (image_index)
  92.         {
  93.             case 0: x += speedHook; break;
  94.             case 1: y -= speedHook; break;
  95.             case 2: x -= speedHook; break;
  96.             case 3: y += speedHook; break;
  97.         }
  98.        
  99.     }break;
  100.  
  101. }
  102.  
  103.  
  104.  
  105. //Finish retract and end state
  106. if (hook <= 0)
  107. {
  108.     hookedEntity = noone;
  109.     state = PLAYERSTATE.FREE;  
  110.     exit;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement