Message
Message
doctype html>
<html>
<head>
<meta charset ="UTF-8">
<title>Игра гонки</title>
</head>
<body>
<div style="display: flex; justify-content: center; align-items: center;
height: 100vh;">
<canvas id="canvas" width="400" height="500"></canvas>
</div>
<style>
body {
background-color: green;
}
</style>
<div>
<button
onclick="document.getElementById('photoInput1').click()">Выбрать фото 1</button>
<input id="photoInput1" type="file" style="display: none">
</div>
<div>
<button
onclick="document.getElementById('photoInput2').click()">Выбрать фото 2</button>
<input id="photoInput2" type="file" style="display: none">
</div>
<div>
<button
onclick="document.getElementById('photoInput3').click()">Выбрать фото 3</button>
<input id="photoInput3" type="file" style="display: none">
</div>
<script>
var canvas = document.getElementById("canvas");
var lives = 5;
var okLeft = false;
var okRight = false;
function drawRect() {
ctx.fillStyle = "Gray";
ctx.fillRect(0, 0, 400, 500);
}
function drawLives() {
ctx.font = "30px Arial";
ctx.fillStyle = "White";
ctx.fillText("Lives: " + lives, 235, 48);
}
function drawLines() {
ctx.drawImage(line, line.X, line.Y);
line.Y += 3;
if (line.Y > 500) {
line.Y = -140;
}
function stop() {
cancelAnimationFrame(myReq);
ctx.font = "60px Arial";
ctx.fillStyle = "Red";
ctx.fillText("Game over", 40, 200);
stop = true;
}
function drawMyCar() {
if (okLeft === true && myCar.X > 0) {
myCar.X -= 5;
}
if (okRight === true && myCar.X < 335) {
myCar.X += 5;
}
function drawEnemyCar1() {
if (!crash) {
ctx.drawImage(enemyCar1, enemyCar1.X, enemyCar1.Y);
enemyCar1.Y += 2;
if (enemyCar1.Y > 500) {
enemyCar1.Y = -100;
enemyCar1.X = Math.floor(Math.random() * 335);
}
}
}
function drawEnemyCar2() {
if (!crash) {
ctx.drawImage(enemyCar2, enemyCar2.X, enemyCar2.Y);
enemyCar2.Y += 2;
if (enemyCar2.Y > 500) {
enemyCar2.Y = -100;
enemyCar2.X = Math.floor(Math.random() * 335);
}
}
}
function render() {
if (stop === true) {
return;
}
drawRect();
drawLives();
drawLines();
drawMyCar();
drawEnemyCar1();
drawEnemyCar2();
myReq = requestAnimationFrame(render);
}
render();