CellModel.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { CELL_TYPE, ANITIME, CELL_STATUS, GRID_HEIGHT } from "./ConstValue";
  2. export default class CellModel {
  3. constructor() {
  4. this.type = null;
  5. this.status = CELL_STATUS.COMMON;
  6. this.x = 1;
  7. this.y = 1;
  8. this.startX = 1;
  9. this.startY = 1;
  10. this.cmd = [];
  11. this.isDeath = false;
  12. this.objecCount = Math.floor(Math.random() * 1000);
  13. }
  14. init(type) {
  15. this.type = type;
  16. }
  17. isEmpty() {
  18. return this.type == CELL_TYPE.EMPTY;
  19. }
  20. setEmpty() {
  21. this.type = CELL_TYPE.EMPTY;
  22. }
  23. setXY(x, y) {
  24. this.x = x;
  25. this.y = y;
  26. }
  27. setStartXY(x, y) {
  28. this.startX = x;
  29. this.startY = y;
  30. }
  31. setStatus(status) {
  32. this.status = status;
  33. }
  34. moveToAndBack(pos) {
  35. var srcPos = cc.v2(this.x, this.y);
  36. this.cmd.push({
  37. action: "moveTo",
  38. keepTime: ANITIME.TOUCH_MOVE,
  39. playTime: 0,
  40. pos: pos
  41. });
  42. this.cmd.push({
  43. action: "moveTo",
  44. keepTime: ANITIME.TOUCH_MOVE,
  45. playTime: ANITIME.TOUCH_MOVE,
  46. pos: srcPos
  47. });
  48. }
  49. moveTo(pos, playTime) {
  50. var srcPos = cc.v2(this.x, this.y);
  51. this.cmd.push({
  52. action: "moveTo",
  53. keepTime: ANITIME.TOUCH_MOVE,
  54. playTime: playTime,
  55. pos: pos
  56. });
  57. this.x = pos.x;
  58. this.y = pos.y;
  59. }
  60. toDie(playTime) {
  61. this.cmd.push({
  62. action: "toDie",
  63. playTime: playTime,
  64. keepTime: ANITIME.DIE
  65. });
  66. this.isDeath = true;
  67. }
  68. toShake(playTime) {
  69. this.cmd.push({
  70. action: "toShake",
  71. playTime: playTime,
  72. keepTime: ANITIME.DIE_SHAKE
  73. });
  74. }
  75. setVisible(playTime, isVisible) {
  76. this.cmd.push({
  77. action: "setVisible",
  78. playTime: playTime,
  79. keepTime: 0,
  80. isVisible: isVisible
  81. });
  82. }
  83. moveToAndDie(pos) {
  84. }
  85. isBird() {
  86. return this.type == CELL_TYPE.G;
  87. }
  88. }