0

Who

const canvas = document.getElementById('game-canvas'); const ctx = canvas.getContext('2d'); // Variabel game let dino = { x: 50, y: 200, width: 50, height: 50, velocity: 0, gravity: 0.5 }; let obstacle = { x: 400, y: 350, width: 50, height: 50, velocity: -5 }; let score = 0; // Fungsi gambar function draw() { ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.fillStyle = 'green'; ctx.fillRect(dino.x, dino.y, dino.width, dino.height); ctx.fillStyle = 'red'; ctx.fillRect(obstacle.x, obstacle.y, obstacle.width, obstacle.height); ctx.font = '24px Arial'; ctx.fillStyle = 'black'; ctx.fillText(`Skor: ${score}`, 10, 30); } // Fungsi update function update() { dino.velocity += dino.gravity; dino.y += dino.velocity; if (dino.y + dino.height > canvas.height) { dino.y = canvas.height - dino.height; dino.velocity = 0; } obstacle.x += obstacle.velocity; if (obstacle.x < 0) { obstacle.x = canvas.width; score++; } if (checkCollision(dino, obst

1st Jul 2025, 12:19 PM
Wldn Hdyt
Wldn Hdyt - avatar
1 ответ
+ 4
Hi and welcome to Sololearn, Do you have a question? The forum is for programming related questions and answers. If you have a problem with your code then please tell us more. These guides might help. https://www.sololearn.com/discuss/3021159/?ref=app https://sololearn.com/compiler-playground/Wek0V1MyIR2r/?ref=app https://sololearn.com/compiler-playground/W3uiji9X28C1/?ref=app https://sololearn.com/compiler-playground/W0uW3Wks8UBk/?ref=app
1st Jul 2025, 12:26 PM
Ausgrindtube
Ausgrindtube - avatar