-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
141 lines (125 loc) · 3.42 KB
/
script.js
File metadata and controls
141 lines (125 loc) · 3.42 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// const startGame = () => {
const moveLeft = () => {
let left = parseInt(
window.getComputedStyle(character).getPropertyValue("left")
);
left -= 100 * 2.4;
if (left >= 0) {
character.style.left = left + "px";
}
};
const moveRight = () => {
let left = parseInt(
window.getComputedStyle(character).getPropertyValue("left")
);
left += 100 * 2.4;
if (left < 600 * 2.4) {
character.style.left = left + "px";
}
};
document.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
moveLeft();
}
if (event.key === "ArrowRight") {
moveRight();
}
});
const moveLeftGeo = (number) => {
let left = parseInt(
window.getComputedStyle(character).getPropertyValue("left")
);
left -= number;
if (left >= 0 && left < 500 * 2.4) {
character.style.left = left + "px";
}
};
const moveRightGeo = (number) => {
let left = parseInt(
window.getComputedStyle(character).getPropertyValue("left")
);
left += number;
if (left >= 0) {
character.style.left = left + "px";
}
};
window.addEventListener("deviceorientation", function (e) {
const x = Math.round(e.beta);
const y = Math.round(e.gamma);
const z = Math.round(e.alpha);
moveRightGeo(y);
//Parallax Effect
// document.getElementsByClassName(
// "rocket"
// )[0].style.transform = `translateY(-${x}%)`;
});
// Painzzz
var painz = document.getElementById("painz");
let counter = 0;
let gainzz = 0;
document.getElementById("painz").style.animation = "slide2 3s infinite";
painz.addEventListener("animationiteration", () => {
var colors = [
'url("img/blocker-stone.png")',
'url("img/tre.png")',
'url("img/blocker-ice.png")',
];
var randomImage = Math.floor(Math.random() * 3) + 0;
document.getElementById("painz").style.backgroundImage = colors[randomImage];
var random = Math.floor(Math.random() * 6);
left = random * 100 * 2.4;
painz.style.left = left + "px";
});
setInterval(() => {
var characterLeft = parseInt(
window.getComputedStyle(character).getPropertyValue("left")
);
var characterTop = parseInt(
window.getComputedStyle(character).getPropertyValue("top")
);
var blockLeft = parseInt(
window.getComputedStyle(painz).getPropertyValue("left")
);
var blockTop = parseInt(
window.getComputedStyle(painz).getPropertyValue("top")
);
if (
characterLeft == blockLeft &&
blockTop < 470 * 2.4 &&
blockTop > 350 * 2.4
) {
// alert("game over, Score:" + counter + "gainz" + gainzz);
counter = 0;
gainzz = 0;
}
}, 1);
//Gainzzz
var gainz = document.getElementById("gainz");
document.getElementById("gainz").style.animation = "slide 1s infinite";
gainz.addEventListener("animationiteration", () => {
// var colors = ["#ff0000", "#00ff00", "#0000ff"];
// var random_color = colors[Math.floor(Math.random() * colors.length)];
// document.getElementById("block1").style.backgroundColor = random_color;
var random = Math.floor(Math.random() * 6);
left = random * 100 * 2.4;
gainz.style.left = left + "px";
});
setInterval(() => {
var characterLeft = parseInt(
window.getComputedStyle(character).getPropertyValue("left")
);
var blockLeft = parseInt(
window.getComputedStyle(gainz).getPropertyValue("left")
);
var blockTop = parseInt(
window.getComputedStyle(gainz).getPropertyValue("top")
);
if (
characterLeft === blockLeft &&
blockTop < 400 * 2.4 &&
blockTop > 350 * 2.4
) {
gainzz++;
}
}, 100);
// };