-
Notifications
You must be signed in to change notification settings - Fork 0
/
StartPanel.java
170 lines (139 loc) · 5.82 KB
/
StartPanel.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package game;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
public class StartPanel extends JPanel implements ActionListener
{
public final static int BUTTON_X = 310;
public final static int BUTTON_WIDTH = 380;
public final static int BUTTON_HEIGHT = 100;
public final static int NEWGAME_Y = 200;
public final static int HOWTO_Y = 320;
public final static int OPTIONS_Y = 440;
private Timer timer;
private int[] xpos;
private final static Color BACKGROUND_COLOR = new Color(217, 217, 217);
private final static Color CYAN = new Color(27, 226, 217);
private final static Color DEEPSKYBLUE = new Color(0,191,255);
private final static Color DODGERBLUE = new Color(28,134,238);
private static Font TITLE_FONT;
private static Font BUTTON_FONT;
private static Font BUTTON_FONT_2;
private Image img1, img2, img3, img4, img5, img6, img7, pathImage;
private ImageIcon background;
public StartPanel()
{
timer = new Timer(25, this);
xpos = new int[7];
xpos[0] = -100;
xpos[1] = -350;
xpos[2] = -600;
xpos[3] = -850;
xpos[4] = -1100;
xpos[5] = -1350;
xpos[6] = -1600;
try
{
TITLE_FONT = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("res/fonts/calm.ttf")).deriveFont(100f);
BUTTON_FONT = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("res/fonts/calm.ttf")).deriveFont(54f);
BUTTON_FONT_2 = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("res/fonts/calm.ttf")).deriveFont(42f);
img1 = ImageIO.read(getClass().getResourceAsStream("res/images/enemies/jetpack_right.png"));
img2 = ImageIO.read(getClass().getResourceAsStream("res/images/enemies/ancient_right.png"));
img3 = ImageIO.read(getClass().getResourceAsStream("res/images/enemies/osprey_right.png"));
img4 = ImageIO.read(getClass().getResourceAsStream("res/images/enemies/runner_right.png"));
img5 = ImageIO.read(getClass().getResourceAsStream("res/images/enemies/kela_right.png"));
img6 = ImageIO.read(getClass().getResourceAsStream("res/images/enemies/sargas_right.png"));
img7 = ImageIO.read(getClass().getResourceAsStream("res/images/enemies/vor_right.png"));
pathImage = ImageIO.read(getClass().getResourceAsStream("res/images/tiles/path/path_white_1.png"));
background = new ImageIcon(getClass().getResource("res/images/scoreboard/background.gif"));
}
catch(IOException | FontFormatException ex)
{
System.out.println(ex);
}
setBackground(BACKGROUND_COLOR);
setVisible(true);
timer.start();
}
public void stopTimer()
{
timer.stop();
}
public void startTimer()
{
timer.start();
}
public void reset()
{
xpos[0] = -100;
xpos[1] = -350;
xpos[2] = -600;
xpos[3] = -850;
xpos[4] = -1100;
xpos[5] = -1350;
xpos[6] = -1600;
}
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
background.paintIcon(this, g, 0, 0);
g2d.setFont(TITLE_FONT);
g2d.setColor(Color.DARK_GRAY);
g2d.drawString("PROMETHEUS", 135, 140);
g.setColor(Color.DARK_GRAY);
g.fillRect(BUTTON_X, NEWGAME_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
g.setColor(CYAN);
g.fillRect(BUTTON_X + 10, NEWGAME_Y + 10, BUTTON_WIDTH - 20, BUTTON_HEIGHT - 20);
g2d.setFont(BUTTON_FONT_2);
g2d.setColor(Color.DARK_GRAY);
g2d.drawString("NEW GAME", BUTTON_X + 58, NEWGAME_Y + 66);
g.setColor(Color.DARK_GRAY);
g.fillRect(BUTTON_X, HOWTO_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
g.setColor(DEEPSKYBLUE);
g.fillRect(BUTTON_X + 10, HOWTO_Y + 10, BUTTON_WIDTH - 20, BUTTON_HEIGHT - 20);
g2d.setFont(BUTTON_FONT_2);
g2d.setColor(Color.DARK_GRAY);
g2d.drawString("HOW TO PLAY", BUTTON_X + 23, HOWTO_Y + 66);
g.setColor(Color.DARK_GRAY);
g.fillRect(BUTTON_X, OPTIONS_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
g.setColor(DODGERBLUE);
g.fillRect(BUTTON_X + 10, OPTIONS_Y + 10, BUTTON_WIDTH - 20, BUTTON_HEIGHT - 20);
g2d.setFont(BUTTON_FONT_2);
g2d.setColor(Color.DARK_GRAY);
g2d.drawString("OPTIONS", BUTTON_X + 83, OPTIONS_Y + 66);
for(int i = 0; i < 15; i++)
{
g.drawImage(pathImage, i * 70 - 23, 600, null);
}
g.drawImage(img1, xpos[0], 590, null);
g.drawImage(img2, xpos[1], 580, null);
g.drawImage(img3, xpos[2], 615, null);
g.drawImage(img4, xpos[3], 587, null);
g.drawImage(img5, xpos[4], 570, null);
g.drawImage(img6, xpos[5], 570, null);
g.drawImage(img7, xpos[6], 560, null);
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == timer)
{
for(int i = 0; i < xpos.length; i++)
{
if(xpos[i] > 1050)
xpos[i] = -700;
else
xpos[i] += 2;
}
repaint();
}
}
}