PlayerStates.gml 8.5 KB

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