-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
67 lines (57 loc) · 1.42 KB
/
functions.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
$(document).on('mousemove', function (e) {
basket.css('left', e.pageX);
});
function egg_down(egg) {
egg_current_position = parseInt(egg.css('top'));
egg.css('top', egg_current_position + speed);
}
function check_egg_hits_floor(egg) {
if (collision(egg, floor)) {
show_bulls_eye(egg);
decrement_life();
return true;
}
return false;
}
function set_egg_to_initial_position(egg) {
egg.css('top', egg_initial_position);
}
function show_bulls_eye(egg) {
bullseye_num = egg.attr('data-bullseye');
$('#bullseye' + bullseye_num).show();
hide_bulls_eye(bullseye_num);
}
function hide_bulls_eye(bullseye_num) {
setTimeout(function () {
$('#bullseye' + bullseye_num).hide();
}, 800);
}
function decrement_life() {
life--;
life_span.text(life);
}
function check_egg_hits_basket(egg) {
if (collision(egg, basket)) {
egg_top = parseInt(egg.css('top'));
if (egg_top < basket_top) {
update_score();
return true;
}
}
return false;
}
function update_score() {
score++;
if (score % 10 === 0 && speed <= max_speed) {
speed++;
}
score_span.text(score);
score_1.text(score);
}
function stop_the_game() {
cancelAnimationFrame(anim_id);
restart.slideDown();
}
restart.click(function () {
location.reload();
});