-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeline.js
165 lines (145 loc) · 4.36 KB
/
Timeline.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
var delta_x=0;
var delta_y=0;
document.addEventListener('keydown',(e)=>{
var ev = e || window.event;
switch(ev.keyCode){
case 65:
delta_x=-1;
$('adam').style.transform = 'scaleX(1)'
isRunL = true;
break;
case 87:
delta_y=-1;
isRunT = true;
break;
case 68:
delta_x=1;
$('adam').style.transform = 'scaleX(-1)'
isRunR = true;
break;
case 83:
delta_y=1;
isRunD = true;
break;
case 74:
console.log("74")
isAttack = true;
if ( $('adam').style.transform === 'scaleX(1)'){
isHit(0)
}else {
isHit(1)
}
break;
default:
break;
}
},false);
document.addEventListener('keyup',(e)=>{
var ev = e || window.event;
switch(ev.keyCode){
case 65:
delta_x=0;
isRunL = false;
break;
case 87:
delta_y=0;
isRunT = false;
break;
case 68:
delta_x=0;
isRunR = false;
break;
case 83:
delta_y=0;
isRunD = false;
break;
case 74:
isAttack = false;
break;
default:
break;
}
},false);
var timer = window.setInterval(()=>{
//碰撞实现
const mapEx = parseInt(mapE.style.left);
const mapEy = parseInt(mapE.style.top);
CollisionImplementation2Future(adam,adam._x + delta_x*10,adam._y + delta_y,arrE)
var isC = Impact_checking((adam._x+delta_x*10) - mapEx,(adam._y+delta_y) - mapEy,adam.h,adam.w,parseInt($('slm1').style.left),parseInt($('slm1').style.top),80,80)
if (isCollide || isC){
$('adam').style.backgroundColor = 'yellow'
delta_y = delta_x = 0
}
//碰撞背景元素移动
var unit = 10;
var p = document.getElementsByTagName('div')[4];
var left = window.getComputedStyle(p,null).left;
var top = window.getComputedStyle(p,null).top;
p.style.left=parseInt(left)-delta_x*unit+'px';
p.style.top=parseInt(top)-delta_y*unit+'px';
//底层背景移动
var bgPX = stage.style.backgroundPositionX
var bgPY = stage.style.backgroundPositionY
stage.style.backgroundPositionX=parseInt(bgPX)-delta_x*unit+'px'
stage.style.backgroundPositionY=parseInt(bgPY)-delta_y*unit+'px'
if (isAttack){
adam.attack()
isAttack = false
}else{
}
if (isRunL || isRunR || isRunD || isRunT){
adam.run()
adam.run()
adam.run()
}else{
adam.standby()
}
if (isAttack){
adam.attack()
}
},50);
const debugScope = document.createElement('div')
function isHit(direction = 0){
const slm1 = $('slm1')
const mapEx = parseInt(mapE.style.left);
const mapEy = parseInt(mapE.style.top);
var x1 = adam._x - 80 - mapEx
const y1 = adam._y - mapEy + 50
const h1 = adam.h - 100
const w1 = adam.w
const x2 = parseInt(slm1.style.left)
const y2 = parseInt(slm1.style.top)
const h2 = parseInt(slm1.style.height)
const w2 = parseInt(slm1.style.width)
if (direction === 1){
x1 = x1 + w1 + w2 + 2
}
if(Impact_checking(x1,y1,h1,w1,x2,y2,h2,w2)) {
$('slm1').style.backgroundColor = 'yellow'
VectorHit($('slm1'),-80,0,10,10,30)
slm._blood = slm._blood - adam.harm
$('boosBlood').style.width = parseInt($('boosBlood').style.width) - (adam.harm/slm.blood)*parseInt($('boosBlood').style.width) + 'px'
if (slm._blood <= 0) {
$('slm1').style.backgroundColor = 'red'
sleep(200).then(()=>{
$('slm1').style.display = 'none'
$('slm1').style.left = ''
$('slm1').style.top = ''
})
$('boosBloodBox').style.border = ''
return
}
sleep(500).then(()=>{
$('slm1').style.backgroundColor = ''
})
}
debugScope.id = 'debugScope'
debugScope.style.width = w1+'px'
debugScope.style.height = h1+'px'
debugScope.style.left = x1+'px'
debugScope.style.top = y1+'px'
debugScope.style.border = '2px solid red'
debugScope.style.zIndex = 99
debugScope.style.position = 'absolute'
mapE.appendChild(debugScope)
}