-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
50 lines (38 loc) · 1.25 KB
/
Player.java
File metadata and controls
50 lines (38 loc) · 1.25 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
package mainPackage;
import java.awt.Color;
import java.awt.Graphics;
public class Player extends Creature{
public Player(Handler handler, float x, float y) {
super(handler, x, y, Creature.DEFAULT_CREATURE_WIDTH, Creature.DEFAULT_CREATURE_HEIGHT);
bounds.x = 16; // collision box 16 pixels left of x of player
bounds.y = 32; // " " 32 " down of x of player
bounds.width = 32;
bounds.height = 32;
}
@Override
public void tick() {
getInput();
move();
handler.getGameCamera().centerOnEntity(this);
}
private void getInput() {
xMove = 0;
yMove = 0;
if(handler.getKeyManager().up)
yMove = -speed;
if(handler.getKeyManager().down)
yMove = speed;
if(handler.getKeyManager().left)
xMove = -speed;
if(handler.getKeyManager().right)
xMove = speed;
}
@Override
public void render(Graphics g) {
g.drawImage(Assets.player, (int) (x - handler.getGameCamera().getxOffset()),
(int) (y - handler.getGameCamera().getyOffset()), width, height, null);
// g.setColor(Color.red);
// g.fillRect((int) (x + bounds.x - handler.getGameCamera().getxOffset()),
// (int) (y + bounds.y - handler.getGameCamera().getyOffset()), bounds.width, bounds.height);
}
}