-
Notifications
You must be signed in to change notification settings - Fork 0
/
Liebre.js
56 lines (48 loc) · 1023 Bytes
/
Liebre.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
//HARE SPEED
setInterval(liebreMove, speed)
//HARE MOVEMENT
function liebreDown() {
if (liebreY < 700) {
liebreY += characterSize;
liebre.style.top = liebreY + "px";
}
}
function liebreUp() {
if (liebreY > 0) {
liebreY -= characterSize;
liebre.style.top = liebreY + "px";
}
}
function liebreRight() {
if (liebreX < 700) {
liebreX += characterSize;
liebre.style.left = liebreX + "px";
}
}
function liebreLeft() {
if (liebreX > 0) {
liebreX -= characterSize;
liebre.style.left = liebreX + "px";
}
}
//NUMBER RANDOMIZER
function randomize(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
function liebreMove() {
randomNumber = randomize(1, 5)
switch (randomNumber) {
case 1:
liebreDown();
break;
case 2:
liebreUp();
break;
case 3:
liebreRight();
break;
case 4:
liebreLeft();
break;
}
}