diff --git a/Bugs and things to do.txt b/Bugs and things to do.txt index 88c899c3a..b14cba3c4 100644 --- a/Bugs and things to do.txt +++ b/Bugs and things to do.txt @@ -1,12 +1,15 @@ ---Quick TODO's--- -continue commeting code -(see note about canWool in Entity.java) +-display current player score in score mode Note to self: for more little bugs/ideas/concerns, search code for "TODO" ----------------------------------------------------------------------------------- ####BUGS#### #### +Mobs hits prevent you from moving, and Skeleton arrows go through trees (only Player arrows should go through trees, in debug mode). +#### Sound effects don't always play when they should; mostly it seems when other sounds should be on at the same time. #### new worlds use the current/previous keyboard presets, rather than the default ones, when creating a new world after loading a previous one. @@ -27,6 +30,14 @@ wierd unreprodoucable glitch: game screen went all gray for a second after press ****IDEAS(that should probably be implemented)**** **** +Make respawn without bed += 20 blocks x/y of last spawn. + +**** + +Make a Chest class, with sub-classes DungeonChest and DeathChest. + +**** + There's a lot to do in the Tile classes... many methods have many unnecessary parameters... and the torch effects account for all the "light" and "torch" static tiles in Tile.java. I think I'll make a HashMap out of that list, as well. **** @@ -42,15 +53,11 @@ I have a system in place to save custom key controls, but lack the menu to edit **** -Make the loading system more forgiving, so that if I add a requirement to the save files, the old ones will still work. The idea is that when it expects 5 options and only finds 4, it just keeps those at default. - -**** - ----------------------------------------------------------------------------------- *?*?*?* Questionable Improvements (But still seem important)*?*?*?* -remove OptionsMenu from title screen? All the features, besides sound, perhaps, seem like they should be world-specific... well.... actually, they should be *user* specific... but "users" aren't a thing at the moment, so I just assume that different worlds are different users. That probably needs to change... for now, though, I'll just leave it be. +Move OptionsMenu loads to a "profile" save, one that applies to all worlds, and that is loaded on startup. Whether the airwizard suit is worn will probably be part of these options, both because it makes sense, and becuase it simplifies things. *?*?*?* @@ -65,3 +72,12 @@ I don't know... *?*?*?* +Fix up the write system, here and there: Menu writeCentered() should write the given text in the center x of the menu window; Screen writeCentered() should write a string centered in the screen's x. Font should not do anything with centering, instead, maybe it should have a drawShadowed() method? It should have a default text color, too, maybe... +How about, just overload them all... whatever's provided, is used. Though, since they're all ints, that may not work too well... + +*?*?*?* + +Change saving/loading system dramatically... instead of a simple array, make loadFromFile load HashMaps! I probably love them too much... but that way, future changes would be WAY easier to account for; instead of changing ALL the indexes, I could just stop worrying about a name! or change it. But... this has it's downsides. Entities wouldn't go over well; they really are better off as lists... +Hey! maybe I can keep that one, and just make another loader for loadGame and such! That might work! + +*?*?*?* \ No newline at end of file diff --git a/ChangeLog.txt b/ChangeLog.txt index 2c5b77e17..837af166a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,7 +1,23 @@ -Minicraft+ version 1.9 +Minicraft+ version 1.9.1 + += Armor now functions as a damage buffer rather than extra hearts; you take damage after only a certain number of damage points accumulate. ++ Armor lasts longer. += Rate of hunger bar healing health depends on hunger; still happens when less than full health. +- removed player's restriction on movement while being hurt ++ Added version number to save file +Minicraft+ version 1.9 +=Everything reimplemented +=stuff works ++Game window is resizable ++more entries in debug display ++added debug features ++key preferences... well, kinda. You can't really change them... ++airwizard suit status and key prefs saved with game file ++modifier keys supported (shift, alt, ctrl) ++added obsidian brick and door to creative inventory ----- Noteable additions in v1.8 ----- @@ -9,6 +25,7 @@ Minicraft+ version 1.9 * Airwizard's health appears above his head * Added colored clothes to change the player's outfit. They are craftable in the loom, or dropped rarely by zombies. * You can set the timer for score mode: 20m (default), 30m, 40m, or 1h +* you can unlock new score mode times with high enough scores: 10 min and 2 hours. * "Airwizard II" boss shows up on the surface after you unlock all the locked chests * Once you defeat the Air Wizard, you can wear his costume by going into the settings menu. This suit allows the player to walk on air tiles. diff --git a/Classes left to comment or revise.txt b/Classes left to comment or revise.txt index 55bf908e3..88e40e212 100644 --- a/Classes left to comment or revise.txt +++ b/Classes left to comment or revise.txt @@ -1,17 +1,44 @@ -Comment: - -item/* -item/resource/* +Comment from shylor's repo: level/Level level/levelgen/LevelGen level/tile/* (not Tile) -saveload/*.... but they are new... -------------------------------------- -There are more... but they are new, and have no previous comments. To find them, search for a comment on the first line of the class. -Usually, it's "//new class, no comments." But some are "//new features, less comments." or something like that. - +Comment anew: + +entity/Arrow +entity/Creeper +entity/DungeonChest +entity/Knight +entity/Skeleton +entity/Snake +entity/Tnt +entity/Spawner +entity/(Pig/Sheep/Cow) -- will likely combine these later. + +(slightly more than a page:) +item/BookItem +item/BucketItem +item/BucketLavaItem +item/BucketWaterItem +item/resource/ArmorResource +item/resource/ClothesResource + +item/resource/PotionResource +item/resource/TorchResource + +saveload/* + +screen/CraftInvMenu +screen/LoadingMenu (about a page) +screen/ModeMenu +screen/OptionsMenu +screen/PauseMenu +screen/PlayerInfoMenu +screen/TitleMenu +screen/WonMenu (needs a LOT more than comments!) +screen/WorldGenMenu +screen/WorldSelectMenu ******************************************************************************* Classes that need attention: @@ -19,6 +46,7 @@ Classes that need attention: -Chest.java: reformat -Furniture.java: maybe combine subclasses, to remove a bunch of the bulk... or maybe, just move more of the code into this class. +Same deal with the friendly mobs, and the evil mobs. -WonMenu.java: reformat; freshly decompiled, it seems... diff --git a/README.md b/README.md index 0bd0c2810..b650a2088 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,6 @@ Things I will probably add later, rather than sooner. * Auto-update system -- though, I might move this up, if this actually becomes something many people use. * Add back Experience bar, from version 1.4 -* Make the game window resizeable; full-screen _is_ a possibility; I changed the scale variable, and that worked! so now, I just need to black out the sides that aren't square... yeah, I know it isn't pretty, but it's _technically_ fullscreen... * Add some nice music! Maybe pixely... #### Far, far away... @@ -53,6 +52,7 @@ If their implementation becomes more likely, they will be moved to a different s * Chickens * Minecarts * Milk & bad status effects +* World editors ##### Random Note: LevelGen.java has it's own main method; it's used for debug purposes, to make images of the randomly generated maps that the class makes. \ No newline at end of file diff --git a/build/icons2.png b/build/icons2.png deleted file mode 100644 index c882b5457..000000000 Binary files a/build/icons2.png and /dev/null differ diff --git a/ideas for new additions.txt b/ideas for new additions.txt index 93f127d6c..1404de890 100644 --- a/ideas for new additions.txt +++ b/ideas for new additions.txt @@ -1,4 +1,7 @@ -------- Simple Ideas -------- +---- + +Add world copy option, like rename and delete. ---- @@ -63,6 +66,8 @@ Make a way to resize the font... In specific instances only, though, I'm thinkin Support Color.get(String) where the string is four characters, made up of t,w,b; t=transparent, w=white, and b=black. That might look better. Of course, what WOULD look better is Color.red, Color.white, etc. Maybe I could even devise Color.lighten and/or Color.darken methods, that would work for making the daylight cycle color sets. +Better idea: simplify it another way; just make a simple method in Color.java to make it so that if the last 3 colors are the same, you just type it once; so instead of Color.get(-1, 555, 555, 555), it's just Color.get(-1, 555). + ???? Make menu frames change size based on the largest (text) item in it. Not totally sure I want to do it... diff --git a/src/com/mojang/ld22/Game.java b/src/com/mojang/ld22/Game.java index c17fbda65..fa6cb8ba0 100644 --- a/src/com/mojang/ld22/Game.java +++ b/src/com/mojang/ld22/Game.java @@ -3,9 +3,7 @@ import com.mojang.ld22.entity.Bed; import com.mojang.ld22.entity.Entity; import com.mojang.ld22.entity.Furniture; -import com.mojang.ld22.entity.Inventory; import com.mojang.ld22.entity.IronLantern; -import com.mojang.ld22.entity.ItemEntity; import com.mojang.ld22.entity.Mob; import com.mojang.ld22.entity.Player; import com.mojang.ld22.gfx.Color; @@ -15,15 +13,14 @@ import com.mojang.ld22.item.FurnitureItem; import com.mojang.ld22.item.ListItems; import com.mojang.ld22.item.ResourceItem; -import com.mojang.ld22.item.resource.ItemResource; -import com.mojang.ld22.item.resource.PotionResource; -import com.mojang.ld22.item.resource.Resource; import com.mojang.ld22.item.ToolItem; import com.mojang.ld22.item.ToolType; +import com.mojang.ld22.item.resource.PotionResource; +import com.mojang.ld22.item.resource.Resource; import com.mojang.ld22.level.Level; import com.mojang.ld22.level.tile.Tile; -import com.mojang.ld22.saveload.Save; import com.mojang.ld22.saveload.Load; +import com.mojang.ld22.saveload.Save; import com.mojang.ld22.screen.DeadMenu; import com.mojang.ld22.screen.LevelTransitionMenu; import com.mojang.ld22.screen.LoadingMenu; @@ -53,16 +50,15 @@ public class Game extends Canvas implements Runnable { private static Random random = new Random(); public static boolean debug = false; - public static final String gameDir = System.getenv("APPDATA") + "/.playminicraft/mods/Minicraft-Plus"; // The directory in which all the game files are stored; APPDATA is meant for windows... + public static final String gameDir = System.getenv("APPDATA") + "/.playminicraft/mods/Minicraft Plus"; // The directory in which all the game files are stored; APPDATA is meant for windows... /// MANAGERIAL VARS AND RUNNING public static final String NAME = "Minicraft Plus"; // This is the name on the application window - public static final String VERSION = "1.9"; + public static final String VERSION = "1.9.1"; public static final int HEIGHT = 192; public static final int WIDTH = 288; private static float SCALE = 3; - //does the *scale part mean anything to the graphics, or does java accomodate it? /// TIME AND TICKS @@ -75,6 +71,7 @@ public class Game extends Canvas implements Runnable { public static int sleepTime = 42000; //this value determines when the player allowed to sleep. private boolean running; // This is about more than simply being paused -- it keeps the game loop running. + public int fra, tik; //these store the number of frames and ticks in the previous second; used for fps, at least. public int gameTime; // This stores the total time (number of ticks) you've been playing your game. /// RENDERING @@ -99,13 +96,12 @@ public class Game extends Canvas implements Runnable { private int playerDeadTime; // the time after you die before the dead menu shows up. private int pendingLevelChange; // used to determine if the player should change levels or not. private int wonTimer; // the paused time when you win before the win menu shows up. - public boolean hasWon; // If the player wins this is set to true + public boolean hasWon; // If the player wins this is set to true. /// AUTOSAVE AND NOTIFICATIONS public static boolean autosave; //if autosave feature is enabled. public static int astime; //stands for Auto-Save Time (interval) - //public static String savedtext = ""; // TODO use this for special overlays, maybe. public static List notifications = new ArrayList(); public int asTick; // The time interval between autosaves. @@ -115,21 +111,12 @@ public class Game extends Canvas implements Runnable { /// SCORE MODE - public static int multiplyer = 1; // Score multiplier - public static int mtm = 300, ism = 1; // more time stuff for score mode. - public static int multiplyertime = mtm; // Time left on the current multiplier. - - public int scoreTime, newscoreTime; //more for Score mode. - - /// MISCELLANEOUS + public static int multiplier = 1; // Score multiplier + public static int mtm = 300; // time given to increase multiplier before it goes back to 1. + public static int multipliertime = mtm; // Time left on the current multiplier. - //used to display "error" messages - public static int infotime = 120; //duration of message, in ticks; as with all other time references (unless otherwise stated, of course) - public static boolean infoplank = false, infosbrick = false; // "can only place on planks / stone brick" - - public int fra, tik; //these store the number of frames and ticks in the previous second; used for fps, at least. - int count; //something with colors..? - boolean reverse; //related to count + public int scoreTime; // time remaining for score mode game. + public int newscoreTime; // time you start with in score mode. /// *** CONSTRUSTOR *** /// public Game() { @@ -148,8 +135,6 @@ public Game() { newscoreTime = 72000; scoreTime = newscoreTime; - count = 0; - reverse = false; autosave = false; asTick = 0; @@ -214,11 +199,11 @@ private void init() { } /* differences from resetstartGame: - -has deadmenu.shudrespawn conditional - +matches other if shudrespawn = true: + -has deadmenu.shouldRespawn conditional + +matches other if shouldRespawn = true: sets current level, player.respawn, adds player to level - BUT: if shudrespawn == false... + BUT: if shouldRespawn == false... -calls: levels[3] = new Level(worldSize, worldSize, 0, levels[4]); -calls player.findStartPos directly, rather than player.respawn. *this means that bed and previous spawn are ignored... @@ -236,8 +221,8 @@ public void resetGame() { // adds a new player player = new Player(this, input); - // "shudrespawn" is false on hardcore, or when making a new world. - if (DeadMenu.shudrespawn) { // respawn, don't regenerate level. + // "shouldRespawn" is false on hardcore, or when making a new world. + if (DeadMenu.shouldRespawn) { // respawn, don't regenerate level. if (debug) System.out.println("Current Level = " + currentLevel); level = levels[currentLevel]; @@ -250,7 +235,7 @@ public void resetGame() { level = levels[currentLevel]; // Set level variable to the surface (b/c currentlevel is always 3) - DeadMenu.shudrespawn = true; // player should respawn on death + DeadMenu.shouldRespawn = true; // player should respawn on death player.findStartPos(level); // finds the start position for the player if (debug) System.out.println("spawned player in new surface level, resetGame"); } @@ -273,7 +258,10 @@ public void resetGame() { wonTimer = 0; gameTime = 0; Player.hasSetHome = false; + Player.moveSpeed = 1; Bed.hasBedSet = false; //no bed + Game.gamespeed = 1; + notifications.clear(); if (!OptionsMenu.hasSetDiff) OptionsMenu.diff = 2; @@ -293,7 +281,6 @@ public void resetGame() { if (ModeMenu.score) { scoreTime = newscoreTime; - ism = 1; } Player.score = 0; @@ -342,7 +329,7 @@ public void resetGame() { if (WorldSelectMenu.loadworld)// { new Load(this, WorldSelectMenu.worldname); - DeadMenu.shudrespawn = true; + DeadMenu.shouldRespawn = true; if(WorldGenMenu.theme == WorldGenMenu.hell) { player.inventory.add(new ResourceItem(Resource.lavapotion)); @@ -356,9 +343,7 @@ public void tick() { if (Bed.hasBedSet) { // IN BED level.remove(player); - //nsPerTick = 781250.0D; gamespeed = 20; - //if (debug) System.out.println("SLEEPING... tickCount: " + tickCount); if (tickCount <= sleepTime) { // it has reached morning. level.add(player); gamespeed = 1; @@ -399,37 +384,17 @@ public void tick() { /// SCORE MODE ONLY if (ModeMenu.score) { - if (!paused) scoreTime--; - - if (scoreTime < 1 && !player.removed) { + if (scoreTime < 1 && !player.removed) { // GAME OVER setMenu(new WonMenu(player)); - if(Game.debug) System.out.println("final player score: "+player.score); - //Extra score from drops. - player.score += (Inventory.scored(Resource.cloth) * (random.nextInt(2) + 1) * ism); - player.score += (Inventory.scored(Resource.slime) * (random.nextInt(2) + 1) * ism); - player.score += (Inventory.scored(Resource.bone) * (random.nextInt(2) + 1) * ism); - player.score += (Inventory.scored(Resource.gunp) * (random.nextInt(2) + 1) * ism); - player.score += (Inventory.scored(Resource.bookant) * (random.nextInt(2) + 1) * (random.nextInt(2) + 1) * ism); player.remove(); } + if (!paused) scoreTime--; - if (multiplyer > 1) { - if (multiplyertime != 0) multiplyertime--; - if (multiplyertime == 0) { - multiplyer = 1; - multiplyertime = mtm; - } + if (multiplier > 1) { + if (multipliertime != 0) multipliertime--; + if (multipliertime == 0) setMultiplier(1); } - if (multiplyer > 50) multiplyer = 50; - } - - //what's this for? - if (!reverse) { - count++; - if (count == 25) reverse = true; - } else { - count--; - if (count == 0) reverse = false; + if (multiplier > 50) multiplier = 50; } //This is the general action statement thing! Regulates menus, mostly. @@ -460,7 +425,7 @@ public void tick() { setMenu(new LevelTransitionMenu(pendingLevelChange)); pendingLevelChange = 0; } - + //I'm guessing that this is like DeadMenu, but you can't respawn. if (wonTimer > 0) { wonTimer--; @@ -490,30 +455,43 @@ public void tick() { player.inventory.add((com.mojang.ld22.item.Item) ListItems.items.get(i)); } } + + if(input.getKey("ctrl-h").clicked) player.health--; + if (input.getKey("creative").clicked) ModeMenu.updateModeBools(2); if (input.getKey("survival").clicked) ModeMenu.updateModeBools(1); + if (ModeMenu.score && input.getKey("shift-t").clicked) scoreTime = normSpeed * 5; // 5 seconds - if (input.getKey("shift-alt-equals").clicked && gamespeed >= 1) gamespeed++; - else if (input.getKey("shift-alt-equals").clicked && gamespeed < 1) gamespeed *= 2; - if (input.getKey("shift-alt-minus").clicked && gamespeed > 1) gamespeed--; - else if (input.getKey("shift-alt-minus").clicked && gamespeed <= 1) gamespeed /= 2; + if (input.getKey("equals").clicked) Player.moveSpeed += 0.5D; + if (input.getKey("minus").clicked && Player.moveSpeed > 0.5D) Player.moveSpeed -= 0.5D; - if (input.getKey("shift-equals").clicked) Player.moveSpeed++; - if (input.getKey("shift-minus").clicked && Player.moveSpeed > 1) Player.moveSpeed--; + if (input.getKey("shift-equals").clicked) { + if(gamespeed >= 1) gamespeed++; + else gamespeed *= 2; + } + if (input.getKey("shift-minus").clicked) { + if(gamespeed > 1) gamespeed--; + else gamespeed /= 2; + } } // end debug only cond. } // end "menu-null" conditional } // end hasfocus conditional } // end tick() + public static void setMultiplier(int value) { + multiplier = value; + multipliertime = mtm; + } + /// this is the proper way to change the tickCount. public static void setTime(int ticks) { - if (ticks < 0) ticks = 0; + if (ticks < 0) ticks = 0; // error correct if (ticks < 7200) time = 0; // morning else if (ticks < 36000) time = 1; // day else if (ticks < 43200) time = 2; // evening else if (ticks < 64800) time = 3; // night - else {//if(ticks >= 64800) { // morning + else { // back to morning time = 0; ticks = 0; } @@ -584,7 +562,8 @@ public void render() { level.renderSprites(screen, xScroll, yScroll); // renders level sprites on screen // this creates the darkness in the caves - if (!ModeMenu.creative && currentLevel < 4 && (currentLevel < 3 || time > 1)) { + //if (!ModeMenu.creative && currentLevel < 4 && (currentLevel < 3 || time > 1)) { + if (!ModeMenu.creative && currentLevel < 3) { if (currentLevel < 3) lightScreen.clear(0); // clears the light screen to a black color level.renderLight(lightScreen, xScroll, yScroll); // finds (and renders) all the light from objects (like the player, lanterns, and lava). screen.overlay(lightScreen, xScroll, yScroll); // overlays the light screen over the main screen. @@ -628,16 +607,6 @@ private void renderGui() { screen.render(x * 7, screen.h - 16 + 1 * 8, 32, Color.get(0, 0, 0, 0), 0); } - if (saving) { - //if (Game.debug) System.out.println("SAVING GAME..."); - String loadingText = "Saving... " + LoadingMenu.percentage + "%"; - int xPos = screen.centertext(loadingText); - int yPos = screen.h / 2 - 32; - Font.draw(loadingText, screen, xPos+1, yPos+1, Color.get(-1, 111, 111, 111)); - Font.draw(loadingText, screen, xPos, yPos, Color.get(-1, 4, 4, 4)); - } // TODO see if I can get this and the sleeping overlay into one; maybe use savedtext... - - //int xfps = fra; // fra is the last second's fps. // player.xx and yy stores previous player position. int txlevel = player.x / 16; int tylevel = player.y / 16; @@ -662,6 +631,12 @@ private void renderGui() { } } + if(player.armor > 0) { + info.add("armor: " + player.armor); + info.add("dam buffer: " + player.armorDamageBuffer); + //info.add("armor lvl: " + player.curArmor.level); + } + for(int i = 0; i < info.size(); i++) { Font.draw(info.get(i), screen, 1, 2 + i*10, col0); } @@ -675,18 +650,18 @@ private void renderGui() { //displays arrow icon screen.render(10 * 8 + 4, screen.h - 16, 13 + 5 * 32, Color.get(0, 111, 222, 430), 0); - if (Bed.hasBedSet) { // twice for the shadow text effect - Font.draw("Sleeping...", screen, screen.w / 2 + 1 - 44, screen.h - 119, Color.get(-1, 222, 222, 222)); - Font.draw("Sleeping...", screen, screen.w / 2 - 44, screen.h - 120, Color.get(-1, 555, 555, 555)); - } // TODO again, merge with saving dialog if possible + String msg = ""; + if (saving) msg = "Saving... " + LoadingMenu.percentage + "%"; + else if (Bed.hasBedSet) msg = "Sleeping..."; - /// NOTIFICATIONS + if(msg.length() > 0) { + Font.draw(msg, screen, screen.centertext(msg)+1, screen.h / 2 - 19, Color.get(-1, 222, 222, 222)); + Font.draw(msg, screen, screen.centertext(msg), screen.h / 2 - 20, Color.get(-1, 555, 555, 555)); + } - if (infoplank) {notifications.add("Can only be placed on planks!"); infoplank = false;} - if (infosbrick) {notifications.add("Can only be placed on stone brick!"); infosbrick = false;} - // TODO either revise the above system, or add infoobrick (obsidian placement) + /// NOTIFICATIONS - if (notifications.size() > 0) { + if (notifications.size() > 0 && msg.length() == 0) { notetick++; if (notifications.size() > 3) { //only show 3 notifs max at one time; erase old notifs. notifications = notifications.subList(notifications.size() - 3, notifications.size()); @@ -710,7 +685,7 @@ private void renderGui() { // SCORE MODE ONLY: if (ModeMenu.score) { - int seconds = scoreTime / 60; + int seconds = (int)Math.ceil(scoreTime / (double)normSpeed); int minutes = seconds / 60; int hours = minutes / 60; minutes %= 60; @@ -719,13 +694,13 @@ private void renderGui() { int timeCol; if(scoreTime >= 18000) timeCol = Color.get(0, 555, 555, 555); else if (scoreTime >= 3600) timeCol = Color.get(330, 555, 555, 555); - else timeCol = Color.get(330, 555, 555, 555); + else timeCol = Color.get(400, 555, 555, 555); - Font.draw("Time left " + minutes + "m " + seconds + "s", screen, 84, screen.h - 190, timeCol); + Font.draw("Time left " + (hours > 0 ? hours+"h ":"") + minutes + "m " + seconds + "s", screen, 84, screen.h - 190, timeCol); - if(multiplyer > 1) { - int multColor = multiplyer < 50 ? Color.get(-1, 540, 540, 540) : Color.get(-1, 500, 500, 500); - Font.draw("X" + multiplyer, screen, 260, screen.h - 190, multColor); + if(multiplier > 1) { + int multColor = multiplier < 50 ? Color.get(-1, 540, 540, 540) : Color.get(-1, 500, 500, 500); + Font.draw("X" + multiplier, screen, 260, screen.h - 190, multColor); } } @@ -742,10 +717,10 @@ private void renderGui() { // the key is potion type, value is remaining potion duration. for(int i = 0; i < effects.length; i++) { String pType = effects[i].getKey(); - int pTime = effects[i].getValue(); + int pTime = effects[i].getValue() / normSpeed; int pcol = Color.get(PotionResource.potionColor(pType), 555, 555, 555); Font.draw("("+input.getMapping("potionEffects")+" to hide!)", screen, 180, 9, Color.get(0, 555, 555, 555)); - Font.draw(pType + " (" + (pTime / 60 / 60) + ":" + ((pTime / 60) % 60) + ")", screen, 180, 17 + i * 8, pcol); + Font.draw(pType + " (" + (pTime / 60) + ":" + (pTime % 60) + ")", screen, 180, 17 + i * 8, pcol); } } @@ -764,7 +739,8 @@ private void renderGui() { screen.render(i * 8 + 208, screen.h - 16, 2 + 12 * 32, color, 0); // renders armor - color = (i < player.armor) ? Color.get(-1, 333, 444, 555) : Color.get(-1, -1, -1, -1); + int armor = player.armor*10/player.maxArmor; + color = (i <= armor && player.curArmor != null) ? player.curArmor.color/*Color.get(-1, 333, 444, 555)*/ : Color.get(-1, -1, -1, -1); screen.render(i * 8 + 208, screen.h - 8, 3 + 12 * 32, color, 0); if (player.staminaRechargeDelay > 0) { @@ -791,7 +767,7 @@ private void renderGui() { private void renderFocusNagger() { String msg = "Click to focus!"; // the message when you click off the screen. paused = true; //perhaps paused is only used for this. - int xx = Menu.centertext(msg); // the width of the box + int xx = screen.centertext(msg); // the width of the box int yy = (HEIGHT - 8) / 2; // the height of the box int w = msg.length(); // length of message in characters. int h = 1; @@ -846,7 +822,8 @@ public void run() { //main game loop? calls tick() and render(). while (running) { long now = System.nanoTime(); - double nsPerTick = 1E9D / (normSpeed*gamespeed); // nanosecs per sec divided by ticks per sec = nanosecs per tick + double nsPerTick = 1E9D / normSpeed; // nanosecs per sec divided by ticks per sec = nanosecs per tick + if(menu == null) nsPerTick /= gamespeed; unprocessed += (now - lastTime) / nsPerTick; //figures out the unprocessed time between now and lastTime. lastTime = now; boolean shouldRender = true; @@ -885,27 +862,21 @@ public static void main(String[] args) { Game.debug = debug; Game game = new Game(); game.setMinimumSize(new Dimension(1, 1)); - //game.setMaximumSize(getWindowSize()); game.setPreferredSize(getWindowSize()); JFrame frame = new JFrame(Game.NAME); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); // sets the layout of the window frame.add(game, BorderLayout.CENTER); // Adds the game (which is a canvas) to the center of the screen. frame.pack(); //squishes everything into the preferredSize. - //frame.setResizable(false); // prevents the user from resizing the window. frame.setLocationRelativeTo(null); // the window will pop up in the middle of the screen when launched. - //System.out.println("frame size:" + frame.getWidth() + "x" + frame.getHeight()); frame.addComponentListener(new ComponentAdapter() { - public void componentResized(ComponentEvent e) { + public void componentResized(ComponentEvent e) { float w = frame.getWidth() - frame.getInsets().left - frame.getInsets().right; float h = frame.getHeight() - frame.getInsets().top - frame.getInsets().bottom; Game.SCALE = Math.min(w / Game.WIDTH, h / Game.HEIGHT); - //System.out.println("Window Resized to: " + frame.getWidth() + "x" + frame.getHeight() + ";\tnew Game Scale: " + Game.SCALE + ";\tnew game screen size: " + getWindowSize().width + "x" + getWindowSize().height); - //game.WIDTH = frame.getWidth(); - //game.HEIGHT = frame.getHeight(); - } - }); + } + }); frame.setVisible(true); diff --git a/src/com/mojang/ld22/GameApplet.java b/src/com/mojang/ld22/GameApplet.java index e64806ae2..66a5009df 100644 --- a/src/com/mojang/ld22/GameApplet.java +++ b/src/com/mojang/ld22/GameApplet.java @@ -1,6 +1,5 @@ package com.mojang.ld22; -import com.mojang.ld22.Game; import java.applet.Applet; import java.awt.BorderLayout; import java.io.BufferedReader; diff --git a/src/com/mojang/ld22/InputHandler.java b/src/com/mojang/ld22/InputHandler.java index 179a6a6f9..b6bbef7e4 100644 --- a/src/com/mojang/ld22/InputHandler.java +++ b/src/com/mojang/ld22/InputHandler.java @@ -7,7 +7,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; public class InputHandler implements MouseListener, KeyListener { //note: there needs to be an options menu for changing the key controls. @@ -175,7 +174,6 @@ private Key getKey(String keytext, boolean getFromMap) { Key key; // make a new key to return at the end keytext = keytext.toUpperCase(); // prevent errors due to improper "casing" - String fullKeytext = keytext; if(getFromMap) { // if false, we assume that keytext is a physical key. synchronized ("lock") { @@ -185,6 +183,8 @@ private Key getKey(String keytext, boolean getFromMap) { } } + String fullKeytext = keytext; + if (keytext.contains("|")) { /// multiple key possibilities exist for this action; so, combine the results of each one! key = new Key(); @@ -240,6 +240,8 @@ private Key getKey(String keytext, boolean getFromMap) { } else if(!modMatch) key = new Key(); + //if(key.down) System.out.println("processed key: " + keytext + " is down"); + return key; // return the Key object. } diff --git a/src/com/mojang/ld22/crafting/ArrowRecipe.java b/src/com/mojang/ld22/crafting/ArrowRecipe.java index 88c679297..ae6ba6107 100644 --- a/src/com/mojang/ld22/crafting/ArrowRecipe.java +++ b/src/com/mojang/ld22/crafting/ArrowRecipe.java @@ -1,6 +1,5 @@ package com.mojang.ld22.crafting; -import com.mojang.ld22.Game; import com.mojang.ld22.entity.Player; import com.mojang.ld22.item.ResourceItem; import com.mojang.ld22.item.resource.Resource; diff --git a/src/com/mojang/ld22/entity/AirWizard.java b/src/com/mojang/ld22/entity/AirWizard.java index 55e819ac1..cae671c50 100644 --- a/src/com/mojang/ld22/entity/AirWizard.java +++ b/src/com/mojang/ld22/entity/AirWizard.java @@ -26,7 +26,7 @@ public class AirWizard extends Mob { public AirWizard(boolean secondform) { folder = new File(location); - + lvl = secondform?2:1; x = random.nextInt(64 * 16); // x position is anywhere between (0 to 1023) [Tile position (0 to 64)] y = random.nextInt(64 * 16); // y position is anywhere between (0 to 1023) [Tile position (0 to 64)] diff --git a/src/com/mojang/ld22/entity/Arrow.java b/src/com/mojang/ld22/entity/Arrow.java index 0c37d56a3..2e5b07776 100644 --- a/src/com/mojang/ld22/entity/Arrow.java +++ b/src/com/mojang/ld22/entity/Arrow.java @@ -12,8 +12,7 @@ public class Arrow extends Entity { private final int speed = 2; private int time; private int damage; - private Mob owner; - private Player player; + public Mob owner; private int color; private int speeddmg; private boolean edmg = false; @@ -77,12 +76,7 @@ public void tick() { } } } - /* - if(owner instanceof Player) { - level.getTile(x / 16, y / 16).interact(level, x, y, (Player)owner, ListItems.gempickaxe, ((Player)owner).attackDir); - level.getTile(x / 16, y / 16).interact(level, x, y, (Player)owner, ListItems.gemshovel, ((Player)owner).attackDir); - } - */ + if (level.getTile(x / 16, y / 16).mayPass(level, x / 16, y / 16, this) || level.getTile(x / 16, y / 16).connectsToWater || level.getTile(x / 16, y / 16).id == 16) { diff --git a/src/com/mojang/ld22/entity/Bed.java b/src/com/mojang/ld22/entity/Bed.java index 4abaf3631..82f2fc36b 100644 --- a/src/com/mojang/ld22/entity/Bed.java +++ b/src/com/mojang/ld22/entity/Bed.java @@ -1,13 +1,11 @@ -//new class, no comments package com.mojang.ld22.entity; import com.mojang.ld22.Game; import com.mojang.ld22.gfx.Color; public class Bed extends Furniture { - public static boolean hasBedSet = false; - //public static boolean hasBeenTrigged = false; - public int saveSpawnX, saveSpawnY; + public static boolean hasBedSet = false; // If the player (as there is only one) has set their home/bed. + public int saveSpawnX, saveSpawnY; // the saved spawn locations... never used, though, I don't think... public Bed() { super("Bed"); @@ -18,23 +16,24 @@ public Bed() { col = Color.get(-1, 100, 444, 400); sprite = 8; + // set the x and y radius of the Bed. xr = 3; yr = 2; } - + + /** Called when the player attempts to get in bed. */ public boolean use(Player player, int attackDir) { - //hasBedSet = true; - //hasBeenTrigged = true; - if (Game.tickCount >= Game.sleepTime) { - hasBedSet = true; + if (Game.tickCount >= Game.sleepTime) { // if it is late enough in the day to sleep... + hasBedSet = true; // the bed is now set. + // set the player spawn coord. to here, in tile coords, hence "/ 16" Player.spawnx = x / 16; Player.spawny = y / 16; - player.bedSpawn = true; - if(Game.debug) System.out.println("bedPos: ("+x+","+y+"); spawnPos: ("+player.spawnx+","+player.spawny+")"); + player.bedSpawn = true; // wait, but then... what's hasBedSet for??? The two should always go hand in hand! + //if(Game.debug) System.out.println("bedPos: ("+(x/16)+","+(y/16)+"); spawnPos: ("+player.spawnx+","+player.spawny+")"); // debug to print the bed loc and spawn loc } else { - int sec = (Game.tickCount - Game.sleepTime) / Game.normSpeed; // normSpeed is in tiks/sec. - Game.notifications.add( - "Can't sleep! " + (sec / 60) + "Min " + (sec - sec % 60) + " Sec left!"); + // it is too early to sleep; display how much time is remaining. + int sec = (Game.sleepTime - Game.tickCount) / Game.normSpeed; // gets the seconds until sleeping is allowed. // normSpeed is in tiks/sec. + Game.notifications.add("Can't sleep! " + (sec / 60) + "Min " + (sec % 60) + " Sec left!"); // add the notification displaying the time remaining in minutes and seconds. } return true; diff --git a/src/com/mojang/ld22/entity/Chest.java b/src/com/mojang/ld22/entity/Chest.java index b35d70eb8..1713bab68 100644 --- a/src/com/mojang/ld22/entity/Chest.java +++ b/src/com/mojang/ld22/entity/Chest.java @@ -1,21 +1,16 @@ -//new features, limited comments. package com.mojang.ld22.entity; import com.mojang.ld22.gfx.Color; import com.mojang.ld22.screen.ContainerMenu; -import com.mojang.ld22.screen.OptionsMenu; public class Chest extends Furniture { - public Inventory inventory = new Inventory(); // Inventory of the chest - public boolean isdeathchest = false; // whether this is a death chest (from when the player dies) - public int time = 0; // time passed (used for death chest despawn) - public String name; // perhaps for deathchest name? - // no idea what these are for-- death chests are new! - int redtick = 0; - boolean reverse; - - public Chest() { - super("Chest"); //Name of the chest..? + public Inventory inventory; // Inventory of the chest + + public Chest() {this("Chest");} + public Chest(String name) { + super(name); // Name of the chest + + inventory = new Inventory(); // initialize the inventory. // chest colors if (canLight()) { @@ -34,90 +29,9 @@ public Chest() { sprite = 1; // Location of the sprite } - // for death chest time count, I imagine. - public void tick() { - super.tick(); - if (isdeathchest) { - name = "Death Chest:" + time / 60 + "S"; - if (inventory.items.size() < 1) { - remove(); - } - - if (time < 3600) { - name = "Death Chest:" + time / 60 + "S"; - if (!reverse) { - redtick++; - } else { - redtick--; - } - - if (redtick < 5) { - col0 = Color.get(-1, 100, 200, 300); - col1 = Color.get(-1, 100, 200, 300); - col2 = Color.get(-1, 100, 200, 300); - col3 = Color.get(-1, 100, 200, 300); - } else if (redtick > 7 && redtick < 11) { - col0 = Color.get(-1, 200, 300, 400); - col1 = Color.get(-1, 200, 300, 400); - col2 = Color.get(-1, 200, 300, 400); - col3 = Color.get(-1, 200, 300, 400); - } else if (redtick > 10) { - col0 = Color.get(-1, 300, 400, 500); - col1 = Color.get(-1, 300, 400, 500); - col2 = Color.get(-1, 300, 400, 500); - col3 = Color.get(-1, 300, 400, 500); - } - - if (redtick > 13) { - reverse = true; - } - - if (redtick < 0) { - reverse = false; - } - } - - if (time > 0) { - time--; - } - - if (time == 0) { - remove(); - } - } - } - - // another constructor! must also be for deathchests... - public Chest(boolean deathchest) { - super("Death Chest"); - isdeathchest = true; - if (OptionsMenu.diff == 1) { - time = '\u8ca0'; - } else if (OptionsMenu.diff == 2) { - time = 18000; - } else if (OptionsMenu.diff == 3) { - time = 1200; - } - - if (canLight()) { - col0 = Color.get(-1, 220, 331, 552); - col1 = Color.get(-1, 220, 331, 552); - col2 = Color.get(-1, 220, 331, 552); - col3 = Color.get(-1, 220, 331, 552); - } else { - col0 = Color.get(-1, 110, 220, 441); - col1 = Color.get(-1, 220, 331, 552); - col2 = Color.get(-1, 110, 220, 441); - col3 = Color.get(-1, 0, 110, 330); - } - - col = Color.get(-1, 220, 331, 552); - sprite = 1; - } - /** This is what occurs when the player uses the "Menu" command near this */ public boolean use(Player player, int attackDir) { - player.game.setMenu(new ContainerMenu(player, "Chest", inventory)); + player.game.setMenu(new ContainerMenu(player, this)); return true; } } diff --git a/src/com/mojang/ld22/entity/Creeper.java b/src/com/mojang/ld22/entity/Creeper.java index aa25f3b69..6ee475aa1 100644 --- a/src/com/mojang/ld22/entity/Creeper.java +++ b/src/com/mojang/ld22/entity/Creeper.java @@ -17,7 +17,7 @@ public class Creeper extends Mob { private int BLAST_DAMAGE = 10; private int xa, ya; - private int lvl; + //private int lvl; private int randomWalkTime = 0; private int fuseTime = 0; private boolean fuseLit = false; @@ -449,10 +449,10 @@ protected void die() { } } if (level.player != null) { - level.player.score += (50 * lvl) * Game.multiplyer; + level.player.score += (50 * lvl) * Game.multiplier; } - Game.multiplyer++; - Game.multiplyertime = Game.mtm -= 5; + Game.multiplier++; + Game.multipliertime = Game.mtm -= 5; } } diff --git a/src/com/mojang/ld22/entity/DeathChest.java b/src/com/mojang/ld22/entity/DeathChest.java new file mode 100644 index 000000000..7b1561eb5 --- /dev/null +++ b/src/com/mojang/ld22/entity/DeathChest.java @@ -0,0 +1,90 @@ +package com.mojang.ld22.entity; + +import com.mojang.ld22.Game; +import com.mojang.ld22.gfx.Color; +import com.mojang.ld22.screen.OptionsMenu; + +public class DeathChest extends Chest { + //public String name; + public int time; // time passed (used for death chest despawn) + int redtick = 0; // this is used to determine the shade of red when the chest is about to expire. + boolean reverse; // what direction the red shade (redtick) is changing. + + public DeathChest() { + super("Death Chest"); + + /// set the expiration time based on the world difficulty. + if (OptionsMenu.diff == 1) { + time = 36000; + } else if (OptionsMenu.diff == 2) { + time = 18000; + } else if (OptionsMenu.diff == 3) { + time = 1200; + } + + if (canLight()) { + col0 = Color.get(-1, 220, 331, 552); + col1 = Color.get(-1, 220, 331, 552); + col2 = Color.get(-1, 220, 331, 552); + col3 = Color.get(-1, 220, 331, 552); + } else { + col0 = Color.get(-1, 110, 220, 441); + col1 = Color.get(-1, 220, 331, 552); + col2 = Color.get(-1, 110, 220, 441); + col3 = Color.get(-1, 0, 110, 330); + } + + col = Color.get(-1, 220, 331, 552); + sprite = 1; + } + + // for death chest time count, I imagine. + public void tick() { + super.tick(); + name = "Death Chest:" + time / Game.normSpeed + "S"; // add the current + + if (inventory.invSize() < 1) { + remove(); + } + + if (time < 3600) { // if there is less than 3600 ticks left... (1 min @ 60tiks/sec) + redtick += reverse ? -1 : 1; // inc/dec-rement redtick, changing the red shading. + + // set the chest color based on redtick's value + if (redtick < 5) { + col0 = Color.get(-1, 100, 200, 300); + col1 = Color.get(-1, 100, 200, 300); + col2 = Color.get(-1, 100, 200, 300); + col3 = Color.get(-1, 100, 200, 300); + } else if (redtick > 7 && redtick < 11) { + col0 = Color.get(-1, 200, 300, 400); + col1 = Color.get(-1, 200, 300, 400); + col2 = Color.get(-1, 200, 300, 400); + col3 = Color.get(-1, 200, 300, 400); + } else if (redtick > 10) { + col0 = Color.get(-1, 300, 400, 500); + col1 = Color.get(-1, 300, 400, 500); + col2 = Color.get(-1, 300, 400, 500); + col3 = Color.get(-1, 300, 400, 500); + } + + /// these two statements keep the red color oscillating. + if (redtick > 13) { + reverse = true; + } + if (redtick < 0) { + reverse = false; + } + } + + if (time > 0) { + time--; // decrement the time if it is not already zero. + } + + if (time == 0) { + remove(); // remove the death chest when the time expires. + } + } + + public void take(Player player) {} // can't grab a death chest. +} diff --git a/src/com/mojang/ld22/entity/DungeonChest.java b/src/com/mojang/ld22/entity/DungeonChest.java index 3c1e2acd9..862bf1e59 100644 --- a/src/com/mojang/ld22/entity/DungeonChest.java +++ b/src/com/mojang/ld22/entity/DungeonChest.java @@ -8,216 +8,128 @@ import com.mojang.ld22.item.ToolItem; import com.mojang.ld22.item.ToolType; import com.mojang.ld22.item.resource.Resource; -import com.mojang.ld22.screen.ContainerMenu; import com.mojang.ld22.screen.ModeMenu; import java.util.Random; -public class DungeonChest extends Furniture { +public class DungeonChest extends Chest { - public Inventory inventory = new Inventory(); public Random random = new Random(); - public boolean islocked = true; + public boolean isLocked; private static int openCol = Color.get(-1, 2, 115, 225); public DungeonChest() { super("Dungeon Chest"); - getInventory(inventory); + populateInv(); + isLocked = true; sprite = 1; col = Color.get(-1, 222, 333, 555); - - if(canLight()) { - if(islocked) // can light, and locked. - col0 = col1 = col2 = col3 = col; - else { // can light, unlocked. - col0 = Color.get(-1, 111, 115, 225); - col1 = Color.get(-1, 222, 115, 225); - col2 = Color.get(-1, 111, 115, 225); - col3 = Color.get(-1, 2, 115, 225); - } - } else if(!islocked) // can't light, unlocked. - col0 = col1 = col2 = col3 = openCol; - else { // can't light, locked. - col0 = Color.get(-1, 111, 222, 444); - col1 = Color.get(-1, 222, 333, 555); - col2 = Color.get(-1, 111, 222, 444); - col3 = Color.get(-1, 0, 111, 333); - } + col0 = Color.get(-1, 111, 222, 444); + col1 = Color.get(-1, 222, 333, 555); + col2 = Color.get(-1, 111, 222, 444); + col3 = Color.get(-1, 0, 111, 333); } public boolean use(Player player, int attackDir) { - if(!islocked) { - player.game.setMenu(new ContainerMenu(player, "Dungeon Chest", inventory)); - return true; - } else { - int aw; - AirWizard wizard; - + if (isLocked) { boolean activeKey = player.activeItem != null && player.activeItem.getName().equals("Key"); boolean invKey = player.inventory.hasResources(Resource.key, 1); - if(activeKey || invKey) { - if (!ModeMenu.creative) { - if (activeKey) { + if(activeKey || invKey) { // if the player has a key... + if (!ModeMenu.creative) { // remove the key unless on creative mode. + if (activeKey) { // remove activeItem ResourceItem key = (ResourceItem)player.activeItem; key.count--; - } else { + } else { // remove from inv player.inventory.removeResource(Resource.key, 1); } } - islocked = false; - player.game.setMenu(new ContainerMenu(player, "Dungeon Chest", inventory)); - col = col0 = col1 = col2 = col3 = openCol; + isLocked = false; + col = col0 = col1 = col2 = col3 = openCol; // set to the unlocked color level.add(new SmashParticle(x * 16 + 8, y * 16 + 8)); level.add(new TextParticle("-1 key", x, y, Color.get(-1, 500, 500, 500))); level.chestcount--; - if(level.chestcount == 0) { - for(aw = 0; aw < 5; aw++) { + if(level.chestcount == 0) { // if this was the last chest... + for(int i = 0; i < 5; i++) { // add 5 golden apples to the level level.add(new ItemEntity(new ResourceItem(Resource.goldapple), x, y)); } - Game.notifications.add("You hear a noise from the surface!"); - wizard = new AirWizard(true); + Game.notifications.add("You hear a noise from the surface!"); // notify the player of the developments + // add a level 2 airwizard to the middle surface level. + AirWizard wizard = new AirWizard(true); wizard.x = Game.levels[3].w / 2; wizard.y = Game.levels[3].h / 2; Game.levels[3].add(wizard); } + + return super.use(player, attackDir); // the player unlocked the chest. } - return true; + return false; // the chest is locked, and the player has no key. } + else return super.use(player, attackDir); // the chest was already unlocked. } - - public void getInventory(Inventory itemlist) { - if(random.nextInt(8) == 1) { - itemlist.add(new ResourceItem(Resource.gemarmor)); - } - - if(random.nextInt(6) == 1) { - itemlist.add(new ResourceItem(Resource.garmor)); - } - - if(random.nextInt(5) == 1) { - itemlist.add(new ResourceItem(Resource.iarmor, 2)); - } - - if(random.nextInt(4) == 1) { - itemlist.add(new ResourceItem(Resource.speedpotion, 2)); - } - - if(random.nextInt(3) == 1) { - itemlist.add(new ResourceItem(Resource.lightpotion, 2)); - } - - if(random.nextInt(3) == 1) { - itemlist.add(new ResourceItem(Resource.potion, 10)); - } - - if(random.nextInt(4) == 1) { - itemlist.add(new ResourceItem(Resource.lightpotion, 3)); - } - - if(random.nextInt(5) == 1) { - itemlist.add(new ResourceItem(Resource.steak, 6)); - } - - if(random.nextInt(5) == 1) { - itemlist.add(new ResourceItem(Resource.cookedpork, 6)); - } - - if(random.nextInt(6) == 1) { - itemlist.add(new ToolItem(ToolType.claymore, 2)); - } - - if(random.nextInt(4) == 1) { - itemlist.add(new ToolItem(ToolType.sword, 3)); - } - - if(random.nextInt(4) == 1) { - itemlist.add(new ToolItem(ToolType.claymore, 1)); - } - - if(random.nextInt(6) == 1) { - itemlist.add(new ToolItem(ToolType.bow, 3)); - } - - if(random.nextInt(7) == 1) { - itemlist.add(new ToolItem(ToolType.bow, 4)); - } - - if(random.nextInt(7) == 1) { - itemlist.add(new ToolItem(ToolType.sword, 4)); - } - - if(random.nextInt(5) == 1) { - itemlist.add(new ResourceItem(Resource.gem, 7)); - } - - if(random.nextInt(5) == 1) { - itemlist.add(new ResourceItem(Resource.gem, 8)); - } - - if(random.nextInt(6) == 1) { - itemlist.add(new ResourceItem(Resource.speedpotion, 5)); - } - - if(random.nextInt(4) == 1) { - itemlist.add(new ResourceItem(Resource.wood, 20)); - } - - if(random.nextInt(4) == 1) { - itemlist.add(new ResourceItem(Resource.wool, 12)); - } - - if(random.nextInt(2) == 1) { - itemlist.add(new ResourceItem(Resource.coal, 4)); - } - - if(random.nextInt(7) == 1) { - itemlist.add(new ResourceItem(Resource.regenpotion, 1)); - } - - if(random.nextInt(7) == 1) { - itemlist.add(new ResourceItem(Resource.energypotion, 1)); - } - - if(random.nextInt(14) == 1) { - itemlist.add(new ResourceItem(Resource.timepotion, 1)); - } - - if(random.nextInt(14) == 1) { - itemlist.add(new ResourceItem(Resource.shieldpotion, 1)); - } - - if(random.nextInt(7) == 1) { - itemlist.add(new ResourceItem(Resource.lavapotion, 1)); - } - - if(random.nextInt(5) == 1) { - itemlist.add(new ResourceItem(Resource.hastepotion, 3)); - } - - if(inventory.items.size() < 1) { - inventory.items.add(new ResourceItem(Resource.steak, 6)); - inventory.items.add(new ResourceItem(Resource.timepotion, 1)); - inventory.items.add(new ToolItem(ToolType.hatchet, 4)); + + /** Populate the inventory of the DungeonChest, psudo-randomly. */ + private void populateInv() { + inventory.clearInv(); // clear the inventory. + + tryAdd(5, Resource.steak, 6); + tryAdd(5, Resource.cookedpork, 6); + tryAdd(4, Resource.wood, 20); + tryAdd(4, Resource.wool, 12); + tryAdd(2, Resource.coal, 4); + tryAdd(5, Resource.gem, 7); + tryAdd(5, Resource.gem, 8); + tryAdd(8, Resource.gemarmor, 1); + tryAdd(6, Resource.garmor, 1); + tryAdd(5, Resource.iarmor, 2); + tryAdd(3, Resource.potion, 10); + tryAdd(4, Resource.speedpotion, 2); + tryAdd(6, Resource.speedpotion, 5); + tryAdd(3, Resource.lightpotion, 2); + tryAdd(4, Resource.lightpotion, 3); + tryAdd(7, Resource.regenpotion, 1); + tryAdd(7, Resource.energypotion, 1); + tryAdd(14, Resource.timepotion, 1); + tryAdd(14, Resource.shieldpotion, 1); + tryAdd(7, Resource.lavapotion, 1); + tryAdd(5, Resource.hastepotion, 3); + + tryAdd(6, ToolType.bow, 3); + tryAdd(7, ToolType.bow, 4); + tryAdd(4, ToolType.sword, 3); + tryAdd(7, ToolType.sword, 4); + tryAdd(4, ToolType.claymore, 1); + tryAdd(6, ToolType.claymore, 2); + + if(inventory.invSize() < 1) { // add this if none of the above was added. + inventory.add(new ResourceItem(Resource.steak, 6)); + inventory.add(new ResourceItem(Resource.timepotion, 1)); + inventory.add(new ToolItem(ToolType.axe, 4)); } - } - + + /** The functions that (possibly) add Resources and Tools to the chest, respectively. */ + private void tryAdd(int chance, Resource item, int num) { + if(random.nextInt(chance) == 1) + inventory.add(new ResourceItem(item, num)); + } + private void tryAdd(int chance, ToolType type, int lvl) { + if(random.nextInt(chance) == 1) + inventory.add(new ToolItem(type, lvl)); + } + + /** what happens if the player tries to push a Dungeon Chest. */ protected void touchedBy(Entity entity) { - if(entity instanceof Player && pushTime == 0 && !islocked) { - pushDir = ((Player)entity).dir; - pushTime = 10; - } - + if(!isLocked) // can only be pushed if unlocked. + super.touchedBy(entity); } - + + /** what happens if the player tries to grab a Dungeon Chest. */ public void take(Player player) { - if(!islocked) { - shouldTake = player; - } - + if(!isLocked) // can only be taken if unlocked. + super.take(player); } } diff --git a/src/com/mojang/ld22/entity/Enchanter.java b/src/com/mojang/ld22/entity/Enchanter.java index 831551cc6..f59fb9cbd 100644 --- a/src/com/mojang/ld22/entity/Enchanter.java +++ b/src/com/mojang/ld22/entity/Enchanter.java @@ -1,4 +1,3 @@ -//new class, no comments. package com.mojang.ld22.entity; import com.mojang.ld22.crafting.Crafting; diff --git a/src/com/mojang/ld22/entity/Entity.java b/src/com/mojang/ld22/entity/Entity.java index b5c087af0..b47543404 100644 --- a/src/com/mojang/ld22/entity/Entity.java +++ b/src/com/mojang/ld22/entity/Entity.java @@ -140,7 +140,10 @@ protected boolean move2(int xa, int ya) { } /** if this entity is touched by another entity (extended by sub-classes) */ - protected void touchedBy(Entity entity) {} + protected void touchedBy(Entity entity) { + //if(this instanceof Player == false && this instanceof Mob && entity instanceof Player) + //System.out.println("player touched " + getClass().getName().replace("com.mojang.ld22.entity.","") + " of level " + ((Mob)this).lvl); + } /** returns if mobs can block this entity (aka: can't pass through them) */ public boolean isBlockableBy(Mob mob) { diff --git a/src/com/mojang/ld22/entity/Furniture.java b/src/com/mojang/ld22/entity/Furniture.java index 27ff468be..ced9f099e 100644 --- a/src/com/mojang/ld22/entity/Furniture.java +++ b/src/com/mojang/ld22/entity/Furniture.java @@ -12,7 +12,6 @@ public class Furniture extends Entity { protected int pushDir = -1; // the direction to push the furniture public int col, col0, col1, col2, col3, sprite; // color and sprite vars. public String name; - //public int lightTimer = 0; //? protected Player shouldTake; // the player that should take the furniture public Furniture(String name) { @@ -77,18 +76,14 @@ public boolean blocks(Entity e) { protected void touchedBy(Entity entity) { /// ADD TO THIS METHOD TO REMOVE UNNECESSARY CLASSES? maybe combine others into a "CraftingFurniture" class? if (entity instanceof Player && pushTime == 0) { - if (name != "D.Chest") { // can't push death chests - pushDir = ((Player) entity).dir; // set pushDir to the player's dir. - pushTime = 10; // set pushTime to 10. - } + pushDir = ((Player) entity).dir; // set pushDir to the player's dir. + pushTime = 10; // set pushTime to 10. } } /** Used in PowerGloveItem.java */ public void take(Player player) { - if (name != "D.Chest") { //can't grab death chests - shouldTake = player; // assigns the player that should take this - } + shouldTake = player; // assigns the player that should take this } public boolean canWool() { diff --git a/src/com/mojang/ld22/entity/GodLantern.java b/src/com/mojang/ld22/entity/GodLantern.java index adfb0a336..0224720e9 100644 --- a/src/com/mojang/ld22/entity/GodLantern.java +++ b/src/com/mojang/ld22/entity/GodLantern.java @@ -1,4 +1,3 @@ -//new class, no comments. package com.mojang.ld22.entity; import com.mojang.ld22.gfx.Color; diff --git a/src/com/mojang/ld22/entity/GoldLantern.java b/src/com/mojang/ld22/entity/GoldLantern.java index 6babb0a00..d02201f33 100644 --- a/src/com/mojang/ld22/entity/GoldLantern.java +++ b/src/com/mojang/ld22/entity/GoldLantern.java @@ -1,4 +1,3 @@ -//new class, no comments. package com.mojang.ld22.entity; import com.mojang.ld22.gfx.Color; diff --git a/src/com/mojang/ld22/entity/Inventory.java b/src/com/mojang/ld22/entity/Inventory.java index 2b718ed37..4023766b8 100644 --- a/src/com/mojang/ld22/entity/Inventory.java +++ b/src/com/mojang/ld22/entity/Inventory.java @@ -1,6 +1,5 @@ package com.mojang.ld22.entity; -import com.mojang.ld22.item.BucketLavaItem; import com.mojang.ld22.item.Item; import com.mojang.ld22.item.ResourceItem; import com.mojang.ld22.item.ToolItem; @@ -8,22 +7,24 @@ import com.mojang.ld22.item.resource.Resource; import java.util.ArrayList; import java.util.List; +import java.util.Random; public class Inventory { - public List items = new ArrayList(); // the list of items that is in the inventory. - public static List itemss = new ArrayList(); // a static list, of the last inventory that was added to with add(Item). - public boolean playerinventory = false; // if this is a player inventory. + private Random random = new Random(); + private List items = new ArrayList(); // the list of items that is in the inventory. public Inventory() {} - - public Inventory(Player player) { - this.playerinventory = true; - } + + public List getItems() {return items;} + public void clearInv() {items.clear();} + public int invSize() {return items.size();} + + public Item get(int idx) {return items.get(idx);} + public Item remove(int idx) {return items.remove(idx);} /** Adds an item to the inventory */ public void add(Item item) { add(items.size(), item); // adds the item to the end of the inventory list - itemss = items; // sets static inv. to this one. } /** Adds an item to a specific spot in the inventory */ @@ -50,24 +51,15 @@ private ResourceItem findResource(Resource resource) { if (has.resource == resource) return has; // returns if the loop has found a ResourceItem with a matching resource in your inventory } } + // TODO should I check the activeItem too? Seems like a good idea, but I should check the code for anything that may take advantake of the absence of this feature, before I just put it in. + return null; // else it will return null } - /** this is findResourceStatic, not multiple. It's like the one above. */ - private static ResourceItem findResources(Resource resource) { - for (int i = 0; i < itemss.size(); i++) { - if (itemss.get(i) instanceof ResourceItem) { - ResourceItem has = (ResourceItem) itemss.get(i); - if (has.resource == resource) return has; - } - } - return null; - } - /** like findResource, but for other items. */ private Item findItem(Item item) { - for(int i = 0; i < this.items.size(); i++) { - Item has = (Item)this.items.get(i); + for(int i = 0; i < items.size(); i++) { + Item has = (Item)items.get(i); if(has.getName().equals(item.getName())) { // compares item name for match. return has; } @@ -121,15 +113,12 @@ public boolean removeResource(Resource r, int count) { public boolean removeTool(ToolType t, int level) { ToolItem ti = findtool(t, level, false); // find the exact tool. if (ti == null) return false; - //if (ti.level < level) return false; // - //ti.level -= level; - //if (ti.level <= 0) items.remove(ti); // remove if the item was entirely used up. items.remove(ti); return true; } /** removes item from this inv. */ - public boolean removeItem(Item i) { // This was expected to only be a lava bucket, it seems. + public boolean removeItem(Item i) { Item item = findItem(i); if(item == null) return false; else items.remove(item); // remove the item. @@ -137,20 +126,9 @@ public boolean removeItem(Item i) { // This was expected to only be a lava bucke return true; } - /** that gets the score for items...? Really, all it's doing is counting the given resource... */ - public static int scored(Resource r) { - int lscore = 0; - ResourceItem ri = findResources(r); - if (ri == null) { - lscore = 0; - } else if (ri != null) { - lscore = ri.count; - } - return lscore; - } - /** Returns the how many of an item you have in the inventory */ public int count(Item item) { + if (item == null) return 0; if (item instanceof ResourceItem) { // if the item is a resource... ResourceItem ri = findResource(((ResourceItem) item).resource); // find the ResourceItem in your inv if (ri != null) return ri.count; // if the ResourceItem was found, return the stored amount. @@ -161,6 +139,10 @@ public int count(Item item) { } return count; // return count } - return 0; // should never reach here. + + return 0; // reaches here if a ResourceItem is requested that isn't in the inventory. + } + public int count(Resource r) { + return count(findResource(r)); } } diff --git a/src/com/mojang/ld22/entity/IronLantern.java b/src/com/mojang/ld22/entity/IronLantern.java index 9465b288d..46973152b 100644 --- a/src/com/mojang/ld22/entity/IronLantern.java +++ b/src/com/mojang/ld22/entity/IronLantern.java @@ -1,4 +1,3 @@ -//new class, no comments. package com.mojang.ld22.entity; import com.mojang.ld22.gfx.Color; diff --git a/src/com/mojang/ld22/entity/ItemEntity.java b/src/com/mojang/ld22/entity/ItemEntity.java index 9458fe4b3..070f2f3b2 100644 --- a/src/com/mojang/ld22/entity/ItemEntity.java +++ b/src/com/mojang/ld22/entity/ItemEntity.java @@ -2,37 +2,33 @@ import com.mojang.ld22.gfx.Color; import com.mojang.ld22.gfx.Screen; -import com.mojang.ld22.item.Item; +import com.mojang.ld22.item.ResourceItem; import com.mojang.ld22.sound.Sound; public class ItemEntity extends Entity { private int lifeTime; // the life time of this entity in the level - protected int walkDist = 0; - protected int dir = 0; - //public int hurtTime = 0; - protected int xKnockback, yKnockback; - public double xa, ya, za; // the x, y, and z acceleration - public double xx, yy, zz; // the x, y, and z coordinates - public Item item; // the item that this entity is based off of. + public double xa, ya, za; // the x, y, and z accelerations. + public double xx, yy, zz; // the x, y, and z coordinates; in double precision. + public ResourceItem item; // the item that this entity is based off of. private int time = 0; // time it has lasted in the level - - public ItemEntity(Item item, int x, int y) { + + public ItemEntity(ResourceItem item, int x, int y) { this.item = item; xx = this.x = x; yy = this.y = y; xr = 3; // x radius (size) yr = 3; // y radius (size) - + zz = 2; // random direction for each acceleration xa = random.nextGaussian() * 0.3; ya = random.nextGaussian() * 0.2; za = random.nextFloat() * 0.7 + 1; - + lifeTime = 60 * 10 + random.nextInt(70); // sets the lifetime of the item. min = 600 ticks, max = 669 ticks. // the idea was to have it last 10-11 seconds, I think. } - + public void tick() { time++; if (time >= lifeTime) { // if the time is larger or equal to lifeTime then... @@ -43,7 +39,7 @@ public void tick() { xx += xa; yy += ya; zz += za; - if (zz < 0) { // if z pos is smaller than 0 (which is probably marks hitting the ground) + if (zz < 0) { // if z pos is smaller than 0 (which probably marks hitting the ground) zz = 0; // set it to zero // multiply the accelerations by an amount: za *= -0.5; @@ -70,8 +66,6 @@ public void tick() { // Basically, this accounts for any error in the whole double-to-int position conversion thing: xx += gotx - expectedx; yy += goty - expectedy; - - //if (hurtTime > 0) hurtTime--; // what's hurtTime even for? } public boolean isBlockableBy(Mob mob) { diff --git a/src/com/mojang/ld22/entity/Knight.java b/src/com/mojang/ld22/entity/Knight.java index 1fe038bbf..83641435d 100644 --- a/src/com/mojang/ld22/entity/Knight.java +++ b/src/com/mojang/ld22/entity/Knight.java @@ -14,7 +14,7 @@ public class Knight extends Mob { int ya; int xe = xa; int ye = ya; - private int lvl; + //private int lvl; private int randomWalkTime = 0; public Knight(int lvl) { diff --git a/src/com/mojang/ld22/entity/Loom.java b/src/com/mojang/ld22/entity/Loom.java index bdfa17302..ae524b5d8 100644 --- a/src/com/mojang/ld22/entity/Loom.java +++ b/src/com/mojang/ld22/entity/Loom.java @@ -1,4 +1,3 @@ -//new class, no comments. package com.mojang.ld22.entity; import com.mojang.ld22.crafting.Crafting; @@ -19,9 +18,10 @@ public Loom() { xr = 7; yr = 2; } - + + /// called when the player presses menu button with the loom in front of them. public boolean use(Player player, int attackDir) { - player.game.setMenu(new CraftingMenu(Crafting.loomRecipes, player)); + player.game.setMenu(new CraftingMenu(Crafting.loomRecipes, player)); // open the loom menu. return true; } } diff --git a/src/com/mojang/ld22/entity/Mob.java b/src/com/mojang/ld22/entity/Mob.java index b64416da6..9a7ec53b9 100644 --- a/src/com/mojang/ld22/entity/Mob.java +++ b/src/com/mojang/ld22/entity/Mob.java @@ -55,9 +55,6 @@ public boolean move(int xa, int ya) { // Move the mob, overrides from Entity if (isWooling()) { // same as above, for wool if (woolTimer++ % 2 == 0) return true; } - /*if (isLight()) { // this seems useless. - if (lightTimer++ % 8000 == 0) return true; - }*/ /// These 4 following conditionals check the direction of the knockback, move the Mob accordingly, and bring knockback closer to 0. if (xKnockback < 0) { // If we have negative horizontal knockback (to the left) @@ -76,7 +73,7 @@ public boolean move(int xa, int ya) { // Move the mob, overrides from Entity move2(0, 1); yKnockback--; } - if (hurtTime > 0) return true; // If we have been hurt recently and haven't yet cooled down, don't continue with the movement (so only knockback will be performed) + if (hurtTime > 0 && this instanceof Player == false) return true; // If we have been hurt recently and haven't yet cooled down, don't continue with the movement (so only knockback will be performed) if (xa != 0 || ya != 0) { // Only if horizontal or vertical movement is actually happening walkDist++; // Increment our walking/movement counter diff --git a/src/com/mojang/ld22/entity/Oven.java b/src/com/mojang/ld22/entity/Oven.java index 8d4a9fdbe..541ad194e 100644 --- a/src/com/mojang/ld22/entity/Oven.java +++ b/src/com/mojang/ld22/entity/Oven.java @@ -4,7 +4,6 @@ import com.mojang.ld22.gfx.Color; import com.mojang.ld22.screen.CraftingMenu; -// just another crafting furniture class... public class Oven extends Furniture { public Oven() { super("Oven"); @@ -19,7 +18,8 @@ public Oven() { xr = 3; yr = 2; } - + + /// opens the Oven menu. public boolean use(Player player, int attackDir) { player.game.setMenu(new CraftingMenu(Crafting.ovenRecipes, player)); return true; diff --git a/src/com/mojang/ld22/entity/Player.java b/src/com/mojang/ld22/entity/Player.java index ca36ec984..0f2617bdf 100644 --- a/src/com/mojang/ld22/entity/Player.java +++ b/src/com/mojang/ld22/entity/Player.java @@ -4,7 +4,6 @@ import com.mojang.ld22.InputHandler; import com.mojang.ld22.crafting.Crafting; import com.mojang.ld22.entity.particle.TextParticle; -import com.mojang.ld22.entity.ItemEntity; import com.mojang.ld22.gfx.Color; import com.mojang.ld22.gfx.Screen; import com.mojang.ld22.item.FurnitureItem; @@ -14,8 +13,9 @@ import com.mojang.ld22.item.ResourceItem; import com.mojang.ld22.item.ToolItem; import com.mojang.ld22.item.ToolType; -import com.mojang.ld22.item.resource.Resource; +import com.mojang.ld22.item.resource.ArmorResource; import com.mojang.ld22.item.resource.PotionResource; +import com.mojang.ld22.item.resource.Resource; import com.mojang.ld22.level.Level; import com.mojang.ld22.level.tile.Tile; import com.mojang.ld22.saveload.Save; @@ -28,59 +28,55 @@ import com.mojang.ld22.screen.PlayerInfoMenu; import com.mojang.ld22.screen.WorldSelectMenu; import com.mojang.ld22.sound.Sound; -import java.util.ArrayList; -import java.util.List; import java.util.HashMap; +import java.util.List; public class Player extends Mob { private InputHandler input; public Game game; - public static int moveSpeed = 1; // the number of coordinate squares to move; each tile is 16x16. - public static Inventory Sinventory; //static inventory, I guess. + public static final int playerHurtTime = 30; + public static double moveSpeed = 1; // the number of coordinate squares to move; each tile is 16x16. public static int score; // the player's score - public static int SHealth = 10; - public static int SHunger = 10; public static boolean hasSetHome = false, skinon; //These 2 ints are ints saved from the first spawn - this way the spawn pos is always saved. public static int spawnx = 0, spawny = 0; // these are stored as tile coordinates, not entity coordinates. - //public static int xx, yy; + public static int maxStamina = 10, maxHunger = 10, maxArmor = 100; // the maximum stats that the player can have. public Inventory inventory; public Item attackItem, activeItem; public boolean energy; public int attackTime, attackDir; - public int maxStamina, armor, maxHunger; // the maximum stats that the player can have public int homeSetX, homeSetY; public boolean bedSpawn; - + private int onStairDelay; // the delay before changing levels. public int stepCount; int tickCounter; int timesTick; - - public int hunger, stamina; + + public int hunger, stamina, armor; // the current stats + public int armorDamageBuffer; + public ArmorResource curArmor; // the color of the armor to be displayed. public int staminaRecharge; // the recharge rate of the player's stamina public int staminaRechargeDelay; // the recharge delay when the player uses up their stamina. public int hungStamCnt; - int hungerChargeDelay; - int hungerStarveDelay; + int hungerChargeDelay; // the delay between each time the hunger bar increases your health + int hungerStarveDelay; // the delay between each time the hunger bar decreases your health boolean alreadyLostHunger; boolean repeatHungerCyc; - - public int invulnerableTime; // the invulnerability time the player has when hit; this replaces hurtTime of Mob.java in terms of functionality, but hurtTime is still used, to make the player flash white. - // TODO switch hurtTime back to original functionality; make different int for flash, or better yet, just do "if(hurtTime <= 10)" for flash duration. then the above int should be able to be removed. + public boolean showinfo; public int px, py; - public HashMap potioneffects; - public boolean showpotioneffects; - int cooldowninfo; - int regentick; + public HashMap potioneffects; // the potion effects currently applied to the player + public boolean showpotioneffects; // whether to display the current potion effects on screen + int cooldowninfo; // prevents you from toggling the info pane on and off super fast. + int regentick; // counts time between each time the regen potion effect heals you. - int acs = 25; // default arrow count + int acs = 25; // default ("start") arrow count public int ac; // arrow count - public int r = 50, g = 50, b; + public int r = 50, g = 50, b; // player shirt color. // Note: the player's health & max health are inherited from Mob.java @@ -96,14 +92,13 @@ public Player(Game game, InputHandler input) { tickCounter = 0; energy = false; - maxStamina = 10; - maxHunger = 10; + //maxStamina = 10; + //maxHunger = 10; repeatHungerCyc = false; px = this.x; py = this.y; - invulnerableTime = 0; potioneffects = new HashMap(); showpotioneffects = true; @@ -116,6 +111,8 @@ public Player(Game game, InputHandler input) { b = 0; armor = 0; + curArmor = null; + armorDamageBuffer = 0; stamina = maxStamina; hunger = maxHunger; @@ -134,7 +131,6 @@ public void tick() { super.tick(); // ticks Mob.java isenemy = false; tickCounter++; - //if(Game.debug) System.out.println(tickCounter); if(potioneffects.size() > 0 && !Bed.hasBedSet) { for(String potionType: potioneffects.keySet().toArray(new String[0])) { @@ -156,8 +152,6 @@ public void tick() { showpotioneffects = !showpotioneffects; } - if (invulnerableTime > 0) invulnerableTime--; // if invulnerableTime is above 0, then decrease it by 1. - Tile onTile = level.getTile(x >> 4, y >> 4); // gets the current tile the player is on. if (onTile == Tile.stairsDown || onTile == Tile.stairsUp || onTile == Tile.lightstairsDown || onTile == Tile.lightstairsUp) { if (onStairDelay == 0) { // when the delay time has passed... @@ -200,10 +194,6 @@ public void tick() { if (staminaRechargeDelay > 0) staminaRechargeDelay--; - SHealth = health; // this saves health - SHunger = hunger; // this saves hunger - Sinventory = inventory; - if (staminaRechargeDelay == 0) { staminaRecharge++; // this is used to determine the time between each bolt recharge. @@ -217,14 +207,20 @@ public void tick() { } } - if (hungerChargeDelay == 0) { + /*if (hungerChargeDelay == 0) { hungerChargeDelay = 100; + }*/ + + /// system that heals you depending on your hunger + if (health < maxHealth && hunger > maxHunger/2) { + //if (hungerChargeDelay > 0) hungerChargeDelay--; + hungerChargeDelay++; + if (hungerChargeDelay > 50*Math.pow(maxHunger-hunger+1, 2)) { + health++; + hungerChargeDelay = 0; + } } - - if (hunger == 10 && health < 10) { - if (hungerChargeDelay > 0) hungerChargeDelay--; - if (hungerChargeDelay == 0) health++; - } + else hungerChargeDelay = 0; if (hungerStarveDelay == 0) { hungerStarveDelay = 120; @@ -235,7 +231,7 @@ public void tick() { stepCount = 0; } } - + // on easy mode, hunger doesn't deplete? if (OptionsMenu.diff == OptionsMenu.hard) { if (stepCount >= 5000) { hunger--; @@ -284,33 +280,25 @@ public void tick() { } } - // this is the movement detection; apparently, we shouldn't move while fishing. + // this is where movement detection occurs. int xa = 0, ya = 0; - //if (!Game.isfishing) { - for(int moves = 1; moves <= moveSpeed; moves++) { // allows for multiple steps walked per tick. - if (input.getKey("up").down) { - ya--; - stepCount++; - } - if (input.getKey("down").down) { - ya++; - stepCount++; - } - if (input.getKey("left").down) { - xa--; - stepCount++; - } - if (input.getKey("right").down) { - xa++; - stepCount++; - } - } - //} + if (input.getKey("up").down) { + ya--; + stepCount++; + } + if (input.getKey("down").down) { + ya++; + stepCount++; + } + if (input.getKey("left").down) { + xa--; + stepCount++; + } + if (input.getKey("right").down) { + xa++; + stepCount++; + } - // TODO why is this necessary? well... x and y are updated below by Mob.java, and Entity.java in turn; perhaps it is necessary to save the previous position? - //This is ONLY used in Game.java, in the renderGui method... - //xx = x; - //yy = y; if (isSwimming() && tickTime % 60 == 0 && !potioneffects.containsKey("Swim")) { // if drowning... :P if (stamina > 0) stamina--; // take away stamina else hurt(this, 1, dir ^ 1); // if no stamina, take damage. @@ -337,7 +325,7 @@ public void tick() { //executes if not saving; and... essentially halves speed if out of stamina. if (staminaRechargeDelay % 2 == 0 && game.savecooldown == 0 && !game.saving) { - double spd = moveSpeed * (potioneffects.containsKey("Time") ? 1.5f : 1); + double spd = moveSpeed * (potioneffects.containsKey("Time") ? (potioneffects.containsKey("Speed") ? 1.5D : 2) : 1); move((int) (xa * spd), (int) (ya * spd)); // THIS is where the player moves; part of Mob.java } @@ -425,12 +413,6 @@ private void attack() { level.add(new Arrow(this, spx, spy, tool.level, done)); done = true; // we have attacked! } - - /*if(tool.type == ToolType.rod) { - goFishing(); - tool.dur--; - if(tool.dur == 0) activeItem = null; - }*/ } // if we are simply holding an item... @@ -499,32 +481,21 @@ private void attack() { } public void goFishing(int x, int y) { - //isfishing = true; int fcatch = random.nextInt(90); - //if (activeItem instanceof ResourceItem && ((ResourceItem)activeItem).resource instanceof ItemResource && ((ItemResource)(((ResourceItem)activeItem).resource)).dur == 0) activeItem.isDepleted(); - - //if(activeItem != null) activeItem.isDepleted(); - if (fcatch <= 8) { - if(Game.debug) System.out.println("Caught a Fish!"); level.add(new ItemEntity(new ResourceItem(Resource.rawfish), x + random.nextInt(11) - 5, y + random.nextInt(11) - 5)); - //isfishing = false; } if (fcatch == 25 || fcatch == 43 || fcatch == 32 || fcatch == 15 || fcatch == 42) { - if(Game.debug) System.out.println("Caught some slime?"); level.add(new ItemEntity(new ResourceItem(Resource.slime), x + random.nextInt(11) - 5, y + random.nextInt(11) - 5)); - //isfishing = false; } if (fcatch == 56) { - if(Game.debug) System.out.println("Rare Armor!"); level.add(new ItemEntity(new ResourceItem(Resource.larmor), x + random.nextInt(11) - 5, y + random.nextInt(11) - 5)); - //isfishing = false; } else { - if(Game.debug) System.out.println("FAIL!"); - //isfishing = false; + if(Game.debug) System.out.println("Nothing caught..."); + if(random.nextInt(200) == 42) System.out.println("CHUCKNORRIS got away..."); } } @@ -648,7 +619,7 @@ public void render(Screen screen) { if(Game.time == 3) col = col3; } else col = col4; - if (hurtTime > 0) { // if the player is getting hurt at the moment... + if (hurtTime > playerHurtTime - 10) { // if the player has just gotten hurt... col = Color.get(-1, 555, 555, 555); // make the sprite white. } @@ -700,6 +671,9 @@ public void touchItem(ItemEntity itemEntity) { itemEntity.take(this); // calls the take() method in ItemEntity if (itemEntity.item.getName() == "arrow") { ac++; // if it's an arrow, then just add to arrow count, not inventory. + } else if(activeItem != null && activeItem.getName() == itemEntity.item.getName() && activeItem instanceof ResourceItem && itemEntity.item instanceof ResourceItem) { + // picked up item matches the one in your hand + ((ResourceItem)activeItem).count += ((ResourceItem)itemEntity.item).count; } else { inventory.add(itemEntity.item); // add item to inventory } @@ -798,7 +772,7 @@ public int getLightRadius() { //if (Game.currentLevel == 3) return 0; // I don't want the player to have an automatic halo on the surface. float light = potioneffects.containsKey("Light") ? 2.5f : 1; // multiplier for the light potion effect. - float r = 3/*.25f*/ * light; // the radius of the light. + float r = 3 * light; // the radius of the light. if (Game.currentLevel == 5) r = 5 * light; // more light than usual on dungeon level. @@ -817,22 +791,18 @@ protected void die() { super.die(); // calls the die() method in Mob.java int lostscore = score / 3; // finds score penalty score -= lostscore; // subtracts score penalty - Game.ism = 1; // still not totally sure what this is... + game.setMultiplier(1); //make death chest - Chest dc = new Chest(true); + Chest dc = new DeathChest(); dc.x = this.x; dc.y = this.y; - PowerGloveItem pg = new PowerGloveItem(); dc.inventory = this.inventory; if (activeItem != null) { dc.inventory.add(activeItem); } - - for (int i = 0; i < inventory.items.size(); i++) - if (((Item) inventory.items.get(i)).matches(pg)) - dc.inventory.items.remove((Item) inventory.items.get(i)); - + dc.inventory.removeItem(new PowerGloveItem()); + Game.levels[Game.currentLevel].add(dc); Sound.playerDeath.play(); @@ -848,34 +818,51 @@ protected void touchedBy(Entity entity) { /** What happens when the player is hurt */ protected void doHurt(int damage, int attackDir) { if (ModeMenu.creative) return; // can't get hurt in creative - if (hurtTime > 0 || invulnerableTime > 0) return; // currently in hurt cooldown - + if (hurtTime > 0) return; // currently in hurt cooldown + + int healthDam = 0, armorDam = 0; Sound.playerHurt.play(); - if (armor <= 0) { // no armor - level.add(new TextParticle("" + damage, x, y, Color.get(-1, 504, 504, 504))); // adds a text particle telling how much damage was done. + if (curArmor == null) { // no armor health -= damage; // subtract that amount + } else { // has armor + armorDamageBuffer += damage; + armorDam += damage; + + while (armorDamageBuffer >= curArmor.level+1) { + armorDamageBuffer -= curArmor.level+1; + healthDam++; + } } - if (armor > 0) { // has armor - level.add(new TextParticle("" + damage, x, y, Color.get(-1, 333, 333, 333))); // adds a text particle telling how much damage was done. - if (damage > armor) { // will still hurt the player's hearts - int dmgleft = damage - armor; // this much is subtracted from health - health -= dmgleft; - armor = 0; // no armor left - } else armor -= damage; // the armor took all the damage + + // adds a text particle telling how much damage was done to the player, and the armor. + if(armorDam > 0) { + level.add(new TextParticle("" + damage, x, y, Color.get(-1, 333, 333, 333))); + armor -= armorDam; + if(armor <= 0) { + healthDam -= armor; // adds armor damage overflow to health damage (minus b/c armor would be negative) + armor = 0; + armorDamageBuffer = 0; // ensures that new armor doesn't inherit partial breaking from this armor. + curArmor = null; // removes armor + } + } + if(healthDam > 0) { + level.add(new TextParticle("" + damage, x, y, Color.get(-1, 504, 504, 504))); + health -= healthDam; } + // apply the appropriate knockback if (attackDir == 0) yKnockback = +6; if (attackDir == 1) yKnockback = -6; if (attackDir == 2) xKnockback = -6; if (attackDir == 3) xKnockback = +6; // set hurt and invulnerable times - hurtTime = 10; - invulnerableTime = 30; + hurtTime = playerHurtTime; } + /** What happens when the player wins */ public void gameWon() { - level.player.invulnerableTime = 60 * 5; // sets the invulnerable time to 300 + hurtTime = 60 * 5; // sets the invulnerable time to 300 game.won(); // win the game } } diff --git a/src/com/mojang/ld22/entity/Skeleton.java b/src/com/mojang/ld22/entity/Skeleton.java index 3e69f5137..044415b74 100644 --- a/src/com/mojang/ld22/entity/Skeleton.java +++ b/src/com/mojang/ld22/entity/Skeleton.java @@ -11,7 +11,7 @@ public class Skeleton extends Mob { int xa, ya, xe, ye; - private int lvl; + //private int lvl; private int randomWalkTime; public int arrowtime; public int artime; @@ -24,7 +24,7 @@ public Skeleton(int lvl) { arrowtime = 70 / (lvl + 1); artime = arrowtime; - + this.lvl = lvl; col0 = Color.get(-1, 111, 40, 444); col1 = Color.get(-1, 222, 50, 555); col2 = Color.get(-1, 111, 40, 444); @@ -250,6 +250,7 @@ public void render(Screen screen) { } protected void touchedBy(Entity entity) { + super.touchedBy(entity); if (OptionsMenu.diff == OptionsMenu.easy) { if (entity instanceof Player) { //entity.hurt(this, lvl, dir); @@ -377,10 +378,10 @@ else if (rand >= 29) } if (level.player != null) { - level.player.score += (50 * lvl) * Game.multiplyer; + level.player.score += (50 * lvl) * Game.multiplier; } - Game.multiplyer++; - Game.multiplyertime = Game.mtm -= 5; + Game.multiplier++; + Game.multipliertime = Game.mtm -= 5; } } diff --git a/src/com/mojang/ld22/entity/Slime.java b/src/com/mojang/ld22/entity/Slime.java index 056653a0a..d0e6c021a 100644 --- a/src/com/mojang/ld22/entity/Slime.java +++ b/src/com/mojang/ld22/entity/Slime.java @@ -11,7 +11,7 @@ public class Slime extends Mob { private int xa, ya; // x and y acceleration private int jumpTime = 0; // jumpTimer, also acts as a rest timer before the next jump - private int lvl; // how tough the slime is + //private int lvl; // how tough the slime is public Slime(int lvl) { this.col0 = Color.get(-1, 20, 40, 10); @@ -27,32 +27,6 @@ public Slime(int lvl) { // Health based on level and difficulty: if (ModeMenu.creative) health = maxHealth = 1; else health = maxHealth = lvl * lvl * (OptionsMenu.diff * OptionsMenu.diff + 1); - /* if (OptionsMenu.diff == OptionsMenu.easy) health = maxHealth = lvl * lvl * (OptionsMenu.diff * OptionsMenu.diff + 1); - if (OptionsMenu.diff == OptionsMenu.norm) health = maxHealth = lvl * lvl * 5; - if (OptionsMenu.diff == OptionsMenu.hard) health = maxHealth = lvl * lvl * 10; - } - /* - if (OptionsMenu.diff == OptionsMenu.easy) { - this.lvl = lvl; - x = random.nextInt(64 * 16); - y = random.nextInt(64 * 16); - if (ModeMenu.creative) health = maxHealth = 1; - else health = maxHealth = lvl * lvl * 3; - } - - if (OptionsMenu.diff == OptionsMenu.norm) { - this.lvl = lvl; - x = random.nextInt(64 * 16); - y = random.nextInt(64 * 16); - if (ModeMenu.creative) health = maxHealth = 1; - else health = maxHealth = lvl * lvl * 5; - } - - if (OptionsMenu.diff == OptionsMenu.hard) { - - - // gives it a random x,y position anywhere between (0 to 1023) [Tile position (0 to 64)] else health = maxHealth = lvl * lvl * 10; - }*/ } public void tick() { @@ -95,44 +69,13 @@ protected void die() { for (int i = 0; i < count; i++) { level.add(new ItemEntity(new ResourceItem(Resource.slime), x + random.nextInt(11) - 5, y + random.nextInt(11) - 5)); //creates slime items } - /* - if (OptionsMenu.diff == OptionsMenu.easy) { - int count = random.nextInt(3) + 1; // Random amount of slime(item) to drop from 1 to 2 - for (int i = 0; i < count; i++) { - level.add( - new ItemEntity( - new ResourceItem(Resource.slime), - x + random.nextInt(11) - 5, - y + random.nextInt(11) - 5)); - } - } - if (OptionsMenu.diff == OptionsMenu.norm) { - int count = random.nextInt(2) + 1; - for (int i = 0; i < count; i++) { - level.add( - new ItemEntity( - new ResourceItem(Resource.slime), - x + random.nextInt(11) - 5, - y + random.nextInt(11) - 5)); - } - } - if (OptionsMenu.diff == OptionsMenu.hard) { - int count = random.nextInt(1) + 1; - for (int i = 0; i < count; i++) { - level.add( - new ItemEntity( - new ResourceItem(Resource.slime), - x + random.nextInt(11) - 5, - y + random.nextInt(11) - 5)); - } - } - */ + if (level.player != null) { - level.player.score += (25 * lvl) * Game.multiplyer; // add score for slime death + level.player.score += (25 * lvl) * Game.multiplier; // add score for slime death } - Game.multiplyer++; // increment game multiplier - Game.multiplyertime = Game.mtm -= 5; + Game.multiplier++; // increment game multiplier + Game.multipliertime = Game.mtm -= 5; } public void render(Screen screen) { @@ -256,24 +199,10 @@ public boolean canWool() { } protected void touchedBy(Entity entity) { + super.touchedBy(entity); int damage = OptionsMenu.diff == OptionsMenu.hard ? 2 : 1; if (entity instanceof Player) { // if we touch the player entity.hurt(this, lvl*damage, dir); // attack } - /*if (OptionsMenu.diff == OptionsMenu.easy) { - if (entity instanceof Player) { // if we touch the player - entity.hurt(this, lvl, dir); // attack - } - } - if (OptionsMenu.diff == OptionsMenu.norm) { - if (entity instanceof Player) { - entity.hurt(this, lvl, dir); - } - } - if (OptionsMenu.diff == OptionsMenu.hard) { - if (entity instanceof Player) { - entity.hurt(this, lvl * 2, dir); - } - }*/ } } diff --git a/src/com/mojang/ld22/entity/Snake.java b/src/com/mojang/ld22/entity/Snake.java index fe25594ed..268d63c92 100644 --- a/src/com/mojang/ld22/entity/Snake.java +++ b/src/com/mojang/ld22/entity/Snake.java @@ -14,7 +14,7 @@ public class Snake extends Mob { int ya; int xe = xa; int ye = ya; - private int lvl; + //private int lvl; private int randomWalkTime = 0; public Snake(int lvl) { @@ -217,6 +217,7 @@ public void render(Screen screen) { } protected void touchedBy(Entity entity) { + super.touchedBy(entity); if (OptionsMenu.diff == OptionsMenu.easy) { if (entity instanceof Player) { if (lvl > 1) { diff --git a/src/com/mojang/ld22/entity/Spawner.java b/src/com/mojang/ld22/entity/Spawner.java index 2d4c97aac..43f1cf7a9 100644 --- a/src/com/mojang/ld22/entity/Spawner.java +++ b/src/com/mojang/ld22/entity/Spawner.java @@ -1,5 +1,6 @@ package com.mojang.ld22.entity; +import com.mojang.ld22.Game; import com.mojang.ld22.entity.particle.FireParticle; import com.mojang.ld22.entity.particle.TextParticle; import com.mojang.ld22.gfx.Color; @@ -58,9 +59,9 @@ private void trySpawn() { newmob.x = randX * 16; newmob.y = randY * 16; //(newmob).hasspawned = true; - if (com.mojang.ld22.Game.debug) System.out.println("spawning new " + mob + " on level "+lvl+": x=" + (newmob.x/16)+" y="+(newmob.y/16) + "..."); + if (Game.debug) System.out.println("spawning new " + mob + " on level "+lvl+": x=" + (newmob.x/16)+" y="+(newmob.y/16) + "..."); level.add(newmob); - + Sound.monsterHurt.play(); for(int i = 0; i < 6; i++) { randX = rnd.nextInt(16); randY = rnd.nextInt(12); diff --git a/src/com/mojang/ld22/entity/Zombie.java b/src/com/mojang/ld22/entity/Zombie.java index 74bbe5b7c..f94527719 100644 --- a/src/com/mojang/ld22/entity/Zombie.java +++ b/src/com/mojang/ld22/entity/Zombie.java @@ -11,7 +11,7 @@ // TODO compress the enemy mobs into an Enemy class... further, similar compression can happen in many places... public class Zombie extends Mob { int xa, ya; - private int lvl; // how tough the zombie is + //private int lvl; // how tough the zombie is private int randomWalkTime = 0; //time till next walk public Zombie(int lvl) { @@ -26,26 +26,7 @@ public Zombie(int lvl) { x = random.nextInt(64 * 16); y = random.nextInt(64 * 16); if (ModeMenu.creative) health = maxHealth = 1; - else health = maxHealth = lvl * lvl * 5*Math.pow(2, OptionsMenu.diff-1); // 5, 10, 20 - /* - if (OptionsMenu.diff == OptionsMenu.easy) { - - - } - - if (OptionsMenu.diff == OptionsMenu.norm) { - x = random.nextInt(64 * 16); - y = random.nextInt(64 * 16); - if (ModeMenu.creative) health = maxHealth = 1; - else health = maxHealth = lvl * lvl * 10; - } - - if (OptionsMenu.diff == OptionsMenu.hard) { - x = random.nextInt(64 * 16); - y = random.nextInt(64 * 16); - if (ModeMenu.creative) health = maxHealth = 1; - else health = maxHealth = lvl * lvl * 20; - }*/ + else health = maxHealth = lvl * lvl * 5*((Double)(Math.pow(2, OptionsMenu.diff-1))).intValue(); // 5, 10, 20 } public void tick() { @@ -195,13 +176,14 @@ public void render(Screen screen) { } protected void touchedBy(Entity entity) { // if the entity touches the player + super.touchedBy(entity); // hurts the player, damage is based on lvl. - if (OptionsMenu.diff == OptionsMenu.easy) { - if (entity instanceof Player) { + if(entity instanceof Player) { + if (OptionsMenu.diff != OptionsMenu.hard) entity.hurt(this, lvl, dir); - } + else entity.hurt(this, lvl * 2, dir); } - if (OptionsMenu.diff == OptionsMenu.norm) { + /*if (OptionsMenu.diff == OptionsMenu.norm) { if (entity instanceof Player) { entity.hurt(this, lvl, dir); } @@ -210,7 +192,7 @@ protected void touchedBy(Entity entity) { // if the entity touches the player if (entity instanceof Player) { entity.hurt(this, lvl * 2, dir); } - } + }*/ } public boolean canWool() { @@ -243,11 +225,7 @@ protected void die() { if (OptionsMenu.diff == OptionsMenu.hard) { int count = random.nextInt(1) + 1; for (int i = 0; i < count; i++) { - level.add( - new ItemEntity( - new ResourceItem(Resource.cloth), - x + random.nextInt(11) - 5, - y + random.nextInt(11) - 5)); + level.add(new ItemEntity(new ResourceItem(Resource.cloth), x + random.nextInt(11) - 5, y + random.nextInt(11) - 5)); } } @@ -267,10 +245,11 @@ protected void die() { } if (level.player != null) { // if player is on zombie level - level.player.score += (50 * lvl) * Game.multiplyer; // add score for zombie death + level.player.score += (50 * lvl) * Game.multiplier; // add score for zombie death } - - Game.multiplyer++; // add to multiplier - Game.multiplyertime = Game.mtm -= 5; // ? + + // TODO implement Game.setMultiplier (maybe make it addMultiplier() and resetMultiplier()). + Game.multiplier++; // add to multiplier + Game.multipliertime = Game.mtm -= 5; } } diff --git a/src/com/mojang/ld22/entity/particle/FireParticle.java b/src/com/mojang/ld22/entity/particle/FireParticle.java index d0e2c5afd..7cc755240 100644 --- a/src/com/mojang/ld22/entity/particle/FireParticle.java +++ b/src/com/mojang/ld22/entity/particle/FireParticle.java @@ -1,31 +1,11 @@ package com.mojang.ld22.entity.particle; -import com.mojang.ld22.entity.Entity; import com.mojang.ld22.gfx.Color; -import com.mojang.ld22.gfx.Screen; -import com.mojang.ld22.sound.Sound; - -//This is used only for potions, I believe. -public class FireParticle extends Entity { - - private int time = 0; +public class FireParticle extends Particle { + /// This is used for Spawners, when they spawn an entity. + public FireParticle(int x, int y) { - this.x = x; - this.y = y; - Sound.monsterHurt.play(); - } - - public void tick() { - time++; - if(time > 30) { - remove(); - } - - } - - public void render(Screen screen) { - int col = Color.get(-1, 520, 550, 500); - screen.render(x - 8, y - 8, 425, col, 0); + super(x, y, 30, Color.get(-1, 520, 550, 500)); } } diff --git a/src/com/mojang/ld22/entity/particle/Particle.java b/src/com/mojang/ld22/entity/particle/Particle.java new file mode 100644 index 000000000..2f4b1bc58 --- /dev/null +++ b/src/com/mojang/ld22/entity/particle/Particle.java @@ -0,0 +1,29 @@ +package com.mojang.ld22.entity.particle; + +import com.mojang.ld22.entity.Entity; +import com.mojang.ld22.gfx.Screen; + +public class Particle extends Entity { + private int time = 0; // lifetime elapsed. + protected int lifetime; + protected int color; + + public Particle(int x, int y, int lifetime, int color) { + // make a particle at the given coordinates + this.x = x; + this.y = y; + this.lifetime = lifetime; + this.color = color; + } + + public void tick() { + time++; + if(time > lifetime) { + remove(); + } + } + + public void render(Screen screen) { + screen.render(x - 8, y - 8, 425, color, 0); // render the particle. + } +} diff --git a/src/com/mojang/ld22/entity/particle/SmashParticle.java b/src/com/mojang/ld22/entity/particle/SmashParticle.java index 8c4f7658b..3c9007d69 100644 --- a/src/com/mojang/ld22/entity/particle/SmashParticle.java +++ b/src/com/mojang/ld22/entity/particle/SmashParticle.java @@ -1,34 +1,21 @@ package com.mojang.ld22.entity.particle; -import com.mojang.ld22.entity.Entity; import com.mojang.ld22.gfx.Color; import com.mojang.ld22.gfx.Screen; import com.mojang.ld22.sound.Sound; -public class SmashParticle extends Entity { - private int time = 0; // the time that the particle is on screen - +public class SmashParticle extends Particle { + public SmashParticle(int x, int y) { - this.x = x; // assigns the x position of the particle - this.y = y; // assigns the y position of the particle + super(x, y, 10, Color.get(-1, 555, 555, 555)); Sound.monsterHurt.play(); // plays the sound of a monster getting hit. } - /// Essentially, removes the particle after 10 ticks. - public void tick() { - time++; - if (time > 10) { - remove(); - } - } - public void render(Screen screen) { - int col = Color.get(-1, 555, 555, 555); // color of the particle (white) - - // renders each corner... - screen.render(x - 8, y - 8, 5 + 12 * 32, col, 2); //top-left - screen.render(x - 0, y - 8, 5 + 12 * 32, col, 3); //top-right - screen.render(x - 8, y - 0, 5 + 12 * 32, col, 0); //bottom-left - screen.render(x - 0, y - 0, 5 + 12 * 32, col, 1); //bottom-right + // renders each corner from the same sprite. + screen.render(x - 8, y - 8, 5 + 12 * 32, color, 2); //top-left + screen.render(x - 0, y - 8, 5 + 12 * 32, color, 3); //top-right + screen.render(x - 8, y - 0, 5 + 12 * 32, color, 0); //bottom-left + screen.render(x - 0, y - 0, 5 + 12 * 32, color, 1); //bottom-right } } diff --git a/src/com/mojang/ld22/entity/particle/TextParticle.java b/src/com/mojang/ld22/entity/particle/TextParticle.java index e3c300e41..a44692a62 100644 --- a/src/com/mojang/ld22/entity/particle/TextParticle.java +++ b/src/com/mojang/ld22/entity/particle/TextParticle.java @@ -1,22 +1,18 @@ package com.mojang.ld22.entity.particle; -import com.mojang.ld22.entity.Entity; import com.mojang.ld22.gfx.Color; import com.mojang.ld22.gfx.Font; import com.mojang.ld22.gfx.Screen; -public class TextParticle extends Entity { +public class TextParticle extends Particle { private String msg; // Message of the text particle - private int col; // Color of the text particle - private int time = 0; // time (in ticks) that the particle has been alive public double xa, ya, za; // x,y,z acceleration public double xx, yy, zz; // x,y,z coordinates public TextParticle(String msg, int x, int y, int col) { + super(x, y, 60, col); + this.msg = msg; - this.x = x; - this.y = y; - this.col = col; xx = x; //assigns x pos yy = y; //assigns y pos zz = 2; //assigns z pos to be 2 @@ -28,11 +24,8 @@ public TextParticle(String msg, int x, int y, int col) { } public void tick() { - time++; - if (time > 60) { - //remove text particle after 60 ticks. - remove(); - } + super.tick(); + //move the particle according to the acceleration xx += xa; yy += ya; @@ -52,6 +45,6 @@ public void tick() { public void render(Screen screen) { Font.draw(msg, screen, x - msg.length() * 4 + 1, y - (int) (zz) + 1, Color.get(-1, 0, 0, 0)); //renders the backdrop - Font.draw(msg, screen, x - msg.length() * 4, y - (int) (zz), col); // renders the text + Font.draw(msg, screen, x - msg.length() * 4, y - (int) (zz), color); // renders the text } } diff --git a/src/com/mojang/ld22/gfx/Font.java b/src/com/mojang/ld22/gfx/Font.java index 2b16a7286..9353b52ff 100644 --- a/src/com/mojang/ld22/gfx/Font.java +++ b/src/com/mojang/ld22/gfx/Font.java @@ -54,7 +54,8 @@ else if (x == x1)// x at end, render right endpoint draw(title, screen, x0 * 8 + 8, y0 * 8, Color.get(5, 5, 5, 550)); } - + + /// renders crafting menu frame. public static void rendercraftFrame(Screen screen, String title, int x0, int y0, int x1, int y1) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { @@ -77,7 +78,7 @@ else if (x == x1 && y == y1) draw(title, screen, x0 * 8 + 8, y0 * 8, Color.get(300, 300, 300, 555)); } - ///Oh, pooh, David never explained this... + /// self-explanitory; renders book frame. public static void renderFrameBook(Screen screen, String title, int x0, int y0, int x1, int y1) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { @@ -99,4 +100,12 @@ else if (x == x1 && y == y1) draw(title, screen, x0 * 8 + 8, y0 * 8, Color.get(-1, 222, 222, 222)); } } + + public static int textWidth(String text) { + return text.length() * 8; + } + + public static void drawCentered(String msg, Screen screen, int y, int color) { + draw(msg, screen, screen.centertext(msg), y, color); + } } diff --git a/src/com/mojang/ld22/gfx/Screen.java b/src/com/mojang/ld22/gfx/Screen.java index 97147b2d3..2e9130ad2 100644 --- a/src/com/mojang/ld22/gfx/Screen.java +++ b/src/com/mojang/ld22/gfx/Screen.java @@ -1,5 +1,6 @@ package com.mojang.ld22.gfx; + public class Screen { /// x and y offset of screen: @@ -30,11 +31,11 @@ public void clear(int color) { } public int centertext(String text) { - return (w - text.length() * 8) / 2; + return (w - Font.textWidth(text)) / 2; } - /** Renders an object from the sprite sheet based on screen coordinates, tile (SpriteSheet location), colors, and bits (for mirroring) */ + // TODO make a method that calls this 4 times, for each corner. public void render(int xp, int yp, int tile, int colors, int bits) { xp -= xOffset; //account for screen offset yp -= yOffset; diff --git a/src/com/mojang/ld22/item/FurnitureItem.java b/src/com/mojang/ld22/item/FurnitureItem.java index f88286fe4..459264e14 100644 --- a/src/com/mojang/ld22/item/FurnitureItem.java +++ b/src/com/mojang/ld22/item/FurnitureItem.java @@ -10,47 +10,55 @@ import com.mojang.ld22.level.tile.Tile; public class FurnitureItem extends Item { - public Furniture furniture; - public boolean placed = false; + public Furniture furniture; // the furniture of this item + public boolean placed = false; // value if the furniture has been placed or not. public FurnitureItem(Furniture furniture) { - this.furniture = furniture; + this.furniture = furniture; // Assigns the furniture to the item } - + public int getColor() { return furniture.col; - } - + + /** Determines if you can attack enemies with furniture (you can't) */} + public int getSprite() { return furniture.sprite + 10 * 32; } - + + /** Renders the icon used for the furniture. */ public void renderIcon(Screen screen, int x, int y) { screen.render(x, y, getSprite(), getColor(), 0); } - + + /** Renders the icon, and name of the furniture */ public void renderInventory(Screen screen, int x, int y) { - screen.render(x, y, getSprite(), getColor(), 0); - Font.draw(furniture.name, screen, x + 8, y, Color.get(-1, 555, 555, 555)); + screen.render(x, y, getSprite(), getColor(), 0); // renders the icon + Font.draw(furniture.name, screen, x + 8, y, Color.get(-1, 555, 555, 555)); // draws the name of the furniture } - + + /** What happens when you pick up the item off the ground (Not with the power glove) */ public void onTake(ItemEntity itemEntity) {} - + + /** Determines if you can attack enemies with furniture (you can't) */ public boolean canAttack() { return false; } - + + /** What happens when you press the "Attack" key with the furniture in your hands */ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, int attackDir) { - if (tile.mayPass(level, xt, yt, furniture)) { + if (tile.mayPass(level, xt, yt, furniture)) { // If the furniture can go on the tile + // Placed furniture's X and Y positions furniture.x = xt * 16 + 8; furniture.y = yt * 16 + 8; - level.add(furniture); - placed = true; + level.add(furniture); // adds the furniture to the world + placed = true; // the value becomes true, which removes it from the player's active item return true; } return false; } - + + /** Removes this item from the player's active item slot when depleted is true */ public boolean isDepleted() { return placed; } diff --git a/src/com/mojang/ld22/item/Item.java b/src/com/mojang/ld22/item/Item.java index a4374f086..c5f68e28a 100644 --- a/src/com/mojang/ld22/item/Item.java +++ b/src/com/mojang/ld22/item/Item.java @@ -10,9 +10,13 @@ public class Item implements ListItem { + /* Note: Most of the stuff in the class is expanded upon in ResourceItem/PowerGloveItem/FurnitureItem/etc */ + + /** called to add this item to the item list in ListItems. */ public Item addItem() { - if (!ListItems.items.contains(this)) { - ListItems.items.add(this); + if (!ListItems.items.contains(this)) { // if this Item isn't already part of the list... + ListItems.items.add(this); // add it. + //System.out.println("adding item to list: " + getName()); } return this; @@ -25,37 +29,47 @@ public int getColor() { public int getSprite() { return 0; } - + + /** What happens when you pick up the item off the ground */ public void onTake(ItemEntity itemEntity) {} - + + /** Renders an item (sprite & name) in an inventory */ public void renderInventory(Screen screen, int x, int y) {} - + + /** Determines what happens when the player interacts with a entity */ public boolean interact(Player player, Entity entity, int attackDir) { return false; } - + + /** Renders the icon of the Item */ public void renderIcon(Screen screen, int x, int y) {} - + + /** Determines what happens when you use a item in a tile */ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, int attackDir) { return false; } - + + /** Returns if the item is depleted or not */ public boolean isDepleted() { return false; } - + + /** Returns if the item can attack mobs or not */ public boolean canAttack() { return false; } - + + /** Gets the attack bonus from an item/tool (sword/axe) */ public int getAttackDamageBonus(Entity e) { return 0; } - + + /** Gets the name of the item */ public String getName() { return ""; } - + + /** Sees if an item matches another item */ public boolean matches(Item item) { return item.getClass() == getClass(); } diff --git a/src/com/mojang/ld22/item/ListItems.java b/src/com/mojang/ld22/item/ListItems.java index bf80e8425..bc921e7a2 100644 --- a/src/com/mojang/ld22/item/ListItems.java +++ b/src/com/mojang/ld22/item/ListItems.java @@ -1,27 +1,18 @@ package com.mojang.ld22.item; -import com.mojang.ld22.entity.AirWizard; import com.mojang.ld22.entity.Anvil; import com.mojang.ld22.entity.Bed; import com.mojang.ld22.entity.Chest; -import com.mojang.ld22.entity.Creeper; import com.mojang.ld22.entity.Enchanter; import com.mojang.ld22.entity.Furnace; import com.mojang.ld22.entity.GoldLantern; import com.mojang.ld22.entity.IronLantern; -import com.mojang.ld22.entity.Knight; import com.mojang.ld22.entity.Lantern; import com.mojang.ld22.entity.Loom; import com.mojang.ld22.entity.Oven; -import com.mojang.ld22.entity.Pig; -import com.mojang.ld22.entity.Sheep; -import com.mojang.ld22.entity.Skeleton; -import com.mojang.ld22.entity.Slime; -import com.mojang.ld22.entity.Snake; import com.mojang.ld22.entity.Spawner; import com.mojang.ld22.entity.Tnt; import com.mojang.ld22.entity.Workbench; -import com.mojang.ld22.entity.Zombie; import com.mojang.ld22.item.resource.Resource; import java.util.ArrayList; import java.util.List; @@ -30,34 +21,34 @@ public class ListItems { public static List items = new ArrayList(); - public Item spawnercow = (new FurnitureItem(new Spawner("Cow", 1))).addItem(); - public Item spawnerpig = (new FurnitureItem(new Spawner("Pig", 1))).addItem(); - public Item spawnersheep = (new FurnitureItem(new Spawner("Sheep", 1))).addItem(); - public Item spawnerslime = (new FurnitureItem(new Spawner("Slime", 1))).addItem(); - public Item spawnerzombie = (new FurnitureItem(new Spawner("Zombie", 1))).addItem(); - public Item spawnercreeper = (new FurnitureItem(new Spawner("Creeper", 1))).addItem(); - public Item spawnerskeleton = (new FurnitureItem(new Spawner("Skeleton", 1))).addItem(); - public Item spawnersnake = (new FurnitureItem(new Spawner("Snake", 1))).addItem(); - public Item spawnerknight = (new FurnitureItem(new Spawner("Knight", 1))).addItem(); - public Item spawnerairwizard = (new FurnitureItem(new Spawner("AirWizard", 1))).addItem(); - public Item spawnerairwizardii = (new FurnitureItem(new Spawner("AirWizardII", 1))).addItem(); + public Item spawnercow; + public Item spawnerpig; + public Item spawnersheep; + public Item spawnerslime; + public Item spawnerzombie; + public Item spawnercreeper; + public Item spawnerskeleton; + public Item spawnersnake; + public Item spawnerknight; + public Item spawnerairwizard; + public Item spawnerairwizardii; - public Item powglove = (new PowerGloveItem()).addItem(); - public Item workbench = (new FurnitureItem(new Workbench())).addItem(); - public Item oven = (new FurnitureItem(new Oven())).addItem(); - public Item furnace = (new FurnitureItem(new Furnace())).addItem(); - public Item anvil = (new FurnitureItem(new Anvil())).addItem(); - public Item chest = (new FurnitureItem(new Chest())).addItem(); - public Item lantern = (new FurnitureItem(new Lantern())).addItem(); - public Item ironlantern = (new FurnitureItem(new IronLantern())).addItem(); - public Item goldlantern = (new FurnitureItem(new GoldLantern())).addItem(); - public Item enchanter = (new FurnitureItem(new Enchanter())).addItem(); - public Item loom = (new FurnitureItem(new Loom())).addItem(); - public Item tnt = (new FurnitureItem(new Tnt())).addItem(); - public Item bed = (new FurnitureItem(new Bed())).addItem(); - public Item bucket = (new BucketItem()).addItem(); - public Item wbucket = (new BucketWaterItem()).addItem(); - public Item lbucket = (new BucketLavaItem()).addItem(); + public Item powglove; + public Item workbench; + public Item oven; + public Item furnace; + public Item anvil; + public Item chest; + public Item lantern; + public Item ironlantern; + public Item goldlantern; + public Item enchanter; + public Item loom; + public Item tnt; + public Item bed; + public Item bucket; + public Item wbucket; + public Item lbucket; public Item arrow; public Item torch; @@ -200,6 +191,35 @@ public class ListItems { public Item hastepotion; public ListItems() { + this.spawnercow = (new FurnitureItem(new Spawner("Cow", 1))).addItem(); + this.spawnerpig = (new FurnitureItem(new Spawner("Pig", 1))).addItem(); + this.spawnersheep = (new FurnitureItem(new Spawner("Sheep", 1))).addItem(); + this.spawnerslime = (new FurnitureItem(new Spawner("Slime", 1))).addItem(); + this.spawnerzombie = (new FurnitureItem(new Spawner("Zombie", 1))).addItem(); + this.spawnercreeper = (new FurnitureItem(new Spawner("Creeper", 1))).addItem(); + this.spawnerskeleton = (new FurnitureItem(new Spawner("Skeleton", 1))).addItem(); + this.spawnersnake = (new FurnitureItem(new Spawner("Snake", 1))).addItem(); + this.spawnerknight = (new FurnitureItem(new Spawner("Knight", 1))).addItem(); + this.spawnerairwizard = (new FurnitureItem(new Spawner("AirWizard", 1))).addItem(); + this.spawnerairwizardii = (new FurnitureItem(new Spawner("AirWizardII", 1))).addItem(); + + this.powglove = (new PowerGloveItem()).addItem(); + this.workbench = (new FurnitureItem(new Workbench())).addItem(); + this.oven = (new FurnitureItem(new Oven())).addItem(); + this.furnace = (new FurnitureItem(new Furnace())).addItem(); + this.anvil = (new FurnitureItem(new Anvil())).addItem(); + this.chest = (new FurnitureItem(new Chest())).addItem(); + this.lantern = (new FurnitureItem(new Lantern())).addItem(); + this.ironlantern = (new FurnitureItem(new IronLantern())).addItem(); + this.goldlantern = (new FurnitureItem(new GoldLantern())).addItem(); + this.enchanter = (new FurnitureItem(new Enchanter())).addItem(); + this.loom = (new FurnitureItem(new Loom())).addItem(); + this.tnt = (new FurnitureItem(new Tnt())).addItem(); + this.bed = (new FurnitureItem(new Bed())).addItem(); + this.bucket = (new BucketItem()).addItem(); + this.wbucket = (new BucketWaterItem()).addItem(); + this.lbucket = (new BucketLavaItem()).addItem(); + this.arrow = (new ResourceItem(Resource.arrow)).addItem(); this.torch = (new ResourceItem(Resource.torch)).addItem(); this.wood = (new ResourceItem(Resource.wood)).addItem(); @@ -336,22 +356,23 @@ public ListItems() { this.hastepotion = (new ResourceItem(Resource.hastepotion)).addItem(); } + /** fetches an item from the list given it's name. I mean, I would have just used a HashMap... */ public static Item getItem(String name) { Item newItem = new Item(); - if(!name.equals("")) { - if(name.contains(";")) { - name = name.substring(0, name.indexOf(";")); + if(!name.equals("")) { // name is not nothing + if(name.contains(";")) { // if has ";" in name for whatever reason... + name = name.substring(0, name.indexOf(";")); // cut it off, plus anything after it. } - for(int i = 0; i < items.size(); i++) { - if(((Item)items.get(i)).getName().equals(name)) { - newItem = (Item)items.get(i); - return newItem; + for(int i = 0; i < items.size(); i++) { // loop through the items + if(((Item)items.get(i)).getName().equals(name)) { // if names match + newItem = (Item)items.get(i); // set the item + return newItem; // return the item } } } - return newItem; + return newItem; // would return new Item(); } } diff --git a/src/com/mojang/ld22/item/PowerGloveItem.java b/src/com/mojang/ld22/item/PowerGloveItem.java index 645d6d96d..0d74c73fc 100644 --- a/src/com/mojang/ld22/item/PowerGloveItem.java +++ b/src/com/mojang/ld22/item/PowerGloveItem.java @@ -8,21 +8,22 @@ import com.mojang.ld22.gfx.Screen; public class PowerGloveItem extends Item { + public int getColor() { - return Color.get(-1, 100, 320, 430); + return Color.get(-1, 100, 320, 430); // sets the color of the powerglove } public int getSprite() { - return 7 + 4 * 32; + return 7 + 4 * 32; // returns the location of the sprite (image of the glove) } public void renderIcon(Screen screen, int x, int y) { - screen.render(x, y, getSprite(), getColor(), 0); + screen.render(x, y, getSprite(), getColor(), 0); // Renders the icon of the power glove to the screen } public void renderInventory(Screen screen, int x, int y) { - screen.render(x, y, getSprite(), getColor(), 0); - Font.draw(getName(), screen, x + 8, y, Color.get(-1, 555, 555, 555)); + screen.render(x, y, getSprite(), getColor(), 0); // renders the icon of the power glove to the screen + Font.draw(getName(), screen, x + 8, y, Color.get(-1, 555, 555, 555)); // renders the name of the powerglove to the screen } public String getName() { @@ -30,11 +31,11 @@ public String getName() { } public boolean interact(Player player, Entity entity, int attackDir) { - if (entity instanceof Furniture) { + if (entity instanceof Furniture) { // If the power glove is used on a piece of furniture... Furniture f = (Furniture) entity; - f.take(player); + f.take(player); // Takes (picks up) the furniture return true; } - return false; + return false; // method returns false if we were not given a furniture entity. } } diff --git a/src/com/mojang/ld22/item/ResourceItem.java b/src/com/mojang/ld22/item/ResourceItem.java index aedcbe781..c9e4a371d 100644 --- a/src/com/mojang/ld22/item/ResourceItem.java +++ b/src/com/mojang/ld22/item/ResourceItem.java @@ -1,27 +1,25 @@ package com.mojang.ld22.item; -import com.mojang.ld22.Game; import com.mojang.ld22.entity.ItemEntity; import com.mojang.ld22.entity.Player; import com.mojang.ld22.gfx.Color; import com.mojang.ld22.gfx.Font; import com.mojang.ld22.gfx.Screen; -import com.mojang.ld22.item.resource.ItemResource; import com.mojang.ld22.item.resource.Resource; import com.mojang.ld22.level.Level; import com.mojang.ld22.level.tile.Tile; import com.mojang.ld22.screen.ModeMenu; public class ResourceItem extends Item { - public Resource resource; + public Resource resource; // The resource of this item public int count = 1; public int level = 0; - public int amount = 1; + public int amount = 1; // The amount of resources public ResourceItem(Resource resource) { this.resource = resource; } - + public ResourceItem(Resource resource, int count) { this.resource = resource; this.count = count; @@ -44,21 +42,22 @@ public void renderIcon(Screen screen, int x, int y) { screen.render(x, y, resource.sprite, resource.color, 0); } + /** Renders the icon, name, and count of the resource. */ public void renderInventory(Screen screen, int x, int y, boolean ininv) { - screen.render(x, y, this.resource.sprite, this.resource.color, 0); - String name = this.resource.name; - if(name.length() > 11 && !ininv) { + screen.render(x, y, resource.sprite, resource.color, 0); // renders the icon + String name = resource.name; // draws the name of the resource + if(name.length() > 11 && !ininv) { // only draw part of the name if it's too long, and in the inventory. Font.draw(name.substring(0, 11), screen, x + 32, y, Color.get(-1, 555, 555, 555)); } else { Font.draw(name, screen, x + 32, y, Color.get(-1, 555, 555, 555)); } - int cc = this.count; - if(cc > 999) { + int cc = count; // count of the resource + if(cc > 999) { // If the resource count is above 999, then just render 999 (for spacing reasons) cc = 999; } - Font.draw("" + cc, screen, x + 8, y, Color.get(-1, 444, 444, 444)); + Font.draw("" + cc, screen, x + 8, y, Color.get(-1, 444, 444, 444)); // draws the resource count } public void renderInventory(Screen screen, int x, int y) { @@ -72,18 +71,21 @@ public void renderInventory(Screen screen, int x, int y) { public String getName() { return resource.name; } - + + /** What happens when you pick up the item off the ground */ public void onTake(ItemEntity itemEntity) {} - + + /** What happens when you try to use this item on a tile. */ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, int attackDir) { - if (resource.interactOn(tile, level, xt, yt, player, attackDir)) { + if (resource.interactOn(tile, level, xt, yt, player, attackDir)) { // Calls the resource's 'interactOn()' method as a check if (!ModeMenu.creative) - count--; + count--; // interaction was successful, meaning the item was used; so remove it. return true; } return false; } + /** If the count is equal to, or less than 0. Then this will return true. */ public boolean isDepleted() { return count <= 0; } diff --git a/src/com/mojang/ld22/item/ToolItem.java b/src/com/mojang/ld22/item/ToolItem.java index 78e95f765..a39cdfc38 100644 --- a/src/com/mojang/ld22/item/ToolItem.java +++ b/src/com/mojang/ld22/item/ToolItem.java @@ -14,22 +14,23 @@ public class ToolItem extends Item { private Random random = new Random(); - public static final int MAX_LEVEL = 5; - public static final String[] LEVEL_NAMES = {"Wood", "Rock", "Iron", "Gold", "Gem"}; - - public ToolType type; - public int level = 0; - public int dur; - - public static final int[] LEVEL_COLORS = { - Color.get(-1, 100, 321, 431), - Color.get(-1, 100, 321, 111), - Color.get(-1, 100, 321, 555), - Color.get(-1, 100, 321, 550), - Color.get(-1, 100, 321, 055), + public static final int MAX_LEVEL = 5; // How many different levels of tools there are + public static final String[] LEVEL_NAMES = {"Wood", "Rock", "Iron", "Gold", "Gem"}; // The names of the different levels. A later level means a stronger tool. + + public ToolType type; // Type of tool (Sword, hoe, axe, pickaxe, shovel) + public int level = 0; // Level of said tool + public int dur; // the durability of the tool; currently only used for fishing rod. + // TODO implement durabilities for all tools? + + public static final int[] LEVEL_COLORS = { // Colors of the tools, same position as LEVEL_NAMES + Color.get(-1, 100, 321, 431), // wood + Color.get(-1, 100, 321, 111), // rock/stone + Color.get(-1, 100, 321, 555), // iron + Color.get(-1, 100, 321, 550), // gold + Color.get(-1, 100, 321, 055), // gem }; - public static final int[] BOW_COLORS = { + public static final int[] BOW_COLORS = { // Colors of the bows, specifically. Color.get(-1, 100, 444, 431), Color.get(-1, 100, 444, 111), Color.get(-1, 100, 444, 555), @@ -37,12 +38,13 @@ public class ToolItem extends Item { Color.get(-1, 100, 444, 055), }; + /** Tool Item, requires a tool type (ToolType.sword, ToolType.axe, ToolType.hoe, etc) and a level (0 = wood, 2 = iron, 4 = gem, etc) */ public ToolItem(ToolType type, int level) { this.type = type; this.level = level; - dur = type.durability; + dur = type.durability; // initial durability fetched from the ToolType } - + public int getColor() { if (type == ToolType.bow) { return BOW_COLORS[level]; @@ -52,25 +54,27 @@ public int getColor() { return LEVEL_COLORS[level]; } } - + public int getSprite() { return type.sprite + 5 * 32; } - + public void renderIcon(Screen screen, int x, int y) { screen.render(x, y, getSprite(), getColor(), 0); } - + + /** Renders the icon & name of this tool for inventory/crafting purposes. */ public void renderInventory(Screen screen, int x, int y) { screen.render(x, y, getSprite(), getColor(), 0); Font.draw(getName(), screen, x + 8, y, Color.get(-1, 555, 555, 555)); } - + + /** Gets the name of this tool (and it's type) */ public String getName() { if (type == ToolType.rod) return "Fishing Rod"; return LEVEL_NAMES[level] + " " + type.name; } - + public void onTake(ItemEntity itemEntity) {} public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, int attackDir) { @@ -89,27 +93,30 @@ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, public boolean isDepleted() { return dur <= 0 && type.durability > 0; } - + + /** You can attack mobs with tools. */ public boolean canAttack() { return true; } - + + /** Calculates Damage */ public int getAttackDamageBonus(Entity e) { if (type == ToolType.hatchet) { return (level + 1) * 2 + random.nextInt(3); } if (type == ToolType.axe) { - return (level + 1) * 2 + random.nextInt(4); + return (level + 1) * 2 + random.nextInt(4); // axes: (level + 1) * 2 + random number beteween 0 and 3, do slightly less damage than swords. } if (type == ToolType.sword) { - return (level + 1) * 3 + random.nextInt(2 + level * level * 2); + return (level + 1) * 3 + random.nextInt(2 + level * level * 2); //swords: (level + 1) * 3 + random number between 0 and (2 + level * level * 2) } if (type == ToolType.claymore) { return (level + 1) * 3 + random.nextInt(4 + level * level * 3); } return 1; } - + + /** Sees if this item matches another. */ public boolean matches(Item item) { if (item instanceof ToolItem) { ToolItem other = (ToolItem) item; diff --git a/src/com/mojang/ld22/item/ToolType.java b/src/com/mojang/ld22/item/ToolType.java index ca561aabb..d0e1d5b1f 100644 --- a/src/com/mojang/ld22/item/ToolType.java +++ b/src/com/mojang/ld22/item/ToolType.java @@ -1,20 +1,21 @@ package com.mojang.ld22.item; public class ToolType { + // creates the various tool types; the number next to the name deals with the sprite's location. public static ToolType shovel = new ToolType("Shovel", 0); public static ToolType hoe = new ToolType("Hoe", 1); public static ToolType sword = new ToolType("Sword", 2); public static ToolType pickaxe = new ToolType("Pickaxe", 3); public static ToolType axe = new ToolType("Axe", 4); public static ToolType bow = new ToolType("Bow", 5); - public static ToolType rod = new ToolType("Rod", 6, 15); + public static ToolType rod = new ToolType("Rod", 6, 15); // if there's a third number, it specifies durability. public static ToolType claymore = new ToolType("Claymore", 7); public static ToolType hatchet = new ToolType("Hatchet", 10); public static ToolType spade = new ToolType("Spade", 11); public static ToolType pick = new ToolType("Pick", 12); public final String name; - public final int sprite; + public final int sprite; // sprite location on the spritesheet public final int durability; private ToolType(String name, int sprite, int dur) { @@ -23,6 +24,6 @@ private ToolType(String name, int sprite, int dur) { durability = dur; } private ToolType(String name, int sprite) { - this(name, sprite, -1); + this(name, sprite, -1); // durability defualts to -1 if not specified (means infinite durability) } } diff --git a/src/com/mojang/ld22/item/resource/ArmorResource.java b/src/com/mojang/ld22/item/resource/ArmorResource.java index 79de1cb43..32e982b7c 100644 --- a/src/com/mojang/ld22/item/resource/ArmorResource.java +++ b/src/com/mojang/ld22/item/resource/ArmorResource.java @@ -5,20 +5,23 @@ import com.mojang.ld22.level.tile.Tile; public class ArmorResource extends Resource { - private int heal; + //private int heal; private int armor; private int staminaCost; + public int level; - public ArmorResource(String name, int sprite, int color, int heal, int staminaCost) { + public ArmorResource(String name, int sprite, int color, int health, int level, int staminaCost) { super(name, sprite, color); - this.heal = heal; - this.armor = heal; + //this.heal = heal; + this.armor = health; + this.level = level; this.staminaCost = staminaCost; } public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, int attackDir) { - if (player.armor < 1 && player.payStamina(staminaCost)) { - player.armor = heal; + if (player.curArmor == null && player.payStamina(staminaCost)) { + player.curArmor = this; // set the current armor being worn to this. + player.armor = ((Double)(armor/10.0*player.maxArmor)).intValue();//level * (50 + level * 10); // armor is how many hits are left return true; } return false; diff --git a/src/com/mojang/ld22/item/resource/FoodResource.java b/src/com/mojang/ld22/item/resource/FoodResource.java index c7d7f1159..37fc4e14e 100644 --- a/src/com/mojang/ld22/item/resource/FoodResource.java +++ b/src/com/mojang/ld22/item/resource/FoodResource.java @@ -5,20 +5,21 @@ import com.mojang.ld22.level.tile.Tile; public class FoodResource extends Resource { - private int heal; - private int staminaCost; + private int heal; // the amount of hunger the food "satisfies" you by. + private int staminaCost; // the amount of stamina it costs to consume the food. public FoodResource(String name, int sprite, int color, int heal, int staminaCost) { super(name, sprite, color); this.heal = heal; this.staminaCost = staminaCost; } - + + /** What happens when the player uses the item on a tile */ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, int attackDir) { - if (player.hunger < 10) { - if (player.payStamina(staminaCost)) { - player.hunger += heal; - if (player.hunger > 10) { + if (player.hunger < 10) { // if the player has hunger to fill + if (player.payStamina(staminaCost)) { // if the stamina payment was successful... + player.hunger += heal; // restore the hunger + if (player.hunger > 10) { // make sure the hunger doesn't go above ten. player.hunger = 10; return true; } else { diff --git a/src/com/mojang/ld22/item/resource/ItemResource.java b/src/com/mojang/ld22/item/resource/ItemResource.java index b06812688..9e4693f0b 100644 --- a/src/com/mojang/ld22/item/resource/ItemResource.java +++ b/src/com/mojang/ld22/item/resource/ItemResource.java @@ -1,6 +1,5 @@ package com.mojang.ld22.item.resource; -import com.mojang.ld22.Game; import com.mojang.ld22.crafting.Crafting; import com.mojang.ld22.entity.Player; import com.mojang.ld22.level.Level; diff --git a/src/com/mojang/ld22/item/resource/PlantableResource.java b/src/com/mojang/ld22/item/resource/PlantableResource.java index 8b432bbbb..0ceff6a27 100644 --- a/src/com/mojang/ld22/item/resource/PlantableResource.java +++ b/src/com/mojang/ld22/item/resource/PlantableResource.java @@ -1,6 +1,5 @@ package com.mojang.ld22.item.resource; -import com.mojang.ld22.Game; import com.mojang.ld22.entity.Player; import com.mojang.ld22.level.Level; import com.mojang.ld22.level.tile.Tile; @@ -8,45 +7,35 @@ import java.util.List; public class PlantableResource extends Resource { - private List sourceTiles; - private Tile targetTile; + private List sourceTiles; // list of tiles it can be planted on + private Tile targetTile; // what the source tile turns into when planted. - public PlantableResource( - String name, int sprite, int color, Tile targetTile, Tile... sourceTiles1) { - this(name, sprite, color, targetTile, Arrays.asList(sourceTiles1)); + public PlantableResource(String name, int sprite, int color, Tile targetTile, Tile... sourceTiles1) { + this(name, sprite, color, targetTile, Arrays.asList(sourceTiles1)); // calls other constructor + /** "Obj... name" as a parameter can be used to specify an indefinite number of parameters, without making it a list! So useful... + */ } - public PlantableResource( - String name, int sprite, int color, Tile targetTile, List sourceTiles) { + public PlantableResource(String name, int sprite, int color, Tile targetTile, List sourceTiles) { super(name, sprite, color); this.sourceTiles = sourceTiles; this.targetTile = targetTile; } - + + /** Determines what happens when the resource is used on a certain tile */ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, int attackDir) { if (sourceTiles.contains(tile)) { level.setTile(xt, yt, targetTile, 0); return true; } - if (name == "Plank Wall") { - if (!sourceTiles.contains(tile)) { - Game.infoplank = true; - } - } - if (name == "Wood Door") { - if (!sourceTiles.contains(tile)) { - Game.infoplank = true; - } - } - if (name == "St.BrickWall") { - if (!sourceTiles.contains(tile)) { - Game.infosbrick = true; - } + // at this point this resource cannot be planted on the given tile. + + if (name == "Plank Wall" || name == "Wood Door") { + player.game.notifications.add("Can only be placed on planks!"); } - if (name == "Stone Door") { - if (!sourceTiles.contains(tile)) { - Game.infosbrick = true; - } + + if (name == "St.BrickWall" || name == "Stone Door") { + player.game.notifications.add("Can only be placed on stone brick!"); } return false; } diff --git a/src/com/mojang/ld22/item/resource/PotionResource.java b/src/com/mojang/ld22/item/resource/PotionResource.java index 90893ec72..6cc75f2bf 100644 --- a/src/com/mojang/ld22/item/resource/PotionResource.java +++ b/src/com/mojang/ld22/item/resource/PotionResource.java @@ -38,8 +38,8 @@ public static boolean applyPotion(Player player, String type, int time) { if(player.potioneffects.containsKey(type) != addEffect) { // if hasEffect, and is disabling, or doesn't have effect, and is enabling... switch(type) { // these are the only effects that actually do anything not accounted for in other parts of the code: - case "Speed": player.moveSpeed += (int)( addEffect ? 1 : (player.moveSpeed > 1 ? -1 : 0) ); break; - case "Time": Game.gamespeed *= (addEffect ? 0.5f : 2); + case "Speed": player.moveSpeed += (double)( addEffect ? 1 : (player.moveSpeed > 1 ? -1 : 0) ); break; + case "Time": Game.gamespeed *= (addEffect ? 0.5f : 2);// player.moveSpeed += (addEffect ? 1 : -1); } } diff --git a/src/com/mojang/ld22/item/resource/Resource.java b/src/com/mojang/ld22/item/resource/Resource.java index c1017affc..08bb74eba 100644 --- a/src/com/mojang/ld22/item/resource/Resource.java +++ b/src/com/mojang/ld22/item/resource/Resource.java @@ -9,6 +9,8 @@ public class Resource { //public static ArrayList resList = new ArrayList(); + //format: public static Resource resource = new Resource("Name", x-sprite position + y-sprite position * 32, Color.get(-1,###,###,###)); + public static Resource wood = new Resource("Wood", 1 + 4 * 32, Color.get(-1, 200, 531, 430)); public static Resource stone = new Resource("Stone", 2 + 4 * 32, Color.get(-1, 111, 333, 555)); public static Resource flower = new PlantableResource("Flower", 0 + 4 * 32, Color.get(-1, 10, 444, 330), Tile.flower, Tile.grass, Tile.lightgrass); @@ -54,11 +56,11 @@ public class Resource { public static Resource steak = new FoodResource("Steak", 20 + 4 * 32, Color.get(-1, 100, 333, 211), 3, 5); public static Resource goldapple = new FoodResource("G.Apple", 9 + 4 * 32, Color.get(-1, 110, 440, 550), 10, 5); - public static Resource larmor = new ArmorResource("L.Armor", 3 + 12 * 32, Color.get(-1, 100, 211, 322), 3, 9); - public static Resource sarmor = new ArmorResource("S.Armor", 3 + 12 * 32, Color.get(-1, 10, 20, 30), 4, 9); - public static Resource iarmor = new ArmorResource("I.Armor", 3 + 12 * 32, Color.get(-1, 100, 322, 544), 5, 9); - public static Resource garmor = new ArmorResource("G.Armor", 3 + 12 * 32, Color.get(-1, 110, 330, 553), 7, 9); - public static Resource gemarmor = new ArmorResource("Gem Armor", 3 + 12 * 32, Color.get(-1, 101, 404, 545), 10, 9); + public static Resource larmor = new ArmorResource("L.Armor", 3 + 12 * 32, Color.get(-1, 100, 211, 322), 3, 1, 9); + public static Resource sarmor = new ArmorResource("S.Armor", 3 + 12 * 32, Color.get(-1, 10, 20, 30), 4, 2, 9); + public static Resource iarmor = new ArmorResource("I.Armor", 3 + 12 * 32, Color.get(-1, 100, 322, 544), 5, 3, 9); + public static Resource garmor = new ArmorResource("G.Armor", 3 + 12 * 32, Color.get(-1, 110, 330, 553), 7, 4, 9); + public static Resource gemarmor = new ArmorResource("Gem Armor", 3 + 12 * 32, Color.get(-1, 101, 404, 545), 10, 5, 9); public static Resource redclothes = new ClothesResource("Red Clothes", 390, Color.get(-1, Color.rgb(50, 0, 0), Color.rgb(200, 0, 0), Color.rgb(250, 0, 0)), 200, 0, 0); public static Resource blueclothes = new ClothesResource("Blue Clothes", 390, Color.get(-1, Color.rgb(0, 0, 50), Color.rgb(0, 0, 200), Color.rgb(0, 0, 250)), 0, 0, 200); public static Resource greenclothes = new ClothesResource("Green Clothes", 390, Color.get(-1, Color.rgb(0, 50, 0), Color.rgb(0, 200, 0), Color.rgb(0, 250, 0)), 0, 200, 0); @@ -105,9 +107,9 @@ public class Resource { public static Resource scale = new Resource("Scale", 22 + 4 * 32, Color.get(-1, 10, 30, 20)); public static Resource shard = new Resource("Shard", 23 + 4 * 32, Color.get(-1, 222, 333, 444)); - public final String name; - public final int sprite; - public final int color; + public final String name; // the name of the resource + public final int sprite; // the sprite location of the resource + public final int color; // the color of the resource public Resource(String name, int sprite, int color) { if (name.length() > 20) @@ -116,7 +118,8 @@ public Resource(String name, int sprite, int color) { this.sprite = sprite; this.color = color; } - + + /** Determines what happens when the resource is used on a certain tile; used in subclasses. */ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, int attackDir) { return false; } diff --git a/src/com/mojang/ld22/level/Level.java b/src/com/mojang/ld22/level/Level.java index 11505b88a..34fff76ce 100644 --- a/src/com/mojang/ld22/level/Level.java +++ b/src/com/mojang/ld22/level/Level.java @@ -40,60 +40,55 @@ public class Level { private Random random = new Random(); - public int w, h; - public int sux, suy; - - public byte[] tiles; - public byte[] data; - public List[] entitiesInTiles; + public int w, h; // width and height of the level + //public int sux, suy; // player start position? + + public byte[] tiles; // an array of all the tiles in the world. + public byte[] data; // an array of the data of the tiles in the world. // ? + public List[] entitiesInTiles; // An array of lists of entities in the world, by tile + public int curLvl = 0; // current level public int grassColor = 141; public int dirtColor = 322; - public int cl = 0; public int woolColor = 444; public int redwoolColor = 500; public int yellowwoolColor = 550; public int sandColor = 550; - public int depth; - public int monsterDensity = 8; + public int depth; // depth level of the level + public int monsterDensity = 8; // affects the number of monsters that are on the level, bigger the number the less monsters spawn. public static int depthlvl; public int chestcount; public static List ls = new ArrayList(); - public List entities = new ArrayList(); - private Comparator spriteSorter = - new Comparator() { - public int compare(Entity e0, Entity e1) { - if (e1.y < e0.y) return +1; - if (e1.y > e0.y) return -1; - return 0; - } - }; - - public static String c(int i) { - return "" + i; - } + public List entities = new ArrayList(); // A list of all the entities in the world + private Comparator spriteSorter = new Comparator() { // creates a sorter for all the entities to be rendered. + public int compare(Entity e0, Entity e1) { // compares 2 entities + if (e1.y < e0.y) return +1; // If the y position of the first entity is less (higher up) than the second entity, then it will be moved up in sorting. + if (e1.y > e0.y) return -1; // If the y position of the first entity is more (lower) than the second entity, then it will be moved down in sorting. + return 0; // ends the method + } + }; /// This is a solely debug method I made, to make printing repetetive stuff easier. // should be changed to accept prepend and entity, or a tile (as an Object). It will get the coordinates and class name from the object, and will divide coords by 16 if passed an entity. private void printLevelLoc(String prepend, int x, int y) { - //if(!Game.debug) return; - String[] levelNames = {"Sky", "Surface", "Iron", "Gold", "Lava", "Dungeon"}; String levelName = levelNames[-1*depth+1]; System.out.println(prepend + " on " + levelName + " level: x="+x + " y="+y); } - @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") // @SuppressWarnings ignores the warnings (yellow underline) in this method. + /** Level which the world is contained in */ public Level(int w, int h, int level, Level parentLevel) { this.depth = level; - cl = level; + curLvl = level; this.w = w; this.h = h; - byte[][] maps; + byte[][] maps; // multidimensional array (an array within a array), used for the map int saveTile; + // set the dirt colors if (level != 0) { if (DirtTile.dirtc == 0) { dirtColor = 222; @@ -123,29 +118,26 @@ public Level(int w, int h, int level, Level parentLevel) { if (level == 1) { dirtColor = 444; } - if (level == 0) maps = LevelGen.createAndValidateTopMap(w, h); - else if (level < 0 && level > -4) { + if (level == 0) maps = LevelGen.createAndValidateTopMap(w, h); // If the level is 0 (surface), create a surface map for the level + else if (level < 0 && level > -4) { // create an undergound map maps = LevelGen.createAndValidateUndergroundMap(w, h, -level); - monsterDensity = 4; - - } else if (level == -4) { - //if(Game.debug) System.out.println("making dungeon..."); + monsterDensity = 4; // lowers the monsterDensity value, which makes more enemies spawn + } else if (level == -4) { // create a dungeon map maps = LevelGen.createAndValidateDungeon(w, h); - - } else { + } else { // if level is anything else, which is just sky, then... maps = LevelGen.createAndValidateSkyMap(w, h); // Sky level monsterDensity = 4; } - tiles = maps[0]; - data = maps[1]; + tiles = maps[0]; // assigns the tiles in the map + data = maps[1]; // assigns the data of the tiles - if (parentLevel != null) { - for (int y = 0; y < h; y++) - for (int x = 0; x < w; x++) { - if (parentLevel.getTile(x, y) == Tile.stairsDown) { - setTile(x, y, Tile.stairsUp, 0); - if (level == -4) { + if (parentLevel != null) { // If the level above this one is not null (aka, if this isn't the sky level) + for (int y = 0; y < h; y++) { // loop through height + for (int x = 0; x < w; x++) { // loop through width + if (parentLevel.getTile(x, y) == Tile.stairsDown) { // If the tile in the level above the current one is a stairs down then... + setTile(x, y, Tile.stairsUp, 0); // set a stairs up tile in the same position on the current level + if (level == -4) { /// make the obsidian wall formation around the stair to the dungeon level setTile(x - 1, y, Tile.o, 0); setTile(x + 1, y, Tile.o, 0); setTile(x + 2, y, Tile.odc, 0); @@ -211,10 +203,12 @@ else if (level < 0 && level > -4) { setTile(x - 2, y - 1, Tile.ow, 0); setTile(x - 1, y - 2, Tile.ow, 0); } - if (level == 0) { - sux = x; - suy = y; - if(Game.debug) System.out.println("X = " + sux + " " + "Y = " + suy + " "); //printLevelLoc("Player start pos", sux, suy); + if (level == 0) { // surface + // some sort of var for player position? + //sux = x; + //suy = y; + //if(Game.debug) System.out.println("X = " + sux + " " + "Y = " + suy + " "); //printLevelLoc("Player start pos", sux, suy); + /// surround the sky stairs with hard rock: setTile(x - 1, y, Tile.hardRock, 0); setTile(x + 1, y, Tile.hardRock, 0); setTile(x, y - 1, Tile.hardRock, 0); @@ -226,6 +220,7 @@ else if (level < 0 && level > -4) { } if (level != 0 && level != -4) { + // any other level, the up-stairs should have dirt on all sides. setTile(x - 1, y, Tile.dirt, 0); setTile(x + 1, y, Tile.dirt, 0); setTile(x, y - 1, Tile.dirt, 0); @@ -237,18 +232,22 @@ else if (level < 0 && level > -4) { } } } + } } - entitiesInTiles = new ArrayList[w * h]; // This is actually an array of arrayLists (of entities). + entitiesInTiles = new ArrayList[w * h]; // This is actually an array of arrayLists (of entities), with one arraylist per tile. for (int i = 0; i < w * h; i++) { - entitiesInTiles[i] = new ArrayList(); + entitiesInTiles[i] = new ArrayList(); // Adds a entity list in that tile. } - + + /// if the level is the dungeon, and we're not just loading the world... if (level == -4 && !WorldSelectMenu.loadworld) { - for (int i = 0; i < (Game.debug?1:10 * (w / 128)); i++) { + for (int i = 0; i < 10 * (w / 128); i++) { + /// make DungeonChests! DungeonChest d = new DungeonChest(); boolean addedchest = false; - while(!addedchest) { + while(!addedchest) { // keep running until we successfully add a DungeonChest + //pick a random tile: int x2 = this.random.nextInt(16 * w) / 16; int y2 = this.random.nextInt(16 * h) / 16; if (this.getTile(x2, y2) == Tile.o) { @@ -278,7 +277,6 @@ else if (level < 0 && level > -4) { this.add(d); this.chestcount++; addedchest = true; - //if (Game.debug) printLevelLoc("Added dungeon chest", x2, y2); } } } @@ -286,15 +284,14 @@ else if (level < 0 && level > -4) { if (level < 0 && !WorldSelectMenu.loadworld) { for (int i = 0; i < 18 / -level * (w / 128); i++) { /// for generating spawner dungeons - //Mob m = new Mob(); String m = ""; int r = this.random.nextInt(5); if (r == 1) { - m = "Skeleton";//new Skeleton(-level); + m = "Skeleton"; } else if (r == 2 || r == 0) { - m = "Slime";//new Slime(-level); + m = "Slime"; } else { - m = "Zombie";//new Zombie(-level); + m = "Zombie"; } Spawner sp = new Spawner(m, -level); @@ -341,14 +338,12 @@ else if (level < 0 && level > -4) { } this.add(sp); - //if (Game.debug) printLevelLoc("Added Spawner", sp.x/16, sp.y/16); for(int rpt = 1; rpt <= 2; rpt++) { if (random.nextInt(2) == 0) { Chest c = new Chest(); addtoinv(c.inventory, -level); c.x = sp.x - 16; c.y = sp.y - 16; - //if(Game.debug) printLevelLoc("Added Chest", c.x/16, c.y/16); this.add(c); } } @@ -361,30 +356,14 @@ else if (level < 0 && level > -4) { aw.x = w * 16 / 2; aw.y = h * 16 / 2; add(aw); - //if(Game.debug) System.out.println("Added Air Wizard I! X = " + aw.x + ", Y = " + aw.y); } if(Game.debug) { - //System.out.println((WorldSelectMenu.loadworld?"Loading":"Making")+" level "+level+"..."); - // print stair locations for (int x = 0; x < w; x++) for (int y = 0; y < h; y++) if(getTile(x, y) == Tile.stairsDown) printLevelLoc("Stairs down", x, y); - - // print Dungeon chest and airwizard locations - /*//for (int x = 0; x < w; x++) { - // for (int y = 0; y < h; y++) { - for (Entity e: getEntities(0, 0, w, h)) { - if(e instanceof DungeonChest) - printLevelLoc("Added Dungeon chest", e.x/16, e.y/16); - else if (e instanceof AirWizard) - printLevelLoc("Added AirWizard"+(((AirWizard)e).secondform?" II":""), e.x/16, e.y/16); - //else if (e instanceof Spawner)*/ - // } - //} - //} System.out.println(); } } @@ -542,7 +521,7 @@ public void addtoinv(Inventory inventory, int chance) { if (random.nextInt(4 / chance) == 0) { inventory.add(new ResourceItem(Resource.arrow, 5)); } - if (inventory.items.size() < 1) { + if (inventory.invSize() < 1) { inventory.add(new ResourceItem(Resource.potion, 1)); inventory.add(new ResourceItem(Resource.coal, 3)); inventory.add(new ResourceItem(Resource.apple, 3)); @@ -717,7 +696,7 @@ public void trySpawn(int count) { else if (rnd <= 75) mob = new Zombie(lvl); else if (rnd >= 85) mob = new Skeleton(lvl); else mob = new Creeper(lvl); - + //System.out.println("making new mob on level " + lvl + "; lvl=" + mob.lvl); if (mob.findStartPos(this)) this.add(mob); } } diff --git a/src/com/mojang/ld22/level/levelgen/LevelGen.java b/src/com/mojang/ld22/level/levelgen/LevelGen.java index 90d90ff45..52e4a4367 100644 --- a/src/com/mojang/ld22/level/levelgen/LevelGen.java +++ b/src/com/mojang/ld22/level/levelgen/LevelGen.java @@ -104,12 +104,7 @@ public static byte[][] createAndValidateTopMap(int w, int h) { } else { if (count[Tile.stairsDown.id & 0xff] < 12) continue; } - /* - if(com.mojang.ld22.Game.debug) { - for (int i = 0; i < w * h; i++) { - if(result[0][i] == Tile.stairsDown.id) - System.out.println("stairs on surface: x="); - }}*/ + return result; } while (true); @@ -480,8 +475,7 @@ private static byte[][] createDungeon(int w, int h) { } map[x + y * w] = Tile.ow.id; - //if(com.mojang.ld22.Game.debug) System.out.println("Obsidian, x="+x+" y="+y); - + count++; if (count == 2) break; } @@ -620,7 +614,6 @@ private static byte[][] createUndergroundMap(int w, int h, int depth) { } map[x + y * w] = Tile.stairsDown.id; - //if(com.mojang.ld22.Game.debug) System.out.println("stairs, x="+x+" y="+y); count++; if (WorldGenMenu.sized == 128) { if (count == 4) break; @@ -689,7 +682,6 @@ private static byte[][] createSkyMap(int w, int h) { } map[x + y * w] = Tile.stairsDown.id; - //if(com.mojang.ld22.Game.debug) System.out.println("sky stairs, x="+x+" y="+y); count++; if (count == 2) break; } diff --git a/src/com/mojang/ld22/level/tile/InfiniteFallTile.java b/src/com/mojang/ld22/level/tile/InfiniteFallTile.java index 2ef0e3bd9..cf8dd70dd 100644 --- a/src/com/mojang/ld22/level/tile/InfiniteFallTile.java +++ b/src/com/mojang/ld22/level/tile/InfiniteFallTile.java @@ -5,7 +5,6 @@ import com.mojang.ld22.entity.Player; import com.mojang.ld22.gfx.Screen; import com.mojang.ld22.level.Level; -import com.mojang.ld22.level.tile.Tile; public class InfiniteFallTile extends Tile { public InfiniteFallTile(int id) { diff --git a/src/com/mojang/ld22/level/tile/LavaTile.java b/src/com/mojang/ld22/level/tile/LavaTile.java index 09f60fc60..ee98bf01d 100644 --- a/src/com/mojang/ld22/level/tile/LavaTile.java +++ b/src/com/mojang/ld22/level/tile/LavaTile.java @@ -272,7 +272,7 @@ public void render(Screen screen, Level level, int x, int y) { } if (level.dirtColor == 222) { - if (level.cl != -4) { + if (level.curLvl != -4) { wRandom.setSeed( (tickCount + (x / 2 - y) * 4311) / 10 * 54687121l + x * 3271612l + y * 3412987161l); int col = col4; @@ -327,7 +327,7 @@ public void render(Screen screen, Level level, int x, int y) { (r ? 16 : 15) + (d ? 2 : 1) * 32, (sd || sr) ? transitionColor2 : transitionColor1, 0); - } else if (level.cl == -4) { + } else if (level.curLvl == -4) { wRandom.setSeed( (tickCount + (x / 2 - y) * 4311) / 10 * 54687121l + x * 3271612l + y * 3412987161l); int col = col5; diff --git a/src/com/mojang/ld22/level/tile/TreeTile.java b/src/com/mojang/ld22/level/tile/TreeTile.java index 78b6ddebe..5a3eceaa1 100644 --- a/src/com/mojang/ld22/level/tile/TreeTile.java +++ b/src/com/mojang/ld22/level/tile/TreeTile.java @@ -111,11 +111,11 @@ public void render(Screen screen, Level level, int x, int y) { screen.render(x * 16 + 8, y * 16 + 8, 10 + 3 * 32, barkCol2, 0); } } else if (Game.time == 1) { - + int col = col1; int barkCol1 = col11; int barkCol2 = col111; - + boolean u = level.getTile(x, y - 1) == this; boolean l = level.getTile(x - 1, y) == this; boolean r = level.getTile(x + 1, y) == this; @@ -124,7 +124,7 @@ public void render(Screen screen, Level level, int x, int y) { boolean ur = level.getTile(x + 1, y - 1) == this; boolean dl = level.getTile(x - 1, y + 1) == this; boolean dr = level.getTile(x + 1, y + 1) == this; - + if (u && ul && l) { screen.render(x * 16 + 0, y * 16 + 0, 10 + 1 * 32, col, 0); } else { @@ -189,10 +189,11 @@ public void tick(Level level, int xt, int yt) { } public boolean mayPass(Level level, int x, int y, Entity e) { - /*if(e instanceof com.mojang.ld22.entity.Arrow) { + /// make arrow fly through trees! + if(Game.debug && e instanceof com.mojang.ld22.entity.Arrow && ((com.mojang.ld22.entity.Arrow)e).owner instanceof Player) { hurt(level, x, y, 25); return true; - }*/ + } return false; } diff --git a/src/com/mojang/ld22/saveload/Load.java b/src/com/mojang/ld22/saveload/Load.java index 19e4d3ee8..95ace1461 100644 --- a/src/com/mojang/ld22/saveload/Load.java +++ b/src/com/mojang/ld22/saveload/Load.java @@ -7,11 +7,11 @@ import com.mojang.ld22.entity.Chest; import com.mojang.ld22.entity.Cow; import com.mojang.ld22.entity.Creeper; +import com.mojang.ld22.entity.DeathChest; import com.mojang.ld22.entity.DungeonChest; import com.mojang.ld22.entity.Enchanter; import com.mojang.ld22.entity.Entity; import com.mojang.ld22.entity.Furnace; -import com.mojang.ld22.entity.Furniture; import com.mojang.ld22.entity.GoldLantern; import com.mojang.ld22.entity.Inventory; import com.mojang.ld22.entity.IronLantern; @@ -33,6 +33,7 @@ import com.mojang.ld22.item.Item; import com.mojang.ld22.item.ListItems; import com.mojang.ld22.item.ResourceItem; +import com.mojang.ld22.item.resource.ArmorResource; import com.mojang.ld22.item.resource.PotionResource; import com.mojang.ld22.level.tile.Tile; import com.mojang.ld22.screen.LoadingMenu; @@ -55,15 +56,26 @@ public class Load { List data; List extradata; public boolean hasloadedbigworldalready; + Version currentVer, worldVer; + boolean oldSave = false; public Load(Game game, String worldname) { + currentVer = new Version(Game.VERSION); folder = new File(location); extention = ".miniplussave"; data = new ArrayList(); extradata = new ArrayList(); hasloadedbigworldalready = false; location += "/saves/" + worldname + "/"; - loadGame("Game", game); + + worldVer = null; + File testFile = new File(location + "KeyPrefs" + extention); + if(!testFile.exists()) { + worldVer = new Version("1.8"); + oldSave = true; + } + + loadGame("Game", game); // more of the version will be determined here loadPrefs("KeyPrefs", game); loadWorld("Level"); loadPlayer("Player", game.player); @@ -80,6 +92,62 @@ public Load(Game game, String worldname) { } + class Version implements Comparable { + public Integer make, major, minor, dev; + + public Version(String version) { + String[] nums = version.split("\\."); + try { + if(nums.length > 0) make = Integer.parseInt(nums[0]); + else make = 0; + + if(nums.length > 1) major = Integer.parseInt(nums[1]); + else major = 0; + + String min; + if(nums.length > 2) min = nums[2]; + else min = ""; + + if(min.contains("-")) { + String[] mindev = min.split("-"); + minor = Integer.parseInt(mindev[0]); + dev = Integer.parseInt(mindev[1].replace("pre", "").replace("dev", "")); + } else { + if(!min.equals("")) minor = Integer.parseInt(min); + else minor = 0; + dev = 0; + } + } catch(NumberFormatException ex) { + System.out.println("INVALID version number: " + version); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + + // the returned value of this method (-1, 0, or 1) is determined by whether this object is less than, equal to, or greater than the specified object. + public int compareTo(Object other) throws NullPointerException, ClassCastException { + if(other == null) throw new NullPointerException(); + if(other instanceof Version == false) { // if the passed object is not a Version... + throw new ClassCastException("Cannot compare type Version with type " + other.getClass().getTypeName()); + } + Version ov = (Version)other; + + if(make != ov.make) return make.compareTo(ov.make); + else if(major != ov.major) return major.compareTo(ov.major); + else if(minor != ov.minor) return minor.compareTo(ov.minor); + else if(dev != ov.dev) { + if(dev == 0) return 1; //0 is the last "dev" version, as it is not a dev. + else if(ov.dev == 0) return -1; + else return dev.compareTo(ov.dev); + } + else return 0; // the versions are equal. + } + + public String toString() { + return make + "." + major + "." + minor + (dev == 0 ? "" : "-dev" + dev); + } + } + public void loadFromFile(String filename) { data.clear(); extradata.clear(); @@ -137,19 +205,41 @@ public void loadFromFile(String filename) { } } - } public void loadGame(String filename, Game game) { loadFromFile(location + filename + extention); - Game.setTime(Integer.parseInt((String)data.get(0))); - Game.astime = Integer.parseInt((String)data.get(1)); - Game.gamespeed = Float.parseFloat((String)data.get(2)); - Game.autosave = Boolean.parseBoolean((String)data.get(3)); - OptionsMenu.isSoundAct = Boolean.parseBoolean((String)data.get(4)); + boolean hasVersion = ((String)data.get(0)).contains("."); + if(hasVersion) { + worldVer = new Version((String)data.get(0)); // gets the world version + Game.setTime(Integer.parseInt((String)data.get(1))); + Game.astime = Integer.parseInt((String)data.get(2)); + Game.autosave = Boolean.parseBoolean((String)data.get(3)); + OptionsMenu.isSoundAct = Boolean.parseBoolean((String)data.get(4)); + } + else { + if(data.size() == 5) { + worldVer = new Version("1.9"); + Game.setTime(Integer.parseInt((String)data.get(0))); + Game.astime = Integer.parseInt((String)data.get(1)); + Game.autosave = Boolean.parseBoolean((String)data.get(3)); + OptionsMenu.isSoundAct = Boolean.parseBoolean((String)data.get(4)); + } else { // version == 1.8? + if(!oldSave) { + System.out.println("UNEXPECTED WORLD VERSION"); + worldVer = new Version("1.8.1"); + } + // for backwards compatibility + Game.astime = Integer.parseInt((String)this.data.get(1)); + game.player.ac = Integer.parseInt((String)this.data.get(3)); + Game.tickCount = Integer.parseInt((String)this.data.get(0)); + Game.autosave = false; + } + } } public void loadPrefs(String filename, Game game) { + if(oldSave) return; loadFromFile(location + filename + extention); Iterator keys = data.iterator(); while(keys.hasNext()) { @@ -182,13 +272,28 @@ public void loadPlayer(String filename, Player player) { Player.spawny = Integer.parseInt((String)data.get(3)); player.health = Integer.parseInt((String)data.get(4)); player.armor = Integer.parseInt((String)data.get(5)); - Player.score = Integer.parseInt((String)data.get(6)); - player.ac = Integer.parseInt((String)data.get(7)); - Game.currentLevel = Integer.parseInt((String)data.get(8)); + String modedata; + if(!oldSave) { + if(data.size() >= 14) { + if(worldVer == null) worldVer = new Version("1.9.1-pre1"); + player.armorDamageBuffer = Integer.parseInt((String)data.get(13)); + player.curArmor = (ArmorResource)(((ResourceItem)ListItems.getItem((String)data.get(14))).resource); + } else player.armor = 0; + + player.ac = Integer.parseInt((String)data.get(7)); + Game.currentLevel = Integer.parseInt((String)data.get(8)); + modedata = (String)data.get(9); + + } else { + // old, 1.8 save. + Game.currentLevel = Integer.parseInt((String)data.get(7)); + modedata = (String)data.get(8); + } + + Player.score = Integer.parseInt((String)data.get(6)); player.game.level = Game.levels[Game.currentLevel]; - String modedata = (String)data.get(9); int mode; if(modedata.contains(";")) { mode = Integer.parseInt(modedata.substring(0, modedata.indexOf(";"))); @@ -202,53 +307,76 @@ public void loadPlayer(String filename, Player player) { ModeMenu.updateModeBools(mode); - if(!((String)data.get(10)).equals("PotionEffects[]")) { - String potiondata = ((String)data.get(10)).replace("PotionEffects[", "").replace("]", ""); + boolean hasEffects; + int potionIdx = 10; + if(oldSave) { + hasEffects = data.size() > 10 && ((String)data.get(data.size()-2)).contains("PotionEffects["); + potionIdx = data.size() - 2; + } else + hasEffects = !((String)data.get(10)).equals("PotionEffects[]"); // newer save + + if(hasEffects) { + String potiondata = ((String)data.get(potionIdx)).replace("PotionEffects[", "").replace("]", ""); List effects = Arrays.asList(potiondata.split(":")); for(int i = 0; i < effects.size(); i++) { List effect = Arrays.asList(((String)effects.get(i)).split(";")); - PotionResource.applyPotion(player, (String)effect.get(0), Integer.parseInt((String)effect.get(1))); + String pName = (String)effect.get(0); + if(oldSave) pName = pName.replace("P.", "Potion"); + PotionResource.applyPotion(player, pName, Integer.parseInt((String)effect.get(1))); } } - String colors = ((String)data.get(11)).replace("[", "").replace("]", ""); + String colors = ((String)data.get(oldSave?data.size()-1:11)).replace("[", "").replace("]", ""); List color = Arrays.asList(colors.split(";")); player.r = Integer.parseInt((String)color.get(0)); player.g = Integer.parseInt((String)color.get(1)); player.b = Integer.parseInt((String)color.get(2)); - Player.skinon = Boolean.parseBoolean((String)data.get(12)); + if(!oldSave) Player.skinon = Boolean.parseBoolean((String)data.get(12)); + else Player.skinon = false; } public void loadInventory(String filename, Inventory inventory) { loadFromFile(location + filename + extention); - inventory.items.clear(); + inventory.clearInv(); for(int i = 0; i < data.size(); i++) { String item = (String)data.get(i); - if(item.contains(";")) { - item = item.substring(0, item.lastIndexOf(";")); - } if(ListItems.getItem(item) instanceof ResourceItem) { - String name = (String)data.get(i) + ";0"; - List curData = Arrays.asList(name.split(";")); - Item newItem = ListItems.getItem((String)curData.get(0)); + if(oldSave && i == 0) item = item.replace(";0", ";1"); + List curData = Arrays.asList(item.split(";")); + String itemName = (String)curData.get(0); + if(oldSave) itemName = subOldItemName(itemName); + + Item newItem = ListItems.getItem(itemName); for(int ii = 0; ii < Integer.parseInt((String)curData.get(1)); ii++) { if(newItem instanceof ResourceItem) { ResourceItem resItem = new ResourceItem(((ResourceItem)newItem).resource); inventory.add(resItem); } else { - inventory.items.add(newItem); + inventory.add(newItem); } } } else { - inventory.items.add(ListItems.getItem((String)data.get(i))); + if(oldSave) item = subOldItemName(item); + Item toAdd = ListItems.getItem(item); + inventory.add(toAdd); } } - + } + + private String subOldItemName(String oldName) { + if(oldName.contains(";")) oldName = oldName.substring(0, oldName.indexOf(";")); + oldName = oldName.replace("P.", "Potion"); + + switch(oldName) { + case "Fish Rod": return "Fishing Rod"; + + default: return oldName; + } } public void loadEntities(String filename, Player player) { @@ -261,7 +389,7 @@ public void loadEntities(String filename, Player player) { for(int i = 0; i < data.size(); i++) { Entity newEntity = getEntity(((String)data.get(i)).substring(0, ((String)data.get(i)).indexOf("[")), player); List info = Arrays.asList(((String)data.get(i)).substring(((String)data.get(i)).indexOf("[") + 1, ((String)data.get(i)).indexOf("]")).split(":")); - if(newEntity != null) { + if(newEntity != null) { // the method never returns null, but... newEntity.x = Integer.parseInt((String)info.get(0)); newEntity.y = Integer.parseInt((String)info.get(1)); int currentlevel; @@ -273,53 +401,38 @@ public void loadEntities(String filename, Player player) { mob.level = Game.levels[Integer.parseInt((String)info.get(5))]; currentlevel = Integer.parseInt((String)info.get(5)); Game.levels[currentlevel].add(mob); - } else if(newEntity instanceof Chest || newEntity instanceof DungeonChest) { - Furniture chest = (Furniture)newEntity; + } else if(newEntity instanceof Chest) { + Chest chest = (Chest)newEntity; + boolean isDeathChest = chest instanceof DeathChest; + boolean isDungeonChest = chest instanceof DungeonChest; + List chestInfo = info.subList(2, info.size()-1); - for(int idx = 2; idx < info.size(); idx++) { - String itemData = (String)info.get(idx); + int endIdx = chestInfo.size()-(isDeathChest||isDungeonChest?1:0); + for(int idx = 0; idx < endIdx; idx++) { + String itemData = (String)chestInfo.get(idx); + if(worldVer.compareTo(new Version("1.9.1")) < 0) // if this world is before 1.9.1 + if(itemData.equals("")) continue; // this skips any null items Item item = ListItems.getItem(itemData); if (item instanceof ResourceItem) { - List curData = Arrays.asList((itemData + ";0").split(";")); - Item newItem = ListItems.getItem((String)curData.get(0)); - - for(int ii = 0; ii < Integer.parseInt((String)curData.get(1)); ii++) { - if(newItem instanceof ResourceItem) { - ResourceItem resItem = new ResourceItem(((ResourceItem)newItem).resource); - addToChest(chest, resItem); - } else if(!item.getName().equals("")) { - addToChest(chest, item); - } - } - } else if(!item.getName().equals("")) { - addToChest(chest, item); - } - - if(idx == info.size() - 2) { - if (chest instanceof Chest && itemData.contains("tl;")) { - ((Chest)chest).time = Integer.parseInt(itemData.replace("tl;", "")); - } if (chest instanceof DungeonChest && (itemData.contains("true") || itemData.contains("false"))) { - ((DungeonChest)chest).islocked = Boolean.parseBoolean(itemData); - } + List curData = Arrays.asList((itemData + ";1").split(";")); // this appends ";1" to the end, meaning one item, to everything; but if it was already there, then it becomes the 3rd element in the list, which is ignored. + ResourceItem ri = (ResourceItem)ListItems.getItem(curData.get(0)); + ri.count = Integer.parseInt(curData.get(1)); + chest.inventory.add(ri); + } else { + chest.inventory.add(item); } } - if (chest instanceof DungeonChest) { - DungeonChest dChest = (DungeonChest)chest; - ArrayList contents = new ArrayList(); - for(int ii = 0; ii < dChest.inventory.items.size(); ii++) { - if(!((Item)dChest.inventory.items.get(ii)).getName().equals(" ") && !((Item)dChest.inventory.items.get(ii)).getName().equals("") && !((Item)dChest.inventory.items.get(ii)).getName().equals(" ")) { - contents.add(((Item)dChest.inventory.items.get(ii)).getName()); - } else { - dChest.inventory.items.remove(ii); - } - } - contents.add("/x=" + dChest.x / 16 + "/y=" + dChest.y / 16); + if (isDeathChest) { + ((DeathChest)chest).time = Integer.parseInt((chestInfo.get(chestInfo.size()-1)).replace("tl;", "")); // "tl;" is only for old save support + } else if (isDungeonChest) { + ((DungeonChest)chest).isLocked = Boolean.parseBoolean(chestInfo.get(chestInfo.size()-1)); } + newEntity.level = Game.levels[Integer.parseInt((String)info.get(info.size() - 1))]; currentlevel = Integer.parseInt((String)info.get(info.size() - 1)); - Game.levels[currentlevel].add((chest instanceof Chest ? (Chest)chest : (DungeonChest)chest)); + Game.levels[currentlevel].add(chest instanceof DeathChest ? (DeathChest)chest : chest instanceof DungeonChest ? (DungeonChest)chest : chest); } else if(newEntity instanceof Spawner) { Spawner egg = (Spawner)newEntity; @@ -329,7 +442,8 @@ else if(newEntity instanceof Spawner) { egg.setMob((String)info.get(2)); currentlevel = Integer.parseInt((String)info.get(info.size() - 1)); Game.levels[currentlevel].add(egg); - } else { + } + else { newEntity.level = Game.levels[Integer.parseInt((String)info.get(2))]; currentlevel = Integer.parseInt((String)info.get(2)); Game.levels[currentlevel].add(newEntity); @@ -338,25 +452,6 @@ else if(newEntity instanceof Spawner) { } } - private void addToChest(Furniture box, Item toAdd) { - if(box instanceof Chest) { - Chest chest = (Chest)box; - if(toAdd instanceof ResourceItem) { - ResourceItem item = (ResourceItem)toAdd; - chest.inventory.items.add(item); - } else - chest.inventory.items.add(toAdd); - } - else if (box instanceof DungeonChest) { - DungeonChest dChest = (DungeonChest)box; - if(toAdd instanceof ResourceItem) { - ResourceItem item = (ResourceItem)toAdd; - dChest.inventory.items.add(item); - } else - dChest.inventory.items.add(toAdd); - } - } - public Entity getEntity(String string, Player player) { switch(string) { case "Zombie": return (Entity)(new Zombie(0)); @@ -370,7 +465,7 @@ public Entity getEntity(String string, Player player) { case "AirWizard": return (Entity)(new AirWizard(false)); case "AirWizardII": return (Entity)(new AirWizard(true)); case "Chest": return (Entity)(new Chest()); - case "DeathChest": return (Entity)(new Chest(true)); + case "DeathChest": return (Entity)(new DeathChest()); case "DungeonChest": return (Entity)(new DungeonChest()); case "Spawner": return (Entity)(new Spawner("Zombie", 1)); case "Anvil": return (Entity)(new Anvil()); @@ -386,7 +481,8 @@ public Entity getEntity(String string, Player player) { case "Player": return (Entity)(player); case "Knight": return (Entity)(new Knight(0)); case "Snake": return (Entity)(new Snake(0)); - default : return new Entity(); + default : if(Game.debug) System.out.println("LOAD: UNKNOWN ENTITY: " + string); + return new Entity(); } } } diff --git a/src/com/mojang/ld22/saveload/Save.java b/src/com/mojang/ld22/saveload/Save.java index 94c0d8d2e..851231677 100644 --- a/src/com/mojang/ld22/saveload/Save.java +++ b/src/com/mojang/ld22/saveload/Save.java @@ -1,14 +1,17 @@ package com.mojang.ld22.saveload; import com.mojang.ld22.Game; +import com.mojang.ld22.entity.AirWizard; import com.mojang.ld22.entity.Chest; +import com.mojang.ld22.entity.DeathChest; import com.mojang.ld22.entity.DungeonChest; import com.mojang.ld22.entity.Entity; import com.mojang.ld22.entity.Inventory; +import com.mojang.ld22.entity.ItemEntity; import com.mojang.ld22.entity.Mob; import com.mojang.ld22.entity.Player; import com.mojang.ld22.entity.Spawner; -import com.mojang.ld22.gfx.Color; +import com.mojang.ld22.entity.particle.Particle; import com.mojang.ld22.item.Item; import com.mojang.ld22.item.ResourceItem; import com.mojang.ld22.screen.LoadingMenu; @@ -90,9 +93,9 @@ public void writeToFile(String filename, List savedata) { } public void writeGame(String filename, Game game) { + data.add(String.valueOf(Game.VERSION)); data.add(String.valueOf(Game.tickCount)); data.add(String.valueOf(Game.astime)); - data.add(String.valueOf(Game.gamespeed)); data.add(String.valueOf(Game.autosave)); data.add(String.valueOf(OptionsMenu.isSoundAct)); writeToFile(location + filename + extention, data); @@ -159,23 +162,27 @@ public void writePlayer(String filename, Player player) { data.add("[" + player.r + ";" + player.g + ";" + player.b + "]"); data.add(String.valueOf(Player.skinon)); + if(player.curArmor != null) { + data.add(String.valueOf(player.armorDamageBuffer)); + data.add(String.valueOf(player.curArmor.name)); + } writeToFile(location + filename + extention, data); } public void writeInventory(String filename, Inventory inventory) { if(player.activeItem != null) { if(player.activeItem instanceof ResourceItem) { - data.add(player.activeItem.getName() + ";" + inventory.count(player.activeItem)); + data.add(player.activeItem.getName() + ";" + ((ResourceItem)player.activeItem).count); } else { data.add(player.activeItem.getName()); } } - for(int i = 0; i < inventory.items.size(); i++) { - if(inventory.items.get(i) instanceof ResourceItem) { - data.add(((Item)inventory.items.get(i)).getName() + ";" + inventory.count((Item)inventory.items.get(i))); + for(int i = 0; i < inventory.invSize(); i++) { + if(inventory.get(i) instanceof ResourceItem) { + data.add(((Item)inventory.get(i)).getName() + ";" + ((ResourceItem)inventory.get(i)).count); } else { - data.add(((Item)inventory.items.get(i)).getName()); + data.add(((Item)inventory.get(i)).getName()); } } @@ -188,49 +195,29 @@ public void writeEntities(String filename) { Entity e = (Entity)Game.levels[l].entities.get(i); String name = e.getClass().getName().replace("com.mojang.ld22.entity.", ""); String extradata = ""; - if(e.col1 == Color.get(-1, 0, 4, 46)) { - name = e.getClass().getCanonicalName().replace("com.mojang.ld22.entity.", "") + "II"; - } + + if(e instanceof ItemEntity || e instanceof Particle) continue; // don't even write ItemEntities or particle effects. + + if(e instanceof AirWizard && ((AirWizard)e).secondform) + name += "II"; if(e instanceof Mob) { - Mob c = (Mob)e; - extradata = ":" + c.health + ":" + c.maxHealth + ":" + c.lvl; + Mob m = (Mob)e; + extradata = ":" + m.health + ":" + m.maxHealth + ":" + m.lvl; } if(e instanceof Chest) { - String data = ""; - Chest c1 = (Chest)e; + Chest chest = (Chest)e; - for(int ii = 0; ii < c1.inventory.items.size(); ii++) { - if(c1.inventory.items.get(ii) instanceof ResourceItem) { - data += ((Item)c1.inventory.items.get(ii)).getName() + ";" + c1.inventory.count((Item)c1.inventory.items.get(ii)) + ":"; - } else { - data += ((Item)c1.inventory.items.get(ii)).getName() + ":"; - } + for(int ii = 0; ii < chest.inventory.invSize(); ii++) { + Item item = (Item)chest.inventory.get(ii); + extradata += ":" + item.getName(); + if(item instanceof ResourceItem) + extradata += ";" + chest.inventory.count(item); } - extradata += ":" + data; - if(c1.isdeathchest) { - name = "DeathChest"; - extradata += ":" + "tl;" + c1.time; - } - } - - if(e instanceof DungeonChest) { - String data = ""; - DungeonChest dChest = (DungeonChest)e; - - for(int ii = 0; ii < dChest.inventory.items.size(); ii++) { - if(!((Item)dChest.inventory.items.get(ii)).getName().equals("") || !((Item)dChest.inventory.items.get(ii)).getName().equals(" ")) { - if(dChest.inventory.items.get(ii) instanceof ResourceItem) { - data += ((Item)dChest.inventory.items.get(ii)).getName() + ";" + dChest.inventory.count((Item)dChest.inventory.items.get(ii)) + ":"; - } else { - data += ((Item)dChest.inventory.items.get(ii)).getName() + ":"; - } - } - } - - extradata += ":" + data + ":" + dChest.islocked; + if(chest instanceof DeathChest) extradata += ":" + ((DeathChest)chest).time; + if(chest instanceof DungeonChest) extradata += ":" + ((DungeonChest)chest).isLocked; } if(e instanceof Spawner) { @@ -245,4 +232,3 @@ public void writeEntities(String filename) { writeToFile(location + filename + extention, data); } } - diff --git a/src/com/mojang/ld22/screen/ContainerMenu.java b/src/com/mojang/ld22/screen/ContainerMenu.java index 4387459f4..66f7554d6 100644 --- a/src/com/mojang/ld22/screen/ContainerMenu.java +++ b/src/com/mojang/ld22/screen/ContainerMenu.java @@ -1,5 +1,6 @@ package com.mojang.ld22.screen; +import com.mojang.ld22.entity.Chest; import com.mojang.ld22.entity.Inventory; import com.mojang.ld22.entity.Player; import com.mojang.ld22.gfx.Font; @@ -14,11 +15,10 @@ public class ContainerMenu extends Menu { private int oSelected; // the old selected option (this is used to temporarily save spots moving from chest to inventory & vice-versa) private int window = 0; // currently selected window (player's inventory, or chest's inventory) - /** The container menu class is used for chests */ - public ContainerMenu(Player player, String title, Inventory container) { + public ContainerMenu(Player player, Chest chest) { this.player = player; - this.title = title; - this.container = container; + container = chest.inventory; + title = chest.name; } public void tick() { @@ -41,7 +41,7 @@ public void tick() { Inventory i = window == 1 ? player.inventory : container; Inventory i2 = window == 0 ? player.inventory : container; - int len = i.items.size(); // Size of the main inventory + int len = i.invSize(); // Size of the main inventory //selection fix if (selected < 0) selected = 0; @@ -59,18 +59,18 @@ public void tick() { // If the "Attack" key is pressed and the inventory's size is bigger than 0... if (input.getKey("attack").clicked && len > 0) { - i2.add(oSelected, i.items.remove(selected)); // It will add the item to the new inventory, and remove it from the old one. - if (selected >= i.items.size()) selected = i.items.size() - 1; // This fixes the selected item to the latest one. + i2.add(oSelected, i.remove(selected)); // It will add the item to the new inventory, and remove it from the old one. + if (selected >= len-1) selected = len-2;// = i.items.size() - 1; // This fixes the selected item to the latest one. } } - + public void render(Screen screen) { if (window == 1) screen.setOffset(6 * 8, 0); // Offsets the windows for when the player's inventory is selected Font.renderFrame(screen, title, 1, 1, 18, 11); // Renders the chest's window - renderItemList(screen, 1, 1, 18, 11, container.items, window == 0 ? selected : -oSelected - 1); // renders all the items from the chest's inventory + renderItemList(screen, 1, 1, 18, 11, container.getItems(), window == 0 ? selected : -oSelected - 1); // renders all the items from the chest's inventory Font.renderFrame(screen, "inventory", 19, 1, 15 + 20, 11); // renders the player's inventory - renderItemList(screen, 19, 1, 15 + 20, 11, player.inventory.items, window == 1 ? selected : -oSelected - 1); // renders all the items from the player's inventory + renderItemList(screen, 19, 1, 15 + 20, 11, player.inventory.getItems(), window == 1 ? selected : -oSelected - 1); // renders all the items from the player's inventory screen.setOffset(0, 0); // Fixes the offset back to normal } } diff --git a/src/com/mojang/ld22/screen/CraftInvMenu.java b/src/com/mojang/ld22/screen/CraftInvMenu.java index 11e7c034d..c1718e5c6 100644 --- a/src/com/mojang/ld22/screen/CraftInvMenu.java +++ b/src/com/mojang/ld22/screen/CraftInvMenu.java @@ -1,4 +1,3 @@ -//new class; no comments package com.mojang.ld22.screen; import com.mojang.ld22.crafting.Recipe; @@ -17,7 +16,7 @@ public class CraftInvMenu extends Menu { private Player player; private int selected = 0; - + private List recipes; public CraftInvMenu(List recipes, Player player) { @@ -71,7 +70,7 @@ public void render(Screen screen) { Font.rendercraftFrame(screen, "Cost", 15, 4, 22, 11); Font.rendercraftFrame(screen, "Crafting", 0, 1, 14, 11); renderItemList(screen, 0, 1, 14, 11, recipes, selected); - + if (recipes.size() > 0) { Recipe recipe = recipes.get(selected); int hasResultItems = player.inventory.count(recipe.resultTemplate); diff --git a/src/com/mojang/ld22/screen/DeadMenu.java b/src/com/mojang/ld22/screen/DeadMenu.java index 5901292c8..5aea3d1e6 100644 --- a/src/com/mojang/ld22/screen/DeadMenu.java +++ b/src/com/mojang/ld22/screen/DeadMenu.java @@ -9,7 +9,7 @@ public class DeadMenu extends Menu { private int inputDelay = 60; // this is an IMPORTANT bool, determines if the user should respawn or not. :) - public static boolean shudrespawn; + public static boolean shouldRespawn; public DeadMenu() {} @@ -18,13 +18,13 @@ public void tick() { inputDelay--; } else if (input.getKey("escape").clicked) { game.setMenu(new TitleMenu()); - shudrespawn = false; + shouldRespawn = false; } //This is so that if the user presses x @ respawn menu, they respawn (what a concept) if (ModeMenu.hardcore == false) { if (input.getKey("enter").clicked) { //This makes it so the player respawns - shudrespawn = true; + shouldRespawn = true; //reset game function game.resetGame(); //sets the menu to nothing @@ -38,7 +38,7 @@ public void render(Screen screen) { Font.draw("You died! Aww!", screen, 16, 32, Color.get(-1, 555, 555, 555)); // the current time elapsed in the game. - int seconds = game.gameTime / 60; + int seconds = game.gameTime / game.normSpeed; int minutes = seconds / 60; int hours = minutes / 60; minutes %= 60; diff --git a/src/com/mojang/ld22/screen/InstructionsMenu.java b/src/com/mojang/ld22/screen/InstructionsMenu.java index 029c5e6b5..3ce1aaac2 100644 --- a/src/com/mojang/ld22/screen/InstructionsMenu.java +++ b/src/com/mojang/ld22/screen/InstructionsMenu.java @@ -1,7 +1,6 @@ package com.mojang.ld22.screen; import com.mojang.ld22.gfx.Color; -import com.mojang.ld22.gfx.Font; import com.mojang.ld22.gfx.Screen; public class InstructionsMenu extends Menu { @@ -53,16 +52,4 @@ private boolean writeParagraph(String para, Screen screen, int minX, int maxX, i } private int textWidth(String text) {return text.length() * 8;} - /* - class Rectangle { - public int minX, int maxX, int minY, int maxY; - - public Rectangle(int minX, int maxX, int minY, int maxY) { - this.minX = minX; - this.maxX = maxX; - this.minY = minY; - this.maxY = maxY; - } - } - */ } diff --git a/src/com/mojang/ld22/screen/InventoryMenu.java b/src/com/mojang/ld22/screen/InventoryMenu.java index 466df21c1..17752e3e3 100644 --- a/src/com/mojang/ld22/screen/InventoryMenu.java +++ b/src/com/mojang/ld22/screen/InventoryMenu.java @@ -1,10 +1,8 @@ package com.mojang.ld22.screen; -import com.mojang.ld22.Game; import com.mojang.ld22.entity.Player; import com.mojang.ld22.gfx.Font; import com.mojang.ld22.gfx.Screen; -import com.mojang.ld22.item.Item; import com.mojang.ld22.sound.Sound; public class InventoryMenu extends Menu { @@ -13,9 +11,9 @@ public class InventoryMenu extends Menu { public InventoryMenu(Player player) { this.player = player; - + if (player.activeItem != null) { // If the player has an active item, then... - player.inventory.items.add(0, player.activeItem); // that active item will go into the inventory + player.inventory.add(0, player.activeItem); // that active item will go into the inventory player.activeItem = null; // the player will not have an active item anymore. } } @@ -27,21 +25,21 @@ public void tick() { if (input.getKey("down").clicked) selected++; if (input.getKey("up").clicked) Sound.pickup.play(); if (input.getKey("down").clicked) Sound.pickup.play(); - - int len = player.inventory.items.size(); + + int len = player.inventory.invSize(); if (len == 0) selected = 0; if (selected < 0) selected += len; if (selected >= len) selected -= len; - + if (input.getKey("attack").clicked && len > 0) { // If your inventory is not empty, and the player presses the "Attack" key... - Item item = player.inventory.items.remove(selected); // The item will be removed from the inventory - player.activeItem = item; // and that item will be placed as the player's active item + player.activeItem = player.inventory.remove(selected); // The item will be removed from the inventory + // = item; // and that item will be placed as the player's active item game.setMenu(null); // the game will go back to the gameplay } } public void render(Screen screen) { Font.renderFrame(screen, "inventory", 1, 1, 22, 11); // renders the blue box for the inventory - renderItemList(screen, 1, 1, 22, 11, player.inventory.items, selected); // renders the icon's and names of all the items in your inventory. + renderItemList(screen, 1, 1, 22, 11, player.inventory.getItems(), selected); // renders the icon's and names of all the items in your inventory. } } diff --git a/src/com/mojang/ld22/screen/LoadingMenu.java b/src/com/mojang/ld22/screen/LoadingMenu.java index df9194fc9..b50535bd7 100644 --- a/src/com/mojang/ld22/screen/LoadingMenu.java +++ b/src/com/mojang/ld22/screen/LoadingMenu.java @@ -1,4 +1,3 @@ -//new class; no comments //respawn mod +dillyg10+ package com.mojang.ld22.screen; diff --git a/src/com/mojang/ld22/screen/Menu.java b/src/com/mojang/ld22/screen/Menu.java index 836629547..4dbc96a3c 100644 --- a/src/com/mojang/ld22/screen/Menu.java +++ b/src/com/mojang/ld22/screen/Menu.java @@ -7,12 +7,13 @@ import com.mojang.ld22.gfx.Screen; import java.util.List; -/** Most all menus have a scroll feature... it should be in this class. */ +/** TODO Most all menus have a scroll feature... it should be in this class. + Frame should also be here..? */ public class Menu { protected Game game; protected InputHandler input; - + public void init(Game game, InputHandler input) { this.input = input; this.game = game; @@ -21,13 +22,9 @@ public void init(Game game, InputHandler input) { public void tick() {} public void render(Screen screen) {} - - public static int centertext(String name) { - return (Game.WIDTH - name.length() * 8) / 2; - } - + public void writeCentered(String text, Screen screen, int y, int color) { - Font.draw(text, screen, centertext(text), y, color); + Font.draw(text, screen, screen.centertext(text), y, color); } public void renderItemList(Screen screen, int xo, int yo, int x1, int y1, diff --git a/src/com/mojang/ld22/screen/ModeMenu.java b/src/com/mojang/ld22/screen/ModeMenu.java index d7018b517..ae2f66d29 100644 --- a/src/com/mojang/ld22/screen/ModeMenu.java +++ b/src/com/mojang/ld22/screen/ModeMenu.java @@ -1,15 +1,9 @@ -//new class; no comments //respawn mod +dillyg10+ package com.mojang.ld22.screen; import com.mojang.ld22.gfx.Color; import com.mojang.ld22.gfx.Font; import com.mojang.ld22.gfx.Screen; -import com.mojang.ld22.screen.LoadingMenu; -import com.mojang.ld22.screen.Menu; -import com.mojang.ld22.screen.TitleMenu; -import com.mojang.ld22.screen.WorldGenMenu; -import com.mojang.ld22.screen.WorldSelectMenu; import com.mojang.ld22.sound.Sound; import java.util.ArrayList; import java.util.Collections; @@ -153,8 +147,10 @@ public void render(Screen screen) { writeCentered(WorldSelectMenu.worldname, screen, screen.h - 170, Color.get(-1, 5, 5, 5)); String modeText = "Game Mode: " + modes[mode - 1]; - Font.draw(modeText, screen, centertext(modeText), 8 * 8 + 1, Color.get(-1, 111, 111, 111)); - Font.draw(modeText, screen, centertext(modeText) + 1, 8 * 8, Color.get(-1, 555, 555, 555)); + Font.draw(modeText, screen, screen.centertext(modeText), 8 * 8 + 1, Color.get(-1, 111, 111, 111)); + Font.draw(modeText, screen, screen.centertext(modeText) + 1, 8 * 8, Color.get(-1, 555, 555, 555)); + + //drawString(modeText, screen, 8 * 8, Color.get(-1, 111, 111, 111)); if(mode == 4) writeCentered("ime: " + time, screen, 95, Color.get(0, 555, 555, 555)); diff --git a/src/com/mojang/ld22/screen/OptionsMenu.java b/src/com/mojang/ld22/screen/OptionsMenu.java index 3151e5009..48f88cf2e 100644 --- a/src/com/mojang/ld22/screen/OptionsMenu.java +++ b/src/com/mojang/ld22/screen/OptionsMenu.java @@ -1,4 +1,3 @@ -//new class; no comments package com.mojang.ld22.screen; import com.mojang.ld22.Game; diff --git a/src/com/mojang/ld22/screen/PauseMenu.java b/src/com/mojang/ld22/screen/PauseMenu.java index b3846e0d8..15d3d6810 100644 --- a/src/com/mojang/ld22/screen/PauseMenu.java +++ b/src/com/mojang/ld22/screen/PauseMenu.java @@ -1,4 +1,3 @@ -//new class; no comments package com.mojang.ld22.screen; import com.mojang.ld22.entity.Player; diff --git a/src/com/mojang/ld22/screen/PlayerInfoMenu.java b/src/com/mojang/ld22/screen/PlayerInfoMenu.java index 82cfa0dba..9c4cbed52 100644 --- a/src/com/mojang/ld22/screen/PlayerInfoMenu.java +++ b/src/com/mojang/ld22/screen/PlayerInfoMenu.java @@ -1,5 +1,3 @@ -//new class; no comments -//respawn mod +dillyg10+ package com.mojang.ld22.screen; import com.mojang.ld22.gfx.Color; @@ -9,7 +7,7 @@ public class PlayerInfoMenu extends Menu { private int inputDelay = 60; // this is an IMPORTANT bool, determines if the user should respawn or not :). - public static boolean shudrespawn; + public static boolean shouldRespawn; public PlayerInfoMenu() {} @@ -24,7 +22,7 @@ public void tick() { public void render(Screen screen) { Font.renderFrame(screen, "Player Info", 1, 1, 30, 15); - int seconds = game.gameTime / 60; + int seconds = game.gameTime / game.normSpeed; int minutes = seconds / 60; int hours = minutes / 60; int cStep = game.player.stepCount; diff --git a/src/com/mojang/ld22/screen/TitleMenu.java b/src/com/mojang/ld22/screen/TitleMenu.java index e43cba73d..27b362cd4 100644 --- a/src/com/mojang/ld22/screen/TitleMenu.java +++ b/src/com/mojang/ld22/screen/TitleMenu.java @@ -1,18 +1,11 @@ -//mostly new... fewer comments. package com.mojang.ld22.screen; -import com.mojang.ld22.GameApplet; import com.mojang.ld22.Game; +import com.mojang.ld22.GameApplet; import com.mojang.ld22.gfx.Color; import com.mojang.ld22.gfx.Font; import com.mojang.ld22.gfx.Screen; -import com.mojang.ld22.screen.AboutMenu; -import com.mojang.ld22.screen.Menu; -import com.mojang.ld22.screen.ModeMenu; -import com.mojang.ld22.screen.OptionsMenu; -import com.mojang.ld22.screen.WorldSelectMenu; import com.mojang.ld22.sound.Sound; -import java.awt.Desktop; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -20,24 +13,17 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import java.net.ConnectException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.net.URLConnection; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Random; -import java.util.Scanner; public class TitleMenu extends Menu { private int selected = 0; protected final Random random = new Random(); public static List splashes = new ArrayList(); private static final String[] options = {"New game", "Instructions", "Tutorial", "Options", "About", "Quit"/*, "Kill"*/}; // Options that are on the main menu. - //public static boolean sentFromMenu; int randcount = 60; int rand = random.nextInt(randcount); int count = 0; // this and reverse are for the logo; they produce the fade-in/out effect. @@ -66,7 +52,6 @@ public TitleMenu() { } public void getSplashes() { - String ee; if(!loadedsplashes) { //The fun little messages that pop up. String[] splashes = { @@ -105,15 +90,13 @@ public void getSplashes() { "Story? What's that?", "Multiplayer? What's that?", "Infinite terrain? What's that?", - "Fullscreen? What's that?", "Redstone? What's that?", - "Bosses? What are those?", //"Spiders? What are those?", "Minecarts? What are those?", "3D? What's that?", "3.1D is the new thing!", "Windows? I perfer Doors!", - "Mouse? I perfer Keyboard!", + //"Mouse? I perfer Keyboard!", "Mouse not included!", "No spiders included!", "No Endermen included!", @@ -151,7 +134,7 @@ public void getSplashes() { "Why?", "You are null!", "That guy is such a sly fox!", - "hola senor!", + "Hola senor!", //"Vote for the Dead Workers Party!", "Sonic Boom!", "Hakuna Matata!", @@ -168,6 +151,7 @@ public void getSplashes() { "Cool!", "Radical!", "Potions ftw!", + "Beds ftw!", "Conquer the Dungeon!", "Defeat the Air Wizard!", "Loom + Wool = String!", @@ -177,9 +161,9 @@ public void getSplashes() { "Farm at Day!", //"Leave a comment below!", "Explanation Mark!", - "!sdrawkcab si siht", + "!sdrawkcab si sihT", "This is forwards!", - "why is this blue?", + "Why is this blue?", //"try with --debug", "MissingNo " + rand }; @@ -195,31 +179,27 @@ public void getSplashes() { splashes.clear(); while(bufferedWriter.hasNextLine()) { - ee = bufferedWriter.nextLine(); - if(ee.contains("]")) { - if(ee.substring(ee.indexOf("]")).length() > 3) { - ee = ee.substring(ee.indexOf("]") + 2, ee.length()); - } else { - ee = ""; - } - } - - if(!ee.equals("")) { - splashes.add(ee); + String splash = bufferedWriter.nextLine(); + if(splash.contains("]")) { + if(splash.substring(splash.indexOf("]")).length() > 3) { + splash = splash.substring(splash.indexOf("]") + 2, splash.length()); + } else continue; } + + if(splash.length() > 0) splashes.add(splash); } bufferedWriter.close(); - } catch (MalformedURLException var43) { - var43.printStackTrace(); + } catch (MalformedURLException urlEx) { + urlEx.printStackTrace(); splashes.clear(); splashes.add(""); - } catch (ConnectException var44) { - var44.printStackTrace(); + } catch (ConnectException conEx) { + conEx.printStackTrace(); splashes.clear(); splashes.add("Connection issue! D:"); - } catch (IOException var45) { - var45.printStackTrace(); + } catch (IOException ioEx) { + ioEx.printStackTrace(); splashes.clear(); splashes.add("Offline Mode :<"); } @@ -229,60 +209,59 @@ public void getSplashes() { if(!loadedunlocks) { ModeMenu.unlockedtimes.clear(); - BufferedReader br1 = null; + BufferedReader unlockReader = null; this.folder.mkdirs(); try { - br1 = new BufferedReader(new FileReader(this.location + "/unlocks.miniplussave")); + unlockReader = new BufferedReader(new FileReader(this.location + "/unlocks.miniplussave")); - String e1; - while((e1 = br1.readLine()) != null) { - List bufferedWriter2 = Arrays.asList(e1.split(",")); - Iterator var5 = bufferedWriter2.iterator(); + String line; + while((line = unlockReader.readLine()) != null) { + Iterator unlocks = Arrays.asList(line.split(",")).iterator(); - while(var5.hasNext()) { - ee = (String)var5.next(); - if(ee.contains("AirSkin")) { + while(unlocks.hasNext()) { + String ulText = (String)unlocks.next(); + if(ulText.contains("AirSkin")) { OptionsMenu.unlockedskin = true; } - if(ee.contains("MINUTEMODE") && !ee.substring(0, ee.indexOf("M") + 1).equals("M")) { - ModeMenu.unlockedtimes.add(ee.substring(0, ee.indexOf("M") + 1)); + if(ulText.contains("MINUTEMODE") && !ulText.substring(0, ulText.indexOf("M") + 1).equals("M")) { + ModeMenu.unlockedtimes.add(ulText.substring(0, ulText.indexOf("M") + 1)); } - if(ee.contains("HOURMODE") && !ee.substring(0, ee.indexOf("H") + 1).equals("H")) { - ModeMenu.unlockedtimes.add(ee.substring(0, ee.indexOf("H") + 1)); + if(ulText.contains("HOURMODE") && !ulText.substring(0, ulText.indexOf("H") + 1).equals("H")) { + ModeMenu.unlockedtimes.add(ulText.substring(0, ulText.indexOf("H") + 1)); } } } - } catch (FileNotFoundException var40) { - BufferedWriter bufferedWriter1 = null; - + } catch (FileNotFoundException fnfEx) { + BufferedWriter fileWriter = null; + try { - bufferedWriter1 = new BufferedWriter(new FileWriter(this.location + "/unlocks.miniplussave")); - bufferedWriter1.write(""); - } catch (IOException var38) { - var38.printStackTrace(); + fileWriter = new BufferedWriter(new FileWriter(this.location + "/unlocks.miniplussave")); + fileWriter.write(""); + } catch (IOException ex) { + ex.printStackTrace(); } finally { try { - if(bufferedWriter1 != null) { - bufferedWriter1.flush(); - bufferedWriter1.close(); + if(fileWriter != null) { + fileWriter.flush(); + fileWriter.close(); } - } catch (IOException var37) { - var37.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); } } - } catch (IOException var41) { - var41.printStackTrace(); + } catch (IOException ioEx) { + ioEx.printStackTrace(); } finally { try { - if(br1 != null) { - br1.close(); + if(unlockReader != null) { + unlockReader.close(); } - } catch (IOException var36) { - var36.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); } } @@ -329,10 +308,7 @@ public void tick() { if(com.mojang.ld22.Game.debug) System.out.println(e.getMessage()); } } - if (options[selected] == "Options") { - //sentFromMenu = true; - game.setMenu(new OptionsMenu(this)); - } + if (options[selected] == "Options") game.setMenu(new OptionsMenu(this)); if (options[selected] == "About") game.setMenu(new AboutMenu(this)); if (options[selected] == "Quit") System.exit(0); //if (options[selected] == "Kill") {game.level.add(game.player); game.setMenu(null);} @@ -385,20 +361,16 @@ public void render(Screen screen) { writeCentered(((String)splashes.get(rand)), screen, 60, cols); if(GameApplet.isApplet) { - if(GameApplet.username.length() < 27) { - Font.draw("Welcome, " + GameApplet.username + "!", screen, this.centertext("Welcome, " + GameApplet.username + "!"), screen.h - 190, Color.get(0, 330, 330, 330)); - } else { - Font.draw("Welcome,", screen, this.centertext("Welcome!"), screen.h - 190, Color.get(0, 330, 330, 330)); - Font.draw(GameApplet.username + "!", screen, this.centertext(GameApplet.username + "!"), screen.h - 180, Color.get(0, 330, 330, 330)); - } + String greeting = "Welcome!", name = GameApplet.username; + if(name.length() < 36) greeting = name+"!"; + if(name.length() < 27) greeting = "Welcome, " + greeting; - writeCentered("Version " + Game.VERSION, screen, screen.h - 10, Color.get(0, 111, 111, 111)); - } - else { - Font.draw("Version " + Game.VERSION, screen, 1, screen.h - 190, Color.get(0, 111, 111, 111)); + writeCentered(greeting, screen, 10, Color.get(0, 330, 330, 330)); } - writeCentered("(Arrow keys to move)", screen, screen.h - (GameApplet.isApplet?35:25), Color.get(0, 111, 111, 111)); - writeCentered("(Enter to accept, Escape to return)", screen, screen.h - (GameApplet.isApplet?25:15), Color.get(0, 111, 111, 111)); + Font.draw("Version " + Game.VERSION, screen, 1, 1, Color.get(0, 111, 111, 111)); + + writeCentered("(Arrow keys to move)", screen, screen.h - 25, Color.get(0, 111, 111, 111)); + writeCentered("(Enter to accept, Escape to return)", screen, screen.h - 15, Color.get(0, 111, 111, 111)); } } diff --git a/src/com/mojang/ld22/screen/WonMenu.java b/src/com/mojang/ld22/screen/WonMenu.java index 6cec7537c..df392a1cd 100644 --- a/src/com/mojang/ld22/screen/WonMenu.java +++ b/src/com/mojang/ld22/screen/WonMenu.java @@ -1,122 +1,90 @@ package com.mojang.ld22.screen; -import com.mojang.ld22.entity.Player; import com.mojang.ld22.Game; +import com.mojang.ld22.entity.Player; import com.mojang.ld22.gfx.Color; import com.mojang.ld22.gfx.Font; import com.mojang.ld22.gfx.Screen; import com.mojang.ld22.item.resource.Resource; -import com.mojang.ld22.screen.Menu; -import com.mojang.ld22.screen.ModeMenu; -import com.mojang.ld22.screen.TitleMenu; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Random; public class WonMenu extends Menu { - private int inputDelay = 0; // variable to delay the input of the player, so they won't skip the won menu the first second. + private int inputDelay = 20; // variable to delay the input of the player, so they won't skip the won menu the first second. Random random = new Random(); - int b1; - int b2; - int b3; - int b4; - int b5; - int b6; - String s1; - String s2; - String s3; - String s4; - String s5; - String s6; - int w; - int ml = 0; + HashMap scores; + int w, ml = 0; int finalscore = 0; String location = Game.gameDir; boolean doneunlocked = false; public WonMenu(Player player) { - this.b1 = player.inventory.scored(Resource.cloth) * (this.random.nextInt(2) + 1) * 10; - this.b2 = player.inventory.scored(Resource.slime) * (this.random.nextInt(2) + 1) * 10; - this.b3 = player.inventory.scored(Resource.bone) * (this.random.nextInt(2) + 1) * 10; - this.b4 = player.inventory.scored(Resource.gunp) * (this.random.nextInt(2) + 1) * 10; - this.b5 = player.inventory.scored(Resource.bookant) * (this.random.nextInt(2) + 1) * (this.random.nextInt(2) + 1) * 15; - this.b6 = player.inventory.scored(Resource.arrow) * (this.random.nextInt(2) + 1) * 10; - this.s1 = "Cloths:+" + this.b1; - this.s2 = "Slimes:+" + this.b2; - this.s3 = "Bones:+" + this.b3; - this.s4 = "Gunpowders:+" + this.b4; - this.s5 = "Books:+" + this.b5; - this.s6 = "Arrows:+" + this.b6; - this.ml = this.s1.length(); - if(this.s2.length() > this.ml) { - this.ml = this.s2.length(); - } - - if(this.s3.length() > this.ml) { - this.ml = this.s3.length(); - } - - if(this.s4.length() > this.ml) { - this.ml = this.s4.length(); - } - - if(this.s5.length() > this.ml) { - this.ml = this.s5.length(); - } - - if(this.s6.length() > this.ml) { - this.ml = this.s6.length(); + scores = new HashMap(); + scores.put("Cloth", player.inventory.count(Resource.cloth) * (random.nextInt(2) + 1) * 10); + scores.put("Slime", player.inventory.count(Resource.slime) * (random.nextInt(2) + 1) * 10); + scores.put("Bone", player.inventory.count(Resource.bone) * (random.nextInt(2) + 1) * 10); + scores.put("Gunpowder", player.inventory.count(Resource.gunp) * (random.nextInt(2) + 1) * 10); + scores.put("A.Book", player.inventory.count(Resource.bookant) * (random.nextInt(2) + 1) * (random.nextInt(2) + 1) * 15); + scores.put("Arrow", player.inventory.count(Resource.arrow) * (random.nextInt(2) + 1) * 10); + + ml = 0; // max length + for(String name: scores.keySet().toArray(new String[0])) { + ml = Math.max(name.length(), ml); + } + + finalscore = Player.score; + for(Integer score: scores.values().toArray(new Integer[0])) { + finalscore += score; } - - this.finalscore = Player.score + this.b1 + this.b2 + this.b3 + this.b4 + this.b5 + this.b6; } public void tick() { - if(this.input.getKey("menu").clicked) { - this.game.setMenu(new TitleMenu()); + if(inputDelay > 0) inputDelay--; + if(input.getKey("enter").clicked && inputDelay <= 0) { + game.setMenu(new TitleMenu()); } - } - public void unlocked(Screen screen, List unlocked) { - Font.renderFrame(screen, "", this.w + 2, 3, this.w + 13, 7 + unlocked.size()); - Font.draw("Unlocked!", screen, this.w * 8 + 32 - 4, 32, Color.get(-1, 50, 50, 50)); - - int i; - for(i = 0; i < unlocked.size(); ++i) { - Font.draw((String)unlocked.get(i), screen, this.w * 8 + 48 + 2, 48 + i * 12, Color.get(-1, 555, 555, 555)); - } - - if(!this.doneunlocked) { - for(i = 0; i < unlocked.size(); ++i) { - BufferedWriter bufferedWriter = null; - + public void writeUnlocks(Screen screen, List unlocks) { + Font.renderFrame(screen, "", w + 2, 3, w + 13, 7 + unlocks.size()); + Font.draw("Unlocked!", screen, w * 8 + 32 - 4, 32, Color.get(-1, 50, 50, 50)); + + for(int i = 0; i < unlocks.size(); ++i) { + Font.draw((String)unlocks.get(i), screen, w * 8 + 48 + 2, 48 + i * 12, Color.get(-1, 555, 555, 555)); + } + + if(!doneunlocked) { + for(int i = 0; i < unlocks.size(); ++i) { + BufferedWriter unlockWriter = null; + try { - bufferedWriter = new BufferedWriter(new FileWriter(this.location + "/unlocks.miniplussave", true)); - if(((String)unlocked.get(i)).contains("M")) { - bufferedWriter.write("," + ((String)unlocked.get(i)).substring(0, ((String)unlocked.get(i)).indexOf("M")) + "MINUTEMODE"); - } else if(((String)unlocked.get(i)).contains("H")) { - bufferedWriter.write("," + ((String)unlocked.get(i)).substring(0, ((String)unlocked.get(i)).indexOf("H")) + "HOURMODE"); + unlockWriter = new BufferedWriter(new FileWriter(location + "/unlocks.miniplussave", true)); + if(((String)unlocks.get(i)).contains("M")) { + unlockWriter.write("," + ((String)unlocks.get(i)).substring(0, ((String)unlocks.get(i)).indexOf("M")) + "MINUTEMODE"); + } else if(((String)unlocks.get(i)).contains("H")) { + unlockWriter.write("," + ((String)unlocks.get(i)).substring(0, ((String)unlocks.get(i)).indexOf("H")) + "HOURMODE"); } - } catch (IOException var14) { - var14.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); } finally { try { - if(bufferedWriter != null) { - bufferedWriter.flush(); - bufferedWriter.close(); + if(unlockWriter != null) { + unlockWriter.flush(); + unlockWriter.close(); } - } catch (IOException var13) { - var13.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); } - + TitleMenu.loadedunlocks = false; - this.doneunlocked = true; + doneunlocked = true; } } } @@ -125,30 +93,26 @@ public void unlocked(Screen screen, List unlocked) { public void render(Screen screen) { boolean hastime = false; - Player var10000 = this.game.player; + if(Player.score <= 9999999) { - this.w = 21; + w = 21; } else { - Player var10003 = this.game.player; - this.w = 14 + 1 + (int)Math.floor(Math.log10((double)Player.score)); - } - - if(this.w <= this.ml) { - this.w = this.ml + 2; - } - - if(this.w <= ("Final Score:" + this.finalscore).length() + 2) { - this.w = ("Final Score:" + this.finalscore).length() + 2; + w = 14 + 1 + (int)Math.floor(Math.log10((double)Player.score)); } + + w = Math.max(w, ml + 2); + w = Math.max(w, ("Final Score:" + finalscore).length() + 2); + w = Math.max(w, ("Press Enter to continue...").length() + 2); - Font.renderFrame(screen, "", 1, 3, this.w, 20); + Font.renderFrame(screen, "", 1, 3, w, 20); Font.draw("Game Over! (" + ModeMenu.time + ")", screen, 16, 32, Color.get(-1, 555, 555, 555)); - ArrayList unlocked = new ArrayList(); - int seconds; + + ArrayList unlocks = new ArrayList(); + if(ModeMenu.time.contains("20M")) { hastime = false; - - for(seconds = 0; seconds < ModeMenu.unlockedtimes.size(); ++seconds) { + + for(int seconds = 0; seconds < ModeMenu.unlockedtimes.size(); seconds++) { if(((String)ModeMenu.unlockedtimes.get(seconds)).contains("10M")) { hastime = true; break; @@ -157,15 +121,15 @@ public void render(Screen screen) { hastime = false; } - if(!hastime && this.finalscore > '\uafc8') { - unlocked.add("10M"); + if(!hastime && finalscore > 1000) { + unlocks.add("10M"); } } if(ModeMenu.time.contains("1H")) { hastime = false; - for(seconds = 0; seconds < ModeMenu.unlockedtimes.size(); ++seconds) { + for(int seconds = 0; seconds < ModeMenu.unlockedtimes.size(); seconds++) { if(((String)ModeMenu.unlockedtimes.get(seconds)).contains("2H")) { hastime = true; break; @@ -174,44 +138,29 @@ public void render(Screen screen) { hastime = false; } - if(!hastime && this.finalscore > 100000) { - unlocked.add("2Hr"); + if(!hastime && finalscore > 100000) { + unlocks.add("2Hr"); } } - if(unlocked.size() > 0) { - this.unlocked(screen, unlocked); - } - - seconds = this.game.gameTime / 60; - int minutes = seconds / 60; - int hours = minutes / 60; - minutes %= 60; - seconds %= 60; - String timeString = ""; - if(hours > 0) { - timeString = hours + "h" + (minutes < 10?"0":"") + minutes + "m"; - } else { - timeString = minutes + "m " + (seconds < 10?"0":"") + seconds + "s"; + if(unlocks.size() > 0) { + writeUnlocks(screen, unlocks); } - - Font.draw("Score:", screen, 16, 48, Color.get(-1, 555, 555, 555)); - StringBuilder var8 = new StringBuilder(); - Player var10001 = this.game.player; - Font.draw(var8.append(Player.score).toString(), screen, 64, 48, Color.get(-1, 550, 550, 550)); + + Font.draw("Player Score: " + Player.score, screen, 16, 48, Color.get(-1, 555, 555, 555)); Font.draw("", screen, 16, 64, Color.get(-1, Color.rgb(0, 200, 0), Color.rgb(0, 200, 0), Color.rgb(0, 200, 0))); - Font.draw(this.s1, screen, 16, 80, Color.get(-1, 550, 550, 550)); - Font.draw(this.s2, screen, 16, 88, Color.get(-1, 550, 550, 550)); - Font.draw(this.s3, screen, 16, 96, Color.get(-1, 550, 550, 550)); - Font.draw(this.s4, screen, 16, 104, Color.get(-1, 550, 550, 550)); - Font.draw(this.s6, screen, 16, 112, Color.get(-1, 550, 550, 550)); - Font.draw(this.s5, screen, 16, 120, Color.get(-1, 550, 550, 550)); - Font.draw("Final Score:", screen, 16, 136, Color.get(-1, 555, 555, 555)); - Font.draw("" + this.finalscore, screen, 112, 136, Color.get(-1, 550, 550, 550)); - if(this.finalscore == 0) { - Font.draw("Fail!", screen, 128, 136, Color.get(-1, 500, 500, 500)); + int i = 0; + for(String bonus: scores.keySet().toArray(new String[0])) { + String label = bonus+"s: "; + while(label.length() < ml+3) label += " "; + Font.draw(label+"+"+scores.get(bonus), screen, 16, 80+(i++)*8, Color.get(-1, 550, 550, 550)); + } + + Font.draw("Final Score: " + finalscore, screen, 16, 136, Color.get(-1, 555, 555, 555)); + if(finalscore == 0) { + Font.draw("Fail!", screen, 136, 136, Color.get(-1, 500, 500, 500)); } - Font.draw("Press X to continue", screen, 16, 152, Color.get(-1, 333, 333, 333)); + Font.draw("Press Enter to continue...", screen, 16, 152, Color.get(-1, 333, 333, 333)); } } diff --git a/src/com/mojang/ld22/screen/WorldGenMenu.java b/src/com/mojang/ld22/screen/WorldGenMenu.java index 7e1130fd9..0d41b496b 100644 --- a/src/com/mojang/ld22/screen/WorldGenMenu.java +++ b/src/com/mojang/ld22/screen/WorldGenMenu.java @@ -1,4 +1,3 @@ -//new class; no comments package com.mojang.ld22.screen; import com.mojang.ld22.gfx.Color; diff --git a/src/com/mojang/ld22/screen/WorldSelectMenu.java b/src/com/mojang/ld22/screen/WorldSelectMenu.java index 2e8a3a06d..b7037290e 100644 --- a/src/com/mojang/ld22/screen/WorldSelectMenu.java +++ b/src/com/mojang/ld22/screen/WorldSelectMenu.java @@ -1,4 +1,3 @@ -//new class; no comments package com.mojang.ld22.screen; import com.mojang.ld22.Game;