-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.pde
39 lines (33 loc) · 741 Bytes
/
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
public class Player
{
private float x, y, size;
private float vX, vY;
public Player(float X, float Y, float s)
{
x = X;
y = Y;
size = s;
}
void Update()
{
x+=vX;
y+=vY;
ellipse(x, y, 2 * size, 2 * size);
keepInBoundaries();
}
void keepInBoundaries()
{
if (x - size < 0) x = size;
if (x + size > width) x = width - size;
if (y - size < 0) y = size;
if (y + size > height) y = height - size;
}
void getInput(boolean[] m, float speed)
{
vY = -speed * (m[0] ? 1 : 0) + speed * (m[1] ? 1 : 0);
vX = -speed * (m[2] ? 1 : 0) + speed * (m[3] ? 1 : 0);
}
float getX() { return x; }
float getY() { return y; }
float getSize() { return size; }
}