private void makeNewZone() { //read all the boxes to get the information necessary int x, y; int width, height; try { x = Convert.ToInt32(zoneXBox.Text); y = Convert.ToInt32(zoneYBox.Text); width = Convert.ToInt32(zoneWidthBox.Text); height = Convert.ToInt32(zoneHeightBox.Text); //make the zone Zone zone = new Zone(width, height, x, y); zone.zoneName = nameTextBox.Text; zone.isRoom = isRoomBox.Checked; game.world.addZone(zone); game.world.changeZone(zone); GameDraw.MakeAdjBuffers(game.world); EditorScreen.lookAtPosition = new Vector3(x, y, 0); this.DialogResult = System.Windows.Forms.DialogResult.OK; //close the form Close(); } catch (FormatException) { /*do nothing*/ } catch (ArgumentException) { MessageBox.Show("Zone with same name already exists"); } }
internal static void SetAll(String tileType) { //shift undo history down by one for (int i = editor.historySize - 1; i > 0; i--) { editor.zoneHistory[i] = editor.zoneHistory[i - 1]; } //save current state as last change for (int x = 0; x < game.world.currentArea.mapWidth; x++) { for (int y = 0; y < game.world.currentArea.mapHeight; y++) { //apply properties game.world.currentArea.tile[x, y].setAccessible(editor.northBox.Checked, editor.eastBox.Checked, editor.southBox.Checked, editor.westBox.Checked); game.world.currentArea.tile[x, y].setRamp(editor.rampBox.Checked); game.world.currentArea.tile[x, y].setJumpable(editor.jumpBox.Checked); game.world.currentArea.tile[x, y].setRandomEncounter(editor.jumpBox.Checked); game.world.currentArea.tile[x, y].setWater(editor.waterBox.Checked); //apply tile image game.world.currentArea.tile[x, y].tileType = tileType; game.world.changeZone(game.world.currentArea); } } //save current zone for undo history editor.zoneHistory[0] = new Zone(game.world.currentArea); //then update buffers all in one fell swoop GameDraw.MakeAdjBuffers(game.world); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load <SpriteFont>("font"); simpleEffect = Content.Load <Effect>("simpleEffect"); // initialize the screenhandler. need to do it here for the font. // ScreenHandler.Initialize(graphics, Content, font); if (!Directory.Exists(Application.StartupPath + "\\TileSets")) { downloadTileSets(); } ScreenHandler.Initialize(graphics, Content, font); ScreenHandler.SwitchScreen(new GameScreen(graphics, Content, font)); world = new World(); Zone zone = new Zone(2, 2); world.addZone(zone); world.changeZone(zone); GameDraw.Initialize(graphics, Content, font); GameDraw.drawAdjObjects = true; GameDraw.MakeAdjBuffers(world); BaseStatsList.initialize(); // We need this so we can edit trainer pokemon in the map maker // TODO: use this.Content to load your game content here }
internal static void SetAll(String tileType) { EditorScreen.updateHistory(); for (int x = 0; x < game.world.currentArea.mapWidth; x++) { for (int y = 0; y < game.world.currentArea.mapHeight; y++) { //apply properties game.world.currentArea.tile[x, y].setAccessible(editor.northBox.Checked, editor.eastBox.Checked, editor.southBox.Checked, editor.westBox.Checked); game.world.currentArea.tile[x, y].setRamp(editor.rampBox.Checked); game.world.currentArea.tile[x, y].setJumpable(editor.jumpBox.Checked); game.world.currentArea.tile[x, y].setRandomEncounter(editor.randomEncounterBox.Checked); game.world.currentArea.tile[x, y].setWater(editor.waterBox.Checked); //apply tile image game.world.currentArea.tile[x, y].tileType = tileType; //game.world.changeZone(game.world.currentArea); } } //if the history index is zero we want to save the current zone if (editor.historyIndex == 0) { editor.zoneHistory[0] = new Zone(game.world.currentArea); } //then update buffers all in one fell swoop GameDraw.MakeAdjBuffers(game.world); }
public static void ApplyImage() { if (editor.selectedTiles.Count < 1) { return; } int x = game.selectedX; int y = game.selectedY; foreach (SelectedTile s in editor.selectedTiles) { //first tile in list is under the mouse int currX = x + s.PositionX - editor.selectedTiles[0].PositionX; int currY = y + s.PositionY - editor.selectedTiles[0].PositionY; if (currX >= 0 && currX < game.world.currentArea.mapWidth && currY >= 0 && currY < game.world.currentArea.mapHeight && !String.IsNullOrWhiteSpace(s.TileType)) { //apply the changes to the properties of the tile game.world.currentArea.tile[currX, currY].setAccessible(editor.northBox.Checked, editor.eastBox.Checked, editor.southBox.Checked, editor.westBox.Checked); game.world.currentArea.tile[currX, currY].setRamp(editor.rampBox.Checked); game.world.currentArea.tile[currX, currY].setJumpable(editor.jumpBox.Checked); game.world.currentArea.tile[currX, currY].setRandomEncounter(editor.randomEncounterBox.Checked); game.world.currentArea.tile[currX, currY].setWater(editor.waterBox.Checked); game.world.currentArea.tile[currX, currY].tileType = s.TileType; } } //check if the tile is already of the selected type //if not then change it game.world.changeZone(game.world.currentArea); GameDraw.MakeAdjBuffers(game.world); }
public static void SetMap(String mapName, int xCoord, int yCoord) { //the while loop makes sure the dialog box is closed before it changes the map //disable drawing while transitioning, cause this is in a separate thread GameScreen.StopDrawing = true; GameScreen.world.changeZone(mapName); GameScreen.world.currentArea.scenery = new List <Map.Scenery>(); GameScreen.player.tileCoords = new Microsoft.Xna.Framework.Point(xCoord, yCoord); GameDraw.MakeAdjBuffers(GameScreen.world); GameDraw.UpdateNPCSpritesheets(GameScreen.world); //reenable drawing GameScreen.StopDrawing = false; }
private void editCurrentZone() { //read all the boxes to get the information necessary int x, y; int width, height; try { x = Convert.ToInt32(zoneXBox.Text); y = Convert.ToInt32(zoneYBox.Text); width = Convert.ToInt32(zoneWidthBox.Text); height = Convert.ToInt32(zoneHeightBox.Text); //make the zone Zone zone = new Zone(width, height, x, y); zone.zoneName = nameTextBox.Text; zone.isRoom = isRoomBox.Checked; zone.scenery = game.world.currentArea.scenery; zone.tileSheetLocation = game.world.currentArea.tileSheetLocation; zone.trainerList = game.world.currentArea.trainerList; zone.randomPokemon = game.world.currentArea.randomPokemon; for (int i = 0; i < Math.Min(zone.mapWidth, game.world.currentArea.mapWidth); i++) { for (int j = 0; j < Math.Min(zone.mapHeight, game.world.currentArea.mapHeight); j++) { zone.tile[i, j] = new Tile(game.world.currentArea.tile[i, j]); } } game.world.addZone(zone); game.world.changeZone(zone); GameDraw.MakeAdjBuffers(game.world); EditorScreen.lookAtPosition = new Vector3(x, y, 0); this.DialogResult = System.Windows.Forms.DialogResult.OK; //close the form Close(); } catch (FormatException) { /*do nothing*/ } catch (ArgumentException) { MessageBox.Show("Zone with same name already exists"); } }
private void loadZone() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Pokemon Zone File (*.zon)|*.zon"; //use default zone path if one exists if (Directory.Exists(DefaultFileLocations.zoneLocation)) { ofd.InitialDirectory = DefaultFileLocations.zoneLocation; } ofd.ShowDialog(); Zone zone = null; try { using (FileStream stream = new FileStream(ofd.FileName, FileMode.Open)) { using (BinaryReader reader = new BinaryReader(stream)) { zone = SaveLoad.LoadZone(reader); } } ImportTileFolder(zone.tileSheetLocation); //for now its just the location of where the tiles are game.world.getBounds(); game.world.addZone(zone); game.world.changeZone(zone); GameDraw.MakeAdjBuffers(game.world); GameDraw.UpdateNPCSpritesheets(game.world); EditorScreen.lookAtPosition = new Vector3(zone.globalX * 32, zone.globalY * 32, 0); toolTab.Enabled = true; //save selected directory as default String[] temp = ofd.FileName.Split('\\'); DefaultFileLocations.zoneLocation = ofd.FileName.Substring(0, ofd.FileName.Length - temp[temp.Length - 1].Length); } catch (ArgumentException) { } }
public static void ApplyImage() { int x = game.selectedX; int y = game.selectedY; //apply the changes to the properties of the tile game.world.currentArea.tile[x, y].setAccessible(editor.northBox.Checked, editor.eastBox.Checked, editor.southBox.Checked, editor.westBox.Checked); game.world.currentArea.tile[x, y].setRamp(editor.rampBox.Checked); game.world.currentArea.tile[x, y].setJumpable(editor.jumpBox.Checked); game.world.currentArea.tile[x, y].setRandomEncounter(editor.randomEncounterBox.Checked); game.world.currentArea.tile[x, y].setWater(editor.waterBox.Checked); //check if the tile is already of the selected type if (game.world.currentArea.tile[x, y].tileType != (String)editor.pbox_TilePreview.Tag && x != -1 && y != -1) { //if not then change it game.world.currentArea.tile[x, y].tileType = (String)editor.pbox_TilePreview.Tag; game.world.changeZone(game.world.currentArea); GameDraw.MakeAdjBuffers(game.world); } }
/// <summary> /// Returns false if the tile we are trying to move to is not accessable, or occupied /// </summary> /// <param name="direction"></param> /// <returns></returns> public bool tryToMove(String direction) { bool canMove = true; bool npcTest = true; //false means an npc is occupying the next tile, thus halting movement try { switch (direction) { case "Up": nextTile = new Point(tileCoords.X, tileCoords.Y - 1); if (GameScreen.Map.tile[tileCoords.X, tileCoords.Y - 1].isAccessibleFrom(Map.Direction.South)) { if (standCoolDown <= 0) { startMove("Up"); } } else if (standCoolDown <= 0) { canMove = false; changeFacingDirection("Up"); } break; case "Down": nextTile = new Point(tileCoords.X, tileCoords.Y + 1); if (GameScreen.Map.tile[tileCoords.X, tileCoords.Y + 1].isAccessibleFrom(Map.Direction.North)) { if (standCoolDown <= 0) { startMove("Down"); } } else if (standCoolDown <= 0) { canMove = false; changeFacingDirection("Down"); } break; case "Left": nextTile = new Point(tileCoords.X - 1, tileCoords.Y); if (GameScreen.Map.tile[tileCoords.X - 1, tileCoords.Y].isAccessibleFrom(Map.Direction.East)) { if (standCoolDown <= 0) { startMove("Left"); } } else if (standCoolDown <= 0) { canMove = false; changeFacingDirection("Left"); } break; case "Right": nextTile = new Point(tileCoords.X + 1, tileCoords.Y); if (GameScreen.Map.tile[tileCoords.X + 1, tileCoords.Y].isAccessibleFrom(Map.Direction.West)) { if (standCoolDown <= 0) { startMove("Right"); } } else if (standCoolDown <= 0) { canMove = false; changeFacingDirection("Right"); } break; default: break; } }//end try catch (IndexOutOfRangeException) { //check whether you can swap to an adjacent map if (GameScreen.world.isAdjacentTile(GameScreen.world.currentArea.globalX + nextTile.X, GameScreen.world.currentArea.globalY + nextTile.Y)) { //unoccupy current tile GameScreen.world.currentArea.tile[tileCoords.X, tileCoords.Y].setOccupied(false); //find global coords nextTile.X += GameScreen.world.currentArea.globalX; nextTile.Y += GameScreen.world.currentArea.globalY; tileCoords.X += GameScreen.world.currentArea.globalX; tileCoords.Y += GameScreen.world.currentArea.globalY; //change zone GameScreen.world.moveToAdjZone(nextTile.X, nextTile.Y); GameDraw.MakeAdjBuffers(GameScreen.world); GameDraw.UpdateNPCSpritesheets(GameScreen.world); //convert back to local coords in new zone nextTile.X -= GameScreen.world.currentArea.globalX; nextTile.Y -= GameScreen.world.currentArea.globalY; tileCoords.X -= GameScreen.world.currentArea.globalX; tileCoords.Y -= GameScreen.world.currentArea.globalY; isMoving = true; startMove(direction); } else { nextTile = tileCoords; switch (direction) { case "Up": changeFacingDirection("Up"); break; case "Down": changeFacingDirection("Down"); break; case "Left": changeFacingDirection("Left"); break; case "Right": changeFacingDirection("Right"); break; default: break; } } } return(canMove); }
static public void update(GameTime gameTime, World world) { //get current state of keyboard and mouse currentMouseState = Mouse.GetState(); currentKeyState = Keyboard.GetState(); //keyboard actions HandleArrowKeys(); if (currentKeyState.IsKeyDown(Keys.A)) { lookAtPosition -= new Vector3(GameDraw.cameraOffset.Length() / 100, 0, 0); } if (currentKeyState.IsKeyDown(Keys.D)) { lookAtPosition += new Vector3(GameDraw.cameraOffset.Length() / 100, 0, 0); } if (currentKeyState.IsKeyDown(Keys.S)) { lookAtPosition += new Vector3(0, GameDraw.cameraOffset.Length() / 100, 0); } if (currentKeyState.IsKeyDown(Keys.W)) { lookAtPosition -= new Vector3(0, GameDraw.cameraOffset.Length() / 100, 0); } //undo action //check whether a ctrl is down, and the Z key has been pressed (was up, is now down) if ((currentKeyState.IsKeyDown(Keys.LeftControl) || currentKeyState.IsKeyDown(Keys.RightControl)) && (currentKeyState.IsKeyDown(Keys.Z) && prevKeyState.IsKeyUp(Keys.Z))) { //make sure the next history isn't empty if (editor.zoneHistory[editor.historyIndex + 1] != null) { //increase history index by one if possible editor.historyIndex++; if (editor.historyIndex >= editor.historySize) { editor.historyIndex = editor.historySize - 1; } //change to the historical zone game.world.addZone(editor.zoneHistory[editor.historyIndex]); game.world.changeZone(editor.zoneHistory[editor.historyIndex]); GameDraw.MakeAdjBuffers(game.world); } } //redo action //check whether a ctrl is down, and the Y key has been pressed (was up, is now down) if ((currentKeyState.IsKeyDown(Keys.LeftControl) || currentKeyState.IsKeyDown(Keys.RightControl)) && (currentKeyState.IsKeyDown(Keys.Y) && prevKeyState.IsKeyUp(Keys.Y))) { //make sure there is room for us to redo if (editor.historyIndex > 0) { editor.historyIndex--; //if so then restore the next zone state game.world.addZone(editor.zoneHistory[editor.historyIndex]); game.world.changeZone(editor.zoneHistory[editor.historyIndex]); GameDraw.MakeAdjBuffers(game.world); } } //mouse actions { //if mouse is down if (currentMouseState.LeftButton == ButtonState.Pressed) { //check if mouse has been pressed, and if so then save current history //that way you can undo to whatever the state was before the mouse was pressed if (prevMouseState.LeftButton == ButtonState.Released && currentMouseState.LeftButton == ButtonState.Pressed) { updateHistory(); } //if we have an actual tile selected do the different options if (game.selectedX != -1 && game.selectedY != -1) { //if we are in the tile section if (editor.toolTab.SelectedTab == editor.TileSpritesTab) { TileTool.ApplyImage(); } //if we are in the tile settings tab if (editor.toolTab.SelectedTab == editor.TilePropertiesTab) { TileTool.ApplySettings(); } //if we are in the NPC tab if (editor.toolTab.SelectedTab == editor.NPCTab) { if (NPCTool.toolType == NPCToolType.PlaceNPC) { NPCTool.PlaceNPC(); } else if (NPCTool.toolType == NPCToolType.SetWanderArea) { //on start setting the wander area if (prevMouseState.LeftButton == ButtonState.Released) { NPCTool.StartSetWander(); } } else if (NPCTool.toolType == NPCToolType.EditNPC) { //on click pick up the NPC if (prevMouseState.LeftButton == ButtonState.Released) { NPCTool.PickUpNPC(); } //update postion of NPC if we have one active if (editor.activeNPCEdit != null) { //if there are no obstables if (world.currentArea.tile[game.selectedX, game.selectedY].isClear()) { editor.activeNPCEdit.tileCoords = new Point(game.selectedX, game.selectedY); } } } else if (NPCTool.toolType == NPCToolType.DeleteNPC) { NPCTool.DeleteNPC(); } } //if we are in the model tab if (editor.toolTab.SelectedTab == editor.SceneryTab) { //place a new model if new is selected if (editor.modelNewRadio.Checked) { if (editor.sceneryBox.SelectedItem != null) { ModelTool.PlaceModel(); } } //if delete is selected then it should act as a delete tool else if (editor.modelDeleteRadio.Checked) { ModelTool.DeleteModel(); } //edit model if edit is selected else if (editor.modelEditRadio.Checked) { //on "click" rather than whenever pressed if (prevMouseState.LeftButton == ButtonState.Released) { ModelTool.EditModel(); //on mouse down we "pick up" the scenery object ModelTool.PickUpScenery(); } } } } } //on mouse release if (prevMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released) { //if we have an actual tile selected do the different options if (game.selectedX != -1 && game.selectedY != -1) { //if we are in the model tab if (editor.toolTab.SelectedTab == editor.SceneryTab && editor.modelEditRadio.Checked) { //on mouse up we "drop" the scenery object ModelTool.DropScenery(); } //if we are on the NPC tab if (editor.toolTab.SelectedTab == editor.NPCTab) { if (NPCTool.toolType == NPCToolType.SetWanderArea && editor.NPCEditRadio.Checked) { NPCTool.EndSetWander(); } else if (NPCTool.toolType == NPCToolType.EditNPC && editor.NPCEditRadio.Checked) { if (NPCTool.holdingNPC) { NPCTool.DropNPC(); } } } } } //when we release the mouse we want to save the current state as the most recent history if (prevMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released) { //if the history index is zero we want to save the current zone if (editor.historyIndex == 0) { editor.zoneHistory[0] = new Zone(game.world.currentArea); } } HandleScrollWheelActions(); } //update previous mouse/keyboard state prevMouseState = currentMouseState; prevKeyState = currentKeyState; }
/// <summary> /// This is for handling actions with the scroll wheel /// </summary> private static void HandleScrollWheelActions() { //regular scrolling will zoom the camera in and out if (currentMouseState.ScrollWheelValue != prevMouseState.ScrollWheelValue && currentKeyState.IsKeyUp(Keys.LeftControl) && currentKeyState.IsKeyUp(Keys.LeftShift)) { Vector3 change = (currentMouseState.ScrollWheelValue - prevMouseState.ScrollWheelValue) * new Vector3(0, 0.01f, 0.01f); GameDraw.cameraOffset -= change; if (GameDraw.cameraOffset.Y < 0.1f) { GameDraw.cameraOffset.Y = 0.1f; } if (GameDraw.cameraOffset.Z < 0.1f) { GameDraw.cameraOffset.Z = 0.1f; } } //scrolling with the shift key down will move the temporary model up and down (if applicable) //it will also change the height of the tile if the tile tab is selected else if (currentMouseState.ScrollWheelValue != prevMouseState.ScrollWheelValue && currentKeyState.IsKeyUp(Keys.LeftControl) && currentKeyState.IsKeyDown(Keys.LeftShift)) { if (editor.toolTab.SelectedTab == editor.SceneryTab) { if ((editor.sceneryBox.SelectedItem != null || !editor.editingBaseScenery) && game.selectedX != -1 && game.selectedY != -1) { Scenery temp = null; if (editor.modelNewRadio.Checked && editor.sceneryBox.SelectedItem != null) { temp = editor.sceneryList[(String)editor.sceneryBox.SelectedItem]; //alter the template } else if (editor.modelEditRadio.Checked) { temp = ModelTool.currentModel; //alter the placed object } if (temp != null) { //make it 10% larger or smaller if (currentMouseState.ScrollWheelValue > prevMouseState.ScrollWheelValue) { if (currentKeyState.IsKeyDown(Keys.LeftShift) && currentKeyState.IsKeyDown(Keys.LeftAlt)) { temp.translation = temp.translation * Matrix.CreateTranslation(0, 1f, 0); } else { temp.translation = temp.translation * Matrix.CreateTranslation(0, 1f / 8f, 0); } } else { if (currentKeyState.IsKeyDown(Keys.LeftShift) && currentKeyState.IsKeyDown(Keys.LeftAlt)) { temp.translation = temp.translation * Matrix.CreateTranslation(0, -1f, 0); } else { temp.translation = temp.translation * Matrix.CreateTranslation(0, -1f / 8f, 0); } } } } } else if ((editor.toolTab.SelectedTab == editor.TileSpritesTab || editor.toolTab.SelectedTab == editor.TilePropertiesTab)) { if (game.selectedX != -1 && game.selectedY != -1 && currentMouseState.ScrollWheelValue != prevMouseState.ScrollWheelValue) { if (currentMouseState.ScrollWheelValue > prevMouseState.ScrollWheelValue) { if (currentKeyState.IsKeyDown(Keys.LeftShift) && currentKeyState.IsKeyDown(Keys.LeftAlt)) { game.world.currentArea.tile[game.selectedX, game.selectedY].Z += 8; } else { game.world.currentArea.tile[game.selectedX, game.selectedY].Z += 1; } } else { if (currentKeyState.IsKeyDown(Keys.LeftShift) && currentKeyState.IsKeyDown(Keys.LeftAlt)) { game.world.currentArea.tile[game.selectedX, game.selectedY].Z -= 8; } else { game.world.currentArea.tile[game.selectedX, game.selectedY].Z -= 1; } } updateHistory(); previousTileHeightChange.X = game.selectedX; previousTileHeightChange.Y = game.selectedY; GameDraw.MakeAdjBuffers(game.world); } } } //scrolling with the ctrl key down will rotate the temporary model if applicable else if (currentMouseState.ScrollWheelValue != prevMouseState.ScrollWheelValue && currentKeyState.IsKeyDown(Keys.LeftControl) && currentKeyState.IsKeyUp(Keys.LeftShift)) { if (editor.toolTab.SelectedTab == editor.SceneryTab) { if ((editor.sceneryBox.SelectedItem != null || !editor.editingBaseScenery) && game.selectedX != -1 && game.selectedY != -1) { Scenery temp = null; if (editor.modelNewRadio.Checked && editor.sceneryBox.SelectedItem != null) { temp = editor.sceneryList[(String)editor.sceneryBox.SelectedItem]; //alter the template } else if (editor.modelEditRadio.Checked) { temp = ModelTool.currentModel; //alter the placed object } if (temp != null) { //rotate it 27.5 degrees if (currentMouseState.ScrollWheelValue > prevMouseState.ScrollWheelValue) { temp.rotation = temp.rotation * Matrix.CreateRotationY(2f / 16f * (float)Math.PI); } else { temp.rotation = temp.rotation * Matrix.CreateRotationY(-2f / 16f * (float)Math.PI); } } } } } }