-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
54 lines (44 loc) · 1.13 KB
/
Copy pathPlayer.java
File metadata and controls
54 lines (44 loc) · 1.13 KB
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
import java.util.ArrayList;
public class Player extends GameObject {
//attributes: instance variables
private Physics physics;
private boolean isJumping;
private Pose currentPose;
public Player (double x, double y) {
super( x*Block.SIZE, y*Block.SIZE, Block.SIZE, Block.SIZE, "Assets/link-down.png");
this.physics = new Physics(4);
this.isJumping = false;
this.currentPose = Pose.RIGHT; //animation poses
super.setImage(currentPose.getImage() );
}
public void move() {
double dx = this.getX() + physics.getVelocityX();
double dy = this.getY() + physics.getVelocityY();
super.move(dx, dy);
}
public void update(ArrayList<Block> blocks) {
physics.update(blocks, this);
this.move();
}
public void jump() {
if (this.isJumping == false) {
physics.jump();
this.isJumping = true;
}
}
public void moveLeft() {
physics.moveLeft();
this.currentPose = Pose.LEFT;
}
public void moveRight() {
physics.moveRight();
this.currentPose = Pose.RIGHT;
}
public void isJumping(boolean isJumping) {
this.isJumping = isJumping;
}
public void draw() {
super.setImage(currentPose.getImage() );
super.draw();
}
}