Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
[Engine]: fixed merge
Browse files Browse the repository at this point in the history
  • Loading branch information
201flaviosilva committed Mar 21, 2022
1 parent dbdca63 commit 25a2ffb
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 51 deletions.
6 changes: 3 additions & 3 deletions src/GameObjects/GameObjectBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ export default class GameObject {
_render() {
if (!this.visible) return;

CanvasInstance.context.fillStyle = this.fillColor;
CanvasInstance.context.strokeStyle = this.strokeColor;
CanvasInstance.context.lineWidth = this.strokeWidth;
CanvasStateInstance.context.fillStyle = this.fillColor;
CanvasStateInstance.context.strokeStyle = this.strokeColor;
CanvasStateInstance.context.lineWidth = this.strokeWidth;
this._renderType();
}
}
14 changes: 7 additions & 7 deletions src/GameObjects/Line/Line.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GameObject from "../GameObjectBase.js";
import { CanvasInstance } from "../../Utils/Canvas.js";
import { CanvasStateInstance } from "../../State/CanvasState.js";
import Types from "../Types.js";

export default class Line extends GameObject {
Expand Down Expand Up @@ -73,11 +73,11 @@ export default class Line extends GameObject {

// Private
_renderType() {
CanvasInstance.context.beginPath();
CanvasInstance.context.moveTo(this.x, this.y);
CanvasInstance.context.lineTo(this.endX, this.endY);
CanvasInstance.context.closePath();
CanvasInstance.context.fill();
CanvasInstance.context.stroke();
CanvasStateInstance.context.beginPath();
CanvasStateInstance.context.moveTo(this.x, this.y);
CanvasStateInstance.context.lineTo(this.endX, this.endY);
CanvasStateInstance.context.closePath();
CanvasStateInstance.context.fill();
CanvasStateInstance.context.stroke();
}
}
20 changes: 10 additions & 10 deletions src/GameObjects/Polygon/Polygon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GameObject from "../GameObjectBase.js";
import { CanvasInstance } from "../../Utils/Canvas.js";
import { CanvasStateInstance } from "../../State/CanvasState.js";
import Types from "../Types.js";

export default class Polygon extends GameObject {
Expand Down Expand Up @@ -80,20 +80,20 @@ export default class Polygon extends GameObject {
_renderType() {
if (this.vertices.length === 0) return;

CanvasInstance.context.save();
CanvasInstance.context.translate(this.x, this.y);
CanvasStateInstance.context.save();
CanvasStateInstance.context.translate(this.x, this.y);

CanvasInstance.context.beginPath();
CanvasStateInstance.context.beginPath();

CanvasInstance.context.moveTo(this.vertices[0].x, this.vertices[0].y);
CanvasStateInstance.context.moveTo(this.vertices[0].x, this.vertices[0].y);
for (let i = 1; i < this.vertices.length; i++) {
CanvasInstance.context.lineTo(this.vertices[i].x, this.vertices[i].y);
CanvasStateInstance.context.lineTo(this.vertices[i].x, this.vertices[i].y);
}
if (this.close) CanvasInstance.context.closePath();
if (this.close) CanvasStateInstance.context.closePath();

CanvasInstance.context.stroke();
CanvasInstance.context.fill();
CanvasStateInstance.context.stroke();
CanvasStateInstance.context.fill();

CanvasInstance.context.restore();
CanvasStateInstance.context.restore();
}
}
26 changes: 13 additions & 13 deletions src/GameObjects/Rectangle/CommonMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ const CommonMethods = {
// ----- Private methods -----
_renderType: function () {
// Ref: https://stackoverflow.com/questions/1255512/how-to-draw-a-rounded-rectangle-using-html-canvas
CanvasInstance.context.beginPath();
CanvasInstance.context.moveTo(this.x + this.round.topLeft, this.y);
CanvasInstance.context.lineTo(this.x + this.width - this.round.topRight, this.y);
CanvasInstance.context.quadraticCurveTo(this.x + this.width, this.y, this.x + this.width, this.y + this.round.topRight);
CanvasInstance.context.lineTo(this.x + this.width, this.y + this.height - this.round.bottomRight);
CanvasInstance.context.quadraticCurveTo(this.x + this.width, this.y + this.height, this.x + this.width - this.round.bottomRight, this.y + this.height);
CanvasInstance.context.lineTo(this.x + this.round.bottomLeft, this.y + this.height);
CanvasInstance.context.quadraticCurveTo(this.x, this.y + this.height, this.x, this.y + this.height - this.round.bottomLeft);
CanvasInstance.context.lineTo(this.x, this.y + this.round.topLeft);
CanvasInstance.context.quadraticCurveTo(this.x, this.y, this.x + this.round.topLeft, this.y);
CanvasInstance.context.fill();
CanvasInstance.context.stroke();
CanvasInstance.context.closePath();
CanvasStateInstance.context.beginPath();
CanvasStateInstance.context.moveTo(this.x + this.round.topLeft, this.y);
CanvasStateInstance.context.lineTo(this.x + this.width - this.round.topRight, this.y);
CanvasStateInstance.context.quadraticCurveTo(this.x + this.width, this.y, this.x + this.width, this.y + this.round.topRight);
CanvasStateInstance.context.lineTo(this.x + this.width, this.y + this.height - this.round.bottomRight);
CanvasStateInstance.context.quadraticCurveTo(this.x + this.width, this.y + this.height, this.x + this.width - this.round.bottomRight, this.y + this.height);
CanvasStateInstance.context.lineTo(this.x + this.round.bottomLeft, this.y + this.height);
CanvasStateInstance.context.quadraticCurveTo(this.x, this.y + this.height, this.x, this.y + this.height - this.round.bottomLeft);
CanvasStateInstance.context.lineTo(this.x, this.y + this.round.topLeft);
CanvasStateInstance.context.quadraticCurveTo(this.x, this.y, this.x + this.round.topLeft, this.y);
CanvasStateInstance.context.fill();
CanvasStateInstance.context.stroke();
CanvasStateInstance.context.closePath();
},
};

Expand Down
2 changes: 2 additions & 0 deletions src/GameObjects/Rectangle/PhysicsRectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export default class PhysicsRectangle extends PhysicsGameObject {
this.width = width;
this.height = height;

this.setRound(0);

this._type = Types.rectangle;
}

Expand Down
2 changes: 2 additions & 0 deletions src/GameObjects/Rectangle/Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export default class Rectangle extends GameObject {
this.width = width;
this.height = height;

this.setRound(0);

this._type = Types.rectangle;
}

Expand Down
20 changes: 10 additions & 10 deletions src/GameObjects/Text/Text.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GameObject from "../GameObjectBase.js";
import { CanvasInstance } from "../../Utils/Canvas.js";
import { CanvasStateInstance } from "../../State/CanvasState.js";
import Types from "../Types.js";

export default class Text extends GameObject {
Expand All @@ -23,7 +23,7 @@ export default class Text extends GameObject {

get width() {
if (this.text === "") return 0;
return CanvasInstance.context.measureText(this.text, this.font).width;
return CanvasStateInstance.context.measureText(this.text, this.font).width;
}

get height() {
Expand Down Expand Up @@ -165,17 +165,17 @@ export default class Text extends GameObject {

// Private
_renderType() {
CanvasInstance.context.save();
CanvasStateInstance.context.save();

CanvasInstance.context.textBaseline = this.alignVertical;
CanvasInstance.context.textAlign = this.alignHorizontal;
CanvasInstance.context.direction = this.direction;
CanvasStateInstance.context.textBaseline = this.alignVertical;
CanvasStateInstance.context.textAlign = this.alignHorizontal;
CanvasStateInstance.context.direction = this.direction;

CanvasInstance.context.font = this.font;
CanvasStateInstance.context.font = this.font;

CanvasInstance.context.fillText(this.text, this.x, this.y);
CanvasInstance.context.strokeText(this.text, this.x, this.y);
CanvasStateInstance.context.fillText(this.text, this.x, this.y);
CanvasStateInstance.context.strokeText(this.text, this.x, this.y);

CanvasInstance.context.restore();
CanvasStateInstance.context.restore();
}
}
16 changes: 8 additions & 8 deletions src/GameObjects/Triangle/Triangle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GameObject from "../GameObjectBase.js";
import { CanvasInstance } from "../../Utils/Canvas.js";
import { CanvasStateInstance } from "../../State/CanvasState.js";
import Types from "../Types.js";

export default class Triangle extends GameObject {
Expand Down Expand Up @@ -59,12 +59,12 @@ export default class Triangle extends GameObject {

// Private
_renderType() {
CanvasInstance.context.beginPath();
CanvasInstance.context.moveTo(this.x, this.y);
CanvasInstance.context.lineTo(this.x + this.width, this.y);
CanvasInstance.context.lineTo(this.x + this.width / 2, this.y + this.height);
CanvasInstance.context.closePath();
CanvasInstance.context.fill();
CanvasInstance.context.stroke();
CanvasStateInstance.context.beginPath();
CanvasStateInstance.context.moveTo(this.x, this.y);
CanvasStateInstance.context.lineTo(this.x + this.width, this.y);
CanvasStateInstance.context.lineTo(this.x + this.width / 2, this.y + this.height);
CanvasStateInstance.context.closePath();
CanvasStateInstance.context.fill();
CanvasStateInstance.context.stroke();
}
}

0 comments on commit 25a2ffb

Please sign in to comment.