-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecialCard.java
More file actions
126 lines (110 loc) · 4.84 KB
/
SpecialCard.java
File metadata and controls
126 lines (110 loc) · 4.84 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
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
125
126
package net.ddns.x444556;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.font.FontRenderContext;
import java.util.Timer;
import java.util.TimerTask;
public class SpecialCard extends Card{
private static final long serialVersionUID = 777930635735238405L;
private int minAlpha = 100, maxAlpha = 200, alphaStep = 4, alpha = 100;
public SpecialCard(String name, int health, int damage) {
super(null, null, name, health, damage);
this.hidebg = true;
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if(alpha <= minAlpha) {
alpha = minAlpha;
alphaStep *= -1;
}
else if(alpha >= maxAlpha) {
alpha = maxAlpha;
alphaStep *= -1;
}
repaint();
alpha += alphaStep;
}
}, 0, 50);
}
public SpecialCard(Color bgColorStart, Color bgColorEnd, String name, int health, int damage) {
super(bgColorStart, bgColorEnd, name, health, damage);
this.hidebg = true;
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if(alpha <= minAlpha) {
alpha = minAlpha;
alphaStep *= -1;
}
else if(alpha >= maxAlpha) {
alpha = maxAlpha;
alphaStep *= -1;
}
repaint();
alpha += alphaStep;
}
}, 0, 50);
}
@Override
public void paintComponent(Graphics g) {
for(int y=0; y<getHeight(); y++) {
for(int x=0; x<getWidth(); x++) {
g.setColor(new Color((int)(255.0 * distNorm(0, 0, x, y)), (int)(255.0 * distNorm(getWidth(), 0, x, y)),
(int)(255.0 * distNorm(0, getHeight(), x, y)), alpha));
g.drawLine(x, y, x, y);
}
}
// Name
g.setFont(new Font("SansSerif", Font.BOLD, (int)(20.0/refX*getWidth())));
g.setColor(new Color(230, 230, 230));
g.drawString(Name, (int)(6.0/refX*getWidth()), (int)(28.0/refX*getWidth()));
// Image
g.setColor(Color.black);
g.fillRect((int)(6.0/refX*getWidth()), (int)(35.0/refX*getWidth()), getWidth() - (int)(12.0/refX*getWidth()), getWidth() -
(int)(12.0/refX*getWidth()));
// Attack
g.setColor(Color.black);
g.fillRect((int)(6.0/refX*getWidth()), (int)(42.0/refX*getWidth()) + getWidth() - (int)(12.0/refX*getWidth()),
(getWidth() - (int)(12.0/refX*getWidth())) / 3, (getWidth() - (int)(12.0/refX*getWidth())) / 3);
g.setFont(new Font("SansSerif", Font.BOLD, (int)(16.0/refX*getWidth())));
g.setColor(new Color(230, 230, 230));
g.drawString(Integer.toString(Damage), (int)(6.0/refX*getWidth()) + (getWidth() - (int)(12.0/refX*getWidth())) / 6 -
(int) (g.getFont().getStringBounds(Integer.toString(Damage),
new FontRenderContext(null, true, true)).getWidth() / 2), (int)(40.0/refX*getWidth()) + getWidth() -
(int)(12.0/refX*getWidth()) + (getWidth() - (int)(12.0/refX*getWidth())) / 3);
// Defense
g.setColor(Color.black);
g.fillRect((int)(13.0/refX*getWidth()) + (getWidth() - (int)(12.0/refX*getWidth())) / 3, (int)(42.0/refX*getWidth()) + getWidth() -
(int)(12.0/refX*getWidth()) , (getWidth() - (int)(12.0/refX*getWidth())) / 3, (getWidth() - (int)(12.0/refX*getWidth())) / 3);
g.setFont(new Font("SansSerif", Font.BOLD, (int)(16.0/refX*getWidth())));
g.setColor(new Color(230, 230, 230));
g.drawString(Integer.toString(Health), (int)(13.0/refX*getWidth()) + (getWidth() - (int)(12.0/refX*getWidth())) / 3 +
(getWidth() - (int)(12.0/refX*getWidth())) / 6 -
(int) (g.getFont().getStringBounds(Integer.toString(Health),
new FontRenderContext(null, true, true)).getWidth() / 2), (int)(40.0/refX*getWidth()) + getWidth() -
(int)(12.0/refX*getWidth()) + (getWidth() - (int)(12.0/refX*getWidth())) / 3);
// Abilities
for(int i=0; i<6; i++) {
g.setColor(Color.black);
g.fillRect((int)(20.0/refX*getWidth()) + (getWidth() - (int)(12.0/refX*getWidth())) / 3 * 2 + (((getWidth() -
(int)(12.0/refX*getWidth())) / 9 + (int)(3.0/refX*getWidth())) * (i / 3)),
(int)(42.0/refX*getWidth()) + getWidth() - (int)(12.0/refX*getWidth()) + (((getWidth() - (int)(12.0/refX*getWidth())) /
9 + (int)(2.0/refX*getWidth())) * (i % 3)),
(getWidth() - (int)(12.0/refX*getWidth())) / 9, (getWidth() - (int)(12.0/refX*getWidth())) / 9);
}
if(Duell != null && ((!Duell.myTurn && DuellPane.index(this, Duell.playerHandCards) != -1) ||
((DuellPane.index(this, Duell.playerCards) != -1 || DuellPane.index(this, Duell.enemyCards) != -1) && roundsSurvived == 0))) {
g.setColor(new Color(0, 0, 0, 90));
for(int y=0; y<getHeight(); y++) {
g.drawLine(0, y, getWidth(), y);
}
}
}
private double distance(int x0, int y0, int x1, int y1) {
return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2));
}
private double distNorm(int x0, int y0, int x1, int y1) {
return distance(x0, y0, x1, y1) / distance(0, 0, getWidth(), getHeight());
}
}