EnemyStates.gml 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. function enemy_move_and_collide()
  2. {
  3. var _y_spd_total = (y_spd + y_spd_kb) * global.time_scale;
  4. var _x_spd_total = (x_spd + x_spd_kb) * global.time_scale;
  5. if place_meeting(x, y + _y_spd_total, oParentSolid)
  6. {
  7. while !place_meeting(x, y + sign(_y_spd_total), oParentSolid)
  8. y += sign(_y_spd_total);
  9. _y_spd_total = 0;
  10. y_spd = 0;
  11. y_spd_kb = 0;
  12. }
  13. y += _y_spd_total;
  14. if place_meeting(x + _x_spd_total, y, oParentSolid)
  15. {
  16. while !place_meeting(x + sign(_x_spd_total), y, oParentSolid)
  17. x += sign(_x_spd_total);
  18. _x_spd_total = 0;
  19. x_spd = 0;
  20. x_spd_kb = 0;
  21. }
  22. x += _x_spd_total;
  23. }
  24. function enemy_check_hitstun()
  25. {
  26. if hitstun_timer > 0
  27. {
  28. hitstun_timer -= global.time_scale;
  29. x_spd_kb = lerp(x_spd_kb, 0, 0.1);
  30. y_spd_kb = lerp(y_spd_kb, 0, 0.1);
  31. x_spd = 0;
  32. y_spd = 0;
  33. }
  34. else
  35. {
  36. x_spd_kb = 0;
  37. y_spd_kb = 0;
  38. }
  39. }
  40. function enemy_get_hit(_damage, _kb_x, _kb_y)
  41. {
  42. hp -= _damage;
  43. if can_hitstun
  44. hitstun_timer = hitstun_max;
  45. x_spd_kb = _kb_x * kb_factor;
  46. y_spd_kb = _kb_y * kb_factor;
  47. image_blend = c_blue;
  48. alarm[0] = 10;
  49. if hp <= 0
  50. {
  51. is_dead = true;
  52. instance_destroy(); // animation
  53. }
  54. }
  55. function enemy_crawl_ai()
  56. {
  57. var _wall_ahead = place_meeting(x + facing, y, oParentSolid);
  58. var _hazard_ahead = place_meeting(x + facing * abs(sprite_width) / 2, y, oParentHazard);
  59. var _ledge_ahead = !place_meeting(x + facing * abs(sprite_width), y + 1, oParentSolid);
  60. if _wall_ahead || _ledge_ahead || _hazard_ahead
  61. facing *= -1;
  62. x_spd = facing * walk_spd;
  63. y_spd += global.g;
  64. }