-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolliderOldSchool.js
124 lines (99 loc) · 3.35 KB
/
colliderOldSchool.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
var collideAll = function(block, plat){
//what is happening when the enemies just slip though????
//falling down
if ( ( block.x + block.velocity.x + block.width/2) > ( plat.x - plat.width/2)
&&
(
(block.x + block.velocity.x - block.width/2) < (plat.x + plat.width/2 ) ||
(block.x - block.width/2) < (plat.x + plat.width/2 )
)
//there is a platform under the block
&&
//it is on the correct side
( block.y - block.height/2) > (plat.y + plat.height/2)
&&
//it is close enough to hit this turn
( block.y -block.height/2 + block.velocity.y) < (plat.y + plat.height/2) )
{
block.grounded = true;
//place block back above, just in case!
block.y = plat.y + plat.height/2 + block.height/2 ;
//block.velocity[1] *= -0.25;
//frictionize(block, 70);
if (gravity){
block.velocity.y *= -0.25;
} else {
block.velocity.y *= -0.75;
}
} ; //else {frictionize(block, 99.95)};
//going upwards
if ( ( block.x + block.velocity.x + block.width/2) > ( plat.x - plat.width/2)
&&
(block.x + block.velocity.x - block.width/2) < (plat.x + plat.width/2 )
//there is a platform under the block
&&
//it is on the correct side
( block.y + block.height/2) < (plat.y - plat.height/2)
&&
//it is close enough to hit this turn
( block.y + block.height/2 + block.velocity.y) > (plat.y - plat.height/2) )
{
//block.grounded = true;
//place block back below, just in case!
block.y = plat.y - plat.height/2 -1 -block.height/2 ;
//block.velocity[1] *= -0.25;
//frictionize(block, 70);
if (gravity){
block.velocity.y *= -0.25;
} else {
block.velocity.y *= -0.75;
}
} ; //else {frictionize(block, 99.95)};
//going right!
if ( ( block.y + block.velocity.y + block.height/2) > ( plat.y - plat.height/2)
&&
(block.y + block.velocity.y - block.height/2) < (plat.y + plat.height/2 )
//there is a platform next to the block
&&
//it is on the correct side
( block.x + block.width/2) < (plat.x - plat.width/2)
&&
//it is close enough to hit this turn
( block.x + block.width/2 + block.velocity.x) > (plat.x - plat.width/2) )
{
//block.grounded = true;
//place block back below, just in case!
block.x = plat.x - plat.width/2 - 1 - block.width/2 ;
//block.velocity[1] *= -0.25;
//frictionize(block, 70);
block.velocity.x *= -0.75;
} ;
//going left!!!
if ( ( block.y + block.velocity.y + block.height/2) > ( plat.y - plat.height/2)
&&
(block.y + block.velocity.y - block.height/2) < (plat.y + plat.height/2 )
//there is a platform under the block
&&
//it is on the correct side
( block.x - block.width/2) > (plat.x + plat.width/2)
&&
//it is close enough to hit this turn
( block.x -block.width/2 + block.velocity.x) < (plat.x + plat.width/2) )
{
//block.grounded = true;
//place block back above, just in case!
block.x = plat.x + plat.width/2 + 1 + block.width/2 ;
//block.velocity[1] *= -0.25;
//frictionize(block, 70);
// if (gravity){
// block.velocity[1] *= -0.25;
// } else {
block.velocity.x *= -0.75;
}
}
var collideAllEvery = function(block){
for (var q = 0; q < platforms.length; q++){
var thisPlat = platforms[q];
collideAll(block, thisPlat);
}
}