SHARE
TWEET

Untitled

a guest Sep 16th, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var spd = 3.5;
  2.  
  3. if jump = false && state != estate.spattack && state != estate.idle && state != estate.charge {
  4.     anim_state = "moving";
  5. }
  6.  
  7. if state = estate.spattack or state = estate.charge or state = estate.knockback {
  8.     r = 5;
  9.     invin = true;
  10. } else if state = estate.move_right or state = estate.move_left {
  11.     r = 1.5;
  12.     invin = false;
  13. } else {
  14.     r = 1;
  15.     invin = false;
  16. }
  17.  
  18. //State speed management
  19. switch (state) {
  20.     case estate.move_right: hspd += 1;
  21.         maxhspd = spd; break;
  22.     case estate.move_left: hspd -= 1;
  23.         maxhspd = spd; break;
  24.     case estate.idle: hspd = 0;
  25.         maxhspd = spd;
  26.         anim_state = "idle"; break;
  27.     case estate.idle_move_left: hspd -= 0.2;
  28.         maxhspd = 1.4; break;
  29.     case estate.idle_move_right: hspd += 0.2;
  30.         maxhspd = 1.4; break;
  31.     case estate.knockback: hspd = 3*flipped;
  32.         if on_ground = true {
  33.             vspd = -4;
  34.             on_ground = false;
  35.         }
  36.         maxhspd = 3
  37.     break;
  38.     case estate.spattack: hspd -= 15*flipped;
  39.         maxhspd = 15;
  40.         anim_state = "spattack"; break;
  41.     case estate.charge: hspd = 0;
  42.         maxhspd = 6;
  43.         anim_state = "charge"; break;
  44. }
  45.  
  46. //Attacks
  47. if state = estate.charge {
  48.     if attack_timer = 25 {
  49.         state = estate.spattack;   
  50.     }
  51. }
  52.  
  53. hspd = clamp(hspd, -maxhspd, maxhspd); //this makes sure hspd doesn't exceed the max value
  54.  
  55. //Jumping
  56. if jump = true && on_ground = true {
  57.     vspd = -8;
  58.     on_ground = false;
  59.     anim_state = "jumping";
  60. }
  61.  
  62. vspd += 0.35//Adds gravity to vspeed
  63.  
  64. ///Collison Code///
  65.  
  66. //Horizontal
  67. if (place_meeting(x+hspd, y, o_wall)){
  68.     while (!place_meeting(x+sign(hspd), y, o_wall)){
  69.         x+=sign(hspd);
  70.     }
  71.     hspd=0;
  72. }
  73. x+=hspd;
  74.  
  75. //Vertical
  76. if (place_meeting(x, y+vspd, o_wall)){
  77.     while (!place_meeting(x, y+sign(vspd), o_wall)){
  78.         y+=sign(vspd);
  79.     }
  80.     vspd=0;
  81.     on_ground = true;
  82.     if state = estate.knockback {
  83.         state = estate.idle;
  84.         jump = false;
  85.     }
  86. }
  87. y+=vspd;
  88.  
  89. //Check to Jump
  90. if state != estate.knockback { //Knockback Check Begin
  91. if (place_meeting(x+(hspd*8), y, o_wall) and on_ground = true) {
  92.     jump = true;
  93. } else if !(place_meeting(x+(hspd*6),y,o_wall)) and on_ground = true {
  94.     jump = false;
  95. }
  96.  
  97. ///Attack Code///
  98.  
  99.  
  100. var p_dir = point_direction(x,y,o_player.x,o_player.y);
  101.  
  102. if collision_rectangle(x-450,y-225,x+450,y+225,o_player,false,true) {
  103.     in_alert_radius = true;
  104.     if collision_rectangle(x-325*r,y-175*r,x+325*r,y+175*r,o_player,false,true) {
  105.         in_radius = true;  
  106.     } else {
  107.         in_radius = false;
  108.     }
  109. } else {
  110.     in_alert_radius = false;
  111. }
  112. } //Knockback Check End
  113.  
  114.  
  115. if attack_timer > 0 {
  116.     attack_timer -= 1;
  117. } else {
  118.     attack_timer = irandom_range(60,80);
  119. }
  120.  
  121. if in_radius = true {
  122.  
  123.  
  124. if attack_timer = 0 {
  125.     if state != estate.spattack {
  126.         var spchance = irandom_range(1,5);
  127.         if spchance = 1 {
  128.             state = estate.charge;
  129.             attack_timer = 50;
  130.         } else {
  131.             attack_timer = irandom_range(60,80);
  132.         }
  133.     } else {
  134.         state = estate.idle;
  135.         attack_timer = irandom_range(60,80);
  136.     }
  137. }
  138.  
  139. if state != estate.knockback {
  140.  
  141.     if state != estate.spattack and state != estate.charge {
  142.         if (p_dir < 45 or p_dir >= 315) {
  143.             e_dir_next = estate.move_right;
  144.         } else if (p_dir >= 135 and p_dir < 225) {
  145.             e_dir_next = estate.move_left; 
  146.         }
  147.        
  148.         state = e_dir_next;
  149.     }
  150. }
  151.     } else {
  152.        
  153.         if in_alert_radius = true {
  154.             if (p_dir < 45 or p_dir >= 315) {
  155.                 state = estate.idle_move_right;
  156.             } else if (p_dir >= 135 and p_dir < 225) {
  157.                 state = estate.idle_move_left; 
  158.             }
  159.             idle_move_timer = 5;
  160.         }
  161.        
  162.         idle_move_timer -= 1;
  163.         if idle_move_timer = 0 {
  164.             state = choose(estate.idle_move_right,estate.idle_move_left,estate.idle,estate.idle);
  165.             idle_move_timer = irandom_range(60,100);
  166.         }
  167.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top