HeroAnimator.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. package me.hammerle.supersnuvi.entity.components.animator;
  2. import me.hammerle.supersnuvi.Keys;
  3. import me.hammerle.supersnuvi.entity.Entity;
  4. import me.hammerle.supersnuvi.entity.components.Health;
  5. import me.hammerle.supersnuvi.javafx.Image;
  6. import me.hammerle.supersnuvi.rendering.IRenderer;
  7. import me.hammerle.supersnuvi.util.Utils;
  8. public class HeroAnimator extends Renderer
  9. {
  10. /*private final static Image[] WALK = new Image[]
  11. {
  12. Utils.getImage("snuvi/walk/walk_f1", true),
  13. Utils.getImage("snuvi/walk/walk_f2", true),
  14. Utils.getImage("snuvi/walk/walk_f3", true),
  15. Utils.getImage("snuvi/walk/walk_f4", true),
  16. Utils.getImage("snuvi/walk/walk_f5", true),
  17. Utils.getImage("snuvi/walk/walk_f6", true),
  18. Utils.getImage("snuvi/walk/walk_f7", true),
  19. Utils.getImage("snuvi/walk/walk_f8", true),
  20. Utils.getImage("snuvi/walk/walk_f9", true)
  21. };
  22. private final static Image JUMP = Utils.getImage("snuvi/jump", true);
  23. static
  24. {
  25. Image block3 = Utils.getImage("snuvi/block/block_f3", true);
  26. BLOCK = new Image[]
  27. {
  28. Utils.getImage("snuvi/block/block_f1", true),
  29. Utils.getImage("snuvi/block/block_f2", true),
  30. block3,
  31. block3,
  32. block3,
  33. block3,
  34. block3,
  35. block3,
  36. block3,
  37. block3
  38. };
  39. Image headHit3 = Utils.getImage("snuvi/combat/cbat_hit_f3", true);
  40. COMBAT_HEAD_HIT = new Image[]
  41. {
  42. Utils.getImage("snuvi/combat/cbat_hit_f1", true),
  43. Utils.getImage("snuvi/combat/cbat_hit_f2", true),
  44. headHit3,
  45. headHit3
  46. };
  47. }
  48. private final static Image[] BLOCK;
  49. private final static Image[] DEATH = new Image[]
  50. {
  51. Utils.getImage("snuvi/death/cbat_death_f1"),
  52. Utils.getImage("snuvi/death/cbat_death_f2"),
  53. Utils.getImage("snuvi/death/cbat_death_f3"),
  54. Utils.getImage("snuvi/death/cbat_death_f4"),
  55. Utils.getImage("snuvi/death/cbat_death_f5"),
  56. Utils.getImage("snuvi/death/cbat_death_f6"),
  57. Utils.getImage("snuvi/death/cbat_death_f7"),
  58. Utils.getImage("snuvi/death/cbat_death_f8"),
  59. Utils.getImage("snuvi/death/cbat_death_f9"),
  60. Utils.getImage("snuvi/death/cbat_death_f10"),
  61. Utils.getImage("snuvi/death/cbat_death_f11"),
  62. Utils.getImage("snuvi/death/cbat_death_f12"),
  63. Utils.getImage("snuvi/death/cbat_death_f13"),
  64. Utils.getImage("snuvi/death/cbat_death_f14"),
  65. Utils.getImage("snuvi/death/cbat_death_f15"),
  66. Utils.getImage("snuvi/death/cbat_death_f16"),
  67. Utils.getImage("snuvi/death/cbat_death_f17")
  68. };
  69. private final static Image[] COMBAT_DEATH = new Image[]
  70. {
  71. Utils.getImage("snuvi/combat_death/death_f1"),
  72. Utils.getImage("snuvi/combat_death/death_f2"),
  73. Utils.getImage("snuvi/combat_death/death_f3"),
  74. Utils.getImage("snuvi/combat_death/death_f4"),
  75. Utils.getImage("snuvi/combat_death/death_f5"),
  76. Utils.getImage("snuvi/combat_death/death_f6"),
  77. Utils.getImage("snuvi/combat_death/death_f7"),
  78. Utils.getImage("snuvi/combat_death/death_f8"),
  79. Utils.getImage("snuvi/combat_death/death_f9"),
  80. Utils.getImage("snuvi/combat_death/death_f10"),
  81. Utils.getImage("snuvi/combat_death/death_f11"),
  82. Utils.getImage("snuvi/combat_death/death_f12"),
  83. Utils.getImage("snuvi/combat_death/death_f13"),
  84. Utils.getImage("snuvi/combat_death/death_f14"),
  85. Utils.getImage("snuvi/combat_death/death_f15"),
  86. Utils.getImage("snuvi/combat_death/death_f16"),
  87. Utils.getImage("snuvi/combat_death/death_f17")
  88. };
  89. private final static Image[] IDLE = new Image[]
  90. {
  91. Utils.getImage("snuvi/idle/idle_f1", true),
  92. Utils.getImage("snuvi/idle/idle_f2", true),
  93. Utils.getImage("snuvi/idle/idle_f3", true),
  94. Utils.getImage("snuvi/idle/idle_f4", true),
  95. Utils.getImage("snuvi/idle/idle_f5", true),
  96. Utils.getImage("snuvi/idle/idle_f6", true),
  97. Utils.getImage("snuvi/idle/idle_f7", true),
  98. Utils.getImage("snuvi/idle/idle_f8", true),
  99. Utils.getImage("snuvi/idle/idle_f9", true),
  100. Utils.getImage("snuvi/idle/idle_f10", true),
  101. Utils.getImage("snuvi/idle/idle_f11", true),
  102. Utils.getImage("snuvi/idle/idle_f12", true),
  103. Utils.getImage("snuvi/idle/idle_f13", true),
  104. Utils.getImage("snuvi/idle/idle_f14", true)
  105. };
  106. private final static Image[] COMBAT_HEAD = new Image[]
  107. {
  108. Utils.getImage("snuvi/combat/cbat_head_f1", true),
  109. Utils.getImage("snuvi/combat/cbat_head_f2", true),
  110. Utils.getImage("snuvi/combat/cbat_head_f3", true),
  111. Utils.getImage("snuvi/combat/cbat_head_f4", true),
  112. Utils.getImage("snuvi/combat/cbat_head_f5", true),
  113. Utils.getImage("snuvi/combat/cbat_head_f6", true),
  114. Utils.getImage("snuvi/combat/cbat_head_f7", true),
  115. Utils.getImage("snuvi/combat/cbat_head_f8", true),
  116. Utils.getImage("snuvi/combat/cbat_head_f9", true),
  117. Utils.getImage("snuvi/combat/cbat_head_f10", true),
  118. Utils.getImage("snuvi/combat/cbat_head_f11", true),
  119. Utils.getImage("snuvi/combat/cbat_head_f12", true),
  120. Utils.getImage("snuvi/combat/cbat_head_f13", true),
  121. Utils.getImage("snuvi/combat/cbat_head_f14", true)
  122. };
  123. private final static Image[] COMBAT_HEAD_HIT;
  124. private final static Image COMBAT_ARMS_IDLE = Utils.getImage("snuvi/combat/cbat_arms_idle", true);
  125. private final static Image[][] COMBAT_ARMS_SWING = new Image[][]
  126. {
  127. {
  128. Utils.getImage("snuvi/combat/cbat_swing1_f1", true),
  129. Utils.getImage("snuvi/combat/cbat_swing1_f2", true),
  130. Utils.getImage("snuvi/combat/cbat_swing1_f3", true)
  131. },
  132. {
  133. Utils.getImage("snuvi/combat/cbat_swing2_f1", true),
  134. Utils.getImage("snuvi/combat/cbat_swing2_f2", true),
  135. Utils.getImage("snuvi/combat/cbat_swing2_f3", true)
  136. },
  137. {
  138. Utils.getImage("snuvi/combat/cbat_swing3_f1", true),
  139. Utils.getImage("snuvi/combat/cbat_swing3_f2", true),
  140. Utils.getImage("snuvi/combat/cbat_swing3_f3", true)
  141. }
  142. };
  143. private final static Image COMBAT_BODY_IDLE = Utils.getImage("snuvi/combat/cbat_idle_body", true);
  144. private final static Image[] COMBAT_BODY_WALK = new Image[]
  145. {
  146. Utils.getImage("snuvi/combat/cbat_walk_f1", true),
  147. Utils.getImage("snuvi/combat/cbat_walk_f2", true),
  148. Utils.getImage("snuvi/combat/cbat_walk_f3", true),
  149. Utils.getImage("snuvi/combat/cbat_walk_f4", true)
  150. };
  151. private final static Image[] COMBAT_SWITCH = new Image[]
  152. {
  153. Utils.getImage("snuvi/combat/switch_f1", true),
  154. Utils.getImage("snuvi/combat/switch_f2", true),
  155. Utils.getImage("snuvi/combat/switch_f3", true),
  156. Utils.getImage("snuvi/combat/switch_f4", true),
  157. Utils.getImage("snuvi/combat/switch_f5", true),
  158. Utils.getImage("snuvi/combat/switch_f6", true),
  159. Utils.getImage("snuvi/combat/switch_f7", true),
  160. Utils.getImage("snuvi/combat/switch_f8", true)
  161. };
  162. private final static Image COMBAT_BODY_DODGE = Utils.getImage("snuvi/dodge", true);
  163. private final static Image COMBAT_BODY_DASH = Utils.getImage("snuvi/dash", true);
  164. private final static Image COMBAT_BODY_JUMP = Utils.getImage("snuvi/cbat_jump", true);
  165. private int counter = 0;
  166. private int counterIdle = 0;
  167. private int counterBody = 0;
  168. private int counterHead = 0;
  169. private int counterArms = 0;
  170. private int frame = 0;
  171. private int frameIdle = 0;
  172. private int frameBody = 0;
  173. private int frameHead = 0;
  174. private int frameHeadHit = 0;
  175. private int frameArms = 0;
  176. private int attackCounter = 0;
  177. private boolean flipped = false;
  178. */
  179. public HeroAnimator(Entity ent)
  180. {
  181. super(ent);
  182. }
  183. /*
  184. @Override
  185. public int getCombatStartTicks()
  186. {
  187. return COMBAT_SWITCH.length * 5;
  188. }
  189. @Override
  190. public int getAttackTicks()
  191. {
  192. return COMBAT_ARMS_SWING[0].length * 5;
  193. }
  194. @Override
  195. public int getBlockTicks()
  196. {
  197. return BLOCK.length * 5;
  198. }
  199. @Override
  200. public int getDeathTicks()
  201. {
  202. return DEATH.length * 5;
  203. }
  204. @Override
  205. public void resetDefaultFrames()
  206. {
  207. counter = 0;
  208. frame = 0;
  209. }
  210. @Override
  211. public void resetIdleFrames()
  212. {
  213. counterIdle = 0;
  214. frameIdle = 0;
  215. }
  216. @Override
  217. public void resetHeadFrames()
  218. {
  219. counterHead = 0;
  220. frameHead = 0;
  221. frameHeadHit = 0;
  222. }
  223. @Override
  224. public void resetBodyFrames()
  225. {
  226. counterBody = 0;
  227. frameBody = 0;
  228. }
  229. @Override
  230. public void resetArmsFrames()
  231. {
  232. counterArms = 0;
  233. frameArms = 0;
  234. }
  235. @Override
  236. public void render(IRenderer renderer)
  237. {
  238. double x = ent.getX() - 2;
  239. double y = ent.getY() + ent.getHeight() - 2;
  240. if(ent.getHealth().isDead())
  241. {
  242. x -= (drawImageFlipped() ? ent.getWidth() : 0);
  243. if(frame >= DEATH.length)
  244. {
  245. frame = 0;
  246. }
  247. if(ent.getController().isInCombatMode())
  248. {
  249. renderer.drawImage(COMBAT_DEATH[frame], x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  250. }
  251. else
  252. {
  253. renderer.drawImage(DEATH[frame], x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  254. }
  255. }
  256. else if(ent.getController().isInCombatMode())
  257. {
  258. x -= (drawImageFlipped() ? ent.getWidth() : 0);
  259. if(ent.getController().isBlocking())
  260. {
  261. if(frame >= BLOCK.length)
  262. {
  263. frame = 0;
  264. }
  265. bindSlot(BLOCK[frame]);
  266. renderer.drawImage(BLOCK[frame], x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  267. }
  268. else
  269. {
  270. // body rendering
  271. if(!ent.isOnGround())
  272. {
  273. bindSlot(COMBAT_BODY_JUMP);
  274. renderer.drawImage(COMBAT_BODY_JUMP, x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  275. }
  276. else if(ent.getController().isDashing())
  277. {
  278. bindSlot(COMBAT_BODY_DASH);
  279. renderer.drawImage(COMBAT_BODY_DASH, x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  280. }
  281. else if(ent.getController().isDodging())
  282. {
  283. bindSlot(COMBAT_BODY_DODGE);
  284. renderer.drawImage(COMBAT_BODY_DODGE, x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  285. }
  286. else if(ent.getPreviousMotionX() != 0)
  287. {
  288. if(frameBody >= COMBAT_BODY_WALK.length)
  289. {
  290. frameBody = 0;
  291. }
  292. bindSlot(COMBAT_BODY_WALK[frameBody]);
  293. renderer.drawImage(COMBAT_BODY_WALK[frameBody], x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  294. }
  295. else
  296. {
  297. bindSlot(COMBAT_BODY_IDLE);
  298. renderer.drawImage(COMBAT_BODY_IDLE, x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  299. }
  300. // arms rendering
  301. int combatStart = ent.getController().getCombatTimer();
  302. if(combatStart != 0)
  303. {
  304. combatStart /= 5;
  305. if(combatStart < 0)
  306. {
  307. combatStart += COMBAT_SWITCH.length;
  308. }
  309. bindSlot(COMBAT_SWITCH[combatStart]);
  310. renderer.drawImage(COMBAT_SWITCH[combatStart], x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  311. }
  312. else if(ent.getController().isAttacking())
  313. {
  314. Image[] attack = COMBAT_ARMS_SWING[attackCounter];
  315. if(frameArms >= attack.length)
  316. {
  317. frameArms = 0;
  318. attackCounter++;
  319. if(attackCounter >= COMBAT_ARMS_SWING.length)
  320. {
  321. attackCounter = 0;
  322. }
  323. }
  324. bindSlot(attack[frameArms]);
  325. renderer.drawImage(attack[frameArms], x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  326. }
  327. else
  328. {
  329. bindSlot(COMBAT_ARMS_IDLE);
  330. renderer.drawImage(COMBAT_ARMS_IDLE, x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  331. }
  332. // head rendering
  333. if(ent.getHealth().hasInvincibility() && frameHeadHit < COMBAT_HEAD_HIT.length)
  334. {
  335. bindSlot(COMBAT_HEAD_HIT[frameHead]);
  336. renderer.drawImage(COMBAT_HEAD_HIT[frameHead], x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  337. }
  338. else
  339. {
  340. if(frameHead >= COMBAT_HEAD.length)
  341. {
  342. frameHead = 0;
  343. }
  344. bindSlot(COMBAT_HEAD[frameHead]);
  345. renderer.drawImage(COMBAT_HEAD[frameHead], x, y, ent.getWidth() * 2, ent.getHeight(), drawImageFlipped());
  346. }
  347. }
  348. }
  349. else if(ent.isOnGround())
  350. {
  351. if(ent.getPreviousMotionX() != 0)
  352. {
  353. if(frame >= WALK.length)
  354. {
  355. frame = 0;
  356. }
  357. bindSlot(WALK[frame]);
  358. renderer.drawImage(WALK[frame], x, y, ent.getWidth(), ent.getHeight(), drawImageFlipped());
  359. }
  360. else
  361. {
  362. if(frameIdle >= IDLE.length)
  363. {
  364. frameIdle = 0;
  365. }
  366. bindSlot(IDLE[frameIdle]);
  367. renderer.drawImage(IDLE[frameIdle], x, y, ent.getWidth(), ent.getHeight(), drawImageFlipped());
  368. }
  369. }
  370. else
  371. {
  372. bindSlot(JUMP);
  373. renderer.drawImage(JUMP, x, y, ent.getWidth(), ent.getHeight(), drawImageFlipped());
  374. }
  375. }
  376. @Override
  377. public boolean drawImageFlipped()
  378. {
  379. return flipped;
  380. }
  381. @Override
  382. public void tick()
  383. {
  384. counter++;
  385. counterIdle++;
  386. counterBody++;
  387. counterHead++;
  388. counterArms++;
  389. if(counter >= 6)
  390. {
  391. counter = 0;
  392. frame++;
  393. }
  394. if(counterIdle >= 12)
  395. {
  396. counterIdle = 0;
  397. frameIdle++;
  398. }
  399. if(counterBody >= 9)
  400. {
  401. counterBody = 0;
  402. frameBody++;
  403. }
  404. if(counterArms >= 9)
  405. {
  406. counterArms = 0;
  407. frameArms++;
  408. }
  409. if(counterHead >= 12)
  410. {
  411. counterHead = 0;
  412. frameHead++;
  413. frameHeadHit++;
  414. }
  415. if(frame < 0)
  416. {
  417. frame = 0;
  418. }
  419. if(frameIdle < 0)
  420. {
  421. frameIdle = 0;
  422. }
  423. if(frameBody < 0)
  424. {
  425. frameBody = 0;
  426. }
  427. if(frameHead < 0)
  428. {
  429. frameHead = 0;
  430. }
  431. if(frameArms < 0)
  432. {
  433. frameArms = 0;
  434. }
  435. if(ent.getController().isInCombatMode())
  436. {
  437. if(Keys.COMBAT_SWITCH_FACE.isReleased())
  438. {
  439. flipped = !flipped;
  440. }
  441. }
  442. else
  443. {
  444. if(ent.getMotionX() < 0)
  445. {
  446. flipped = true;
  447. }
  448. else if(ent.getMotionX() > 0)
  449. {
  450. flipped = false;
  451. }
  452. }
  453. }
  454. private void bindSlot(Image image)
  455. {
  456. if(image != null)
  457. {
  458. Health h = ent.getHealth();
  459. if(h.wasHealed())
  460. {
  461. image.bindSlot(1);
  462. }
  463. else if(h.wasHurt())
  464. {
  465. image.bindSlot(0);
  466. }
  467. else
  468. {
  469. image.bindSlot(-1);
  470. }
  471. }
  472. }*/
  473. }