1
0

PlayerStates.gml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. function player_move_and_collide()
  2. {
  3. y_spd *= global.time_scale;
  4. x_spd *= global.time_scale;
  5. if place_meeting(x, y + y_spd, oParentSolid)
  6. {
  7. while !place_meeting(x, y + sign(y_spd), oParentSolid)
  8. y += sign(y_spd);
  9. y_spd = 0;
  10. }
  11. y += y_spd;
  12. if place_meeting(x + x_spd, y, oParentSolid)
  13. {
  14. var _max_step = (y_spd == 0) ? 16 : 8; //前者地面容错,后者空中容错
  15. var _stepped = false;
  16. for(var i = 0; i < _max_step; i++)
  17. if !place_meeting(x + x_spd, y - i, oParentSolid)
  18. {
  19. y -= i;
  20. _stepped = true;
  21. break;
  22. }
  23. if !_stepped
  24. {
  25. while !place_meeting(x + sign(x_spd), y, oParentSolid)
  26. x += sign(x_spd);
  27. x_spd = 0;
  28. }
  29. }
  30. x += x_spd;
  31. y_spd /= global.time_scale;
  32. x_spd /= global.time_scale;
  33. }
  34. function player_status_update()
  35. {
  36. current_attacker = instance_place(x, y, oEnemyHitbox);
  37. /**/
  38. image_index += animation_spd;
  39. if oInput._dash
  40. dash_buffer = dash_buffer_max;
  41. if oInput._attack
  42. attack_buffer = attack_buffer_max;
  43. _move_dir = oInput._right - oInput._left;
  44. _on_ground = place_meeting(x, y + 1, oParentSolid)
  45. _on_wall = place_meeting(x + 1, y, oBlockClimbable)
  46. - place_meeting(x - 1, y, oBlockClimbable);
  47. if _on_ground || (_on_wall != 0)
  48. can_dash = true;
  49. if _on_ground
  50. {
  51. jump_cnt = 0;
  52. coyote_timer = coyote_max;
  53. }
  54. else if coyote_timer <= 0 && jump_cnt == 0
  55. jump_cnt = 1;
  56. if dash_cooldown > 0
  57. dash_cooldown -= global.time_scale;
  58. if dash_buffer > 0
  59. dash_buffer -= global.time_scale;
  60. if attack_buffer > 0
  61. attack_buffer -= global.time_scale;
  62. if move_lock_timer > 0
  63. move_lock_timer -= global.time_scale;
  64. if coyote_timer > 0
  65. coyote_timer -= global.time_scale;
  66. if invincible_timer > 0
  67. invincible_timer -= global.time_scale;
  68. }
  69. function player_check_dash()
  70. {
  71. if dash_buffer > 0 && dash_cooldown <= 0 && can_dash
  72. {
  73. dash_buffer = 0;
  74. state = state_dash;
  75. set_sprite(sPlayerDash);
  76. dash_cooldown = 36;
  77. x_spd = image_xscale * walk_spd * 3;
  78. y_spd = 0;
  79. can_dash = false;
  80. }
  81. }
  82. function player_check_movement()
  83. {
  84. if move_lock_timer <= 0
  85. x_spd = _move_dir * walk_spd;
  86. }
  87. function player_check_jump()
  88. {
  89. if oInput.jump_buffer_timer > 0
  90. {
  91. if coyote_timer > 0
  92. {
  93. y_spd = jump_spd;
  94. jump_cnt = 1;
  95. oInput.jump_buffer_timer = 0;
  96. coyote_timer = 0;
  97. }
  98. else if _on_wall != 0
  99. {
  100. y_spd = jump_spd;
  101. x_spd = -_on_wall * walk_spd * 1.5;
  102. jump_cnt = 1;
  103. move_lock_timer = 10;
  104. oInput.jump_buffer_timer = 0;
  105. }
  106. else if jump_cnt < jump_max
  107. {
  108. icl(oDoubleJumpEffect);
  109. y_spd = jump_spd * 0.9;
  110. jump_cnt++;
  111. oInput.jump_buffer_timer = 0;
  112. }
  113. }
  114. if oInput._jump_r && y_spd < 0
  115. y_spd *= 0.4;
  116. }
  117. function player_check_attack()
  118. {
  119. if attack_buffer > 0
  120. {
  121. attack_buffer = 0;
  122. state = state_attack;
  123. set_sprite(sPlayerAttack);
  124. }
  125. }
  126. function player_check_dodge()
  127. {
  128. if (oInput._down || oInput._up) && _on_ground
  129. && (oInput._dash || state == state_dash)
  130. {
  131. state = state_dodge;
  132. set_sprite(sPlayerDodgeWait);
  133. dodge_phase = "WAIT";
  134. dodge_timer = 0;
  135. marked_target = noone;
  136. is_marked = false;
  137. is_perfect = false;
  138. var _hb = icl(oPlayerHitboxMark, x + facing * 60, y + 40);
  139. _hb.owner = id;
  140. _hb.x_offset = 60 * facing;
  141. _hb.y_offset = 40;
  142. }
  143. }
  144. function player_check_attacked()
  145. {
  146. if current_attacker == noone || invincible_timer > 0
  147. //|| (state == state_dodge && dodge_phase == "WAIT")
  148. return;
  149. global.playerHP -= current_attacker.damage;
  150. invincible_timer = 80;
  151. var _dir = sign(x - current_attacker.x);
  152. if _dir == 0
  153. _dir = facing;
  154. global.hitstop = 12;
  155. x_spd = _dir * 30;
  156. y_spd = -5;
  157. state = state_hitstun_attacked;
  158. set_sprite(sPlayerHitstunAttacked);
  159. //effects
  160. }
  161. function player_check_hazard()
  162. {
  163. var _hazard = instance_place(x, y, oParentHazard);
  164. if _hazard != noone
  165. {
  166. global.playerHP -= _hazard.damage;
  167. invincible_timer = 150;
  168. var _dir = sign(x - _hazard.x);
  169. if _dir == 0
  170. _dir = facing;
  171. global.hitstop = 18;
  172. x_spd = _dir * 10;
  173. y_spd = -10;
  174. state = state_hitstun_hazard;
  175. set_sprite(sPlayerHitstunHazard);
  176. }
  177. }
  178. function state_hitstun_attacked()
  179. {
  180. x_spd = lerp(x_spd, 0, 0.1);
  181. y_spd += player_calc_gravity();
  182. if animation_end()
  183. state = state_free;
  184. }
  185. function state_hitstun_hazard()
  186. {
  187. x_spd = lerp(x_spd, 0, 0.1);
  188. y_spd += player_calc_gravity();
  189. if animation_end()
  190. {
  191. alarm[1] = 60;
  192. state = state_locked;
  193. var _fade = icl(oFade);
  194. _fade._callback = function()
  195. {
  196. oPlayer.x = 160;//oPlayer.last_safe_x;
  197. oPlayer.y = 2016 - 540;//oPlayer.last_safe_y;
  198. camera_snap();
  199. };
  200. }
  201. }
  202. function state_free()
  203. {
  204. y_spd += player_calc_gravity();
  205. if _on_wall != 0 && y_spd > 0
  206. y_spd = min(y_spd, 3);
  207. /*下面是动画与视觉*/
  208. animation_spd = 0.25;
  209. if _move_dir != 0 //有输入
  210. {
  211. facing = _move_dir;
  212. if _on_ground
  213. set_sprite(sPlayerWalk); //走路
  214. }
  215. else set_sprite(sPlayerIdle); //待机
  216. if !_on_ground
  217. {
  218. if _on_wall == facing
  219. set_sprite(sPlayerWall);
  220. else
  221. {
  222. set_sprite(sPlayerJump);
  223. image_index = (y_spd < 0) ? 0 : 1;
  224. }
  225. }
  226. /*
  227. player_check_dodge();
  228. if state == state_dodge return;
  229. */
  230. player_check_movement();
  231. player_check_dash();
  232. player_check_jump();
  233. player_check_attack();
  234. }
  235. function state_dash()
  236. {
  237. y_spd += 0.2 * player_calc_gravity();
  238. icl(oPlayerAfterImage);
  239. if animation_end()
  240. {
  241. if !_on_ground
  242. jump_cnt = max(jump_cnt, 1);
  243. state = state_free;
  244. player_check_attack();
  245. }
  246. //player_check_dodge();
  247. }
  248. function state_attack()
  249. {
  250. player_check_movement();
  251. player_check_jump();
  252. player_check_dash();
  253. y_spd += player_calc_gravity();
  254. if image_index == 1
  255. {
  256. var _hb;
  257. if oInput._down && !_on_ground
  258. {
  259. _hb = icl(oPlayerHitboxVer, x, y + 64);
  260. _hb.y_offset = 64;
  261. }
  262. else if oInput._up
  263. {
  264. _hb = icl(oPlayerHitboxVer, x, y - 64);
  265. _hb.y_offset = -64;
  266. _hb.kb_factor_y = -5;
  267. }
  268. else
  269. {
  270. _hb = icl(oPlayerHitboxHor, x + 72 * facing);
  271. _hb.x_offset += 72 * facing;
  272. _hb.kb_factor_x *= facing;
  273. }
  274. _hb.owner = id;
  275. }
  276. // 冲刺预输入
  277. // 攻击后摇结束
  278. if facing = -_move_dir
  279. state = state_free;
  280. if animation_end()
  281. state = state_free;
  282. }
  283. function state_locked()
  284. {
  285. x_spd = 0;
  286. y_spd += player_calc_gravity();
  287. }
  288. /// @desc 返回基于玩家当前状态的重力值,注意不会自动赋值
  289. function player_calc_gravity()
  290. {
  291. var _g = global.g;
  292. if y_spd > 0
  293. _g *= 1.2; // 下坠
  294. if abs(y_spd) < 0.5
  295. _g *= 0.75; //滞空
  296. return _g; // * global.time_scale;
  297. }
  298. /*
  299. function state_dodge()
  300. {
  301. if dodge_phase == "WAIT"
  302. {
  303. x_spd = 0;
  304. if current_attacker != noone || animation_end()
  305. {
  306. y_spd = jump_spd;
  307. dodge_phase = "DODGE";
  308. set_sprite(sPlayerDodge);
  309. if current_attacker != noone && is_marked
  310. {
  311. is_perfect = true;
  312. invincible_timer = 150;
  313. global.time_scale = 0.2;
  314. global.hitstop = 20;
  315. }
  316. }
  317. }
  318. else if dodge_phase == "DODGE"
  319. {
  320. y_spd += global.g;
  321. if is_perfect icl(oPlayerAfterImage);
  322. if y_spd > 0
  323. {
  324. timer = 0;
  325. y_spd = 0;
  326. if is_perfect
  327. {
  328. state = state_arc_slash;
  329. set_sprite(sPlayerArcSlash);
  330. }
  331. else
  332. {
  333. state = state_dodge_ending;
  334. set_sprite(sPlayerDodgeEnding);
  335. }
  336. }
  337. }
  338. }
  339. function state_arc_slash()
  340. {
  341. if image_index == 12
  342. {
  343. var _hb = icd(oPlayerHitboxArc);
  344. _hb.owner = id;
  345. if facing == 1
  346. {
  347. _hb.image_xscale = 1;
  348. _hb.image_angle = 30;
  349. _hb.kb_factor_x *= 1;
  350. }
  351. else
  352. {
  353. _hb.image_xscale = -1;
  354. _hb.image_angle = -30;
  355. _hb.kb_factor_x *= -1;
  356. }
  357. }
  358. else if image_index > 12
  359. y_spd += global.g;
  360. if animation_end()
  361. {
  362. global.time_scale = 1.0;
  363. state = state_free;
  364. }
  365. }
  366. function state_dodge_ending()
  367. {
  368. if animation_end()
  369. state = state_free;
  370. }
  371. */