Skip to content

Commit

Permalink
Fix portrait mode
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed Oct 22, 2023
1 parent 2dcd93c commit 2e6678e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export class Game extends EventEmitter {

this.setWorldScale(this.worldScale);

if ((window.isMobile || window.isTablet) && ratio < 1) {
if (ratio < 1) {
this.worldContainer.rotation = Math.PI / 2;
this.halfScreenWidth = this.screenHeight / 2;
this.halfScreenHeight = this.screenWidth / 2;
Expand Down
21 changes: 20 additions & 1 deletion src/ship.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ export class Ship extends PIXI.Container {

this.joystickMove = { x, y };

if (game.portrait) {
// In portrait mode, the ship is rotated 90 degrees.
const tmp = this.joystickMove.x;
this.joystickMove.x = this.joystickMove.y;
this.joystickMove.y = -tmp;
}

this.pointerRotation = Math.atan2(this.joystickMove.y, this.joystickMove.x) + PI05;
this.pointerMove = false;
} else {
Expand All @@ -189,7 +196,7 @@ export class Ship extends PIXI.Container {
this.pointerY = y;
}

update(delta) {
update(delta, game) {
let dx = 0;
let dy = 0;
const d = 0.01;
Expand All @@ -207,6 +214,13 @@ export class Ship extends PIXI.Container {
dy = delta * this.speed * d;
}

if (game.portrait) {
// In portrait mode, the ship is rotated 90 degrees.
const tmp = dx;
dx = dy;
dy = -tmp;
}

if (this.joystickMove) {
dx = delta * this.speed * ((d / maxPointerMovement) * this.joystickMove.x);
dy = delta * this.speed * ((d / maxPointerMovement) * this.joystickMove.y);
Expand Down Expand Up @@ -254,6 +268,11 @@ export class Ship extends PIXI.Container {
this.wantRotation = 180 * (PI / 180);
}

if (game.portrait) {
// In portrait mode, the ship is rotated 90 degrees.
this.wantRotation -= PI05;
}

// We ain for the player cursor, unless the player hasn't moved
// the cursor in a while, then we aim in the direction of movement.
if (this.cancelPointerMoveAfter < performance.now()) {
Expand Down

0 comments on commit 2e6678e

Please sign in to comment.