-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
124 lines (98 loc) · 3.08 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<<<<<<< HEAD
$(document).ready(function() {
// $(this).attr(
// 'src',
// '/Users/jasonjones/Desktop/Codesmith/cohort33/hackathon33/assets/explode.png'
// );
// );
// change img to explosion
// play explosion audio
// randomize position
let monsterA = $('.a');
animateDiv(monsterA);
// console.log('another div animated');
new Monster(monsterA);
animateDiv($('.a'));
let monsterB = $('.b');
$('.b').click(() => console.log('clicked B'));
animateDiv(monsterB);
let monsterC = $('.c');
$('.c').click(() => console.log('clicked C'));
animateDiv(monsterC);
let monsterD = $('.d');
$('.d').click(() => console.log('clicked D'));
animateDiv(monsterD);
// this works, but needs tweaking
// let monster = new Monster($('.a'));
});
function makeNewPosition() {
// Get viewport dimensions (remove the dimension of the div)
var h = $(window).height() - 50;
var w = $(window).width() - 50;
var nh = Math.floor(Math.random() * h);
var nw = Math.floor(Math.random() * w);
return [nh, nw];
}
function animateDiv(alphabet) {
var newq = makeNewPosition();
var oldq = alphabet.offset();
var speed = calcSpeed([oldq.top, oldq.left], newq);
// console.log(alphabet.position().top, alphabet.position().left);
alphabet.animate({ top: newq[0], left: newq[1] }, speed, function() {
animateDiv(alphabet);
});
$('.a').click(function clickBoom() {
this.node = $('<div class="a"></div>');
// console.log('clicked ', this.node);
// this.node.attr('display', 'none');
$('.a').detach();
// console.log('detached');
// a.style.left = x_pos + 'px';
// a.style.top = y_pos + 'px';
// new Monster('body');
$(this.node).appendTo('body');
console.log('appended to body', this.node);
this.node.css({
top: Math.floor(Math.random() * Math.floor(14)) * 50,
left: Math.floor(Math.random() * Math.floor(14)) * 50
});
animateDiv(alphabet);
});
}
function calcSpeed(prev, next) {
var x = Math.abs(prev[1] - next[1]);
var y = Math.abs(prev[0] - next[0]);
var greatest = x > y ? x : y;
var speedModifier = 0.1;
var speed = Math.ceil(greatest / speedModifier);
return speed;
}
=======
$(document).ready(function(){
animateDiv();
});
function makeNewPosition(){
// Get viewport dimensions (remove the dimension of the div)
var h = $(window).height() - 50;
var w = $(window).width() - 50;
var nh = Math.floor(Math.random() * h);
var nw = Math.floor(Math.random() * w);
return [nh,nw];
}
function animateDiv(){
var newq = makeNewPosition();
var oldq = $('.a').offset();
var speed = calcSpeed([oldq.top, oldq.left], newq);
$('.a').animate({ top: newq[0], left: newq[1] }, speed, function(){
animateDiv();
});
};
function calcSpeed(prev, next) {
var x = Math.abs(prev[1] - next[1]);
var y = Math.abs(prev[0] - next[0]);
var greatest = x > y ? x : y;
var speedModifier = 0.1;
var speed = Math.ceil(greatest/speedModifier);
return speed;
}
>>>>>>> bfefe2197b172995c5c0331604646e2b4359646c