html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<div align="center">
<canvas width="600" height="400" id="canv"></canvas>
<p id="one">Player 1:<br>W & S</p>
<p id="two">Player 2:<br> ↑ & ↓</p>
</div>
</body>
</html>
<!-- credit to Mirielle for some help with the
JavaScript, huge thanks!-->
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
body {
background-color: #161621;
color: white;
font-family: Arial;
font-size: 20px;
}
canvas {
border: 2px solid white;
width: 100%;
}
#one {
display: inline;
position: absolute;
left: 10px;
}
#two {
display: inline;
position: absolute;
right: 10px;
}
p {
margin-top: 5px;
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//setup
let canvas = document.getElementById("canv");
let context = canvas.getContext("2d");
var bx = 300;
var by = 200;
let coin;
let specVar;
//randomizing start x
let ix;
coin = Math.floor(Math.random() * 2);
if (coin == 1) {
ix = 2;
}
if (coin == 0) {
ix = -2;
}
//randomizing start y
let iy;
coin = Math.floor(Math.random() * 2);
if (coin == 1) {
iy = Math.ceil(-1 * (Math.random() * 3));
}
if (coin == 0) {
iy = Math.ceil(Math.random() * 3);
}
var enableMovement = 1;
var isBallFrozen = 0;
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run