public Tileset Load(FilePath path) { var tileset = new Tileset(); tileset.FilePath = path; var doc = XDocument.Load(path.Absolute); var reader = doc.Element("Tileset"); if (reader == null) throw new Exception("The specified tileset definition file does not contain a Tileset tag."); var sheetPath = FilePath.FromRelative(reader.Attribute("tilesheet").Value, path.BasePath); tileset.ChangeSheetPath(sheetPath.Absolute); int size; if (!int.TryParse(reader.Attribute("tilesize").Value, out size)) throw new Exception("The tileset definition does not contain a valid tilesize attribute."); tileset.TileSize = size; var propParent = reader.Element("TileProperties"); if (propParent != null) { foreach (XElement propNode in propParent.Elements("Properties")) { var prop = new TileProperties(propNode); tileset.AddProperties(prop); } } foreach (XElement tileNode in reader.Elements("Tile")) { int id = int.Parse(tileNode.Attribute("id").Value); string name = tileNode.Attribute("name").Value; var spriteNode = tileNode.Element("Sprite"); if (spriteNode == null) throw new GameXmlException(tileNode, "All Tile tags must contain a Sprite tag."); var sprite = LoadSprite(spriteNode); var tileSprite = new TileSprite(tileset, sprite); Tile tile = new Tile(id, tileSprite); string propName = "Default"; XAttribute propAttr = tileNode.Attribute("properties"); if (propAttr != null) propName = propAttr.Value; tile.Properties = tileset.GetProperties(propName); tile.Sprite.Play(); tileset.Add(tile); } return tileset; }
public MapSquare(IScreenLayer layer, Tile tile, int x, int y, int tilesize) { this.layer = layer; Tile = tile; X = x; Y = y; screenX = x * tilesize; screenY = y * tilesize; var commonBox = Tile.Sprite.BoundBox; blockBox = new RectangleF(commonBox.X, commonBox.Y, commonBox.Width, commonBox.Height); blockBox.Offset(-Tile.Sprite.HotSpot.X, -Tile.Sprite.HotSpot.Y); }
public override void ChangeTile(Tile tile) { if (_ignoreTileChanged) return; // prevent infinite recursion _ignoreTileChanged = true; var args = new TileBrushSelectedEventArgs() { TileBrush = tile != null ? new SingleTileBrush(tile) : null }; ViewModelMediator.Current.GetEvent<TileBrushSelectedEventArgs>().Raise(this, args); _ignoreTileChanged = false; SelectedBrush = null; OnPropertyChanged("SelectedTile"); OnPropertyChanged("SelectedBrush"); }
public TileButton(Tile tile) { this.Tile = tile; this.Margin = new Padding(2); this.Padding = new Padding(0); this.Text = ""; this.AutoSize = false; if (tile != null) { this.Width = tile.Sprite.Width; this.Height = tile.Sprite.Height; } Program.AnimateTick += new Action(Program_FrameTick); this.MouseEnter += new EventHandler(EnableHover); this.MouseLeave += new EventHandler(DisableHover); }
public SingleTileBrush(Tile tile) { this.tile = tile; }
public TileBrushCell(int x, int y, Tile tile) { this.x = x; this.y = y; this.tile = tile; }
public void AddTile(Tile tile, int x, int y) { TileBrushCell cell = new TileBrushCell {x = x, y = y, tile = tile}; cells[x][y] = cell; CellSize = (int)tile.Width; }
public abstract void ChangeTile(Tile tile);
public override void ChangeTile(Tile tile) { SelectedTile = tile; if (tile != null) Sprite = new SpriteEditorViewModel(tile.Sprite); else Sprite = null; OnPropertyChanged("Sprite"); if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("SelectedTile")); } }
public override void ChangeTile(Tile tile) { // NOP }
public override void ChangeTile(Tile tile) { SelectedTile = tile; if (SelectedTile != null) { ConstructTool(); } else { Tool = null; ToolCursor = null; } if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("SelectedTile")); } }
public SingleTileCursor(Tile tile) { _tile = tile; }
public void RemoveTile(Tile tile) { Tileset.Remove(tile); if (TilesetModified != null) TilesetModified(this, new EventArgs()); }
public override void Start(IGameplayContainer container) { if (Direction == Direction.Unknown) { Direction = Direction.Right; } container.GameAct += Update; pushX = pushY = 0; dragX = dragY = resistX = resistY = 1; if (Parent.Screen != null && position != null) { overTile = Parent.Screen.TileAt(position.Position.X, position.Position.Y); } }
public SingleTileBrush(Tile tile) { this._tile = tile; _cells = new TileBrushCell[][] { new TileBrushCell[] { new TileBrushCell() { tile = _tile, x = 0, y = 0 } } }; }
protected override void Update() { if (!CanMove || Parent.Paused) return; float accelX = (pendingVx - vx) * dragX; vx += accelX; float accelY = (pendingVy - vy) * dragY; vy += accelY; if (!Flying) { float gmult = (overTile != null) ? overTile.Properties.GravityMult : 1; if (Parent.Container.IsGravityFlipped) { vy -= Parent.Container.Gravity * gmult; if (vy < -Const.TerminalVel) vy = -Const.TerminalVel; } else { vy += Parent.Container.Gravity * gmult; if (vy > Const.TerminalVel) vy = Const.TerminalVel; } } if (FlipSprite) { SpriteComponent sprite = Parent.GetComponent<SpriteComponent>(); if (sprite != null) sprite.HorizontalFlip = (Direction == Direction.Left); } Tile nextOverTile = null; if (position != null) { float deltaX = vx + pushX; float deltaY = vy + pushY; PointF pos = position.Position; if (collision == null) { pos.X += deltaX; pos.Y += deltaY; } else { if ((!collision.BlockLeft && deltaX < 0) || (!collision.BlockRight && deltaX > 0)) pos.X += deltaX; if ((!collision.BlockTop && deltaY < 0) || (!collision.BlockBottom && deltaY > 0)) pos.Y += deltaY; } position.SetPosition(pos); nextOverTile = Parent.Screen.TileAt(position.Position.X, position.Position.Y); } if (Parent.Name == "Player") { if (overTile != null && nextOverTile != null && nextOverTile.Properties.Name != overTile.Properties.Name) { if (overTile.Properties.OnLeave != null) EffectParser.GetLateBoundEffect(overTile.Properties.OnLeave)(Parent); if (nextOverTile.Properties.OnEnter != null) EffectParser.GetLateBoundEffect(nextOverTile.Properties.OnEnter)(Parent); } if (nextOverTile != null && nextOverTile.Properties.OnOver != null) { EffectParser.GetLateBoundEffect(nextOverTile.Properties.OnOver)(Parent); } } vx *= resistX; vy *= resistY; resistX = resistY = 1; pendingVx = vx; pendingVy = vy; overTile = nextOverTile; pushX = pushY = 0; dragX = dragY = 1; }
public void AddTile(Tile tile, int x, int y) { TileBrushCell cell = new TileBrushCell { x = x, y = y, tile = tile }; _cells[x][y] = cell; }
private void TileChanged(Tile tile) { this.CurrentBrush = tile == null ? null : new SingleTileBrush(tile); AssembleTool(); }
public virtual void ChangeTile(Tile tile) { _selectedTile = tile; OnPropertyChanged("SelectedTile"); }