-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSword.pde
76 lines (63 loc) · 1.52 KB
/
Sword.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
import java.util.Set;
import java.util.HashSet;
class Sword extends PlayerAttack {
static final int WIDTH = 51;
static final int HEIGHT = 10;
static final int DAMAGE = 20;
static final int TTL = (int) (1.0/3 * FPS);
final color COLOR = color(180, 0, 20);
Player player;
int timer;
Set<Entity> damagedTargets;
Sword(Player player) {
super();
this.player = player;
this.timer = TTL;
this.damagedTargets = new HashSet();
this.width = 0;
this.height = HEIGHT;
this.fillColor = COLOR;
}
int zIndex() {
return 5;
}
int getDamage(Entity entity) {
if (damagedTargets.contains(entity)) {
return 0;
}
damagedTargets.add(entity);
return DAMAGE;
}
void update() {
super.setVelocity();
this.timer--;
if (timer <= 0) {
player.swordDrawn = false;
delete();
}
else if (timer <= TTL / 3) {
width -= round((WIDTH / (TTL / 3)));
}
else if (timer > TTL * 2 / 3) {
width += round((WIDTH / (TTL / 3)));
}
this.x = player.x;
if (player.facingRight) {
this.x += player.width;
}
else {
this.x -= this.width;
}
this.y = player.y + Player.BLADE_HEIGHT;
}
void renderGraphics() {
String frame = "sword0.png";
if (width > WIDTH * 0.8) {
frame = "sword1.png";
}
else if (timer < TTL * 2 / 3) {
frame = "sword2.png";
}
Graphics.drawImage(frame, x + 3 + (player.facingRight ? 0 : width - WIDTH), y, !player.facingRight);
}
}