1 | import java.awt.GraphicsEnvironment;
|
---|
2 | import java.awt.event.KeyEvent;
|
---|
3 | import java.awt.event.MouseEvent;
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.io.IOException;
|
---|
6 | import javax.imageio.ImageIO;
|
---|
7 | import gamegui.Button;
|
---|
8 | import gamegui.Member;
|
---|
9 | import gamegui.Label;
|
---|
10 | import java.awt.Point;
|
---|
11 | import java.awt.Toolkit;
|
---|
12 | import java.awt.Graphics;
|
---|
13 | import java.awt.image.BufferStrategy;
|
---|
14 | import java.awt.GraphicsConfiguration;
|
---|
15 | import java.awt.GraphicsDevice;
|
---|
16 | import gamegui.Textbox;
|
---|
17 | import java.awt.image.BufferedImage;
|
---|
18 | import gamegui.Window;
|
---|
19 | import java.awt.Cursor;
|
---|
20 | import java.awt.Image;
|
---|
21 | import java.awt.Font;
|
---|
22 | import java.awt.Frame;
|
---|
23 | import java.awt.DisplayMode;
|
---|
24 | import java.awt.event.MouseListener;
|
---|
25 | import java.awt.event.KeyListener;
|
---|
26 |
|
---|
27 | public class GalacticHeroes implements KeyListener, MouseListener {
|
---|
28 | private static DisplayMode[] BEST_DISPLAY_MODES;
|
---|
29 | Frame mainFrame;
|
---|
30 | boolean done;
|
---|
31 | GameState gameState;
|
---|
32 | boolean firing;
|
---|
33 | Font font12;
|
---|
34 | Font font14;
|
---|
35 | Font font20;
|
---|
36 | Font font24;
|
---|
37 | Image cursorImage;
|
---|
38 | Cursor defaultCursor;
|
---|
39 | Cursor blankCursor;
|
---|
40 | Window wndMain;
|
---|
41 | Window wndGame;
|
---|
42 | Window wndLoad;
|
---|
43 | Window wndInstruct;
|
---|
44 | Window wndFame;
|
---|
45 | Window wndCredits;
|
---|
46 | Window wndWin;
|
---|
47 | Window wndLose;
|
---|
48 | BufferedImage fighter;
|
---|
49 | BufferedImage bomber;
|
---|
50 | BufferedImage xfighter;
|
---|
51 | BufferedImage boss;
|
---|
52 | BufferedImage player;
|
---|
53 | BufferedImage fighterbullet;
|
---|
54 | BufferedImage bomberbullet;
|
---|
55 | BufferedImage bossbullet;
|
---|
56 | BufferedImage bossminishot;
|
---|
57 | BufferedImage playerbullet;
|
---|
58 | HumanShip playerShip;
|
---|
59 | Level[] levels;
|
---|
60 | Level currentLevel;
|
---|
61 | int levelNum;
|
---|
62 | long timeLastFired;
|
---|
63 | int points;
|
---|
64 | Textbox selectedText;
|
---|
65 |
|
---|
66 | static {
|
---|
67 | GalacticHeroes.BEST_DISPLAY_MODES = new DisplayMode[] { new DisplayMode(800, 600, 32, 0), new DisplayMode(800, 600, 16, 0), new DisplayMode(800, 600, 8, 0) };
|
---|
68 | }
|
---|
69 |
|
---|
70 | public GalacticHeroes(final GraphicsDevice device) {
|
---|
71 | Label_0173: {
|
---|
72 | try {
|
---|
73 | final GraphicsConfiguration gc = device.getDefaultConfiguration();
|
---|
74 | (this.mainFrame = new Frame(gc)).setUndecorated(true);
|
---|
75 | this.mainFrame.setIgnoreRepaint(true);
|
---|
76 | device.setFullScreenWindow(this.mainFrame);
|
---|
77 | if (device.isDisplayChangeSupported()) {
|
---|
78 | chooseBestDisplayMode(device);
|
---|
79 | }
|
---|
80 | this.mainFrame.addMouseListener(this);
|
---|
81 | this.mainFrame.addKeyListener(this);
|
---|
82 | this.mainFrame.createBufferStrategy(2);
|
---|
83 | final BufferStrategy bufferStrategy = this.mainFrame.getBufferStrategy();
|
---|
84 | this.done = false;
|
---|
85 | this.gameState = GameState.MAIN;
|
---|
86 | this.firing = false;
|
---|
87 | this.initGUIElements();
|
---|
88 | this.initGameElements();
|
---|
89 | while (!this.done) {
|
---|
90 | final Graphics g = bufferStrategy.getDrawGraphics();
|
---|
91 | this.render(g);
|
---|
92 | g.dispose();
|
---|
93 | bufferStrategy.show();
|
---|
94 | }
|
---|
95 | }
|
---|
96 | catch (Exception e) {
|
---|
97 | e.printStackTrace();
|
---|
98 | break Label_0173;
|
---|
99 | }
|
---|
100 | finally {
|
---|
101 | device.setFullScreenWindow(null);
|
---|
102 | }
|
---|
103 | device.setFullScreenWindow(null);
|
---|
104 | return;
|
---|
105 | }
|
---|
106 | device.setFullScreenWindow(null);
|
---|
107 | }
|
---|
108 |
|
---|
109 | private void initGUIElements() {
|
---|
110 | this.font12 = new Font("Arial", 0, 12);
|
---|
111 | this.font14 = new Font("Arial", 0, 14);
|
---|
112 | this.font20 = new Font("Arial", 0, 20);
|
---|
113 | this.font24 = new Font("Arial", 0, 24);
|
---|
114 | this.defaultCursor = this.mainFrame.getCursor();
|
---|
115 | final Image cursorImage = Toolkit.getDefaultToolkit().getImage("");
|
---|
116 | this.blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point(0, 0), "");
|
---|
117 | (this.wndMain = new Window("main", 0, 0, 800, 600, true)).add(new Label("title", 250, 65, 300, 20, "Galactic Heroes", this.font24, true));
|
---|
118 | this.wndMain.add(new Button("new game", 300, 170, 200, 40, "New Game", this.font12));
|
---|
119 | this.wndMain.add(new Button("load game", 300, 230, 200, 40, "Load Game", this.font12));
|
---|
120 | this.wndMain.add(new Button("instructions", 300, 290, 200, 40, "Instructions", this.font12));
|
---|
121 | this.wndMain.add(new Button("hall of fame", 300, 350, 200, 40, "Hall of Fame", this.font12));
|
---|
122 | this.wndMain.add(new Button("credits", 300, 410, 200, 40, "Credits", this.font12));
|
---|
123 | this.wndMain.add(new Button("quit", 300, 470, 200, 40, "Quit", this.font12));
|
---|
124 | this.wndGame = new Window("game", 0, 0, 800, 600, true);
|
---|
125 | (this.wndLoad = new Window("load", 0, 0, 800, 600, true)).add(new Label("title", 250, 65, 300, 20, "Load Game", this.font20, true));
|
---|
126 | this.wndLoad.add(new Button("back", 340, 520, 120, 30, "Back", this.font12));
|
---|
127 | (this.wndInstruct = new Window("instruct", 0, 0, 800, 600, true)).add(new Label("title", 250, 65, 300, 20, "Instructions", this.font20, true));
|
---|
128 | this.wndInstruct.add(new Button("back", 340, 520, 120, 30, "Back", this.font12));
|
---|
129 | (this.wndFame = new Window("fame", 0, 0, 800, 600, true)).add(new Label("title", 250, 65, 300, 20, "Hall of Fame", this.font20, true));
|
---|
130 | this.wndFame.add(new Button("back", 340, 520, 120, 30, "Back", this.font12));
|
---|
131 | (this.wndCredits = new Window("credits", 0, 0, 800, 600, true)).add(new Label("title", 250, 65, 300, 20, "Credits", this.font20, true));
|
---|
132 | this.wndCredits.add(new Label("lblDesign", 250, 140, 300, 20, "Design", this.font14, true));
|
---|
133 | this.wndCredits.add(new Label("design", 250, 160, 300, 20, "Dmitry Portnoy", this.font12, true));
|
---|
134 | this.wndCredits.add(new Label("lblProgramming", 250, 220, 300, 20, "Programming", this.font14, true));
|
---|
135 | this.wndCredits.add(new Label("programming", 250, 240, 300, 20, "Dmitry Portnoy", this.font12, true));
|
---|
136 | this.wndCredits.add(new Label("lblArtwork", 250, 300, 300, 20, "Artwork", this.font14, true));
|
---|
137 | this.wndCredits.add(new Label("artwork", 250, 320, 300, 20, "Dmitry Portnoy", this.font12, true));
|
---|
138 | this.wndCredits.add(new Button("back", 340, 520, 120, 30, "Back", this.font12));
|
---|
139 | }
|
---|
140 |
|
---|
141 | private void initGameElements() {
|
---|
142 | try {
|
---|
143 | this.fighter = ImageIO.read(this.getClass().getResource("compfighter.png"));
|
---|
144 | this.bomber = ImageIO.read(this.getClass().getResource("compbomber.png"));
|
---|
145 | this.xfighter = ImageIO.read(this.getClass().getResource("compxfighter.png"));
|
---|
146 | this.boss = ImageIO.read(this.getClass().getResource("compboss.png"));
|
---|
147 | this.player = ImageIO.read(this.getClass().getResource("ship.png"));
|
---|
148 | this.fighterbullet = ImageIO.read(this.getClass().getResource("compbullet.png"));
|
---|
149 | this.bomberbullet = ImageIO.read(this.getClass().getResource("compbomberbullet.png"));
|
---|
150 | this.bossbullet = ImageIO.read(this.getClass().getResource("compbossbullet.png"));
|
---|
151 | this.bossminishot = ImageIO.read(this.getClass().getResource("compbossminishot.png"));
|
---|
152 | this.playerbullet = ImageIO.read(this.getClass().getResource("bullet.png"));
|
---|
153 | this.playerShip = new HumanShip(400, 500, 200, 50, 1, -400, 200, this.player, this.playerbullet);
|
---|
154 | this.levels = new Level[26];
|
---|
155 | for (int x = 1; x < this.levels.length; ++x) {
|
---|
156 | this.levels[x] = new Level();
|
---|
157 | }
|
---|
158 | final Ship compBoss1 = new Ship(400, 75, 100, 20, 680, 5, 400, 1000, this.boss, this.bossbullet);
|
---|
159 | compBoss1.addShotType(new ShotType(-36, 25, 1, 500, 500, this.bossminishot));
|
---|
160 | compBoss1.addShotType(new ShotType(36, 25, 1, 500, 500, this.bossminishot));
|
---|
161 | final Ship compBoss2 = new Ship(400, 75, 100, 20, 680, 5, 400, 1000, this.boss, this.bossbullet);
|
---|
162 | compBoss2.addShotType(new ShotType(-36, 25, 1, 500, 500, this.bossminishot));
|
---|
163 | compBoss2.addShotType(new ShotType(36, 25, 1, 500, 500, this.bossminishot));
|
---|
164 | final Ship compBoss3 = new Ship(400, 75, 100, 20, 680, 5, 400, 1000, this.boss, this.bossbullet);
|
---|
165 | compBoss3.addShotType(new ShotType(-36, 25, 1, 500, 500, this.bossminishot));
|
---|
166 | compBoss3.addShotType(new ShotType(36, 25, 1, 500, 500, this.bossminishot));
|
---|
167 | final Ship compBoss4 = new Ship(400, 75, 100, 20, 680, 5, 400, 1000, this.boss, this.bossbullet);
|
---|
168 | compBoss4.addShotType(new ShotType(-36, 25, 1, 500, 500, this.bossminishot));
|
---|
169 | compBoss4.addShotType(new ShotType(36, 25, 1, 500, 500, this.bossminishot));
|
---|
170 | final Ship compBoss5 = new Ship(400, 75, 100, 20, 680, 5, 400, 1000, this.boss, this.bossbullet);
|
---|
171 | compBoss5.addShotType(new ShotType(-36, 25, 1, 500, 500, this.bossminishot));
|
---|
172 | compBoss5.addShotType(new ShotType(36, 25, 1, 500, 500, this.bossminishot));
|
---|
173 | this.levels[1].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
174 | this.levels[1].add(new Ship(300, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
175 | this.levels[1].add(new Ship(400, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
176 | this.levels[1].add(new Ship(500, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
177 | this.levels[1].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
178 | this.levels[2].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
179 | this.levels[2].add(new Ship(300, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
180 | this.levels[2].add(new Ship(400, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
181 | this.levels[2].add(new Ship(500, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
182 | this.levels[2].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
183 | this.levels[3].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
184 | this.levels[3].add(new Ship(300, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
185 | this.levels[3].add(new Ship(400, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
186 | this.levels[3].add(new Ship(500, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
187 | this.levels[3].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
188 | this.levels[3].add(new Ship(250, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
189 | this.levels[3].add(new Ship(350, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
190 | this.levels[3].add(new Ship(450, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
191 | this.levels[3].add(new Ship(550, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
192 | this.levels[4].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
193 | this.levels[4].add(new Ship(300, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
194 | this.levels[4].add(new Ship(400, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
195 | this.levels[4].add(new Ship(500, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
196 | this.levels[4].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
197 | this.levels[4].add(new Ship(250, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
198 | this.levels[4].add(new Ship(350, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
199 | this.levels[4].add(new Ship(450, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
200 | this.levels[4].add(new Ship(550, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
201 | this.levels[5].add(compBoss1);
|
---|
202 | this.levels[5].add(new Ship(200, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
203 | this.levels[5].add(new Ship(300, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
204 | this.levels[5].add(new Ship(400, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
205 | this.levels[5].add(new Ship(500, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
206 | this.levels[5].add(new Ship(600, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
207 | this.levels[5].add(new Ship(250, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
208 | this.levels[5].add(new Ship(350, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
209 | this.levels[5].add(new Ship(450, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
210 | this.levels[5].add(new Ship(550, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
211 | this.levels[6].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
212 | this.levels[6].add(new Ship(300, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
213 | this.levels[6].add(new Ship(400, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
214 | this.levels[6].add(new Ship(500, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
215 | this.levels[6].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
216 | this.levels[7].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
217 | this.levels[7].add(new Ship(300, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
218 | this.levels[7].add(new Ship(400, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
219 | this.levels[7].add(new Ship(500, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
220 | this.levels[7].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
221 | this.levels[8].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
222 | this.levels[8].add(new Ship(300, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
223 | this.levels[8].add(new Ship(400, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
224 | this.levels[8].add(new Ship(500, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
225 | this.levels[8].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
226 | this.levels[8].add(new Ship(250, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
227 | this.levels[8].add(new Ship(350, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
228 | this.levels[8].add(new Ship(450, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
229 | this.levels[8].add(new Ship(550, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
230 | this.levels[9].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
231 | this.levels[9].add(new Ship(300, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
232 | this.levels[9].add(new Ship(400, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
233 | this.levels[9].add(new Ship(500, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
234 | this.levels[9].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
235 | this.levels[9].add(new Ship(250, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
236 | this.levels[9].add(new Ship(350, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
237 | this.levels[9].add(new Ship(450, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
238 | this.levels[9].add(new Ship(550, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
239 | this.levels[10].add(compBoss2);
|
---|
240 | this.levels[10].add(new Ship(200, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
241 | this.levels[10].add(new Ship(300, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
242 | this.levels[10].add(new Ship(400, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
243 | this.levels[10].add(new Ship(500, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
244 | this.levels[10].add(new Ship(600, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
245 | this.levels[10].add(new Ship(250, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
246 | this.levels[10].add(new Ship(350, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
247 | this.levels[10].add(new Ship(450, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
248 | this.levels[10].add(new Ship(550, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
249 | this.levels[11].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
250 | this.levels[11].add(new Ship(300, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
251 | this.levels[11].add(new Ship(400, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
252 | this.levels[11].add(new Ship(500, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
253 | this.levels[11].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
254 | this.levels[12].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
255 | this.levels[12].add(new Ship(300, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
256 | this.levels[12].add(new Ship(400, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
257 | this.levels[12].add(new Ship(500, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
258 | this.levels[12].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
259 | this.levels[13].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
260 | this.levels[13].add(new Ship(300, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
261 | this.levels[13].add(new Ship(400, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
262 | this.levels[13].add(new Ship(500, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
263 | this.levels[13].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
264 | this.levels[13].add(new Ship(250, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
265 | this.levels[13].add(new Ship(350, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
266 | this.levels[13].add(new Ship(450, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
267 | this.levels[13].add(new Ship(550, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
268 | this.levels[14].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
269 | this.levels[14].add(new Ship(300, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
270 | this.levels[14].add(new Ship(400, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
271 | this.levels[14].add(new Ship(500, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
272 | this.levels[14].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
273 | this.levels[14].add(new Ship(250, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
274 | this.levels[14].add(new Ship(350, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
275 | this.levels[14].add(new Ship(450, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
276 | this.levels[14].add(new Ship(550, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
277 | this.levels[15].add(compBoss3);
|
---|
278 | this.levels[15].add(new Ship(200, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
279 | this.levels[15].add(new Ship(300, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
280 | this.levels[15].add(new Ship(400, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
281 | this.levels[15].add(new Ship(500, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
282 | this.levels[15].add(new Ship(600, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
283 | this.levels[15].add(new Ship(250, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
284 | this.levels[15].add(new Ship(350, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
285 | this.levels[15].add(new Ship(450, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
286 | this.levels[15].add(new Ship(550, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
287 | this.levels[16].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
288 | this.levels[16].add(new Ship(300, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
289 | this.levels[16].add(new Ship(400, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
290 | this.levels[16].add(new Ship(500, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
291 | this.levels[16].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
292 | this.levels[17].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
293 | this.levels[17].add(new Ship(300, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
294 | this.levels[17].add(new Ship(400, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
295 | this.levels[17].add(new Ship(500, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
296 | this.levels[17].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
297 | this.levels[18].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
298 | this.levels[18].add(new Ship(300, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
299 | this.levels[18].add(new Ship(400, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
300 | this.levels[18].add(new Ship(500, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
301 | this.levels[18].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
302 | this.levels[18].add(new Ship(250, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
303 | this.levels[18].add(new Ship(350, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
304 | this.levels[18].add(new Ship(450, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
305 | this.levels[18].add(new Ship(550, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
306 | this.levels[19].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
307 | this.levels[19].add(new Ship(300, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
308 | this.levels[19].add(new Ship(400, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
309 | this.levels[19].add(new Ship(500, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
310 | this.levels[19].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
311 | this.levels[19].add(new Ship(250, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
312 | this.levels[19].add(new Ship(350, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
313 | this.levels[19].add(new Ship(450, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
314 | this.levels[19].add(new Ship(550, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
315 | this.levels[20].add(compBoss4);
|
---|
316 | this.levels[20].add(new Ship(200, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
317 | this.levels[20].add(new Ship(300, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
318 | this.levels[20].add(new Ship(400, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
319 | this.levels[20].add(new Ship(500, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
320 | this.levels[20].add(new Ship(600, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
321 | this.levels[20].add(new Ship(250, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
322 | this.levels[20].add(new Ship(350, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
323 | this.levels[20].add(new Ship(450, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
324 | this.levels[20].add(new Ship(550, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
325 | this.levels[21].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
326 | this.levels[21].add(new Ship(300, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
327 | this.levels[21].add(new Ship(400, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
328 | this.levels[21].add(new Ship(500, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
329 | this.levels[21].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
330 | this.levels[22].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
331 | this.levels[22].add(new Ship(300, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
332 | this.levels[22].add(new Ship(400, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
333 | this.levels[22].add(new Ship(500, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
334 | this.levels[22].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
335 | this.levels[23].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
336 | this.levels[23].add(new Ship(300, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
337 | this.levels[23].add(new Ship(400, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
338 | this.levels[23].add(new Ship(500, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
339 | this.levels[23].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
340 | this.levels[23].add(new Ship(250, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
341 | this.levels[23].add(new Ship(350, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
342 | this.levels[23].add(new Ship(450, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
343 | this.levels[23].add(new Ship(550, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
344 | this.levels[24].add(new Ship(200, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
345 | this.levels[24].add(new Ship(300, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
346 | this.levels[24].add(new Ship(400, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
347 | this.levels[24].add(new Ship(500, 100, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
348 | this.levels[24].add(new Ship(600, 100, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
349 | this.levels[24].add(new Ship(250, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
350 | this.levels[24].add(new Ship(350, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
351 | this.levels[24].add(new Ship(450, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
352 | this.levels[24].add(new Ship(550, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
353 | this.levels[25].add(compBoss5);
|
---|
354 | this.levels[25].add(new Ship(200, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
355 | this.levels[25].add(new Ship(300, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
356 | this.levels[25].add(new Ship(400, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
357 | this.levels[25].add(new Ship(500, 150, 100, 5, 360, 2, this.bomber, this.bomberbullet));
|
---|
358 | this.levels[25].add(new Ship(600, 150, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
359 | this.levels[25].add(new Ship(250, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
360 | this.levels[25].add(new Ship(350, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
361 | this.levels[25].add(new Ship(450, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
362 | this.levels[25].add(new Ship(550, 200, 100, 2, 360, 1, this.fighter, this.fighterbullet));
|
---|
363 | (this.currentLevel = new Level()).copy(this.levels[1]);
|
---|
364 | this.levelNum = 1;
|
---|
365 | }
|
---|
366 | catch (IOException ioe) {
|
---|
367 | ioe.printStackTrace();
|
---|
368 | }
|
---|
369 | }
|
---|
370 |
|
---|
371 | private void render(final Graphics g) {
|
---|
372 | g.setColor(Color.black);
|
---|
373 | g.fillRect(0, 0, 800, 600);
|
---|
374 | switch (this.gameState) {
|
---|
375 | case MAIN: {
|
---|
376 | this.drawMain(g);
|
---|
377 | break;
|
---|
378 | }
|
---|
379 | case GAME: {
|
---|
380 | this.drawGame(g);
|
---|
381 | break;
|
---|
382 | }
|
---|
383 | case LOAD: {
|
---|
384 | this.drawLoad(g);
|
---|
385 | break;
|
---|
386 | }
|
---|
387 | case INSTRUCT: {
|
---|
388 | this.drawInstruct(g);
|
---|
389 | break;
|
---|
390 | }
|
---|
391 | case FAME: {
|
---|
392 | this.drawFame(g);
|
---|
393 | break;
|
---|
394 | }
|
---|
395 | case CREDITS: {
|
---|
396 | this.drawCredits(g);
|
---|
397 | break;
|
---|
398 | }
|
---|
399 | case WIN: {
|
---|
400 | this.drawWin(g);
|
---|
401 | break;
|
---|
402 | }
|
---|
403 | case LOSE: {
|
---|
404 | this.drawLose(g);
|
---|
405 | break;
|
---|
406 | }
|
---|
407 | }
|
---|
408 | }
|
---|
409 |
|
---|
410 | private void drawMain(final Graphics g) {
|
---|
411 | if (this.mainFrame.getCursor() == this.blankCursor) {
|
---|
412 | this.mainFrame.setCursor(this.defaultCursor);
|
---|
413 | }
|
---|
414 | this.wndMain.draw(g);
|
---|
415 | }
|
---|
416 |
|
---|
417 | private void drawGame(final Graphics g) {
|
---|
418 | if (this.mainFrame.getCursor() == this.defaultCursor) {
|
---|
419 | this.mainFrame.setCursor(this.blankCursor);
|
---|
420 | }
|
---|
421 | if (this.currentLevel.size() == 0) {
|
---|
422 | this.currentLevel.copy(this.nextLevel());
|
---|
423 | this.playerShip.getShots().clear();
|
---|
424 | }
|
---|
425 | if (this.firing) {
|
---|
426 | this.playerShip.produceVolley();
|
---|
427 | }
|
---|
428 | this.fireVolley(this.currentLevel);
|
---|
429 | this.patrol(this.currentLevel);
|
---|
430 | this.checkCollision(this.currentLevel);
|
---|
431 | this.wndGame.draw(g);
|
---|
432 | this.playerShip.draw(g);
|
---|
433 | this.currentLevel.draw(g);
|
---|
434 | g.setColor(Color.green);
|
---|
435 | g.fillRect(790, 600 - this.playerShip.getHitpoints() * 10, 10, this.playerShip.getHitpoints() * 10);
|
---|
436 | }
|
---|
437 |
|
---|
438 | private void drawLoad(final Graphics g) {
|
---|
439 | if (this.mainFrame.getCursor() == this.blankCursor) {
|
---|
440 | this.mainFrame.setCursor(this.defaultCursor);
|
---|
441 | }
|
---|
442 | this.wndLoad.draw(g);
|
---|
443 | }
|
---|
444 |
|
---|
445 | private void drawInstruct(final Graphics g) {
|
---|
446 | if (this.mainFrame.getCursor() == this.blankCursor) {
|
---|
447 | this.mainFrame.setCursor(this.defaultCursor);
|
---|
448 | }
|
---|
449 | this.wndInstruct.draw(g);
|
---|
450 | }
|
---|
451 |
|
---|
452 | private void drawFame(final Graphics g) {
|
---|
453 | if (this.mainFrame.getCursor() == this.blankCursor) {
|
---|
454 | this.mainFrame.setCursor(this.defaultCursor);
|
---|
455 | }
|
---|
456 | this.wndFame.draw(g);
|
---|
457 | }
|
---|
458 |
|
---|
459 | private void drawCredits(final Graphics g) {
|
---|
460 | if (this.mainFrame.getCursor() == this.blankCursor) {
|
---|
461 | this.mainFrame.setCursor(this.defaultCursor);
|
---|
462 | }
|
---|
463 | this.wndCredits.draw(g);
|
---|
464 | }
|
---|
465 |
|
---|
466 | private void drawWin(final Graphics g) {
|
---|
467 | if (this.mainFrame.getCursor() == this.blankCursor) {
|
---|
468 | this.mainFrame.setCursor(this.defaultCursor);
|
---|
469 | }
|
---|
470 | this.wndWin.draw(g);
|
---|
471 | }
|
---|
472 |
|
---|
473 | private void drawLose(final Graphics g) {
|
---|
474 | if (this.mainFrame.getCursor() == this.blankCursor) {
|
---|
475 | this.mainFrame.setCursor(this.defaultCursor);
|
---|
476 | }
|
---|
477 | this.wndLose.draw(g);
|
---|
478 | }
|
---|
479 |
|
---|
480 | private Level nextLevel() {
|
---|
481 | ++this.levelNum;
|
---|
482 | if (this.levelNum >= this.levels.length) {
|
---|
483 | this.gameState = GameState.WIN;
|
---|
484 | this.points += 360;
|
---|
485 | (this.wndWin = new Window("win", 0, 0, 800, 600, true)).add(new Label("title", 250, 65, 300, 20, "Victory", this.font24, true));
|
---|
486 | this.wndWin.add(new Label("info", 250, 100, 300, 100, "Press ESC to return to the main menu", this.font14, true));
|
---|
487 | this.wndWin.add(new Label("score", 250, 200, 300, 100, "Score: " + this.points, new Font("Arial", 0, 14), true));
|
---|
488 | return this.levels[1];
|
---|
489 | }
|
---|
490 | return this.levels[this.levelNum];
|
---|
491 | }
|
---|
492 |
|
---|
493 | private void fireVolley(final Level curLevel) {
|
---|
494 | for (int x = 0; x < curLevel.size(); ++x) {
|
---|
495 | ((Ship)curLevel.get(x)).produceVolley();
|
---|
496 | }
|
---|
497 | }
|
---|
498 |
|
---|
499 | private void patrol(final Level curLevel) {
|
---|
500 | for (int x = 0; x < curLevel.size(); ++x) {
|
---|
501 | ((Ship)curLevel.get(x)).patrol();
|
---|
502 | }
|
---|
503 | }
|
---|
504 |
|
---|
505 | private void checkCollision(final Level currentLevel) {
|
---|
506 | Shot collidingShot = new Shot();
|
---|
507 | Ship collidingShip = new Ship();
|
---|
508 | Ship shotOwner = new Ship();
|
---|
509 | for (int x = 0; x < currentLevel.size(); ++x) {
|
---|
510 | for (int y = 0; y < this.playerShip.getShots().size(); ++y) {
|
---|
511 | if (((Ship)currentLevel.get(x)).collides((Shot)this.playerShip.getShots().get(y)) && ((Ship)currentLevel.get(x)).getHitpoints() > 0) {
|
---|
512 | collidingShot = (Shot)this.playerShip.getShots().get(y);
|
---|
513 | collidingShip = (Ship)currentLevel.get(x);
|
---|
514 | }
|
---|
515 | }
|
---|
516 | }
|
---|
517 | this.playerShip.getShots().remove(collidingShot);
|
---|
518 | collidingShip.setHitpoints(collidingShip.getHitpoints() - collidingShot.getDamage());
|
---|
519 | if (collidingShip.getHitpoints() == 0) {
|
---|
520 | this.points += collidingShip.getMaxHitpoints() * this.playerShip.getHitpoints();
|
---|
521 | }
|
---|
522 | collidingShot = new Shot();
|
---|
523 | for (int x = 0; x < currentLevel.size(); ++x) {
|
---|
524 | for (int y = 0; y < ((Ship)currentLevel.get(x)).getShots().size(); ++y) {
|
---|
525 | if (this.playerShip.collides((Shot)((Ship)currentLevel.get(x)).getShots().get(y))) {
|
---|
526 | collidingShot = (Shot)((Ship)currentLevel.get(x)).getShots().get(y);
|
---|
527 | shotOwner = (Ship)currentLevel.get(x);
|
---|
528 | }
|
---|
529 | }
|
---|
530 | }
|
---|
531 | shotOwner.getShots().remove(collidingShot);
|
---|
532 | this.playerShip.setHitpoints(this.playerShip.getHitpoints() - collidingShot.getDamage());
|
---|
533 | if (this.playerShip.getHitpoints() == 0) {
|
---|
534 | this.gameState = GameState.LOSE;
|
---|
535 | (this.wndLose = new Window("lose", 0, 0, 800, 600, true)).add(new Label("title", 250, 65, 300, 20, "Defeat", this.font24, true));
|
---|
536 | this.wndLose.add(new Label("info", 250, 100, 300, 100, "Press ESC to return to the main menu", this.font14, true));
|
---|
537 | this.wndLose.add(new Label("score", 250, 200, 300, 100, "Score: " + this.points, new Font("Arial", 0, 14), true));
|
---|
538 | }
|
---|
539 | }
|
---|
540 |
|
---|
541 | private void reset() {
|
---|
542 | this.playerShip.reset();
|
---|
543 | for (int x = 1; x < this.levels.length; ++x) {
|
---|
544 | this.levels[x].reset();
|
---|
545 | }
|
---|
546 | this.levelNum = 1;
|
---|
547 | this.currentLevel.copy(this.levels[1]);
|
---|
548 | }
|
---|
549 |
|
---|
550 | private static DisplayMode getBestDisplayMode(final GraphicsDevice device) {
|
---|
551 | for (int x = 0; x < GalacticHeroes.BEST_DISPLAY_MODES.length; ++x) {
|
---|
552 | final DisplayMode[] modes = device.getDisplayModes();
|
---|
553 | for (int i = 0; i < modes.length; ++i) {
|
---|
554 | if (modes[i].getWidth() == GalacticHeroes.BEST_DISPLAY_MODES[x].getWidth() && modes[i].getHeight() == GalacticHeroes.BEST_DISPLAY_MODES[x].getHeight() && modes[i].getBitDepth() == GalacticHeroes.BEST_DISPLAY_MODES[x].getBitDepth()) {
|
---|
555 | return GalacticHeroes.BEST_DISPLAY_MODES[x];
|
---|
556 | }
|
---|
557 | }
|
---|
558 | }
|
---|
559 | return null;
|
---|
560 | }
|
---|
561 |
|
---|
562 | public static void chooseBestDisplayMode(final GraphicsDevice device) {
|
---|
563 | final DisplayMode best = getBestDisplayMode(device);
|
---|
564 | if (best != null) {
|
---|
565 | device.setDisplayMode(best);
|
---|
566 | }
|
---|
567 | }
|
---|
568 |
|
---|
569 | public void mousePressed(final MouseEvent e) {
|
---|
570 | }
|
---|
571 |
|
---|
572 | public void mouseReleased(final MouseEvent e) {
|
---|
573 | }
|
---|
574 |
|
---|
575 | public void mouseEntered(final MouseEvent e) {
|
---|
576 | }
|
---|
577 |
|
---|
578 | public void mouseExited(final MouseEvent e) {
|
---|
579 | }
|
---|
580 |
|
---|
581 | public void mouseClicked(final MouseEvent e) {
|
---|
582 | switch (this.gameState) {
|
---|
583 | case MAIN: {
|
---|
584 | if (this.wndMain.getMember("new game").isClicked(e.getX(), e.getY())) {
|
---|
585 | this.gameState = GameState.GAME;
|
---|
586 | break;
|
---|
587 | }
|
---|
588 | if (this.wndMain.getMember("load game").isClicked(e.getX(), e.getY())) {
|
---|
589 | this.gameState = GameState.LOAD;
|
---|
590 | break;
|
---|
591 | }
|
---|
592 | if (this.wndMain.getMember("instructions").isClicked(e.getX(), e.getY())) {
|
---|
593 | this.gameState = GameState.INSTRUCT;
|
---|
594 | break;
|
---|
595 | }
|
---|
596 | if (this.wndMain.getMember("hall of fame").isClicked(e.getX(), e.getY())) {
|
---|
597 | this.gameState = GameState.FAME;
|
---|
598 | break;
|
---|
599 | }
|
---|
600 | if (this.wndMain.getMember("credits").isClicked(e.getX(), e.getY())) {
|
---|
601 | this.gameState = GameState.CREDITS;
|
---|
602 | break;
|
---|
603 | }
|
---|
604 | if (this.wndMain.getMember("quit").isClicked(e.getX(), e.getY())) {
|
---|
605 | this.done = true;
|
---|
606 | break;
|
---|
607 | }
|
---|
608 | break;
|
---|
609 | }
|
---|
610 | case LOAD: {
|
---|
611 | if (this.wndLoad.getMember("back").isClicked(e.getX(), e.getY())) {
|
---|
612 | this.gameState = GameState.MAIN;
|
---|
613 | break;
|
---|
614 | }
|
---|
615 | break;
|
---|
616 | }
|
---|
617 | case INSTRUCT: {
|
---|
618 | if (this.wndInstruct.getMember("back").isClicked(e.getX(), e.getY())) {
|
---|
619 | this.gameState = GameState.MAIN;
|
---|
620 | break;
|
---|
621 | }
|
---|
622 | break;
|
---|
623 | }
|
---|
624 | case FAME: {
|
---|
625 | if (this.wndFame.getMember("back").isClicked(e.getX(), e.getY())) {
|
---|
626 | this.gameState = GameState.MAIN;
|
---|
627 | break;
|
---|
628 | }
|
---|
629 | break;
|
---|
630 | }
|
---|
631 | case CREDITS: {
|
---|
632 | if (this.wndCredits.getMember("back").isClicked(e.getX(), e.getY())) {
|
---|
633 | this.gameState = GameState.MAIN;
|
---|
634 | break;
|
---|
635 | }
|
---|
636 | break;
|
---|
637 | }
|
---|
638 | }
|
---|
639 | }
|
---|
640 |
|
---|
641 | public void keyTyped(final KeyEvent e) {
|
---|
642 | }
|
---|
643 |
|
---|
644 | public void keyPressed(final KeyEvent e) {
|
---|
645 | if (this.selectedText != null) {
|
---|
646 | this.selectedText.handleEvent(e);
|
---|
647 | }
|
---|
648 | switch (this.gameState) {
|
---|
649 | case GAME: {
|
---|
650 | if (e.getKeyCode() == 38 || e.getKeyCode() == 40 || e.getKeyCode() == 37 || e.getKeyCode() == 39) {
|
---|
651 | this.playerShip.handleEvent(e);
|
---|
652 | }
|
---|
653 | if (e.getKeyCode() == 32) {
|
---|
654 | this.firing = true;
|
---|
655 | }
|
---|
656 | if (e.getKeyCode() == 27) {
|
---|
657 | this.reset();
|
---|
658 | this.gameState = GameState.MAIN;
|
---|
659 | break;
|
---|
660 | }
|
---|
661 | break;
|
---|
662 | }
|
---|
663 | case WIN: {
|
---|
664 | if (e.getKeyCode() == 27) {
|
---|
665 | this.reset();
|
---|
666 | this.gameState = GameState.MAIN;
|
---|
667 | break;
|
---|
668 | }
|
---|
669 | break;
|
---|
670 | }
|
---|
671 | case LOSE: {
|
---|
672 | if (e.getKeyCode() == 27) {
|
---|
673 | this.reset();
|
---|
674 | this.gameState = GameState.MAIN;
|
---|
675 | break;
|
---|
676 | }
|
---|
677 | break;
|
---|
678 | }
|
---|
679 | }
|
---|
680 | }
|
---|
681 |
|
---|
682 | public void keyReleased(final KeyEvent e) {
|
---|
683 | if (this.gameState == GameState.GAME) {
|
---|
684 | switch (e.getKeyCode()) {
|
---|
685 | case 38: {
|
---|
686 | this.playerShip.setUpPressed(false);
|
---|
687 | break;
|
---|
688 | }
|
---|
689 | case 40: {
|
---|
690 | this.playerShip.setDownPressed(false);
|
---|
691 | break;
|
---|
692 | }
|
---|
693 | case 37: {
|
---|
694 | this.playerShip.setLeftPressed(false);
|
---|
695 | break;
|
---|
696 | }
|
---|
697 | case 39: {
|
---|
698 | this.playerShip.setRightPressed(false);
|
---|
699 | break;
|
---|
700 | }
|
---|
701 | case 32: {
|
---|
702 | this.firing = false;
|
---|
703 | break;
|
---|
704 | }
|
---|
705 | }
|
---|
706 | }
|
---|
707 | }
|
---|
708 |
|
---|
709 | public static void main(final String[] args) {
|
---|
710 | try {
|
---|
711 | final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
---|
712 | final GraphicsDevice device = env.getDefaultScreenDevice();
|
---|
713 | final GalacticHeroes gameWindow = new GalacticHeroes(device);
|
---|
714 | }
|
---|
715 | catch (Exception e) {
|
---|
716 | e.printStackTrace();
|
---|
717 | }
|
---|
718 | System.exit(0);
|
---|
719 | }
|
---|
720 | }
|
---|