Skip to content

Commit

Permalink
tweaks to game mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
aleatorydialogue committed Aug 9, 2024
1 parent 3025448 commit fda18c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions game.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
let velocityY = 0;
let rotation = 0; // Variable to track the character's rotation
let isGameOver = false;
let facingRight = true; // Track which direction the character is facing

// Load images
const standingImage = new Image();
Expand Down Expand Up @@ -142,7 +143,11 @@
// Switch to jump image and rotate when not on a platform
if (!character.isOnPlatform) {
currentImage = jumpingImage;
rotation += 0.08; // Continue rotating while in the air
if (facingRight) {
rotation += 0.08; // Rotate clockwise
} else {
rotation -= 0.08; // Rotate counterclockwise
}
}

// Move platforms down to simulate upward camera movement
Expand Down Expand Up @@ -185,10 +190,13 @@
ctx.drawImage(platformImage, platform.x, platform.y, platform.width, platform.height);
});

// Draw character with rotation
// Draw character with rotation and inversion if necessary
ctx.save();
ctx.translate(character.x + character.width / 2, character.y + character.height / 2);
ctx.rotate(rotation);
if (!facingRight) {
ctx.scale(-1, 1); // Flip the character horizontally
}
ctx.drawImage(currentImage, -character.width / 2, -character.height / 2, character.width, character.height);
ctx.restore();

Expand All @@ -201,9 +209,15 @@
}
if (event.key === 'ArrowLeft') {
character.velocityX = -5;
if (character.isOnPlatform) {
facingRight = false; // Face left
}
}
if (event.key === 'ArrowRight') {
character.velocityX = 5;
if (character.isOnPlatform) {
facingRight = true; // Face right
}
}
});

Expand Down
Binary file added walk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fda18c4

Please sign in to comment.