-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (32 loc) · 926 Bytes
/
script.js
File metadata and controls
46 lines (32 loc) · 926 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$(function(){
var score = 0;
$('.screen').append('<circle cx="60" cy="60" r="50"/>');
var shooter = $('.shooter')[0];
var velocityX = 10;
var velocityY = 0;
var boxY = Math.floor(Math.random() * 300);
$('.target')[0].setAttribute('y', boxY);
$('svg').on('click', function(){
velocityY += 1;
});
var runGame = function() {
var cx = Number(shooter.getAttribute('cx'));
shooter.setAttribute('cx', cx + velocityX);
var cy = Number(shooter.getAttribute('cy'));
shooter.setAttribute('cy', cy + velocityY);
if (cx > 600) {
if (cy > boxY && cy < boxY + 50) {
score += 1
$('.score').text(score);
boxY = Math.floor(Math.random() * 300);
$('.target')[0].setAttribute('y', boxY);
}
shooter.setAttribute('cx', 10);
shooter.setAttribute('cy', 10);
velocityY = 0;
}
}
// debugger;
setInterval(runGame, 30);
}
);