-
Notifications
You must be signed in to change notification settings - Fork 0
/
objectprops.js
64 lines (61 loc) · 1.7 KB
/
objectprops.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
class Player {
constructor() {
this.loc = createVector(200,400);
this.width=10;
this.crouchHeight=10;
this.standHeight=20;
this.state=1; //1 is standing, 0 is crouch;
this.onGround=0;
}
calcGravity() {
//if(speed.y<9)
speed.y=speed.y+gravity;
}
collisionDetection() {
this.onGround=0;
if(this.st=1) {
for (let i=0; i<world.length; i++) {
//rect(world[i][0], world[i][1], world[i][2], platformWidth);
if(this.loc.x>world[i][0] && this.loc.x<world[i][0]+world[i][2]) {
if(this.loc.y>world[i][1]-platformWidth && this.loc.y<world[i][1]+platformWidth) {
if(speed.y>0) {
this.loc.y-=this.loc.y-(world[i][1]-platformWidth);
speed.y=0;
this.onGround=1;
}
}
}
}
}
else {
for (let i=0; i<world.length; i++) {
//rect(world[i][0], world[i][1], world[i][2], platformWidth);
if(this.loc.x>world[i][0] && this.loc.x<world[i][0]+world[i][2]) {
if(this.loc.y>world[i][1]-platformWidth && this.loc.y<world[i][1]+platformWidth && speed.y<0) {
if(speed.y>0) {
this.loc.y-=this.loc.y-(world[i][1]-platformWidth);
speed.y=0;
this.onGround=1;
}
}
}
}
}
}
display(){
fill(200, 200, 200)
if(playerMotion==1) {
this.loc.x+=speed.x;
}
this.loc.y+=speed.y;
this.calcGravity();
this.collisionDetection();
if(this.state==1) {
ellipse(this.loc.x, this.loc.y, this.width, this.standHeight);
}
else {
ellipse(this.loc.x, this.loc.y+5, this.width, this.crouchHeight);
}
//console.log(this.st)
}
}