uploaded initial breakout files
This commit is contained in:
32
breakout_2.js
Normal file
32
breakout_2.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
var canvas = document.getElementById("myCanvas");
|
||||||
|
var ctx = canvas.getContext("2d");
|
||||||
|
var ballRadius = 12;
|
||||||
|
var x = ballRadius;
|
||||||
|
var y = ballRadius;
|
||||||
|
var dx = 2;
|
||||||
|
var dy = -2;
|
||||||
|
|
||||||
|
function drawBall() {
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(x, y, ballRadius, 0, 2 * Math.PI);
|
||||||
|
ctx.fillStyle = "#FF0000";
|
||||||
|
ctx.fill();
|
||||||
|
ctx.closePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw() {
|
||||||
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
drawBall();
|
||||||
|
|
||||||
|
if(x + dx > canvas.width-ballRadius || x + dx < ballRadius) {
|
||||||
|
dx = -dx;
|
||||||
|
}
|
||||||
|
if(y + dy > canvas.height-ballRadius || y + dy < ballRadius) {
|
||||||
|
dy = -dy;
|
||||||
|
}
|
||||||
|
|
||||||
|
x += dx;
|
||||||
|
y += dy;
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(draw, 10);
|
||||||
5
index.html
Normal file
5
index.html
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<canvas id="myCanvas" width="600" height="400"></canvas>
|
||||||
|
|
||||||
|
<style>canvas { background: #DAEDEB; }</style>
|
||||||
|
|
||||||
|
<script src="breakout_2.js"></script>
|
||||||
Reference in New Issue
Block a user