-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
124 lines (83 loc) · 2.27 KB
/
Player.java
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import java.awt.Graphics;
import java.awt.Rectangle;
public abstract class Player extends Character {
private int mana; //do this later full = 100
private boolean ready;
private PlayerHud hud;
private double velocityY = 5;
private boolean jumping;
Player() {
this.spriteColumnNum = 6;
this.spriteRowNum = 2;
this.spriteLength = 240;
this.spriteWidth = 240;
}
abstract void loadSprites();
public void drawHud(Graphics g, int multiplier){
hud.drawHud(g, multiplier);
}
public void draw(Graphics g) { //pass something from loop
int currentSprite = 0;
if (!isFacingForward()){
currentSprite = currentSprite + 3;
}
if (isAttacking()){
currentSprite = currentSprite + 6;
if(getAttackAnimationCounter()>2){
setAttackAnimationCounter(0);
}
currentSprite = currentSprite + getAttackAnimationCounter();
g.drawImage(sprites[currentSprite],getxPosition(),getyPosition(),null);
long deltaTime = 0L;
while(deltaTime <= 55000000){
long start = System.nanoTime();
long end = System.nanoTime();
deltaTime += (end - start);
}
setAttackAnimationCounter(getAttackAnimationCounter()+1);
}else if(isMoving()){
if (getTimesMoved()<500){//switch between walking
currentSprite = currentSprite + 1;
}else{
currentSprite = currentSprite + 2;
if(getTimesMoved()>1000){
setTimesMoved(-1);
}
}
setTimesMoved(getTimesMoved() + 1);
g.drawImage(sprites[currentSprite],getxPosition(),getyPosition(),null);
}else if(!isMoving()){
g.drawImage(sprites[currentSprite],getxPosition(),getyPosition(),null);
}
}
public int getMana() {
return mana;
}
public void setMana(int mana) {
this.mana = mana;
}
public boolean isReady() {
return ready;
}
public void setReady(boolean ready) {
this.ready = ready;
}
public void setxPosition(int x) {
this.xPosition = x-120;
}
public void setyPosition(int y) {
this.yPosition = y-180;
}
public boolean isJumping() {
return jumping;
}
public void setJumping(boolean jumping) {
this.jumping = jumping;
}
public PlayerHud getHud() {
return hud;
}
public void setHud(PlayerHud hud) {
this.hud = hud;
}
}