public override void acceptInput(GameTime time, KeyboardState currentKeyboardState, MouseState currentMouseState, KeyboardState prevKeyboardState, MouseState prevMouseState) { //jumpTexOffset++; frameSwitcher--; if (frameSwitcher <= 0) { frameSwitcher = frameSwitchPoint; currentFrame++; if (world.player is Player) { PlayerAnimationPackage animationPackage = ((Player)world.player).animationPackage; runTex = animationPackage.runTex[currentFrame % animationPackage.runTex.Length]; jumpTex = animationPackage.jumpTex[0]; jumpTexOffset = -(currentFrame % 20); } } mouseLoc = currentMouseState.Position; if (currentMouseState.LeftButton == ButtonState.Pressed && prevMouseState.LeftButton == ButtonState.Released) { if (keyboardRect.Contains(mouseLoc)) { foreach (Rectangle keyRect in inputMap.Keys) { if (keyRect.Contains(mouseLoc)) { inputSelected = true; selectedRect = keyRect; } } } else { foreach (Rectangle rect in actionMap.Keys) { if (rect.Contains(mouseLoc)) { inputSelected = false; selectedRect = rect; break; } } } } if (currentMouseState.LeftButton == ButtonState.Pressed && selectedRect != Rectangle.Empty) { drawLineToMouse = true; } if (currentMouseState.LeftButton == ButtonState.Released) { if (selectedRect != Rectangle.Empty) { if (inputSelected) { foreach (Rectangle rect in actionMap.Keys) { if (rect.Contains(mouseLoc)) { Game1.keyBindManager.bindings[actionMap[rect]] = inputMap[selectedRect]; } } } else { foreach (Rectangle rect in inputMap.Keys) { if (rect.Contains(mouseLoc)) { Game1.keyBindManager.bindings[actionMap[selectedRect]] = inputMap[rect]; } } } } selectedRect = Rectangle.Empty; drawLineToMouse = false; } if (currentKeyboardState.IsKeyDown(Keys.Escape) && prevKeyboardState.IsKeyUp(Keys.Escape)) { keepGoing(); } }
public static void load(String path) { Logger.log("Loading game at " + path); bool foundWorld = false; WorldBase world = null; try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } else if (File.Exists(path + "save.txt")) { foundWorld = true; using (System.IO.StreamReader file = new System.IO.StreamReader(path + "save.txt")) { World.universeProperties = new UniverseProperties(file.ReadLine()); int difficulty = int.Parse(file.ReadLine()); world = Game1.instance.getWorldBasedOnDifficulty(difficulty); Player player = ((Player)world.player); PlayerAnimationPackage animationPackage = PlayerAnimationPackage.animationPackageKey[int.Parse(file.ReadLine())]; animationPackage.apply(player); Inventory.PlayerInventory inventory = player.inventory; float playerX = float.Parse(file.ReadLine()); float playerY = float.Parse(file.ReadLine()); player.location = new Vector2(playerX, playerY); player.health = float.Parse(file.ReadLine()); player.hunger = float.Parse(file.ReadLine()); player.warmth = float.Parse(file.ReadLine()); int currentCard = 0; string line = file.ReadLine(); while (!line.StartsWith("Keyed Items:")) { if (line.StartsWith("Inventory:")) { line = line.Replace("Inventory:", ""); string[] entry = line.Split(','); int id = int.Parse(entry[0]); int count = int.Parse(entry[1]); inventory.add(ItemRegistrar.getItemFromIdAndCount(id, count)); } else if (line.StartsWith("Card:")) { line = line.Replace("Card:", ""); string[] entry = line.Split(','); int id = int.Parse(entry[0]); float level = float.Parse(entry[1]); player.cards[currentCard] = CardRegistrar.getCardFromIdPlayerAndLevel(id, level, player); currentCard++; } line = file.ReadLine(); } for (int i = 0; i < player.keyedItems.Length; i++) { int itemData = int.Parse(file.ReadLine()); if (itemData != -1) { player.keyedItems[i] = ItemRegistrar.getItemFromIdAndCount(itemData, 1); } } } File.Delete(path + "save.txt"); } } catch (Exception e) { Logger.log(e.ToString()); } if (!foundWorld) { world = Game1.instance.getWorldBasedOnDifficulty(0); Game1.instance.queuedSplashScreens.Add(new PlayerSelectScreen(MetaData.unlocks.ToArray(), world)); } Card.setUpCards(); Game1.instance.switchWorlds(world); }