general.gml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. // @param {Real} _frames 以帧计算的持续时间
  34. function screen_shake(_magnitude)
  35. {
  36. with(global.camera)
  37. {
  38. if _magnitude > shake_magnitude
  39. shake_magnitude = _magnitude;
  40. }
  41. }
  42. function player_add_INK(_amount)
  43. {
  44. if global.playerINK + _amount >
  45. global.save_data.player.maxINK
  46. global.playerINK = global.save_data.player.maxINK;
  47. else
  48. global.playerINK += _amount;
  49. oUI.flash_timer = 10;
  50. oUI.flash_duration = 10;
  51. }
  52. function player_add_HP(_amount)
  53. {
  54. if global.playerHP + _amount >
  55. global.save_data.player.maxHP
  56. global.playerHP = global.save_data.player.maxHP;
  57. else
  58. global.playerHP += _amount;
  59. }
  60. function to_gui(_wx, _wy)
  61. {
  62. var _cam = view_camera[0];
  63. var _cam_x = camera_get_view_x(_cam);
  64. var _cam_y = camera_get_view_y(_cam);
  65. var _cam_w = camera_get_view_width(_cam);
  66. var _cam_h = camera_get_view_height(_cam);
  67. var _gui_w = display_get_gui_width();
  68. var _gui_h = display_get_gui_height();
  69. return
  70. {
  71. x: (_wx - _cam_x) / _cam_w * _gui_w,
  72. y: (_wy - _cam_y) / _cam_h * _gui_h
  73. };
  74. }
  75. function interact_end()
  76. {
  77. if !instance_exists(global.player)
  78. return;
  79. global.player.locked_timer = 0;
  80. }
  81. function camera_set_bounds(_l, _r, _t, _b)
  82. {
  83. oCamera.bound_left = _l;
  84. oCamera.bound_right = _r;
  85. oCamera.bound_top = _t;
  86. oCamera.bound_bottom = _b;
  87. }