-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayerScript.pde
54 lines (45 loc) · 1.31 KB
/
PlayerScript.pde
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
class PlayerScript extends Component {
Physics physics;
Collider collider;
float jumpSpeed = -5;
boolean iJumped = false;
int LEFT = -1; int RIGHT = 1;
float walkSpeed = 3;
PlayerScript(GameObject prnt) {
super(prnt, "PlayerScript");
physics = (Physics) parent.getComponent("Physics");
collider = (Collider) parent.getComponent("Collider");
}
void update() {
this.checkGrounds();
}//end update
void checkGrounds(){
for (int i = 0; i < ground.size(); i++) {
Platform p = (Platform) ground.get(i);
//println(p);
Collider other = (Collider) p.platform.getComponent("Collider");
//println("collider is " + this.collider);
if (collider.checkBottomOverlap(other) ) {
physics.haltDown();
this.iJumped = false;
float dist = this.collider.bottomOverlap(other);
println("dist = " + dist);
physics.moveObject("y", dist * -1);
} else {
physics.applyForce (new PVector(0, gravity) );
}
}
}
public void jump() {
if (!iJumped) {
println("Am I jumping?");
physics.applyVelocity(new PVector(0, jumpSpeed));
iJumped = true;
}
}
public void walk(int direction){
//if (direction == LEFT){
physics.moveObject("x", walkSpeed * (float) direction);
//}
}
}