forked from hajarhesham/SuperCube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.pde
71 lines (59 loc) · 2.04 KB
/
Player.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
public class Player extends AnimatedSprite{
int lives;
boolean onPlatform, inPlace;
PImage[] standLeft;
PImage[] standRight;
PImage[] jumpLeft;
PImage[] jumpRight;
public Player(PImage img, float scale) {
super(img, scale);
lives = 3;
direction = RIGHT_FACING;
onPlatform = true;
inPlace = true;
standLeft = new PImage[1];
standLeft[0] = loadImage("player_stand_left.png");
standRight = new PImage[1];
standRight[0] = loadImage("player_stand_right.png");
jumpLeft = new PImage[1];
jumpLeft[0] = loadImage("player_jump_left1.png");
jumpRight = new PImage[1];
jumpRight[0] = loadImage("player_jump_right1.png");
moveLeft = new PImage[2];
moveLeft[0] = loadImage("player_walk_left1.png");
moveLeft[1] = loadImage("player_walk_left2.png");
moveRight = new PImage[2];
moveRight[0] = loadImage("player_walk_right1.png");
moveRight[1] = loadImage("player_walk_right2.png");
currentImages = standRight;
}
@Override
public void updateAnimation() {
onPlatform = isOnPlatform(this, platforms);
inPlace = change_x == 0 && change_y == 0;
super.updateAnimation();
}
@Override
public void selectDirection() {
if (change_x > 0)
direction = RIGHT_FACING;
else if (change_x < 0)
direction = LEFT_FACING;
}
@Override
public void selectCurrentImages() {
if (direction == RIGHT_FACING) {
if (inPlace) {
currentImages = standRight;
} else if (!onPlatform) currentImages = jumpRight;
else
currentImages = moveRight;
} else if (direction == LEFT_FACING) {
if (inPlace) {
currentImages = standLeft;
} else if (!onPlatform) currentImages = jumpLeft;
else
currentImages = moveLeft;
}
}
}