-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlayer.pde
105 lines (95 loc) · 2.74 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
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
class Player
{
float x, y;
PImage [][] movement;
boolean inMotion; //Lets you know if character is moving or not
int currentDirection;
float currentFrame;
final int UP = 0, LEFT = 1, DOWN = 2, RIGHT =3;
Player()
{
inMotion = false;
currentDirection=3;
currentFrame=3;
x = 100;
y = 625;
setupSprites();
}
void setupSprites()
{
movement= new PImage[12][9]; //Create 2D array for Images
characterChecks();
spriteSheet = loadImage(presetVar); //Load entire spritesheet
for (int i = 0; i < 9; i++)
{
movement[0][i] = spriteSheet.get(21 + 64 * i, 514, 32, 65); //Upward moving sprite
movement[1][i] = spriteSheet.get(16 + 64 * i, 578, 40, 65); //Left moving sprite
movement[2][i] = spriteSheet.get(16 + 64 * i, 642, 32, 65); //Downward moving sprite
movement[3][i] = spriteSheet.get(10 + 64 * i, 706, 40, 65); //Right moving sprite
}
}
void levelChange() {
chestOpen = false;
chestAppearLuck = (int) random(1, 3);
fill(255, 90);
text("Level Up!", 70, 70);
level++;
currentDirection = 3;
x = 100;
y = 625;
monstersDead=true;
}
void drawPlayer() {
weaponX = x;
weaponY = y+40;
if (inMotion) {
image(movement[currentDirection][1 + int(currentFrame)], x, y); //Cycles through the frames with the help of line 46
if (currentDirection ==3) {
image(weaponImage[currentWeapon], weaponX+10, weaponY);
} else {
pushMatrix();
scale(-1, 1);
image(weaponImage[currentWeapon], -weaponX-20, weaponY);
popMatrix();
}
} else {
image(movement[currentDirection][0], x, y);
if (currentDirection ==3) {
image(weaponImage[currentWeapon], weaponX+10, weaponY);
} else {
pushMatrix();
scale(-1, 1);
image(weaponImage[currentWeapon], -weaponX-20, weaponY);
popMatrix();
}
}
}
void updatePlayer(int xDelta, int yDelta)
{
currentFrame = (currentFrame + 0.6 /*Changing the 0.2 changes animation speed*/) % 8; //helps change through the frames
inMotion = true;
if (xDelta ==0 && yDelta ==0)
inMotion =false;
else if (xDelta <= -1)
currentDirection = LEFT;
else if (xDelta >= 1)
currentDirection = RIGHT;
else if (yDelta == -1)
currentDirection = UP;
else if (yDelta == 1)
currentDirection = DOWN;
x = x + xDelta;
y = y + yDelta;
if (isPlayerOffScreen(x, y))
{
x = x - xDelta;
y = y - yDelta;
}
}
boolean isPlayerOffScreen(float x, float y)
{
if (x < 0 || x > width-30 || y<0 || y > height - 56)
return true;
return false;
}
}