-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlayer.java
More file actions
45 lines (34 loc) · 1.02 KB
/
Player.java
File metadata and controls
45 lines (34 loc) · 1.02 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
package dungeon;
import processing.core.PGraphics;
import processing.core.PVector;
public class Player {
private static Player playerInstance = null;
private static String name;
private static PGraphics gfx;
private static PVector direction;
private Player(String name, PGraphics gfx) {
Player.name = name;
Player.gfx = gfx;
direction = new PVector(0, 0);
}
public static void getPlayerInstance(String playerName, PGraphics gfx) {
if (isNull()) {
playerInstance = new Player(playerName, gfx); // C'è una warning un po' bislacca
}
}
public static void setPos(int x, int y) {
direction.x = x;
direction.y = y;
}
public static void draw() {
gfx.fill(255,0,0);
gfx.rect(direction.x*16,direction.y*16,16,16);
}
public static void move(int dx, int dy) {
direction.x += dx;
direction.y += dy;
}
private static boolean isNull() {
return playerInstance == null;
}
}