zodiac_manager.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. function zodiac (params) {
  2. let that = { },
  3. canvas = params.canvas,
  4. image = params.image,
  5. image_black = params.image_black,
  6. image_play = params.image_play,
  7. img;
  8. that.sprite = params.sprite
  9. that.r = 60;
  10. that.id = params.id;
  11. that.name = params.name;
  12. that.ctx = params.ctx;
  13. that.coord = params.coord;
  14. that.deg = params.deg;
  15. that.color = "gray";
  16. that.canvasWidth = canvas.width;
  17. that.canvasHeight = canvas.height;
  18. that.isActivated = false;
  19. that.scale = params.scale;
  20. that.init = function() {
  21. canvas.addEventListener("mousedown", that.onClick, false);
  22. };
  23. that.setup = function() {
  24. that.sprite.setup();
  25. that.setActivate(false);
  26. that.r * this.scale;
  27. };
  28. that.onUpdate = function(){
  29. that.sprite.update();
  30. };
  31. that.onDraw = function() {
  32. that.ctx.save();
  33. that.ctx.beginPath();
  34. that.ctx.translate(that.coord.x ,that.coord.y )
  35. that.ctx.rotate((that.deg + 90)* Math.PI / 180);
  36. that.ctx.drawImage(img, -((image.width * that.scale) / 2), - ((image.height * that.scale) / 2), image.width * that.scale, image.height * that.scale);
  37. that.ctx.closePath();
  38. that.ctx.restore();
  39. };
  40. that.onDrawAnim = function() {
  41. that.sprite.render();
  42. };
  43. that.isAnimStop = function() {
  44. return that.sprite.isAnimStop();
  45. };
  46. that.setPosition = function(x, y) {
  47. that.coord.x = x;
  48. that.coord.y = y;
  49. };
  50. that.setActivate = function(isActivated) {
  51. that.isActivated = isActivated;
  52. if(isActivated) {
  53. img = image_play;
  54. } else {
  55. img = image_black;
  56. }
  57. };
  58. that.setCompleted = function() {
  59. img = image;
  60. }
  61. that.setTriggerColor = function(color) {
  62. that.color = color;
  63. };
  64. that.onClick = function(e) {
  65. let mouseX = e.clientX;
  66. let mouseY = e.clientY;
  67. let isX = false, isY = false;
  68. if(mouseX >= Math.abs((that.coord.x + (that.canvasWidth / 4) - that.r)) && mouseX <= Math.abs((that.coord.x + (that.canvasWidth/ 4) + that.r ))) {
  69. isX = true;
  70. }
  71. if(mouseY >= Math.abs((that.coord.y + (that.canvasWidth / 4)- that.r)) && mouseY <= Math.abs((that.coord.y + (that.canvasWidth / 4) + that.r))) {
  72. isY = true;
  73. }
  74. };
  75. return that;
  76. }