trinRectObject.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. function TrinRectObject(x, y, width, height, color) {
  2. if (x === undefined) {
  3. x = 0;
  4. }
  5. if (y === undefined) {
  6. y = 0;
  7. }
  8. if (width === undefined) {
  9. width = 10;
  10. }
  11. if (height === undefined) {
  12. height = 0;
  13. }
  14. if (color === undefined) {
  15. color = "#ffffff";
  16. }
  17. TrinRectObject.superclass.constructor.apply(this);
  18. this.x = x;
  19. this.y = y;
  20. this.width = width;
  21. this.height = height;
  22. this.color = color;
  23. this.active = this.exists = this.visible = true;
  24. this.alpha = 1;
  25. }
  26. extend(TrinRectObject, TrinEntity);
  27. TrinRectObject.prototype.update = function() {
  28. TrinRectObject.superclass.update.apply(this);
  29. };
  30. TrinRectObject.prototype.draw = function(context) {
  31. TrinRectObject.superclass.draw.apply(this, [context]);
  32. context.beginPath();
  33. context.fillStyle = this.color;
  34. context.globalAlpha = this.alpha;
  35. context.fillRect(this.x, this.y, this.width, this.height);
  36. context.stroke();
  37. };
  38. TrinRectObject.prototype.reset = function(x, y, color) {
  39. TrinRectObject.superclass.reset.apply(this, [x, y]);
  40. this.color = color;
  41. };
  42. TrinRectObject.prototype.intersects = function(x, y, w, h) {
  43. var rect = new TrinRectangle(this.x, this.y, this.width, this.height);
  44. return rect.intersects(x, y, w, h);
  45. };