-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.java
More file actions
108 lines (104 loc) · 2.92 KB
/
Copy pathTimer.java
File metadata and controls
108 lines (104 loc) · 2.92 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
import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;
import java.awt.GraphicsEnvironment;
import java.awt.FontFormatException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
public class Timer extends Thing {
GamePanel gp;
int interval;
int timer;
int labelText;
int fontType;
boolean isOn;
boolean isUpdating;
boolean timersOn;
File fFile;
Font font;
public Timer( GamePanel g, boolean on, int fType, int xPos, int yPos, int time ) {
isOn = on;
this.gp = g;
this.fontType = fType;
if(fType == 0) {
this.x = gp.tileSize * xPos;
this.y = gp.tileSize * yPos;
}
else {
this.x = gp.tileSize * xPos + 18;
this.y = gp.tileSize * yPos - 11;
}
interval = 60;
timer = 0;
labelText = time;
try {
font = Font.createFont(Font.TRUETYPE_FONT,new File("munro.ttf")).deriveFont(40f);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT,new File("munro.ttf")));
}
catch ( FontFormatException e ) {
e.printStackTrace();
}
catch ( IOException e ) {
e.printStackTrace();
}
}
public void updateT1() {
if(isOn) {
timer++;
if( timer >= interval ) {
if ( labelText > 0 ) {
labelText--;
isUpdating = true;
}
else {
isOn = false;
isUpdating = false;
}
timer = 0;
}
}
}
public void drawT1(Graphics g) {
if(fontType == 1 && isUpdating && labelText > 0 ) {
g.setFont(font);
float re = 0.1f;
float gr = 0.9f;
float bl = 0.1f;
g.setColor(new Color(re,gr,bl));
g.drawString(String.valueOf(labelText), this.x, this.y);
}
else {
isUpdating = false;
isOn = false;
}
}
public void drawT0(Graphics g){
if (fontType == 0 && isUpdating && labelText > 0) {
g.setFont(font);
g.setColor(Color.BLACK);
g.drawString(String.valueOf(labelText), this.x, this.y);
}
else {
isUpdating = false;
isOn = false;
}
}
public void reset() {
if(fontType == 0) {
labelText = 0;
isOn = false;
isUpdating = false;
}
else if(fontType == 1) {
labelText = 10;
isOn = false;
isUpdating = false;
}
}
public void drawOff(Graphics g) {
g.setColor(gp.bgC);
g.fillRect(this.x - 20, this.y - 20, gp.tileSize, gp.tileSize);
}
}