Update index.php

This commit is contained in:
2025-12-29 20:41:21 +01:00
parent 515829ecb9
commit 463ef9eac7

View File

@@ -1,43 +1,61 @@
<?php
// PHP startpunt (kan later scores / sessions doen)
// later kan hier PHP score / sessions
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<title>T-REX</title>
<title>loading...</title>
</head>
<body>
<h1>T-Rex Run (in de tab 😎)</h1>
<p>Kijk naar de titel van dit tabblad</p>
<h1>Kijk naar de tab 👆</h1>
<script>
let trex = "🦖";
let ground = "____________________";
let pos = 0;
let dir = 1;
let score = 0;
// vaste dino positie
const dinoPos = 5;
function updateTitle() {
let before = ground.substring(0, pos);
let after = ground.substring(pos + 2);
// wereld (komma = obstakel)
let world = " , , , ";
let jumping = false;
let jumpFrames = 0;
// obstakel
let obstacle = (score % 10 === 0) ? "::" : " ";
function gameTick() {
// wereld schuift naar links
world = world.slice(1) + (Math.random() < 0.15 ? "," : " ");
document.title =
before + trex + after + obstacle + " score:" + score;
pos += dir;
if (pos <= 0 || pos >= ground.length - 2) {
dir *= -1;
let display = "";
for (let i = 0; i < world.length; i++) {
if (i === dinoPos) {
// dino
if (jumping && world[i] === ",") {
display += ";"; // springt over obstakel
} else {
display += ".";
}
} else {
display += world[i];
}
}
score++;
document.title = display;
// jump logica
if (jumping) {
jumpFrames--;
if (jumpFrames <= 0) jumping = false;
}
}
setInterval(updateTitle, 200);
// space = jump
document.addEventListener("keydown", e => {
if (e.code === "Space" && !jumping) {
jumping = true;
jumpFrames = 4;
}
});
setInterval(gameTick, 180);
</script>
</body>