Skip to content

Commit

Permalink
Changing perspective
Browse files Browse the repository at this point in the history
  • Loading branch information
kopiro committed Nov 21, 2023
1 parent ed19ba8 commit 4f54832
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const kBushOffset = 16;
const kBushDensity = 30;

const kCameraOffset = 800;
const kMaxCameraZ = -480;
const kCameraX = kTrackWidth / 4;
const kCameraY = 400;

function loadGame() {
readOptions();
Expand Down Expand Up @@ -192,10 +195,8 @@ function applyCoordinates(p) {
}

function moveCamera(z) {
const x = 85;
const y = 450;
z = Math.max(z - kCameraOffset, -400);
$scene.style.transform = `translate3d(${x}px, ${y}px, ${z}px)`;
const realZ = Math.max(z - kCameraOffset, kMaxCameraZ);
$scene.style.transform = `translate3d(${kCameraX}px, ${kCameraY}px, ${realZ}px)`;
}

function applySrc(obj, src) {
Expand Down Expand Up @@ -255,7 +256,7 @@ function startRenderingLoop() {
// Find the player with the lowest Z
const lowestZ = Object.keys(game.$.players).reduce((acc, key) => {
return Math.min(acc, game.$.players[key].z);
}, Infinity);
}, kInfiniteTrackLength);

moveCamera(lowestZ);
}
Expand Down
4 changes: 2 additions & 2 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ body {
height: var(--screen-size);
position: relative;
margin: 0 auto;
perspective-origin: 100% -20%;
perspective-origin: 90% -10%;
perspective: 1000px;
overflow: hidden;
border: 3px solid var(--primary-color);
}

#scene {
position: absolute;
transform: translate3d(85px, 450px, -400px);
transform-style: preserve-3d;
}

Expand Down

0 comments on commit 4f54832

Please sign in to comment.