public override void Update(GameTime gameTime, TileMap tileMap, bool HandleInput) { //! TODO: let the move be more "real" if (Target != null && mFollowingTarget) { Position = Target.Center + new Vector2(Target.CollisionRadius + CollisionRadius, 0f); FinalPosition = Target.FinalPosition; CurrentDirection = Target.CurrentDirection; } base.Update(gameTime, tileMap, false); }
private void MenuFileNew_Click(object sender, EventArgs e) { var frm = new frmNewMap(); frm.ShowDialog(); if (frm.OKPressed == false) { return; } mTileMap = new TileMap(frm.txtName.Text, int.Parse(frm.txtWidth.Text), int.Parse(frm.txtHeight.Text)); // clear Project ProjectTree.Nodes.Clear(); mCurrentLayer = -1; mTextureRect = Rectangle.Empty; mPreviewTileset = null; mCursorCell.X = mCursorCell.Y = -1; mLastTilesetIndex.Clear(); mLastAutotileIndex.Clear(); mLastAnimationIndex.Clear(); mLastObjectIndex.Clear(); mUndoQueue.Clear(); mRedoQueue.Clear(); // Add Project Main Map ProjectTree.Nodes.Add(mTileMap.Name); ProjectTree.Nodes[0].ImageIndex = 0; ProjectTree.Nodes[0].SelectedImageIndex = 0; ProjectTree.Nodes[0].Tag = mTileMap.Name; ProjectTree.Nodes[0].ContextMenuStrip = ProjectTreeContext; // Add Collision ProjectTree.Nodes[0].Nodes.Add(COLLISION_LAYER_NAME); ProjectTree.Nodes[0].Nodes[0].ImageIndex = 4; ProjectTree.Nodes[0].Nodes[0].SelectedImageIndex = 4; ProjectTree.Nodes[0].Nodes[0].Tag = COLLISION_LAYER_NAME; // Add first BG & FG AddLayerToTree("Hintergrund Ebene 1", true, 1, true, false, true); AddLayerToTree("Vordergrund Ebene 1", true, 3, true, false, false); ProjectTree.ExpandAll(); // auto-select BG 1 (0=Collision, 1=BG, 2=FG) ProjectTree.SelectedNode = ProjectTree.Nodes[0].Nodes[1]; }
private void LoadMap(string Filename) { ProjectTree.Nodes.Clear(); mTextureRect = Rectangle.Empty; mPreviewTileset = null; mCursorCell.X = mCursorCell.Y = -1; mLastTilesetIndex.Clear(); mLastAutotileIndex.Clear(); mLastAnimationIndex.Clear(); mLastObjectIndex.Clear(); mUndoQueue.Clear(); mRedoQueue.Clear(); var result = TileLoadResult.Success; if (Path.GetExtension(Filename) == ".xnb") { mTileMap = EngineCore.ContentLoader.GetMap(Path.GetFileNameWithoutExtension(Filename)); } else { result = TileMap.Load(Filename, out mTileMap); } if (result != TileLoadResult.Success || mTileMap == null) { // w00t oO mTileMap = new TileMap(); // to avoid <null> Crashes var msg = "Fehler beim öffnen der Map!\n"; switch (result) { case TileLoadResult.NoEntryInArchiv: msg += "Es wurde keine Map Datei in dem .bmap Archiv gefunden!"; break; case TileLoadResult.OldType: msg += "Die Map-Version ist zu alt!\n\nBitte benutze den Converter (Extras)"; break; case TileLoadResult.UnkownError: msg += "Die Ursache ist unbekannt :/\n\nWenn du den Editor im Debug laufen hast, schau bitte in das \nAusgabe fenster und kopiere es in einen Bug Post, danke ^.^"; break; } MessageBox.Show(msg, "Fehler beim öffnen", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // update Version to newst mTileMap.VersionMajor = TileMap.VersionMajorNow; mTileMap.VersionMinor = TileMap.VersionMinorNow; // Load content mTileMap.LoadContent(EngineCore.ContentLoader.XnaContent); mCurrentLayer = -1; // add Main Map ProjectTree.Nodes.Add(BuildMapName()); ProjectTree.Nodes[0].ImageIndex = 0; ProjectTree.Nodes[0].SelectedImageIndex = 0; ProjectTree.Nodes[0].Tag = mTileMap.Name; ProjectTree.Nodes[0].ContextMenuStrip = ProjectTreeContext; // add Collision Layer ProjectTree.Nodes[0].Nodes.Add(COLLISION_LAYER_NAME); ProjectTree.Nodes[0].Nodes[0].ImageIndex = 4; ProjectTree.Nodes[0].Nodes[0].SelectedImageIndex = 4; // add Sub Layer for (var layer = 0; layer < mTileMap.Layers.Count; layer++) { ProjectTree.Nodes[0].Nodes.Add(mTileMap.Layers[layer].Name); ProjectTree.Nodes[0].Nodes[layer + 1].ImageIndex = ProjectTree.Nodes[0].Nodes[layer + 1].SelectedImageIndex = (mTileMap.Layers[layer].IsBackground ? 1 : 3); ProjectTree.Nodes[0].Nodes[layer + 1].Tag = mTileMap.Layers[layer].Name; ProjectTree.Nodes[0].Nodes[layer + 1].ContextMenuStrip = ProjectTreeNodeContext; mLastTilesetIndex.Add(0); mLastAutotileIndex.Add(0); mLastAnimationIndex.Add(0); mLastObjectIndex.Add(0); } ProjectTree.SelectedNode = ProjectTree.Nodes[0].Nodes[1]; ProjectTree.ExpandAll(); }
public static TileLoadResult Load(string filename, out TileMap map) { using (var fileStream = System.IO.File.OpenRead(filename)) return Load(fileStream, out map); }
public static TileLoadResult Load(System.IO.Stream fromStream, out TileMap map) { map = null; try { var xml = new XmlSerializer(typeof(TileMap)); var streams = FastBlubbZip.ExtractBlubbZip(fromStream, ""); if (streams.Count == 0) return TileLoadResult.NoEntryInArchiv; foreach (string key in streams.Keys.Where(key => streams[key] != null && streams[key].Length != 0 && streams[key].CanSeek && streams[key].CanRead)) { streams[key].Seek(0, System.IO.SeekOrigin.Begin); map = xml.Deserialize(streams[key]) as TileMap; streams[key].Dispose(); } if (map.VersionMajor < VersionMajorMin || map.VersionMinor < VersionMinorMin) return TileLoadResult.OldType; map.FixxMap(); } catch (Exception e) { map = null; System.Diagnostics.Debug.WriteLine(e); return TileLoadResult.UnkownError; } return TileLoadResult.Success; }
private bool CanMove( Point2D cell, TileMap tileMap ) { if( cell.Y < 0 || cell.X < 0 || cell.X >= tileMap.Width - 1 || cell.Y >= tileMap.Height - 1 ) return false; cell.Y++; // so we check the "Foot Cell" return ( tileMap.CollisionLayer.GetCell( cell ) & ECollisionType.Moveable ) == ECollisionType.Moveable; }
private void TryMove( EDirection MoveDir, TileMap TileMap ) { Point2D newCell = DrawHelper.Vector2ToEngineCell( mPosition ) + MoveDir.ToPoint2D(); mCurrentDirection = MoveDir; if( EngineCore.InputHelper.IsKeyDown( Microsoft.Xna.Framework.Input.Keys.LeftShift ) == true ) return; // no move, only Dir Change if( CanMove( newCell, TileMap ) == false ) return; if( Character != null ) Character.Move( newCell ); mFinalPosition = DrawHelper.EngineCellToVector( newCell ); }
public virtual void Update( GameTime gameTime, TileMap tileMap, bool HandleInput ) { if( Animations.Count == 0 ) return; if( mFinalPosition == mPosition && HandleInput == true && tileMap != null ) { EDirection move = EDirection.None; if( EngineCore.InputHelper.IsActionPressed( EActions.MoveUp ) ) move = EDirection.Up; if( EngineCore.InputHelper.IsActionPressed( EActions.MoveDown ) ) move = EDirection.Down; if( EngineCore.InputHelper.IsActionPressed( EActions.MoveLeft ) ) move = EDirection.Left; if( EngineCore.InputHelper.IsActionPressed( EActions.MoveRight ) ) move = EDirection.Right; if( move != EDirection.None ) TryMove( move, tileMap ); } UpdatePosition(); UpdateAnimation( gameTime ); }
public static TileLoadResult Load(string filename, out TileMap map) { using (var fileStream = System.IO.File.OpenRead(filename)) return(Load(fileStream, out map)); }
public void Apply(int x, int y, TileMap map) { X = System.Math.Max(System.Math.Min(X + x, map.WidthInPixels), 0); Y = System.Math.Max(System.Math.Min(Y + y, map.HeightInPixels), 0); }
public void Apply(IPoint2D p, TileMap map) { Apply(p.X, p.Y, map); }
public void Apply(Point p, TileMap map) { Apply(p.X, p.Y, map); }
public CompiledTileMapData(TileMap bmap, TileLoadResult res) { CompiledData = bmap; Result = res; }