heartdestination.js 916 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. function HeartDestination(startx, starty) {
  2. var position = {x : startx, y: starty};
  3. var expiration = 1000;
  4. this.isConsumed = false;
  5. var level = 1;
  6. var delay = 25;
  7. this.init = function(canvas) {
  8. expiration = 1000;
  9. };
  10. this.update = function(canvas) {
  11. expiration--;
  12. if(expiration <= 0) {
  13. this.isConsumed = true;
  14. }
  15. };
  16. this.draw = function(context, offset) {
  17. context.beginPath();
  18. context.strokeStyle = "#FF0000";
  19. context.rect(position.x - 5, position.y - 5, 10, 10);
  20. context.stroke();
  21. };
  22. this.getPosition = function() {
  23. return position;
  24. }
  25. this.visit = function(hero) {
  26. hero.actionDelay(25);
  27. if(hero.addHeart(level)) {
  28. this.isConsumed = true;
  29. }
  30. return this;
  31. }
  32. this.getType = function() {
  33. return "heart";
  34. }
  35. this.mouseMove = function(canvas, x, y) {
  36. };
  37. this.getName = function() {
  38. return this.getType();
  39. }
  40. this.getLevel = function() {
  41. return level;
  42. }
  43. }