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

Commit

Permalink
[Engine]: GameObject2D move with origin
Browse files Browse the repository at this point in the history
  • Loading branch information
201flaviosilva committed Apr 14, 2022
1 parent 4d2aa0e commit 0877316
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
19 changes: 17 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
_ignore

.doc
.DS_Store
.editorconfig
.eslintrc.json
.gitignore
.gitattributes
.github/
.travis.yml
.vscode/
.doc

node_modules/
.DS_Store
src/
docs/

awesome-impacto.md
rollup.config.dev.js
rollup.config.js
yarn-error.log
webpack.config.js
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:5501",
"webRoot": "${workspaceFolder}"
}
]
}
17 changes: 7 additions & 10 deletions src/GameObjects/GameObject2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export default class GameObject2D {

// Position
setX(x) {
this.setPosition(x, this._y, this.z);
this.setPosition(x + (this.width || this.radius) * this.origin.x, this._y, this.z);
return this;
}
setY(y) {
this.setPosition(this._x, y, this.z);
this.setPosition(this._x, y + (this.height || this.radius) * this.origin.y, this.z);
return this;
}
setZ(z) {
Expand All @@ -42,8 +42,7 @@ export default class GameObject2D {
}
getPosition() { return { x: this.x, y: this.y, z: this.z }; }
getRealPosition() { return { x: this._x, y: this._y, z: this.z }; }
setPosition(x, y, z = this.z, force = false) {
if (this.bodyType === "S" && !force) return;
setPosition(x, y, z = this.z) {
this.lastPosition = { x: this.x, y: this.y, z: this.z };

this._x = x;
Expand All @@ -52,12 +51,10 @@ export default class GameObject2D {
return this;
}
setRandomPosition(x = 0, y = 0, width = CanvasStateInstance.width, height = CanvasStateInstance.height) {
do {
this.setPosition(
x + Math.random() * width,
y + Math.random() * height
);
} while (!this.checkIsInsideWorldBounds());
this.setPosition(
x + Math.random() * width,
y + Math.random() * height
);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class Utils {
this.Math = new ImpactoMath();
}

getVersion() { return "Impacto: 0.9.0-0"; }
getVersion() { return "0.9.0-0"; }
}

export const UtilsInstance = new Utils();

0 comments on commit 0877316

Please sign in to comment.