general.gml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. function check_hitstop()
  2. {
  3. if global.hitstop > 0
  4. return true;
  5. else
  6. return false;
  7. }
  8. /// @desc 优雅地检测该实例的sprite当前动画是否到达最后一帧
  9. function animation_end()
  10. {
  11. if animation_spd == 0
  12. return false;
  13. return (image_index + animation_spd >= image_number);
  14. }
  15. /// @desc 优雅地将该实例的sprite替换为给定值,并将sprite_index归零
  16. /// @param {Asset.GMSprite} _sprite 将要替换为的sprite
  17. function set_sprite(_sprite)
  18. {
  19. if sprite_index != _sprite
  20. {
  21. sprite_index = _sprite;
  22. image_index = 0;
  23. }
  24. }
  25. function camera_snap(_target_x = global.player.x, _target_y = global.player.y)
  26. {
  27. var _cam = global.camera;
  28. _cam.x = clamp(_target_x, _cam.bound_left + _cam.cam_width / 2, _cam.bound_right - _cam.cam_width / 2);
  29. _cam.y = clamp(_target_y, _cam.bound_top + _cam.cam_height / 2, _cam.bound_bottom - _cam.cam_height / 2);
  30. }
  31. /// @desc 触发屏幕震动
  32. /// @param {Real} _magnitude 以像素计算的震动强度
  33. function screen_shake(_magnitude)
  34. {
  35. with(global.camera)
  36. {
  37. if _magnitude > shake_magnitude
  38. shake_magnitude = _magnitude;
  39. }
  40. }
  41. function player_add_INK(_amount)
  42. {
  43. if global.playerINK + _amount >
  44. global.save_data.player.maxINK
  45. global.playerINK = global.save_data.player.maxINK;
  46. else
  47. global.playerINK += _amount;
  48. oUI.flash_timer = 10;
  49. oUI.flash_duration = 10;
  50. }
  51. function player_add_HP(_amount)
  52. {
  53. if global.playerHP + _amount >
  54. global.save_data.player.maxHP
  55. global.playerHP = global.save_data.player.maxHP;
  56. else
  57. global.playerHP += _amount;
  58. }
  59. function to_gui(_wx, _wy)
  60. {
  61. var _cam = view_camera[0];
  62. var _cam_x = camera_get_view_x(_cam);
  63. var _cam_y = camera_get_view_y(_cam);
  64. var _cam_w = camera_get_view_width(_cam);
  65. var _cam_h = camera_get_view_height(_cam);
  66. var _gui_w = display_get_gui_width();
  67. var _gui_h = display_get_gui_height();
  68. return
  69. {
  70. x: (_wx - _cam_x) / _cam_w * _gui_w,
  71. y: (_wy - _cam_y) / _cam_h * _gui_h
  72. };
  73. }
  74. //use together
  75. function lock_player()
  76. {
  77. if !instance_exists(global.player)
  78. return;
  79. global.player.state = state_locked;
  80. global.player.locked_timer = infinity;
  81. global.player.x_spd = 0;
  82. global.player.y_spd = 0;
  83. }
  84. function unlock_player()
  85. {
  86. if !instance_exists(global.player)
  87. return;
  88. global.player.locked_timer = 0;
  89. }
  90. function lock_door()
  91. {
  92. with(oDoorLocker)
  93. {
  94. icd(oDoorLocked, x, y, 0, {unlock : unlock});
  95. instance_destroy();
  96. }
  97. }
  98. function unlock_door()
  99. {
  100. with(oDoorLocked)
  101. {
  102. if unlock
  103. animation_spd = -0.25;
  104. }
  105. }
  106. function camera_set_bounds(_l, _r, _t, _b)
  107. {
  108. oCamera.bound_left = _l;
  109. oCamera.bound_right = _r;
  110. oCamera.bound_top = _t;
  111. oCamera.bound_bottom = _b;
  112. }