-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
150 lines (127 loc) · 4.35 KB
/
index.html
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
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>game</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/MotionPathPlugin.min.js"></script>
</head>
<body>
<div id="person" class="person">
<div class="person__head"></div>
<div class="person__body"></div>
<div class="person__weapon"></div>
<div id="legFirst" class="person__leg-first"></div>
<div id="legSecond" class="person__leg-second"></div>
</div>
<script>
function getCurrentRotation( elid ) {
var st = window.getComputedStyle(elid, null);
var tr = st.getPropertyValue("-webkit-transform") ||
st.getPropertyValue("-moz-transform") ||
st.getPropertyValue("-ms-transform") ||
st.getPropertyValue("-o-transform") ||
st.getPropertyValue("transform") ||
"fail...";
if( tr !== "none") {
var values = tr.split('(')[1];
values = values.split(')')[0];
values = values.split(',');
var a = values[0];
var b = values[1];
var c = values[2];
var d = values[3];
var scale = Math.sqrt(a*a + b*b);
// arc sin, convert from radians to degrees, round
/** /
var sin = b/scale;
var angle = Math.round(Math.asin(sin) * (180/Math.PI));
/*/
var radians = Math.atan2(b, a);
if ( radians < 0 ) {
radians += (2 * Math.PI);
}
var angle = Math.round( radians * (180/Math.PI));
/**/
} else {
var angle = 0;
}
// works!
// console.log('Rotate: ' + angle + 'deg');
return angle;
}
let legSecond = document.getElementById('legSecond');
var deg = 0;
function Counter() {
let count = 0;
this.value =function() {
return count;
}
this.toZero = function(){
return count = 0;
}
this.up = function() {
return ++count;
};
this.down = function() {
return --count;
};
}
function Status() {
let status = "front"; // Это изнчальный статус то что должно быть вначале. КАк и с счетчиком
this.curStatus = function() {
return status
}
this.front = function() {
return status = "front"
};
this.back = function() {
return status = "back";
};
}
let counter = new Counter();
let status = new Status();
let elementLeftValue = 25;
let elementBotValue = 0;
legSecond.onclick = function() {
let adaptRotation = getCurrentRotation(legSecond);
if(counter.value() == 6){
counter.toZero();
if (status.curStatus() == "front"){
status.back();
}else{
status.front();
}
}
console.log(adaptRotation, counter.value(),counter.up(),status.curStatus());
if(status.curStatus() == "front"){
deg -= 15;
elementLeftValue += 3;
elementBotValue += 5;
}else if (status.curStatus() == "back") {
deg += 15;
elementLeftValue -= 3;
elementBotValue -= 5;
}
if(adaptRotation == 300){
counter.toZero();
status.back();
}
if(adaptRotation == 5){
counter.toZero();
status.front();
}
legSecond.style.left = elementLeftValue +"px";
legSecond.style.bottom = elementBotValue +"px";
legSecond.style.webkitTransform = 'rotate('+deg+'deg)';
legSecond.style.mozTransform = 'rotate('+deg+'deg)';
legSecond.style.msTransform = 'rotate('+deg+'deg)';
legSecond.style.oTransform = 'rotate('+deg+'deg)';
legSecond.style.transform = 'rotate('+deg+'deg)';
}
</script>
</body>
</html>