Код игры "Пинг-Понг" на английском Код программы const C = document.querySelector("canvas"); const W = C.width; const H = C.height; const $ = C.getContext("2d"); function drawRect(x, y, w, h, color) { $.fillStyle = color; $.fillRect(x, y, w, h); } drawRect(0, 0, W, H, "black"); const user = { x: 0, y: H / 2 - 50, width: 10, height: 100, color: "white", score: 0 }; const com = { x: W - 10, y: H / 2 - 50, width: 10, height: 100, color: "white", score: 0 }; const net = { x: W / 2 - 1, y: 0, width: 2, height: 10, color: "white" }; const ball = { x: W / 2, y: H / 2, speed: 7, cx: 5, cy: 5, r: 10, color: "white" }; function drawCircle(x, y, r, color) { $.fillStyle = color; $.beginPath(); $.arc(x, y, r, 0, 2 * Math.PI); $.closePath(); $.fill(); } function drawText(text, x, y, color) { $.fillStyle = color; $.font = "75px fantasy"; $.fillText(text, x, y); } function drawNet() { for (let i = 0; i < H; i += 15) { drawRect(net.x, net.y + i, net.width, net.height, net.color); } } function collision
Игра «Пинг- Понг» на английском. Читаем и разбираем код (Javascript)
6 октября 20236 окт 2023
56
2 мин