source: lost-haven/main/LostHavenRPG.java@ 8edd04e

Last change on this file since 8edd04e was 8edd04e, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 4 years ago

Make the decompiled game code compile successfully

  • Property mode set to 100644
File size: 75.2 KB
Line 
1package main;
2
3import java.awt.Color;
4import java.awt.DisplayMode;
5import java.awt.Font;
6import java.awt.FontMetrics;
7import java.awt.Frame;
8import java.awt.Graphics;
9import java.awt.GraphicsConfiguration;
10import java.awt.GraphicsDevice;
11import java.awt.GraphicsEnvironment;
12import java.awt.MouseInfo;
13import java.awt.event.*;
14import java.awt.image.*;
15import java.io.*;
16import java.text.SimpleDateFormat;
17import java.util.Date;
18import java.util.HashMap;
19import java.util.Iterator;
20import java.util.LinkedList;
21
22import javax.imageio.ImageIO;
23
24import gamegui.*;
25
26public class LostHavenRPG implements KeyListener, MouseListener {
27
28 private static DisplayMode[] BEST_DISPLAY_MODES = new DisplayMode[] {
29 new DisplayMode(800, 600, 32, 0),
30 new DisplayMode(800, 600, 16, 0),
31 new DisplayMode(800, 600, 8, 0)
32 };
33
34 public static Map map;
35 public static HashMap<LandType, Land> landMap;
36 public static HashMap<StructureType, Structure> structMap;
37 public static HashMap<CreatureType, Creature> creatureMap;
38 public static HashMap<String, Item> items;
39 public static LinkedList<RespawnPoint> respawnPoints;
40 public static LinkedList<SpawnPoint> spawnPoints;
41
42 public static BufferedImage[] airSprites;
43 public static BufferedImage[] earthSprites;
44 public static BufferedImage[] fireSprites;
45 public static BufferedImage[] waterSprites;
46 public static BufferedImage[] imgBow;
47 public static BufferedImage passiveAura;
48 public static BufferedImage thornsAura;
49 public static BufferedImage confuseAura;
50 public static BufferedImage sandAura;
51 public static Model rangedModel;
52 public static Model meleeModel;
53 public static ScrollList lstInventory;
54 public static ScrollList lstGems;
55 public static Frame frmMain;
56
57 public GameState gameState;
58 public AuxState auxState;
59
60 boolean done;
61 boolean changePending;
62 Player player;
63
64 LinkedList<Gem> gems;
65 LinkedList<Item> drops;
66 LinkedList<Projectile> projectiles;
67
68 BufferedImage imgMap;
69
70 Window wndMain;
71 Window wndCreateAccount;
72 Window wndGameIntro;
73 Window wndGameInfo;
74 Window wndCredits;
75 Window wndStatDisplay;
76 Window wndGameInventory;
77 Window wndGameGems;
78 Window wndGameStats;
79 Window wndGameMap;
80 Window wndVictory;
81 Window[] wndTutorials;
82 Window wndTutOptions;
83 Window wndMessage;
84
85 int wndTutCur;
86 boolean infoStart;
87
88 Button btnMenu;
89 Button btnStats;
90 Button btnGems;
91 Button btnInventory;
92 Button btnMap;
93
94 Label lblGemVal;
95 Label lblSpellCost;
96
97 Graphics g;
98
99 Point startPoint;
100
101 Textbox selectedText;
102
103 boolean started = false;
104
105 public LostHavenRPG(GraphicsDevice device) {
106 try {
107 GraphicsConfiguration gc = device.getDefaultConfiguration();
108 frmMain = new Frame(gc);
109 frmMain.setUndecorated(true);
110 frmMain.setIgnoreRepaint(true);
111 device.setFullScreenWindow(frmMain);
112 if (device.isDisplayChangeSupported())
113 chooseBestDisplayMode(device);
114 frmMain.addMouseListener(this);
115 frmMain.addKeyListener(this);
116 frmMain.createBufferStrategy(2);
117 BufferStrategy bufferStrategy = frmMain.getBufferStrategy();
118 this.g = bufferStrategy.getDrawGraphics();
119 this.done = false;
120 this.changePending = false;
121 this.gameState = GameState.Main;
122 this.auxState = AuxState.None;
123 loadMapElements();
124 this.imgMap = ImageIO.read(getClass().getResource("../images/mapLarge.png"));
125 map = new Map("map.png", "structInfo2.txt", landMap, structMap, true);
126 this.startPoint = new Point(7050, 6150);
127 loadItems();
128 loadCreatures();
129 loadSpawnPoints();
130 loadSpellSprites();
131 initGUIElements();
132 this.started = true;
133 while (!this.done) {
134 this.g = bufferStrategy.getDrawGraphics();
135 handleEvents();
136 render(this.g);
137 this.g.dispose();
138 bufferStrategy.show();
139 }
140 } catch (Exception e) {
141 e.printStackTrace();
142 } finally {
143 device.setFullScreenWindow(null);
144 }
145 }
146
147 private void initGUIElements() {
148 Font font11 = new Font("Arial", 0, 11);
149 Font font12 = new Font("Arial", 0, 12);
150 Font font14 = new Font("Arial", 0, 14);
151 Font font24 = new Font("Arial", 0, 24);
152 BufferedImage imgSub = null;
153 BufferedImage imgAdd = null;
154 BufferedImage imgSkillSub = null;
155 BufferedImage imgSkillAdd = null;
156 String strengthDesc = "Raises damage inflicted by melee weapons.";
157 String dexterityDesc = "Lowers cooldown of all weapons.";
158 String constitutionDesc = "Raises starting hitpoints and hitpoints gained per level.";
159 String wisdomDesc = "Raises starting manapoints and manapoints gained per level.";
160 String lightWeaponDesc = "Raises damage inflicted by light weapons.";
161 String heavyWeaponDesc = "Raises damage inflicted by heavy weapons.";
162 String rangedWeaponDesc = "Raises damage inflicted by ranged weapons.";
163 String evocationDesc = "Raises the possible number of activated gems.";
164 this.wndMain = new Window("main", 0, 0, 800, 600, true);
165 Animation anmTitle = new Animation("title", 144, 0, 512, 95, 83, true);
166 try {
167 anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame1.png")));
168 anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame2.png")));
169 anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame3.png")));
170 anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame4.png")));
171 anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame5.png")));
172 imgSub = ImageIO.read(getClass().getResource("../images/imgSub.png"));
173 imgAdd = ImageIO.read(getClass().getResource("../images/imgAdd.png"));
174 imgSkillSub = ImageIO.read(getClass().getResource("../images/imgSkillSub.png"));
175 imgSkillAdd = ImageIO.read(getClass().getResource("../images/imgSkillAdd.png"));
176 } catch (IOException ioe) {
177 ioe.printStackTrace();
178 }
179 this.wndMain.add(anmTitle);
180 this.wndMain.add(new Button("new game", 500, 140, 200, 40, "New Game", font12));
181 this.wndMain.add(new Button("load game", 500, 230, 200, 40, "Load Game", font12));
182 this.wndMain.add(new Button("game info", 500, 320, 200, 40, "Game Information", font12));
183 this.wndMain.add(new Button("credits", 500, 410, 200, 40, "Credits", font12));
184 this.wndMain.add(new Button("quit", 500, 500, 200, 40, "Quit", font12));
185 this.wndStatDisplay = new Window("stat display", 0, 550, 799, 49, false);
186 this.wndGameStats = new Window("game stats", 0, 125, 320, 425);
187 this.wndGameGems = new Window("inventory", 359, 299, 220, 251);
188 lstGems = new ScrollList("gem list", 0, 0, 200, 251, null, null);
189 lstGems.addScrollBar(new ScrollBar("scrollgem", 200, 0, 20, 251, 3));
190 this.wndGameGems.add(lstGems);
191 this.wndGameInventory = new Window("inventory", 579, 299, 220, 251);
192 lstInventory = new ScrollList("inventory list", 0, 0, 200, 251, null, null);
193 lstInventory.addScrollBar(new ScrollBar("scrollinv", 200, 0, 20, 251, 3));
194 this.wndGameInventory.add(lstInventory);
195 this.wndGameMap = new Window("inventory", 443, 357, 356, 193);
196 this.btnMenu = new Button("main menu", 360, 10, 80, 20, "Main Menu", font12);
197 this.btnStats = new Button("stats", 600, 5, 80, 16, "Character", font12);
198 this.btnInventory = new Button("inventory", 700, 5, 80, 16, "Inventory", font12);
199 this.btnGems = new Button("gems", 600, 29, 80, 16, "Gems", font12);
200 this.btnMap = new Button("map", 700, 29, 80, 16, "Map", font12);
201 this.lblGemVal = new Label("gemVal", 515, 5, 67, 20, "Gem Value: 0", font12, Align.Right);
202 this.lblSpellCost = new Label("spellCost", 515, 24, 67, 20, "Spell Cost: 0", font12, Align.Right);
203 this.wndStatDisplay.add(this.btnMenu);
204 this.wndStatDisplay.add(this.btnStats);
205 this.wndStatDisplay.add(this.btnGems);
206 this.wndStatDisplay.add(this.btnInventory);
207 this.wndStatDisplay.add(this.btnMap);
208 this.wndStatDisplay.add(this.lblGemVal);
209 this.wndStatDisplay.add(this.lblSpellCost);
210 this.wndGameStats.add(new Label("strength", 10, 20, 70, 30, "Strength", font12, Align.Left));
211 this.wndGameStats.add(new Label("strengthDesc", 20, 45, 70, 15, strengthDesc, font11, Align.Left));
212 this.wndGameStats.add(new Label("dexterity", 10, 65, 70, 30, "Dexterity", font12, Align.Left));
213 this.wndGameStats.add(new Label("dexterityDesc", 20, 90, 70, 15, dexterityDesc, font11, Align.Left));
214 this.wndGameStats.add(new Label("constitution", 10, 110, 70, 30, "Constitution", font12, Align.Left));
215 this.wndGameStats.add(new Label("constitutionDesc", 20, 135, 70, 15, constitutionDesc, font11, Align.Left));
216 this.wndGameStats.add(new Label("wisdom", 10, 155, 70, 30, "Wisdom", font12, Align.Left));
217 this.wndGameStats.add(new Label("wisdomDesc", 20, 180, 70, 15, wisdomDesc, font11, Align.Left));
218 this.wndGameStats.add(new Label("strVal", 220, 20, 70, 30, "0", font12, Align.Left));
219 this.wndGameStats.add(new Label("dexVal", 220, 65, 70, 30, "0", font12, Align.Left));
220 this.wndGameStats.add(new Label("conVal", 220, 110, 70, 30, "0", font12, Align.Left));
221 this.wndGameStats.add(new Label("wisVal", 220, 155, 70, 30, "0", font12, Align.Left));
222 this.wndGameStats.add(new Label("light weapons", 10, 220, 70, 30, "Light Weapons", font12, Align.Left));
223 this.wndGameStats.add(new Label("lightWeaponDesc", 20, 245, 70, 15, lightWeaponDesc, font11, Align.Left));
224 this.wndGameStats.add(new Label("heavy weapons", 10, 265, 70, 30, "Heavy Weapons", font12, Align.Left));
225 this.wndGameStats.add(new Label("heavyWeaponDesc", 20, 290, 70, 15, heavyWeaponDesc, font11, Align.Left));
226 this.wndGameStats.add(new Label("ranged weapons", 10, 310, 70, 30, "Ranged Weapons", font12, Align.Left));
227 this.wndGameStats.add(new Label("rangedWeaponDesc", 20, 335, 70, 15, rangedWeaponDesc, font11, Align.Left));
228 this.wndGameStats.add(new Label("evocation", 10, 355, 70, 30, "Evocation", font12, Align.Left));
229 this.wndGameStats.add(new Label("evocationDesc", 20, 380, 70, 15, evocationDesc, font11, Align.Left));
230 this.wndGameStats.add(new Label("lightWeaponVal", 220, 220, 70, 30, "0", font12, Align.Left));
231 this.wndGameStats.add(new Label("heavyWeaponVal", 220, 265, 70, 30, "0", font12, Align.Left));
232 this.wndGameStats.add(new Label("rangedWeaponVal", 220, 310, 70, 30, "0", font12, Align.Left));
233 this.wndGameStats.add(new Label("evocationVal", 220, 355, 70, 30, "0", font12, Align.Left));
234 this.wndGameStats.add(new Label("skillVal", 130, 395, 70, 30, "0", font12, Align.Left));
235 this.wndGameStats.add(new Button("lightWeapon+", 265, 230, 20, 20, imgSkillAdd));
236 this.wndGameStats.add(new Button("heavyWeapon+", 265, 275, 20, 20, imgSkillAdd));
237 this.wndGameStats.add(new Button("rangedWeapon+", 265, 320, 20, 20, imgSkillAdd));
238 this.wndGameStats.add(new Button("evocation+", 265, 365, 20, 20, imgSkillAdd));
239 this.wndGameStats.add(new Label("skilllPoints", 50, 395, 70, 30, "Remaining Points:", font12, Align.Right));
240 this.wndCreateAccount = new Window("create account", 0, 0, 800, 600, true);
241 this.wndCreateAccount.add(new Label("title", 250, 15, 300, 20, "Create an Account", font24));
242 this.wndCreateAccount.add(new Textbox("user", 340, 100, 190, 30, "Username:", font12, false));
243 this.wndCreateAccount.add(new Label("strength", 90, 190, 70, 30, "Strength", font12, Align.Left));
244 this.wndCreateAccount.add(new Label("strengthDesc", 115, 220, 70, 15, strengthDesc, font11, Align.Left));
245 this.wndCreateAccount.add(new Label("dexterity", 90, 250, 70, 30, "Dexterity", font12, Align.Left));
246 this.wndCreateAccount.add(new Label("dexterityDesc", 115, 280, 70, 15, dexterityDesc, font11, Align.Left));
247 this.wndCreateAccount.add(new Label("constitution", 90, 310, 70, 30, "Constitution", font12, Align.Left));
248 this.wndCreateAccount.add(new Label("constitutionDesc", 115, 340, 70, 15, constitutionDesc, font11, Align.Left));
249 this.wndCreateAccount.add(new Label("wisdom", 90, 370, 70, 30, "Wisdom", font12, Align.Left));
250 this.wndCreateAccount.add(new Label("wisdomDesc", 115, 400, 70, 15, wisdomDesc, font11, Align.Left));
251 this.wndCreateAccount.add(new Label("attPoints", 110, 430, 70, 30, "Remaining Points:", font12, Align.Right));
252 this.wndCreateAccount.add(new Label("strVal", 264, 190, 70, 30, "0", font12, Align.Left));
253 this.wndCreateAccount.add(new Label("dexVal", 264, 250, 70, 30, "0", font12, Align.Left));
254 this.wndCreateAccount.add(new Label("conVal", 264, 310, 70, 30, "0", font12, Align.Left));
255 this.wndCreateAccount.add(new Label("wisVal", 264, 370, 70, 30, "0", font12, Align.Left));
256 this.wndCreateAccount.add(new Label("attVal", 215, 430, 70, 30, "0", font12, Align.Left));
257 this.wndCreateAccount.add(new Button("strength-", 205, 198, 20, 20, imgSub));
258 this.wndCreateAccount.add(new Button("strength+", 315, 198, 20, 20, imgAdd));
259 this.wndCreateAccount.add(new Button("dexterity-", 205, 258, 20, 20, imgSub));
260 this.wndCreateAccount.add(new Button("dexterity+", 315, 258, 20, 20, imgAdd));
261 this.wndCreateAccount.add(new Button("constitution-", 205, 318, 20, 20, imgSub));
262 this.wndCreateAccount.add(new Button("constitution+", 315, 318, 20, 20, imgAdd));
263 this.wndCreateAccount.add(new Button("wisdom-", 205, 378, 20, 20, imgSub));
264 this.wndCreateAccount.add(new Button("wisdom+", 315, 378, 20, 20, imgAdd));
265 this.wndCreateAccount.add(new Label("light weapons", 450, 190, 70, 30, "Light Weapons", font12, Align.Left));
266 this.wndCreateAccount.add(new Label("lightWeaponDesc", 475, 220, 70, 15, lightWeaponDesc, font11, Align.Left));
267 this.wndCreateAccount.add(new Label("heavy weapons", 450, 250, 70, 30, "Heavy Weapons", font12, Align.Left));
268 this.wndCreateAccount.add(new Label("heavyWeaponDesc", 475, 280, 70, 15, heavyWeaponDesc, font11, Align.Left));
269 this.wndCreateAccount.add(new Label("ranged weapons", 450, 310, 70, 30, "Ranged Weapons", font12, Align.Left));
270 this.wndCreateAccount.add(new Label("rangedWeaponDesc", 475, 340, 70, 15, rangedWeaponDesc, font11, Align.Left));
271 this.wndCreateAccount.add(new Label("evocation", 450, 370, 70, 30, "Evocation", font12, Align.Left));
272 this.wndCreateAccount.add(new Label("evocationDesc", 475, 400, 70, 15, evocationDesc, font11, Align.Left));
273 this.wndCreateAccount.add(new Label("skilllPoints", 475, 430, 70, 30, "Remaining Points:", font12, Align.Right));
274 this.wndCreateAccount.add(new Label("lightWeaponVal", 620, 190, 70, 30, "0", font12, Align.Left));
275 this.wndCreateAccount.add(new Label("heavyWeaponVal", 620, 250, 70, 30, "0", font12, Align.Left));
276 this.wndCreateAccount.add(new Label("rangedWeaponVal", 620, 310, 70, 30, "0", font12, Align.Left));
277 this.wndCreateAccount.add(new Label("evocationVal", 620, 370, 70, 30, "0", font12, Align.Left));
278 this.wndCreateAccount.add(new Label("skillVal", 575, 430, 70, 30, "0", font12, Align.Left));
279 this.wndCreateAccount.add(new Button("lightWeapon-", 565, 198, 20, 20, imgSkillSub));
280 this.wndCreateAccount.add(new Button("lightWeapon+", 675, 198, 20, 20, imgSkillAdd));
281 this.wndCreateAccount.add(new Button("heavyWeapon-", 565, 258, 20, 20, imgSkillSub));
282 this.wndCreateAccount.add(new Button("heavyWeapon+", 675, 258, 20, 20, imgSkillAdd));
283 this.wndCreateAccount.add(new Button("rangedWeapon-", 565, 318, 20, 20, imgSkillSub));
284 this.wndCreateAccount.add(new Button("rangedWeapon+", 675, 318, 20, 20, imgSkillAdd));
285 this.wndCreateAccount.add(new Button("evocation-", 565, 378, 20, 20, imgSkillSub));
286 this.wndCreateAccount.add(new Button("evocation+", 675, 378, 20, 20, imgSkillAdd));
287 this.wndCreateAccount.add(new Button("create", 245, 520, 140, 30, "Create", font12));
288 this.wndCreateAccount.add(new Button("cancel", 415, 520, 140, 30, "Cancel", font12));
289 this.wndCredits = new Window("main", 0, 0, 800, 600, true);
290 this.wndCredits.add(new Label("title", 250, 15, 300, 20, "Credits", font24));
291 this.wndCredits.add(new Label("1", 250, 160, 300, 20, "Dmitry Portnoy", font14));
292 this.wndCredits.add(new Label("2", 250, 180, 300, 20, "Team Leader", font12));
293 this.wndCredits.add(new Label("3", 250, 195, 300, 20, "Programmer", font12));
294 this.wndCredits.add(new Label("4", 250, 235, 300, 20, "Daniel Vu", font14));
295 this.wndCredits.add(new Label("5", 250, 255, 300, 20, "Graphic Artist", font12));
296 this.wndCredits.add(new Label("6", 250, 295, 300, 20, "Jason Cooper", font14));
297 this.wndCredits.add(new Label("7", 250, 315, 300, 20, "Designer", font12));
298 this.wndCredits.add(new Label("8", 250, 355, 300, 20, "Special thanks to", font14));
299 this.wndCredits.add(new Label("9", 250, 375, 300, 20, "The Game Creation Society", font12));
300 this.wndTutorials = new Window[13];
301 String[] text = new String[13];
302 this.wndTutOptions = new Window("tut", 300, 0, 499, 140, false);
303 this.wndTutOptions.add(new Button("previous", 260, 110, 60, 20, "Previous", font12, Align.Center));
304 this.wndTutOptions.add(new Button("next", 340, 110, 60, 20, "Next", font12, Align.Center));
305 this.wndTutOptions.add(new Button("skip", 420, 110, 60, 20, "Skip", font12, Align.Center));
306 this.wndTutOptions.add(new Label("num", 200, 110, 60, 20, "1 / 13", font12, Align.Center));
307 text[0] = "When you die, you will be resurrected with no penalty at the closest purple pedestal you have activated. To activate a pedestal, you must walk over it. If you have not activated any purple pedestals, you will resurrect where you started the game. It is important to activate any purple pedestals you see to save you time when you die. You can also use purple pedestals to replenish all of your HP and MP by stepping on them.";
308 text[1] = "When you kill enemies, they sometimes drop items. Left-click on an item to pick it up and place it in your inventory. Be careful when picking up items while there are many enemies around because they might kill you.";
309 text[2] = "You can open your inventory from the bar at the bottom of the screen. You can mouse over any item in your inventory and see a description and relevant stats. Left-clicking any weapon in your inventory will equip it and unequip your previously equiped weapon. Left-clicking a gem will activate it provided you have enough evocation skill to do so. ";
310 text[3] = "You can equip both melee and ranged weapons. If you have a ranged weapon, like this bow, you can fire at enemies from a safe distance. Ranged weapons never run out of ammunition. However, they cannot shoot through most obstacles.";
311 text[4] = "Melee weapons are divided into light and heavy weapons. Heavy weapons are slower, but deal much more damage when they hit. Anyone can equip light weapons, but only players with at least 12 Strenth can use heavy weapons. The damage bonus from Strength is also greater for heavy weapons. The heavy weapon skill also adds more damage per hit than the light weapon skill.";
312 text[5] = "You can open the Character window from the bottom bar. The character window shows the levels of all your skills and attributes. When you level up, you get two extra skill points and you can spend them here. Choose your skills carefully since you can't repick your skills later. You also get HP equal to your constitution and MP equal to your wisdom when you level up.";
313 text[6] = "Assuming you have at least one gem activated and enough mana, you can cast spells by right-clicking anywhere on the map. The total mana cost of your spell is half of the value of all the gems used to cast it.Any enemies that your spell collides with will be affected. However, you use MP every time you cast a spell, so you have to be careful not run out of MP in a battle. There are many gems with different effects and you should carefully choose which gems you want to use for your spell.";
314 text[7] = "The Gems window is accessible from the bottom bar. Activated gems will appear in this window and will contribute their effects to any spells you cast. Each gem has a set amount of energy that is displayed if you mouse over it. Your evocation skill limits the amount of gems you can activate at once, so you should raise it to increase the power of your spells. You can left-click on any gem in the Gems window to place it back in your inventory if you want to activate a different gem.";
315 text[8] = "The images under the Blob indicate that it is afflicted with some status effects. Status effects caused by spells usually last a few seconds, but it varies depending on the gem.";
316 text[9] = "You can activate mutliple gems of the same type to get increased effects. Gems that have one-time effects, like dealing damage, will simply do more of that. Gems that cause the target to gain a temporary status effect will make that effect last longer if multiple gems are used.";
317 text[10] = "These red portals will open your way out of this world. However, they have been protected by the magic of powerful artifacts. These artifacts are scattered throughout the land and you will need at least four to break the enchantment and activate these portals.";
318 text[11] = "Yellow pedestals are portals to the aforementioned artifacts. Be warned that these artifacts are well-guarded and capturing them could prove deadly. To view this tutorial again, click on Game Information from the main menu. Good luck!";
319 text[12] = "You can access the world map from the bottom bar. However, it does not show the locations of respawn or teleportation points. The Rectangular areas on top of the screen are the locations of the relics, but you must use teleportation points to get to them.";
320 FontMetrics metrics = this.g.getFontMetrics(font12);
321 try {
322 for (int x = 0; x < this.wndTutorials.length; x++) {
323 this.wndTutorials[x] = new Window("tut" + x, 0, 0, 800, 600, true);
324 this.wndTutorials[x].add(new Button("screen", 0, 0, 800, 600, ImageIO.read(getClass().getResource("../images/Tutorial/ss" + (x + 1) + ".png"))));
325 this.wndTutorials[x].add(this.wndTutOptions);
326 MultiTextbox multiTextbox = new MultiTextbox("text", 305, 5, 490, 100, "", false, font12, metrics);
327 multiTextbox.setBorder(false);
328 multiTextbox.setText(text[x]);
329 this.wndTutorials[x].add(multiTextbox);
330 }
331 this.wndTutCur = 0;
332 this.wndGameIntro = new Window("intro", 0, 0, 800, 600, true);
333 this.wndGameIntro.add(new Label("intro", 250, 15, 300, 20, "Introduction", font24));
334 MultiTextbox txt = new MultiTextbox("text", 50, 150, 650, 350, "", false, font12, metrics);
335 txt.setBorder(false);
336 txt.setText("You suddenly wake up in a strange place you do not recognize. You must find some weapons and some way to get out.\n\nKill creatures to get gems to power your spells and weapons to defend yourself with.\n\nTo get out of this world, you must unlock a portal that is protected by powerful artifacts. Each artifact can be accessed by a yellow portal somewhere in the world. You must collect at least four artifacts to unlock the portal.");
337 this.wndGameIntro.add(txt);
338 this.wndVictory = new Window("victory", 0, 0, 800, 600, true);
339 this.wndVictory.add(new Label("victory", 250, 15, 300, 20, "Victory", font24));
340 MultiTextbox txtV = new MultiTextbox("text", 50, 150, 650, 350, "", false, font12, metrics);
341 txtV.setBorder(false);
342 txtV.setText("As you strike the final blow, the specter's body evaporates, leaving behind a pile of torn clothing. In the last seconds of its existance, you manage to peer under its hood and catch a glimpse of your own face. Was that simply proof of your failing psyche or does some darker secret lie behind that horrible monster? When you once again become aware of your surroundings, you find yourself alone in a forest clearing. There is no sign of hostile monsters and the only indications of your ordeal are your incredible fatigue and a pile of rags a few feet away from you. Was the world you were trapped in merely an illusion or is there some other explanation? You cannot be sure, but you hope to never have to remember that place again.");
343 this.wndVictory.add(txtV);
344 } catch (IOException ioe) {
345 ioe.printStackTrace();
346 }
347 this.wndMessage = new Window("message", 290, 135, 220, 160);
348 this.wndMessage.add(new Label("label", 20, 15, 180, 12, "none", font12));
349 this.wndMessage.add(new Button("button", 70, 115, 80, 30, "OK", font12));
350 }
351
352 private void loadMapElements() {
353 landMap = new HashMap<LandType, Land>();
354 structMap = new HashMap<StructureType, Structure>();
355 respawnPoints = new LinkedList<RespawnPoint>();
356 BufferedImage nullImg = null;
357 landMap.put(LandType.Lava, new Land(LandType.Lava, "Terrain/orange.png", true));
358 landMap.put(LandType.Metal, new Land(LandType.Metal, "Terrain/darkRed.png", true));
359 landMap.put(LandType.Charred, new Land(LandType.Charred, "Terrain/red.png", true));
360 landMap.put(LandType.Swamp, new Land(LandType.Swamp, "Terrain/lightBrown.png", true));
361 landMap.put(LandType.Vines, new Land(LandType.Vines, "Terrain/darkBrown.png", true));
362 landMap.put(LandType.Crystal, new Land(LandType.Crystal, "Terrain/purple.png", true));
363 landMap.put(LandType.CrystalFormation, new Land(LandType.CrystalFormation, "Terrain/darkPurple.png", false));
364 landMap.put(LandType.Water, new Land(LandType.Water, "Terrain/blue.png", true));
365 landMap.put(LandType.Forest, new Land(LandType.Forest, "Terrain/darkGreen.png", true));
366 landMap.put(LandType.Tree, new Land(LandType.Tree, "Terrain/brown.png", false));
367 landMap.put(LandType.Plains, new Land(LandType.Plains, "Terrain/lightGreen.png", true));
368 landMap.put(LandType.Desert, new Land(LandType.Desert, "Terrain/yellow.png", true));
369 landMap.put(LandType.Mountains, new Land(LandType.Mountains, "Terrain/mountain.png", false));
370 landMap.put(LandType.Cave, new Land(LandType.Cave, "Terrain/mountain.png", false));
371 landMap.put(LandType.Ocean, new Land(LandType.Ocean, "Terrain/darkBlue.png", false));
372 landMap.put(LandType.Snow, new Land(LandType.Snow, "Terrain/lightBlue.png", true));
373 landMap.put(LandType.Steam, new Land(LandType.Steam, "Terrain/lightGray.png", true));
374 structMap.put(StructureType.None, new Structure(StructureType.None, nullImg, true));
375 structMap.put(StructureType.LoginPedestal, new Structure(StructureType.LoginPedestal, "YellowPedestal.png", true));
376 structMap.put(StructureType.RejuvenationPedestal, new Structure(StructureType.RejuvenationPedestal, "PurplePedestal.png", true));
377 structMap.put(StructureType.LifePedestal, new Structure(StructureType.LifePedestal, "RedPedestal.png", true));
378 structMap.put(StructureType.ManaPedestal, new Structure(StructureType.ManaPedestal, "BluePedestal.png", true));
379 structMap.put(StructureType.RespawnPoint, new RespawnPoint(StructureType.RespawnPoint, "PurplePedestal.png", true));
380 structMap.put(StructureType.ArtifactPoint, new ArtifactPoint(StructureType.ArtifactPoint, "YellowPedestal.png", true));
381 structMap.put(StructureType.BossPoint, new ArtifactPoint(StructureType.BossPoint, "RedPedestal.png", true));
382 }
383
384 private void loadCreatures() {
385 creatureMap = new HashMap<CreatureType, Creature>();
386 try {
387 BufferedReader in = new BufferedReader(new FileReader("creatures.txt"));
388 while (in.ready()) {
389 Creature cr = Creature.loadTemplate(in);
390 String strItem;
391 while (!(strItem = in.readLine()).equals("---"))
392 cr.addDrop(new ItemDrop(items.get(strItem.substring(0, strItem.indexOf(","))), Integer.valueOf(strItem.substring(strItem.indexOf(",") + 2)).intValue()));
393 creatureMap.put(cr.getType(), cr);
394 }
395 in.close();
396 } catch (IOException ioe) {
397 ioe.printStackTrace();
398 }
399 ((Player)creatureMap.get(CreatureType.Player)).initGems(this.gems);
400 meleeModel = ((Player)creatureMap.get(CreatureType.Player)).loadModel("Player");
401 rangedModel = ((Player)creatureMap.get(CreatureType.Player)).loadModel("Player/ranged");
402 }
403
404 private void loadSpawnPoints() {
405 spawnPoints = new LinkedList<SpawnPoint>();
406 try {
407 BufferedReader in = new BufferedReader(new FileReader("spawnPoints.txt"));
408 while (in.ready()) {
409 Creature type = creatureMap.get(CreatureType.valueOf(in.readLine()));
410 String strLoc = in.readLine();
411 int x = Integer.parseInt(strLoc.substring(0, strLoc.indexOf(",")));
412 strLoc = strLoc.substring(strLoc.indexOf(",") + 1);
413 int y = Integer.parseInt(strLoc.substring(0, strLoc.indexOf(",")));
414 strLoc = strLoc.substring(strLoc.indexOf(",") + 1);
415 int xMin = Integer.parseInt(strLoc.substring(0, strLoc.indexOf(",")));
416 int yMin = Integer.parseInt(strLoc.substring(strLoc.indexOf(",") + 1));
417 Point loc = new Point(x * 100 + xMin, y * 100 + yMin);
418 SpawnPoint sp = new SpawnPoint(type, loc, Integer.parseInt(in.readLine()), Integer.parseInt(in.readLine()));
419 spawnPoints.add(sp);
420 }
421 in.close();
422 } catch (IOException ioe) {
423 ioe.printStackTrace();
424 }
425 }
426
427 private void loadItems() {
428 items = new HashMap<String, Item>();
429 this.drops = new LinkedList<Item>();
430 this.projectiles = new LinkedList<Projectile>();
431 this.gems = new LinkedList<Gem>();
432 try {
433 imgBow = new BufferedImage[8];
434 imgBow[0] = ImageIO.read(getClass().getResource("../images/projectiles/bowNN.png"));
435 imgBow[1] = ImageIO.read(getClass().getResource("../images/projectiles/bowNE.png"));
436 imgBow[2] = ImageIO.read(getClass().getResource("../images/projectiles/bowEE.png"));
437 imgBow[3] = ImageIO.read(getClass().getResource("../images/projectiles/bowSE.png"));
438 imgBow[4] = ImageIO.read(getClass().getResource("../images/projectiles/bowSS.png"));
439 imgBow[5] = ImageIO.read(getClass().getResource("../images/projectiles/bowSW.png"));
440 imgBow[6] = ImageIO.read(getClass().getResource("../images/projectiles/bowWW.png"));
441 imgBow[7] = ImageIO.read(getClass().getResource("../images/projectiles/bowNW.png"));
442 BufferedReader in = new BufferedReader(new FileReader("items.txt"));
443 while (in.ready()) {
444 Item item;
445 int attackSpeed, range, damage, value;
446 String name = in.readLine();
447 String img = String.valueOf(in.readLine()) + ".png";
448 ItemType type = ItemType.valueOf(in.readLine());
449 String desc = in.readLine();
450 BufferedImage[] imgProj = new BufferedImage[8];
451 switch (type) {
452 case LightWeapon:
453 case HeavyWeapon:
454 attackSpeed = Integer.valueOf(in.readLine()).intValue();
455 damage = Integer.valueOf(in.readLine()).intValue();
456 item = new Weapon(name, type, img, null, attackSpeed, 55, damage);
457 break;
458 case RangedWeapon:
459 attackSpeed = Integer.valueOf(in.readLine()).intValue();
460 range = Integer.valueOf(in.readLine()).intValue();
461 damage = Integer.valueOf(in.readLine()).intValue();
462 imgProj = imgBow;
463 item = new Weapon(name, type, img, imgProj, attackSpeed, range, damage);
464 break;
465 case Gem:
466 value = Integer.valueOf(in.readLine()).intValue();
467 item = new Gem(name, img, value, null);
468 this.gems.add((Gem)item);
469 break;
470 default:
471 item = new Item(name, type, img);
472 break;
473 }
474 item.setDescription(desc);
475 items.put(name, item);
476 }
477 in.close();
478 } catch (IOException ioe) {
479 ioe.printStackTrace();
480 }
481 }
482
483 private void loadSpellSprites() {
484 airSprites = loadSprites("air");
485 earthSprites = loadSprites("earth");
486 fireSprites = loadSprites("fire");
487 waterSprites = loadSprites("water");
488 try {
489 passiveAura = ImageIO.read(getClass().getResource("../images/spells/auras/passiveAura.png"));
490 thornsAura = ImageIO.read(getClass().getResource("../images/spells/auras/thornsAura.png"));
491 confuseAura = ImageIO.read(getClass().getResource("../images/spells/auras/confuseAura.png"));
492 sandAura = ImageIO.read(getClass().getResource("../images/spells/auras/sandAura.png"));
493 } catch (IOException ioe) {
494 ioe.printStackTrace();
495 }
496 }
497
498 private BufferedImage[] loadSprites(String name) {
499 BufferedImage[] sprites = new BufferedImage[8];
500 try {
501 sprites[0] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellNN.png"));
502 sprites[1] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellNE.png"));
503 sprites[2] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellEE.png"));
504 sprites[3] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellSE.png"));
505 sprites[4] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellSS.png"));
506 sprites[5] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellSW.png"));
507 sprites[6] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellWW.png"));
508 sprites[7] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellNW.png"));
509 } catch (IOException ioe) {
510 ioe.printStackTrace();
511 }
512 return sprites;
513 }
514
515 public static SpawnPoint getSpawnPoint(int idNum) {
516 if (idNum == -1)
517 return null;
518 Iterator<SpawnPoint> iter = spawnPoints.iterator();
519 while (iter.hasNext()) {
520 SpawnPoint sp;
521 if ((sp = iter.next()).idNum == idNum)
522 return sp;
523 }
524 return null;
525 }
526
527 private void spawnCreatures() {
528 Iterator<SpawnPoint> iter = spawnPoints.iterator();
529 while (iter.hasNext()) {
530 SpawnPoint sp = iter.next();
531 if (Point.dist(this.player.getLoc(), sp.getLoc()) >= 600.0D) {
532 Creature cr = sp.spawn();
533 if (cr != null)
534 map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).addCreature(cr);
535 }
536 }
537 }
538
539 private void moveCreatures() {
540 int xLow = this.player.getLoc().getX() / 100 - 8;
541 int xHigh = xLow + 17;
542 int yLow = this.player.getLoc().getY() / 100 - 6;
543 int yHigh = yLow + 13;
544 if (xLow < 0)
545 xLow = 0;
546 if (xHigh > map.getLength())
547 xHigh = map.getLength();
548 if (yLow < 0)
549 yLow = 0;
550 if (yHigh > map.getHeight())
551 yHigh = map.getHeight();
552 for (int x = 0; x < map.getLength(); x++) {
553 for (int y = 0; y < map.getHeight(); y++) {
554 Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator();
555 while (iter.hasNext()) {
556 Creature cr = iter.next();
557 if (cr != this.player)
558 if (cr.confused > 0) {
559 cr.setEnemyTarget(findClosestTarget(cr));
560 } else {
561 cr.setEnemyTarget(this.player);
562 }
563 if (cr.isDying() && cr.getModel().getAnimation(Direction.West, Action.Dying).reachedEnd()) {
564 cr.setDying(false);
565 if (cr == this.player) {
566 respawnPlayer();
567 continue;
568 }
569 if (cr.getType() == CreatureType.Specter)
570 this.gameState = GameState.Victory;
571 continue;
572 }
573 if (!cr.getModel().hasDeath() && cr.getHitpoints() <= 0) {
574 iter.remove();
575 continue;
576 }
577 move(cr);
578 if (cr.getLoc().getX() / 100 != x || cr.getLoc().getY() / 100 != y) {
579 iter.remove();
580 map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).addCreature(cr);
581 }
582 }
583 }
584 }
585 }
586
587 private void move(Creature cr) {
588 if (cr.isDying())
589 return;
590 Point newLoc = cr.move();
591 int minDist = 50;
592 boolean creatureBlocking = false;
593 cr.checkTimedEffects();
594 Iterator<Item> itemIter = this.drops.iterator();
595 while (itemIter.hasNext()) {
596 Item item = itemIter.next();
597 if (item.getLoc().equals(this.player.getLoc())) {
598 this.player.pickUp(item);
599 itemIter.remove();
600 }
601 }
602 int xLow = newLoc.getX() / 100 - 2;
603 int xHigh = xLow + 5;
604 int yLow = newLoc.getY() / 100 - 2;
605 int yHigh = yLow + 5;
606 if (xLow < 0)
607 xLow = 0;
608 if (xHigh > map.getLength())
609 xHigh = map.getLength();
610 if (yLow < 0)
611 yLow = 0;
612 if (yHigh > map.getHeight())
613 yHigh = map.getHeight();
614 for (int x = xLow; x < xHigh; x++) {
615 for (int y = yLow; y < yHigh; y++) {
616 Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator();
617 while (iter.hasNext()) {
618 Creature temp = iter.next();
619 if (cr.getEnemyTarget() == temp && Point.dist(temp.getLoc(), newLoc) <= cr.getWeapon().getRange()) {
620 creatureBlocking = true;
621 if (temp != this.player || !temp.isDying()) {
622 Projectile proj = cr.attack(temp, AttackType.Weapon);
623 if (proj != null) {
624 proj.setCreator(cr);
625 proj.applySpawnEffects();
626 addProjectile(proj);
627 continue;
628 }
629 if (temp.getHitpoints() <= 0) {
630 temp.setDying(true);
631 if (temp != this.player) {
632 killCreature(temp);
633 this.player.setEnemyTarget(null);
634 this.player.setTarget(this.player.getLoc());
635 }
636 }
637 }
638 continue;
639 }
640 if (temp != cr && Point.dist(temp.getLoc(), newLoc) < minDist)
641 creatureBlocking = true;
642 }
643 }
644 }
645 if (map.getLoc(newLoc.getX() / 100, newLoc.getY() / 100).isPassable() && !creatureBlocking && (!cr.farFromSpawnPoint() || cr.closerToSpawnPoint(newLoc))) {
646 Location oldLoc = map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100);
647 cr.setLoc(newLoc);
648 if (cr == this.player)
649 switch (map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).getStruct().getType()) {
650 case RespawnPoint:
651 ((RespawnPoint)map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).getStruct()).mark();
652 case RejuvenationPedestal:
653 this.player.setManapoints(this.player.getMaxManapoints());
654 case LifePedestal:
655 this.player.setHitpoints(this.player.getMaxHitpoints());
656 break;
657 case ManaPedestal:
658 this.player.setManapoints(this.player.getMaxManapoints());
659 break;
660 case BossPoint:
661 if (!this.player.readyForBoss())
662 break;
663 case ArtifactPoint:
664 if (oldLoc != map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100)) {
665 this.player.setLoc(((ArtifactPoint)map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).getStruct()).getTarget());
666 this.player.setTarget(this.player.getLoc());
667 }
668 break;
669 }
670 } else {
671 cr.setTarget(cr.getLoc());
672 if (cr.getModel().getAction() != Action.Attacking)
673 cr.getModel().setAction(Action.Standing);
674 }
675 }
676
677 private Creature findClosestTarget(Creature cr) {
678 int xLow = cr.getLoc().getX() / 100 - 5;
679 int xHigh = xLow + 11;
680 int yLow = cr.getLoc().getY() / 100 - 5;
681 int yHigh = yLow + 11;
682 Creature closestCr = this.player;
683 double minDist = Point.dist(cr.getLoc(), this.player.getLoc());
684 if (xLow < 0)
685 xLow = 0;
686 if (xHigh > map.getLength())
687 xHigh = map.getLength();
688 if (yLow < 0)
689 yLow = 0;
690 if (yHigh > map.getHeight())
691 yHigh = map.getHeight();
692 for (int x = xLow; x < xHigh; x++) {
693 for (int y = yLow; y < yHigh; y++) {
694 Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator();
695 while (iter.hasNext()) {
696 Creature cur = iter.next();
697 if (cr != cur && minDist > Point.dist(cr.getLoc(), cur.getLoc())) {
698 minDist = Point.dist(cr.getLoc(), cur.getLoc());
699 closestCr = cur;
700 }
701 }
702 }
703 }
704 return closestCr;
705 }
706
707 private synchronized void addProjectile(Projectile proj) {
708 this.projectiles.add(proj);
709 }
710
711 private synchronized void moveProjectiles() {
712 Iterator<Projectile> iter = this.projectiles.iterator();
713 while (iter.hasNext()) {
714 Projectile proj = iter.next();
715 move(proj);
716 if (proj.isDone())
717 iter.remove();
718 }
719 }
720
721 private void move(Projectile proj) {
722 Point newLoc = proj.move();
723 int minDist = 50;
724 for (int x = 0; x < map.getLength(); x++) {
725 for (int y = 0; y < map.getHeight(); y++) {
726 Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator();
727 while (iter.hasNext()) {
728 Creature cr = iter.next();
729 if (Point.dist(cr.getLoc(), newLoc) < minDist && ((cr == this.player && !proj.isPlayerOwned()) || (cr != this.player && proj.isPlayerOwned()))) {
730 if (!proj.penetrates())
731 proj.setDone(true);
732 if (!proj.creatureIsEffected(cr)) {
733 proj.applyContactEffects(cr);
734 proj.effectCreature(cr);
735 }
736 if (cr.getHitpoints() <= 0) {
737 cr.setDying(true);
738 if (cr != this.player) {
739 killCreature(cr);
740 this.player.setEnemyTarget(null);
741 this.player.setTarget(this.player.getLoc());
742 }
743 }
744 }
745 }
746 }
747 }
748 Location curLoc = map.getLoc(newLoc.getX() / 100, newLoc.getY() / 100);
749 if (proj.getTarget().equals(newLoc) || (!curLoc.isPassable() && curLoc.getLand().getType() != LandType.Ocean)) {
750 proj.setDone(true);
751 } else {
752 proj.setLoc(newLoc);
753 }
754 }
755
756 private void killCreature(Creature cr) {
757 Iterator<Item> itemIter = cr.spawnDrops().iterator();
758 while (itemIter.hasNext())
759 this.drops.add(((Item)itemIter.next()).copy(cr.getLoc()));
760 if (cr.getSpawnPoint() != null)
761 cr.getSpawnPoint().removeCreature();
762 this.player.setExperience(this.player.getExperience() + cr.getExperience());
763 if (this.player.getExperience() >= (Math.pow(this.player.getLevel(), 2.0D) + this.player.getLevel()) * 500.0D) {
764 this.player.setExperience(this.player.getExperience() - (int)((Math.pow(this.player.getLevel(), 2.0D) + this.player.getLevel()) * 500.0D));
765 this.player.increaseLevel();
766 }
767 }
768
769 public void respawnPlayer() {
770 Iterator<RespawnPoint> iter = respawnPoints.iterator();
771 RespawnPoint closest = null;
772 double dist = 0.0D;
773 this.player.setHitpoints(this.player.getMaxHitpoints());
774 this.player.setManapoints(this.player.getMaxManapoints());
775 while (iter.hasNext()) {
776 RespawnPoint cur = iter.next();
777 if (cur.isMarked() && (closest == null || dist > Point.dist(cur.getLoc(), this.player.getLoc()))) {
778 closest = cur;
779 dist = Point.dist(cur.getLoc(), this.player.getLoc());
780 }
781 }
782 if (closest == null) {
783 this.player.setLoc(this.startPoint);
784 } else {
785 this.player.setLoc(closest.getLoc());
786 }
787 this.player.setEnemyTarget(null);
788 this.player.setTarget(this.player.getLoc());
789 }
790
791 private void handleEvents() {
792 switch (this.gameState) {
793 case Game:
794 case GameMenu:
795 case GameStats:
796 case GameGems:
797 case GameInventory:
798 case GameMap:
799 spawnCreatures();
800 moveCreatures();
801 moveProjectiles();
802 break;
803 }
804 }
805
806 private void render(Graphics g) {
807 g.setColor(Color.black);
808 g.fillRect(0, 0, 800, 600);
809 switch (this.gameState) {
810 case Main:
811 drawMain(g);
812 break;
813 case CreateAccount:
814 drawCreateAccount(g);
815 break;
816 case LoadGame:
817 drawLoadGame(g);
818 break;
819 case Info:
820 drawInfo(g);
821 break;
822 case Credits:
823 drawCredits(g);
824 break;
825 case Victory:
826 this.wndVictory.draw(g);
827 break;
828 case GameIntro:
829 this.wndGameIntro.draw(g);
830 break;
831 case GameInfo:
832 this.wndTutorials[this.wndTutCur].draw(g);
833 break;
834 case Game:
835 drawMap(g);
836 drawItems(g);
837 drawCreatures(g);
838 drawProjectiles(g);
839 drawStatDisplay(g);
840 break;
841 case GameMenu:
842 drawMap(g);
843 drawItems(g);
844 drawCreatures(g);
845 drawProjectiles(g);
846 drawStatDisplay(g);
847 drawGameMenu(g);
848 break;
849 case GameStats:
850 drawMap(g);
851 drawItems(g);
852 drawCreatures(g);
853 drawProjectiles(g);
854 drawStatDisplay(g);
855 drawGameStats(g);
856 break;
857 case GameGems:
858 drawMap(g);
859 drawItems(g);
860 drawCreatures(g);
861 drawProjectiles(g);
862 drawStatDisplay(g);
863 drawGameGems(g);
864 break;
865 case GameInventory:
866 drawMap(g);
867 drawItems(g);
868 drawCreatures(g);
869 drawProjectiles(g);
870 drawStatDisplay(g);
871 drawGameInventory(g);
872 break;
873 case GameMap:
874 drawMap(g);
875 drawItems(g);
876 drawCreatures(g);
877 drawProjectiles(g);
878 drawStatDisplay(g);
879 drawGameMap(g);
880 break;
881 }
882 switch (this.auxState) {
883 case MsgBox:
884 this.wndMessage.draw(g);
885 break;
886 }
887 }
888
889 public void save() {
890 PrintWriter out = null;
891 try {
892 out = new PrintWriter(new FileWriter("save.txt"));
893 for (int x = 0; x < map.getLength(); x++) {
894 for (int y = 0; y < map.getHeight(); y++) {
895 Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator();
896 while (iter.hasNext()) {
897 Creature cr = iter.next();
898 cr.save(out);
899 }
900 }
901 }
902 out.close();
903 out = new PrintWriter(new FileWriter("savedItems.txt"));
904 Iterator<Item> itrItem = this.drops.iterator();
905 while (itrItem.hasNext()) {
906 Item cur = itrItem.next();
907 out.println(cur.getName());
908 out.println(String.valueOf(cur.getLoc().getX()) + "," + cur.getLoc().getY());
909 }
910 out.close();
911 } catch (IOException ioe) {
912 ioe.printStackTrace();
913 }
914 }
915
916 public void reset() {
917 this.drops.clear();
918 this.projectiles.clear();
919 map.clearCreatures();
920 lstInventory.clear();
921 Iterator<SpawnPoint> iter = spawnPoints.iterator();
922 while (iter.hasNext())
923 ((SpawnPoint)iter.next()).clear();
924 SpawnPoint.numSpawnPoints = 0;
925 Iterator<RespawnPoint> rpIter = respawnPoints.iterator();
926 while (rpIter.hasNext())
927 ((RespawnPoint)rpIter.next()).unmark();
928 }
929
930 public void placeQuestObjects() {
931 this.drops.add(((Item)items.get("Power Sword")).copy(new Point(1650, 150)));
932 this.drops.add(((Item)items.get("Ice Scroll")).copy(new Point(3250, 150)));
933 this.drops.add(((Item)items.get("BNW Shirt")).copy(new Point(4950, 250)));
934 this.drops.add(((Item)items.get("Studded Leather Armor")).copy(new Point(6750, 150)));
935 this.drops.add(((Item)items.get("Patched Leather")).copy(new Point(8450, 150)));
936 this.drops.add(((Item)items.get("Fire Scroll")).copy(new Point(1650, 1450)));
937 Creature cr = ((Creature)creatureMap.get(CreatureType.Specter)).copy();
938 cr.setLoc(new Point(15850, 350));
939 map.getLoc(158, 3).addCreature(cr);
940 }
941
942 public boolean load() {
943 reset();
944 try {
945 BufferedReader in = new BufferedReader(new FileReader("save.txt"));
946 while (in.ready()) {
947 CreatureType type = CreatureType.valueOf(in.readLine());
948 Creature cr = ((Creature)creatureMap.get(type)).copy();
949 cr.load(in);
950 if (cr.getType() == CreatureType.Player)
951 this.player = (Player)cr;
952 map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).addCreature(cr);
953 }
954 Iterator<Creature> iter = map.getLoc(this.player.getTarget().getX() / 100, this.player.getTarget().getY() / 100).getCreatures().iterator();
955 while (iter.hasNext()) {
956 Creature cr2 = iter.next();
957 if (cr2.getLoc().equals(this.player.getTarget()) && cr2 != this.player)
958 this.player.setEnemyTarget(cr2);
959 }
960 in.close();
961 in = new BufferedReader(new FileReader("savedItems.txt"));
962 while (in.ready()) {
963 Item cur = items.get(in.readLine());
964 String loc = in.readLine();
965 int x = Integer.parseInt(loc.substring(0, loc.indexOf(",")));
966 int y = Integer.parseInt(loc.substring(loc.indexOf(",") + 1));
967 this.drops.add(cur.copy(new Point(x, y)));
968 }
969 in.close();
970 } catch (FileNotFoundException fnfe) {
971 showMessage("There is no saved game to load");
972 return false;
973 } catch (IOException ioe) {
974 ioe.printStackTrace();
975 return false;
976 }
977 return true;
978 }
979
980 public static String dateString() {
981 return (new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")).format(new Date());
982 }
983
984 public void showMessage(String text) {
985 this.auxState = AuxState.MsgBox;
986 ((Label)this.wndMessage.getMember("label")).setText(text);
987 }
988
989 private void drawMain(Graphics g) {
990 this.wndMain.draw(g);
991 g.setColor(Color.red);
992 g.drawRect(10, 100, 380, 490);
993 g.drawRect(410, 100, 380, 490);
994 }
995
996 private void drawCreateAccount(Graphics g) {
997 ((Label)this.wndCreateAccount.getMember("strVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Strength)));
998 ((Label)this.wndCreateAccount.getMember("dexVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Dexterity)));
999 ((Label)this.wndCreateAccount.getMember("conVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Constitution)));
1000 ((Label)this.wndCreateAccount.getMember("wisVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Wisdom)));
1001 ((Label)this.wndCreateAccount.getMember("attVal")).setText(Integer.toString(this.player.getAttributePoints()));
1002 ((Label)this.wndCreateAccount.getMember("lightWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.LightWeapons)));
1003 ((Label)this.wndCreateAccount.getMember("heavyWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.HeavyWeapons)));
1004 ((Label)this.wndCreateAccount.getMember("rangedWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.RangedWeapons)));
1005 ((Label)this.wndCreateAccount.getMember("evocationVal")).setText(Integer.toString(this.player.getSkill(Skill.Evocation)));
1006 ((Label)this.wndCreateAccount.getMember("skillVal")).setText(Integer.toString(this.player.getSkillPoints()));
1007 this.wndCreateAccount.draw(g);
1008 }
1009
1010 private void drawLoadGame(Graphics g) {
1011 Font tempFont = new Font("Arial", 0, 12);
1012 FontMetrics metrics = g.getFontMetrics(tempFont);
1013 g.setFont(tempFont);
1014 g.setColor(Color.green);
1015 g.drawString("There is not a whole lot here right now. You can click anywhere on the screen to get back to the main menu.", 0, metrics.getHeight());
1016 }
1017
1018 private void drawInfo(Graphics g) {
1019 if (this.infoStart) {
1020 this.wndGameIntro.draw(g);
1021 } else {
1022 this.wndTutorials[this.wndTutCur].draw(g);
1023 }
1024 }
1025
1026 private void drawCredits(Graphics g) {
1027 this.wndCredits.draw(g);
1028 }
1029
1030 private void drawMap(Graphics g) {
1031 int locX = this.player.getLoc().getX();
1032 int locY = this.player.getLoc().getY();
1033 int xLow = locX / 100 - 5;
1034 int xHigh = xLow + 11;
1035 int yLow = locY / 100 - 4;
1036 int yHigh = yLow + 9;
1037 if (xLow < 0)
1038 xLow = 0;
1039 if (xHigh > map.getLength())
1040 xHigh = map.getLength();
1041 if (yLow < 0)
1042 yLow = 0;
1043 if (yHigh > map.getHeight())
1044 yHigh = map.getHeight();
1045 int x;
1046 for (x = xLow; x < xHigh; x++) {
1047 for (int y = yLow; y < yHigh; y++) {
1048 if (map.getLoc(x, y).getLand().getType() != LandType.Mountains && map.getLoc(x, y).getLand().getType() != LandType.Cave) {
1049 g.drawImage(map.getLoc(x, y).getLand().getImg(), 400 + x * 100 - locX, 300 + y * 100 - locY, null);
1050 g.drawImage(map.getLoc(x, y).getStruct().getImg(), 400 + x * 100 - locX, 300 + y * 100 - locY, null);
1051 } else {
1052 g.drawImage(((Land)landMap.get(LandType.Metal)).getImg(), 400 + x * 100 - locX, 300 + y * 100 - locY, null);
1053 }
1054 }
1055 }
1056 for (x = xLow; x < xHigh; x++) {
1057 for (int y = yLow; y < yHigh; y++) {
1058 if (map.getLoc(x, y).getLand().getType() == LandType.Mountains || map.getLoc(x, y).getLand().getType() == LandType.Cave)
1059 g.drawImage(map.getLoc(x, y).getLand().getImg(), 390 + x * 100 - locX, 290 + y * 100 - locY, null);
1060 }
1061 }
1062 }
1063
1064 private void drawItems(Graphics g) {
1065 Iterator<Item> iter = this.drops.iterator();
1066 while (iter.hasNext())
1067 ((Item)iter.next()).draw(g, this.player.getLoc().getX(), this.player.getLoc().getY());
1068 }
1069
1070 private synchronized void drawProjectiles(Graphics g) {
1071 Iterator<Projectile> iter = this.projectiles.iterator();
1072 while (iter.hasNext())
1073 ((Projectile)iter.next()).draw(g, this.player.getLoc().getX(), this.player.getLoc().getY());
1074 }
1075
1076 private void drawCreatures(Graphics g) {
1077 int xLow = this.player.getLoc().getX() / 100 - 5;
1078 int xHigh = xLow + 11;
1079 int yLow = this.player.getLoc().getY() / 100 - 4;
1080 int yHigh = yLow + 9;
1081 if (xLow < 0)
1082 xLow = 0;
1083 if (xHigh > map.getLength())
1084 xHigh = map.getLength();
1085 if (yLow < 0)
1086 yLow = 0;
1087 if (yHigh > map.getHeight())
1088 yHigh = map.getHeight();
1089 for (int x = xLow; x < xHigh; x++) {
1090 for (int y = yLow; y < yHigh; y++) {
1091 Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator();
1092 while (iter.hasNext())
1093 ((Creature)iter.next()).draw(g, this.player.getLoc().getX(), this.player.getLoc().getY());
1094 }
1095 }
1096 }
1097
1098 private void drawStatDisplay(Graphics g) {
1099 this.lblGemVal.setText("Gem Value: " + this.player.getGemValue());
1100 this.lblSpellCost.setText("Spell Cost: " + ((this.player.getGemValue() + 1) / 2));
1101 this.wndStatDisplay.draw(g);
1102 g.drawString(this.player.getName(), 20, 562);
1103 g.drawString("Level " + this.player.getLevel(), 20, 574);
1104 g.drawString("Relics Acquired: " + this.player.getRelicCount() + "/4", 20, 591);
1105 g.setColor(Color.yellow);
1106 g.drawRect(240, 578, 80, 15);
1107 g.fillRect(240, 578, 80 * this.player.getExperience() / (int)((Math.pow(this.player.getLevel(), 2.0D) + this.player.getLevel()) * 500.0D), 15);
1108 g.setColor(Color.green);
1109 g.drawRect(125, 557, 80, 15);
1110 g.fillRect(125, 557, 80 * this.player.getHitpoints() / this.player.getMaxHitpoints(), 15);
1111 g.setColor(Color.blue);
1112 g.drawRect(240, 557, 80, 15);
1113 g.fillRect(240, 557, 80 * this.player.getManapoints() / this.player.getMaxManapoints(), 15);
1114 g.setColor(Color.red);
1115 g.drawString("HP:", 100, 569);
1116 g.drawString("MP:", 215, 569);
1117 g.drawString("Experience:", 170, 591);
1118 g.drawString(String.valueOf(this.player.getExperience()) + "/" + ((int)(Math.pow(this.player.getLevel(), 2.0D) + this.player.getLevel()) * 500), 245, 590);
1119 g.drawString(String.valueOf(this.player.getHitpoints()) + "/" + this.player.getMaxHitpoints(), 130, 569);
1120 g.drawString(String.valueOf(this.player.getManapoints()) + "/" + this.player.getMaxManapoints(), 245, 569);
1121 this.player.getWeapon().drawStatic(g, 450 + this.wndStatDisplay.getX(), this.wndStatDisplay.getY());
1122 int mouseX = (MouseInfo.getPointerInfo().getLocation()).x;
1123 int mouseY = (MouseInfo.getPointerInfo().getLocation()).y;
1124 if (450 + this.wndStatDisplay.getX() <= mouseX && mouseX < 500 + this.wndStatDisplay.getX() && this.wndStatDisplay.getY() <= mouseY && mouseY < 50 + this.wndStatDisplay.getY()) {
1125 String itemType;
1126 Item i = (this.player.getWeapon()).baseWeapon;
1127 Window popup = new Window("popup", mouseX - 126, mouseY - 100, 126, 100, false);
1128 Font font12 = new Font("Arial", 0, 12);
1129 switch (i.getType()) {
1130 case LightWeapon:
1131 itemType = "Light Weapon";
1132 break;
1133 case HeavyWeapon:
1134 itemType = "Heavy Weapon";
1135 break;
1136 case RangedWeapon:
1137 itemType = "Ranged Weapon";
1138 break;
1139 default:
1140 itemType = i.getType().toString();
1141 break;
1142 }
1143 popup.add(new Label("info", 8, 5, 110, 15, "Equipped Weapon", font12));
1144 popup.add(new Label("name", 8, 20, 110, 15, i.getName(), font12));
1145 popup.add(new Label("type", 8, 50, 110, 15, itemType, font12));
1146 popup.add(new Label("damage", 8, 65, 110, 15, "Damage: " + ((Weapon)i).getDamage() + "(" + this.player.getWeapon().getDamage() + ")", font12));
1147 popup.add(new Label("damage", 8, 80, 110, 15, "Cooldown: " + (((Weapon)i).getAttackSpeed() / 10.0D) + "(" + (this.player.getWeapon().getAttackSpeed() / 10.0D) + ")" + " s", font12));
1148 popup.draw(g);
1149 }
1150 }
1151
1152 private void drawGameMenu(Graphics g) {}
1153
1154 private void drawGameStats(Graphics g) {
1155 ((Label)this.wndGameStats.getMember("strVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Strength)));
1156 ((Label)this.wndGameStats.getMember("dexVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Dexterity)));
1157 ((Label)this.wndGameStats.getMember("conVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Constitution)));
1158 ((Label)this.wndGameStats.getMember("wisVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Wisdom)));
1159 ((Label)this.wndGameStats.getMember("lightWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.LightWeapons)));
1160 ((Label)this.wndGameStats.getMember("heavyWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.HeavyWeapons)));
1161 ((Label)this.wndGameStats.getMember("rangedWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.RangedWeapons)));
1162 ((Label)this.wndGameStats.getMember("evocationVal")).setText(Integer.toString(this.player.getSkill(Skill.Evocation)));
1163 ((Label)this.wndGameStats.getMember("skillVal")).setText(Integer.toString(this.player.getSkillPoints()));
1164 this.wndGameStats.draw(g);
1165 }
1166
1167 private void drawGameGems(Graphics g) {
1168 this.wndGameGems.draw(g);
1169 int mouseX = (MouseInfo.getPointerInfo().getLocation()).x;
1170 int mouseY = (MouseInfo.getPointerInfo().getLocation()).y;
1171 Window w = this.wndGameGems;
1172 if (w.getX() < mouseX && mouseX < w.getX() + w.getWidth() - 20 && w.getY() < mouseY && mouseY < w.getY() + w.getHeight())
1173 this.player.drawInventory(g, lstGems, this.wndGameGems.getX() + 1, this.wndGameGems.getY() + 1);
1174 }
1175
1176 private void drawGameInventory(Graphics g) {
1177 this.wndGameInventory.draw(g);
1178 int mouseX = (MouseInfo.getPointerInfo().getLocation()).x;
1179 int mouseY = (MouseInfo.getPointerInfo().getLocation()).y;
1180 Window w = this.wndGameInventory;
1181 if (w.getX() < mouseX && mouseX < w.getX() + w.getWidth() - 20 && w.getY() < mouseY && mouseY < w.getY() + w.getHeight())
1182 this.player.drawInventory(g, lstInventory, this.wndGameInventory.getX() + 1, this.wndGameInventory.getY() + 1);
1183 }
1184
1185 private void drawGameMap(Graphics g) {
1186 this.wndGameMap.draw(g);
1187 g.drawImage(this.imgMap, this.wndGameMap.getX() + 10, this.wndGameMap.getY() + 10, null);
1188 }
1189
1190 private void selectText(Textbox text) {
1191 if (this.selectedText != null)
1192 this.selectedText.setSelected(false);
1193 this.selectedText = text;
1194 if (text != null)
1195 text.setSelected(true);
1196 }
1197
1198 private static DisplayMode getBestDisplayMode(GraphicsDevice device) {
1199 for (int x = 0; x < BEST_DISPLAY_MODES.length; x++) {
1200 DisplayMode[] modes = device.getDisplayModes();
1201 for (int i = 0; i < modes.length; i++) {
1202 if (modes[i].getWidth() == BEST_DISPLAY_MODES[x].getWidth() && modes[i].getHeight() == BEST_DISPLAY_MODES[x].getHeight() && modes[i].getBitDepth() == BEST_DISPLAY_MODES[x].getBitDepth())
1203 return BEST_DISPLAY_MODES[x];
1204 }
1205 }
1206 return null;
1207 }
1208
1209 public static void chooseBestDisplayMode(GraphicsDevice device) {
1210 DisplayMode best = getBestDisplayMode(device);
1211 if (best != null)
1212 device.setDisplayMode(best);
1213 }
1214
1215 public void mousePressed(MouseEvent e) {
1216 boolean targetSet;
1217 if (!this.started)
1218 return;
1219 switch (this.auxState) {
1220 case None:
1221 switch (this.gameState) {
1222 case Main:
1223 if (this.wndMain.getMember("new game").isClicked(e.getX(), e.getY())) {
1224 this.player = (Player)((Creature)creatureMap.get(CreatureType.Player)).copy();
1225 this.gameState = GameState.CreateAccount;
1226 break;
1227 }
1228 if (this.wndMain.getMember("load game").isClicked(e.getX(), e.getY())) {
1229 if (load()) {
1230 this.player.setTimeLoggedOn(System.currentTimeMillis());
1231 this.gameState = GameState.Game;
1232 }
1233 break;
1234 }
1235 if (this.wndMain.getMember("game info").isClicked(e.getX(), e.getY())) {
1236 this.infoStart = true;
1237 this.gameState = GameState.Info;
1238 break;
1239 }
1240 if (this.wndMain.getMember("credits").isClicked(e.getX(), e.getY())) {
1241 this.gameState = GameState.Credits;
1242 break;
1243 }
1244 if (this.wndMain.getMember("quit").isClicked(e.getX(), e.getY()))
1245 this.done = true;
1246 break;
1247 case CreateAccount:
1248 if (this.wndCreateAccount.getMember("user").isClicked(e.getX(), e.getY())) {
1249 selectText((Textbox)this.wndCreateAccount.getMember("user"));
1250 break;
1251 }
1252 if (this.wndCreateAccount.getMember("create").isClicked(e.getX(), e.getY())) {
1253 String user = ((Textbox)this.wndCreateAccount.getMember("user")).getText();
1254 if (user.equals("")) {
1255 showMessage("The username is empty");
1256 break;
1257 }
1258 if (this.player.getAttributePoints() > 0) {
1259 showMessage("You still have attribute points remaining");
1260 break;
1261 }
1262 if (this.player.getSkillPoints() > 0) {
1263 showMessage("You still have skill points remaining");
1264 break;
1265 }
1266 this.wndCreateAccount.clear();
1267 reset();
1268 placeQuestObjects();
1269 this.player.setName(user);
1270 this.player.setLoc(this.startPoint);
1271 this.player.setTarget(this.player.getLoc());
1272 this.player.setWeapon((Weapon)items.get("Branch"));
1273 this.player.pickUp((this.player.getWeapon()).baseWeapon);
1274 map.getLoc(this.startPoint.getX() / 100, this.startPoint.getY() / 100).addCreature(this.player);
1275 this.gameState = GameState.GameIntro;
1276 break;
1277 }
1278 if (this.wndCreateAccount.getMember("cancel").isClicked(e.getX(), e.getY())) {
1279 selectText(null);
1280 this.wndCreateAccount.clear();
1281 this.gameState = GameState.Main;
1282 break;
1283 }
1284 if (this.wndCreateAccount.getMember("strength-").isClicked(e.getX(), e.getY())) {
1285 this.player.repickAttribute(Attribute.Strength);
1286 break;
1287 }
1288 if (this.wndCreateAccount.getMember("strength+").isClicked(e.getX(), e.getY())) {
1289 this.player.allocateAttribute(Attribute.Strength);
1290 break;
1291 }
1292 if (this.wndCreateAccount.getMember("dexterity-").isClicked(e.getX(), e.getY())) {
1293 this.player.repickAttribute(Attribute.Dexterity);
1294 break;
1295 }
1296 if (this.wndCreateAccount.getMember("dexterity+").isClicked(e.getX(), e.getY())) {
1297 this.player.allocateAttribute(Attribute.Dexterity);
1298 break;
1299 }
1300 if (this.wndCreateAccount.getMember("constitution-").isClicked(e.getX(), e.getY())) {
1301 this.player.repickAttribute(Attribute.Constitution);
1302 break;
1303 }
1304 if (this.wndCreateAccount.getMember("constitution+").isClicked(e.getX(), e.getY())) {
1305 this.player.allocateAttribute(Attribute.Constitution);
1306 break;
1307 }
1308 if (this.wndCreateAccount.getMember("wisdom-").isClicked(e.getX(), e.getY())) {
1309 this.player.repickAttribute(Attribute.Wisdom);
1310 break;
1311 }
1312 if (this.wndCreateAccount.getMember("wisdom+").isClicked(e.getX(), e.getY())) {
1313 this.player.allocateAttribute(Attribute.Wisdom);
1314 break;
1315 }
1316 if (this.wndCreateAccount.getMember("lightWeapon-").isClicked(e.getX(), e.getY())) {
1317 this.player.repickSkill(Skill.LightWeapons);
1318 break;
1319 }
1320 if (this.wndCreateAccount.getMember("lightWeapon+").isClicked(e.getX(), e.getY())) {
1321 this.player.allocateSkill(Skill.LightWeapons);
1322 break;
1323 }
1324 if (this.wndCreateAccount.getMember("heavyWeapon-").isClicked(e.getX(), e.getY())) {
1325 this.player.repickSkill(Skill.HeavyWeapons);
1326 break;
1327 }
1328 if (this.wndCreateAccount.getMember("heavyWeapon+").isClicked(e.getX(), e.getY())) {
1329 this.player.allocateSkill(Skill.HeavyWeapons);
1330 break;
1331 }
1332 if (this.wndCreateAccount.getMember("rangedWeapon-").isClicked(e.getX(), e.getY())) {
1333 this.player.repickSkill(Skill.RangedWeapons);
1334 break;
1335 }
1336 if (this.wndCreateAccount.getMember("rangedWeapon+").isClicked(e.getX(), e.getY())) {
1337 this.player.allocateSkill(Skill.RangedWeapons);
1338 break;
1339 }
1340 if (this.wndCreateAccount.getMember("evocation-").isClicked(e.getX(), e.getY())) {
1341 this.player.repickSkill(Skill.Evocation);
1342 break;
1343 }
1344 if (this.wndCreateAccount.getMember("evocation+").isClicked(e.getX(), e.getY())) {
1345 this.player.allocateSkill(Skill.Evocation);
1346 break;
1347 }
1348 this.wndCreateAccount.handleEvent(e);
1349 break;
1350 case Info:
1351 if (this.infoStart) {
1352 this.infoStart = false;
1353 break;
1354 }
1355 if (this.wndTutOptions.getMember("previous").isClicked(e.getX(), e.getY())) {
1356 if (this.wndTutCur != 0)
1357 this.wndTutCur--;
1358 } else if (this.wndTutOptions.getMember("next").isClicked(e.getX(), e.getY())) {
1359 this.wndTutCur++;
1360 if (this.wndTutCur > 12) {
1361 this.gameState = GameState.Main;
1362 this.wndTutCur = 0;
1363 }
1364 } else if (this.wndTutOptions.getMember("skip").isClicked(e.getX(), e.getY())) {
1365 this.gameState = GameState.Main;
1366 this.wndTutCur = 0;
1367 }
1368 ((Label)this.wndTutOptions.getMember("num")).setText(String.valueOf(this.wndTutCur + 1) + " / 13");
1369 break;
1370 case Credits:
1371 this.gameState = GameState.Main;
1372 break;
1373 case Victory:
1374 this.gameState = GameState.Credits;
1375 break;
1376 case GameIntro:
1377 this.gameState = GameState.GameInfo;
1378 break;
1379 case GameInfo:
1380 if (this.wndTutOptions.getMember("previous").isClicked(e.getX(), e.getY())) {
1381 if (this.wndTutCur != 0)
1382 this.wndTutCur--;
1383 } else if (this.wndTutOptions.getMember("next").isClicked(e.getX(), e.getY())) {
1384 this.wndTutCur++;
1385 if (this.wndTutCur > 12) {
1386 this.gameState = GameState.Game;
1387 this.player.setTimeLoggedOn(System.currentTimeMillis());
1388 this.wndTutCur = 0;
1389 }
1390 } else if (this.wndTutOptions.getMember("skip").isClicked(e.getX(), e.getY())) {
1391 this.gameState = GameState.Game;
1392 this.player.setTimeLoggedOn(System.currentTimeMillis());
1393 this.wndTutCur = 0;
1394 }
1395 ((Label)this.wndTutOptions.getMember("num")).setText(String.valueOf(this.wndTutCur + 1) + " / 13");
1396 break;
1397 case Game:
1398 targetSet = false;
1399 if (e.getY() < 550) {
1400 if (this.player.isDying())
1401 return;
1402 int newX = this.player.getLoc().getX() + e.getX() - 400;
1403 int newY = this.player.getLoc().getY() + e.getY() - 300;
1404 if (e.getButton() == 1) {
1405 Iterator<Item> itemIter = this.drops.iterator();
1406 while (itemIter.hasNext()) {
1407 Item item = itemIter.next();
1408 if (item.getLoc().getX() - 25 <= newX && newX <= item.getLoc().getX() + 25 &&
1409 item.getLoc().getY() - 25 <= newY && newY <= item.getLoc().getY() + 25) {
1410 this.player.setTarget(item.getLoc());
1411 targetSet = true;
1412 }
1413 }
1414 for (int x = 0; x < map.getLength(); x++) {
1415 for (int y = 0; y < map.getHeight(); y++) {
1416 Iterator<Creature> crIter = map.getLoc(x, y).getCreatures().iterator();
1417 while (crIter.hasNext()) {
1418 Creature cr = crIter.next();
1419 if (cr.getLoc().getX() - cr.getModel().getWidth() / 2 <= newX && newX <= cr.getLoc().getX() + cr.getModel().getWidth() / 2 && cr != this.player &&
1420 cr.getLoc().getY() - cr.getModel().getHeight() <= newY && newY <= cr.getLoc().getY()) {
1421 this.player.setEnemyTarget(cr);
1422 targetSet = true;
1423 }
1424 }
1425 }
1426 }
1427 if (map.getLoc((int)Math.floor((newX / 100)), (int)Math.floor((newY / 100))).isPassable() && !targetSet) {
1428 this.player.setTarget(new Point(newX, newY));
1429 this.player.setEnemyTarget(null);
1430 }
1431 if (this.player.getEnemyTarget() != null && this.player.getWeapon().getType() == ItemType.RangedWeapon) {
1432 Projectile proj = this.player.attack(this.player.getEnemyTarget(), AttackType.Weapon);
1433 if (proj != null) {
1434 proj.setCreator(this.player);
1435 proj.applySpawnEffects();
1436 addProjectile(proj);
1437 }
1438 this.player.setTarget(this.player.getLoc());
1439 this.player.setEnemyTarget(null);
1440 }
1441 break;
1442 }
1443 if (e.getButton() == 3 &&
1444 this.player.getSpell() != null && this.player.getManapoints() >= ((ManaDrain)this.player.getSpell().getSpawnEffect(EffectType.ManaDrain)).getMana()) {
1445 Point loc = new Point(this.player.getLoc());
1446 loc.setY(loc.getY() - 55);
1447 Projectile proj = this.player.attack(new Point(newX, newY), AttackType.Spell);
1448 if (proj != null) {
1449 proj.setCreator(this.player);
1450 proj.applySpawnEffects();
1451 addProjectile(proj);
1452 }
1453 }
1454 break;
1455 }
1456 if (this.btnMenu.isClicked(e.getX(), e.getY())) {
1457 this.gameState = GameState.Main;
1458 this.player.updateTimePlayed();
1459 save();
1460 break;
1461 }
1462 if (this.btnStats.isClicked(e.getX(), e.getY())) {
1463 this.gameState = GameState.GameStats;
1464 break;
1465 }
1466 if (this.btnGems.isClicked(e.getX(), e.getY())) {
1467 this.gameState = GameState.GameGems;
1468 break;
1469 }
1470 if (this.btnInventory.isClicked(e.getX(), e.getY())) {
1471 this.gameState = GameState.GameInventory;
1472 break;
1473 }
1474 if (this.btnMap.isClicked(e.getX(), e.getY()))
1475 this.gameState = GameState.GameMap;
1476 break;
1477 case GameStats:
1478 if (this.wndGameStats.getMember("lightWeapon+").isClicked(e.getX(), e.getY())) {
1479 this.player.allocateSkill(Skill.LightWeapons);
1480 break;
1481 }
1482 if (this.wndGameStats.getMember("heavyWeapon+").isClicked(e.getX(), e.getY())) {
1483 this.player.allocateSkill(Skill.HeavyWeapons);
1484 break;
1485 }
1486 if (this.wndGameStats.getMember("rangedWeapon+").isClicked(e.getX(), e.getY())) {
1487 this.player.allocateSkill(Skill.RangedWeapons);
1488 break;
1489 }
1490 if (this.wndGameStats.getMember("evocation+").isClicked(e.getX(), e.getY())) {
1491 this.player.allocateSkill(Skill.Evocation);
1492 break;
1493 }
1494 this.gameState = GameState.Game;
1495 break;
1496 case GameGems:
1497 if (this.wndGameGems.isClicked(e.getX(), e.getY())) {
1498 if (e.getX() < this.wndGameGems.getX() + this.wndGameGems.getWidth() - 20) {
1499 int x = (e.getX() - this.wndGameGems.getX() - 1) / 50;
1500 int y = (e.getY() - this.wndGameGems.getY() - 1 + lstGems.getTextStart()) / 50;
1501 if (x + 4 * y >= 0 && x + 4 * y < lstGems.getList().size()) {
1502 Item i = this.player.getGems().get(x + y * 4);
1503 switch (i.getType()) {
1504 case Gem:
1505 this.player.deactivateGem((Gem)i);
1506 break;
1507 }
1508 }
1509 }
1510 this.wndGameGems.handleEvent(e);
1511 break;
1512 }
1513 this.gameState = GameState.Game;
1514 break;
1515 case GameInventory:
1516 if (this.wndGameInventory.isClicked(e.getX(), e.getY())) {
1517 if (e.getX() < this.wndGameInventory.getX() + this.wndGameInventory.getWidth() - 20) {
1518 int x = (e.getX() - this.wndGameInventory.getX() - 1) / 50;
1519 int y = (e.getY() - this.wndGameInventory.getY() - 1 + lstInventory.getTextStart()) / 50;
1520 if (x + 4 * y >= 0 && x + 4 * y < this.player.getInventory().size()) {
1521 Item i = this.player.getInventory().get(x + y * 4);
1522 switch (i.getType()) {
1523 case HeavyWeapon:
1524 if (this.player.getAttribute(Attribute.Strength) < 12) {
1525 showMessage("You must have at least 12 Strength");
1526 break;
1527 }
1528 case LightWeapon:
1529 case RangedWeapon:
1530 this.player.setWeapon((Weapon)i);
1531 break;
1532 case Gem:
1533 if (!this.player.activateGem((Gem)i))
1534 showMessage("You must have a higher Evocation skill");
1535 break;
1536 }
1537 }
1538 }
1539 this.wndGameInventory.handleEvent(e);
1540 break;
1541 }
1542 this.gameState = GameState.Game;
1543 break;
1544 case GameMap:
1545 this.gameState = GameState.Game;
1546 break;
1547 }
1548 break;
1549 case MsgBox:
1550 if (this.wndMessage.getMember("button").isClicked(e.getX(), e.getY()))
1551 this.auxState = AuxState.None;
1552 break;
1553 }
1554 }
1555
1556 public void mouseReleased(MouseEvent e) {
1557 }
1558
1559 public void mouseEntered(MouseEvent e) {
1560 }
1561
1562 public void mouseExited(MouseEvent e) {
1563 }
1564
1565 public void mouseClicked(MouseEvent e) {
1566 }
1567
1568 public void keyTyped(KeyEvent e) {
1569 }
1570
1571 public void keyPressed(KeyEvent e) {
1572 if (this.selectedText != null)
1573 this.selectedText.handleEvent(e);
1574 if (e.getKeyCode() == 27)
1575 if (this.gameState == GameState.Game) {
1576 this.gameState = GameState.Main;
1577 save();
1578 } else {
1579 this.done = true;
1580 }
1581 }
1582
1583 public void keyReleased(KeyEvent e) {
1584 }
1585
1586 public static void main(String[] args) {
1587 try {
1588 PrintStream st = new PrintStream(new FileOutputStream("err.txt", true));
1589 System.setErr(st);
1590 System.setOut(st);
1591 System.out.println("-----[ Session started on " + dateString() + " ]-----");
1592 GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
1593 GraphicsDevice device = env.getDefaultScreenDevice();
1594 new LostHavenRPG(device);
1595 } catch (Exception e) {
1596 e.printStackTrace();
1597 }
1598 System.exit(0);
1599 }
1600}
Note: See TracBrowser for help on using the repository browser.