-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.js
More file actions
71 lines (58 loc) · 1.59 KB
/
form.js
File metadata and controls
71 lines (58 loc) · 1.59 KB
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
68
69
70
71
/* Control Planet Appearance */
function updatePlanetColor(){
document.getElementById('theplanet').style.background = document.getElementById('planetcolor').value;
}
function updatePlanetName(){
document.getElementById('planetname').innerHTML = document.getElementById('planetnameinput').value;
}
function updatePlanetSize(){
var size = $('#size').val();
$('#theplanet').width(size);
$('#theplanet').height(size);
}
$( '#build' ).click(function() {
updatePlanetColor();
updatePlanetSize();
updatePlanetName();
});
$( '#moon-add' ).click(function() {
$('.moon').toggle()
});
$( '#ring-add' ).click(function() {
$('#planetrings').toggle()
});
var score = 0;
var speed = 5;
$( '#rocket' ).click(function() {
speed -= 0.5;
$('#rocket-box').show()
$('#rocket-box').slideUp(2000)
collision($('#rocket-img'), $('.moon'))
if (speed == 0) {
alert('You scored ' + score + ' points!' )
}
function speedUp(){
$('#square').css({'animation':'orbit ' + speed + 's linear infinite'});
}
setTimeout(speedUp, 2000);
});
function collision($div1, $div2) {
var x1 = $div1.offset().left;
var y1 = $div1.offset().top;
var h1 = $div1.outerHeight(true);
var w1 = $div1.outerWidth(true);
var b1 = y1 + h1;
var r1 = x1 + w1;
var x2 = $div2.offset().left;
var y2 = $div2.offset().top;
var h2 = $div2.outerHeight(true);
var w2 = $div2.outerWidth(true);
var b2 = y2 + h2;
var r2 = x2 + w2;
if (b1 < y2 || y1 > b2 || r1 < x2 || x1 > r2) return false;
return success();
}
function success () {
score += 1;
$('#score').html(score);
}