public static void PlaceNPC() { int selX = game.selectedX; int selY = game.selectedY; if (game.world.currentArea.GetNPCAtLocation(selX, selY) != null) { //do not place if there is already a NPC there } else { NPC tempNPC = editor.CreateNPC(); //check if the sprite is already there if (File.Exists(Directory.GetCurrentDirectory() + "\\Content\\Sprites\\NPCs\\Overworlds\\" + tempNPC.spriteSheet)) { tempNPC.tileCoords = new Microsoft.Xna.Framework.Point(selX, selY); game.world.currentArea.tile[selX, selY].setOccupied(true); game.world.currentArea.trainerList.Add(tempNPC); tempNPC = null; GameDraw.UpdateNPCSpritesheets(game.world); editor.ResetNPCTab(); } } }
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 btn_LoadNPCSprites_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); //use default zone path if one exists if (Directory.Exists(DefaultFileLocations.npcSpriteLocation)) { ofd.InitialDirectory = DefaultFileLocations.npcSpriteLocation; } ofd.Multiselect = false; ofd.ShowDialog(); Image tempImage = null; ImageList tempImageList = new ImageList(); tempImageList.ImageSize = new System.Drawing.Size(116, 153); try { NPCImageToUse = ofd.FileName; tempImage = Bitmap.FromFile(ofd.FileName); NPCImageBox.Image = tempImage; //save selected directory as default String[] temp = ofd.FileName.Split('\\'); DefaultFileLocations.npcSpriteLocation = ofd.FileName.Substring(0, ofd.FileName.Length - temp[temp.Length - 1].Length); } catch (Exception ex) { MessageBox.Show(ex.Message); } //only fires when we are editing an existing NPC if (NPCEditRadio.Checked && activeNPCEdit != null) { //copy the sprite over to the content folder if (!String.IsNullOrWhiteSpace(NPCImageToUse)) { String destination = Directory.GetCurrentDirectory() + "\\Content\\Sprites\\NPCs\\Overworlds\\" + Path.GetFileName(NPCImageToUse); File.Copy(NPCImageToUse, destination, true); } activeNPCEdit.spriteSheet = Path.GetFileName(NPCImageToUse); GameDraw.UpdateNPCSpritesheets(game.world); } }
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) { } }
/// <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); }