public IEnumerable<WorldmapObject> GetObjectsAt(FieldPos Pos)
 {
     List<WorldmapObject> List = ObjectGrid[Pos];
     if(List == null)
         return new List<WorldmapObject> (0);
     return List;
 }
 public uint this[FieldPos Pos]
 {
     get {
         return Field[Pos];
     }
     set {
         Field[Pos] = value;
     }
 }
 private void FloodFillAt(FieldPos pos, int oldId, int newId)
 {
     if (!application.CurrentTilemap.InBounds(pos)) return;
     if (application.CurrentTilemap[pos] != oldId) return;
     application.CurrentTilemap[pos] = newId;
     FloodFillAt ( new FieldPos(pos.X  , pos.Y-1), oldId, newId );
     FloodFillAt ( new FieldPos(pos.X  , pos.Y+1), oldId, newId );
     FloodFillAt ( new FieldPos(pos.X-1, pos.Y  ), oldId, newId );
     FloodFillAt ( new FieldPos(pos.X+1, pos.Y  ), oldId, newId );
 }
Beispiel #4
0
 public T this[FieldPos Pos]
 {
     get
     {
         return(this[Pos.X, Pos.Y]);
     }
     set
     {
         this[Pos.X, Pos.Y] = value;
     }
 }
    public WorldmapLevel(WorldmapSector Sector, List Data)
        : base(Sector)
    {
        string SpriteName = "worldmap/common/leveldot.sprite";
        Properties Props = new Properties(Data);
        Props.Get("name", ref LevelFile);
        FieldPos LevelPos = new FieldPos();
        Props.Get("x", ref LevelPos.X);
        Props.Get("y", ref LevelPos.Y);
        Props.Get("sprite", ref SpriteName);
        Props.PrintUnusedWarnings();

        Sprite = SpriteManager.Create(SpriteName);
        Sprite.Pos = new Vector(LevelPos.X*32 + 16, LevelPos.Y*32 + 16);
    }
Beispiel #6
0
 public bool InBounds(FieldPos pos)
 {
     if (pos.X < 0)
     {
         return(false);
     }
     if (pos.Y < 0)
     {
         return(false);
     }
     if (pos.X >= Width)
     {
         return(false);
     }
     if (pos.Y >= Height)
     {
         return(false);
     }
     return(true);
 }
 public Tile GetTile(FieldPos Pos)
 {
     return Tileset.Get(this[Pos]);
 }
Beispiel #8
0
    /// <summary>
    /// Find the best pattern to use when changing tiles around the given position to one of the stored patterns.
    /// </summary>
    /// <param name="pos">The (center) position at the <paramref name="tilemap"/> to look at.</param>
    /// <param name="tilemap">The tilemap to look at.</param>
    /// <param name="bestPattern">A tileblock that will replace the area.</param>
    /// <returns>
    /// True if <paramref name="bestPattern"/> is different from the calculated
    /// pattern in <paramref name="tilemap"/>, otherwise false.
    /// </returns>
    public bool FindBestPattern(FieldPos pos, Tilemap tilemap, ref TileBlock bestPattern)
    {
        // find upper-left corner of where to apply brush
        int px = pos.X - (int) (width / 2);
        int py = pos.Y - (int) (height / 2);

        return FindBestPattern(px, py, tilemap, ref bestPattern);
    }
Beispiel #9
0
    /// <summary>
    /// Smooths Tilemap by changing tiles around the given position to one of the stored patterns
    /// </summary>
    public void ApplyToTilemap(FieldPos pos, Tilemap tilemap)
    {
        // find upper-left corner of where to apply brush
        int px = pos.X - (width/2);
        int py = pos.Y - (height/2);

        TileBlock bestPattern = null;

        // if we find any usable pattern, we apply it
        if (FindBestPattern(px, py, tilemap, ref bestPattern)) {
            // Only apply to the center
            tilemap[pos] = bestPattern[width/2,height/2];
        }
    }
 public override void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers)
 {
     if ((selection.Width == 1) && (selection.Height == 1) && application.CurrentTilemap.InBounds(TilePos)) {
         Replace(application.CurrentTilemap[TilePos], selection[0,0]);
     }
 }
    private bool UpdateMouseTilePos(Vector MousePos)
    {
        FieldPos NewMouseTilePos = new FieldPos(
                (int) (MousePos.X) / 32,
                (int) (MousePos.Y) / 32);
        if(NewMouseTilePos != MouseTilePos) {
            MouseTilePos = NewMouseTilePos;
            return true;
        }

        return false;
    }
 public override void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers)
 {
     if ((selection.Width == 1) && (selection.Height == 1)) {
         FloodFill(TilePos, selection[0, 0]);
     }
 }
 /// <summary>
 /// Updates the LastPreview if the current mouse position has changed.
 /// </summary>
 private void UpdatePreview()
 {
     if (LastPreviewPos != MouseTilePos) {
         LastPreviewIsChange = brush.FindBestPattern(MouseTilePos, application.CurrentTilemap, ref LastPreview);
         LastPreviewPos = MouseTilePos;
     }
 }
Beispiel #14
0
 public void ApplyToTilemap(FieldPos pos, Tilemap Tilemap, bool skipNull)
 {
     int StartX = Math.Max(0, -pos.X);
     int StartY = Math.Max(0, -pos.Y);
     int W = Math.Min(Tilemap.Width  - pos.X, Width);
     int H = Math.Min(Tilemap.Height - pos.Y, Height);
     for(int y = StartY; y < H; ++y) {
         for(int x = StartX; x < W; ++x) {
             if ((skipNull) && (this[x, y] == 0) && (Width > 1 || Height > 1)) continue;
             Tilemap[ pos.X + x, pos.Y + y ] = this[x, y];
         }
     }
 }
    protected bool UpdateMouseTilePos(Vector MousePos)
    {
        //count position relative to current tilemap
        int XPos = (int) (MousePos.X - application.CurrentTilemap.X);
        int YPos = (int) (MousePos.Y - application.CurrentTilemap.Y);
        FieldPos NewMouseTilePos = new FieldPos(XPos / Tileset.TILE_WIDTH,
                            YPos / Tileset.TILE_HEIGHT);

        if (XPos < 0) NewMouseTilePos.X--;	//Fix for negative X values
        if (YPos < 0) NewMouseTilePos.Y--;	//Fix for negative Y values

        if (NewMouseTilePos != MouseTilePos) {
            MouseTilePos = NewMouseTilePos;
            return true;
        }

        return false;
    }
 public abstract void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers);
 public virtual void PerformActionBetweenPoints(FieldPos p1, FieldPos p2, ModifierType Modifiers)
 {
     // from discussion of Bresenham's line algorithm on Wikipedia, "General Line Drawing Algorithm"
     int x1 = p1.X, y1 = p1.Y,
         x2 = p2.X, y2 = p2.Y,
         dX = Math.Abs(x2 - x1),	dY = Math.Abs(y2 - y1),
         x = x1, y = y1,
         offsetX, offsetY;
     if (x1 > x2) offsetX = -1; else offsetX = 1;
     if (y1 > y2) offsetY = -1; else offsetY = 1;
     PerformActionOnTile(new FieldPos(x,	y), Modifiers);
     if (dX > dY) {
         int error = dX / 2;
         while (x != x2) {
             error -= dY;
             if (error < 0) {
                 y += offsetY;
            		error += dX;
             }
             x += offsetX;
             PerformActionOnTile(new FieldPos(x,	y), Modifiers);
         }
     } else {
         int error = dY / 2;
         while (y != y2) {
             error -= dX;
             if (error < 0) {
                 x += offsetX;
                 error += dY;
             }
             y += offsetY;
             PerformActionOnTile(new FieldPos(x,	y), Modifiers);
         }
     }
 }
    public void OnMouseMotion(Vector mousePos, ModifierType Modifiers)
    {
        if (application.CurrentTilemap == null) return;

        if (UpdateMouseTilePos(mousePos)) {
            if(selection.Width == 0 || selection.Height == 0)
                return;

            if((state == State.DRAWING) &&
               ( (Modifiers & ModifierType.ShiftMask) != 0 ||
                 ((LastDrawPos.X - MouseTilePos.X) % selection.Width == 0 &&
                  (LastDrawPos.Y - MouseTilePos.Y) % selection.Height == 0
                )
               )
              ) {
                PerformActionBetweenPoints(LastDrawPos, MouseTilePos, Modifiers);
            }
            if(state == State.FILLING || state == State.SELECTING)
                UpdateSelection();
            Redraw();
        }

        LastDrawPos = MouseTilePos;
    }
    public void OnMouseButtonPress(Vector mousePos, int button, ModifierType Modifiers)
    {
        if (application.CurrentTilemap == null) return;

        UpdateMouseTilePos(mousePos);
        LastDrawPos = MouseTilePos;

        if(button == 3) {
            if (state == State.DRAWING) {	//both buttons => cancel drawing
                state = State.NONE;
                application.CurrentTilemap.RestoreState(tilemapBackup);
            } else {
                if(MouseTilePos.X < 0 || MouseTilePos.Y < 0
                   || MouseTilePos.X >= application.CurrentTilemap.Width
                   || MouseTilePos.Y >= application.CurrentTilemap.Height)
                    return;

                SelectStartPos = MouseTilePos;
                state = State.SELECTING;
                UpdateSelection();
            }
        } else if(button == 1) {
            if (state == State.DRAWING) {	//both buttons => cancel selection
                state = State.NONE;
                selection.Resize(0, 0, 0);
                selection.FireChangedEvent();
            } else {

                // save backup of Tilemap
                tilemapBackup = application.CurrentTilemap.SaveState();

                if((Modifiers & ModifierType.ShiftMask) != 0) {
                    if(MouseTilePos.X < 0 || MouseTilePos.Y < 0
                       || MouseTilePos.X >= application.CurrentTilemap.Width
                       || MouseTilePos.Y >= application.CurrentTilemap.Height)
                        return;

                    SelectStartPos = MouseTilePos;
                    state = State.FILLING;
                    UpdateSelection();
                } else {
                    PerformActionBetweenPoints(LastDrawPos, MouseTilePos, Modifiers);

                    state = State.DRAWING;
                }
            }
        }
        Redraw();
    }
Beispiel #20
0
 public bool InBounds(FieldPos pos)
 {
     return field.InBounds(pos);
 }
 public override void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers)
 {
     if(application.CurrentTilemap.InBounds(TilePos))
         brush.ApplyToTilemap(TilePos, application.CurrentTilemap);
 }
 public void Spawn(FieldPos TilemapPos)
 {
     this.TilemapPos = TilemapPos;
 }
 private void FloodFill(FieldPos pos, int new_tile)
 {
     if (Tilemap[pos] != new_tile)
         FloodFillAt(pos, Tilemap[pos], new_tile);
 }
 private void FloodFill(FieldPos pos, int new_tile)
 {
     if (application.CurrentTilemap.InBounds(pos) && application.CurrentTilemap[pos] != new_tile)
         FloodFillAt(pos, application.CurrentTilemap[pos], new_tile);
 }
Beispiel #25
0
 public void ApplyToTilemap(FieldPos pos, Tilemap Tilemap)
 {
     ApplyToTilemap(pos, Tilemap, true);
 }
 private void FloodFillAt(FieldPos pos, int oldId, int newId)
 {
     if (!Tilemap.InBounds(pos)) return;
     if (Tilemap[pos] != oldId) return;
     Tilemap[pos] = newId;
     FloodFillAt(pos.Up, oldId, newId);
     FloodFillAt(pos.Down, oldId, newId);
     FloodFillAt(pos.Left, oldId, newId);
     FloodFillAt(pos.Right, oldId, newId);
 }
Beispiel #27
0
 public int this[FieldPos pos]
 {
     get {
         return (InBounds(pos)) ? field[pos] : 0;
     }
     set {
         if(InBounds(pos))
             field[pos] = value;
     }
 }
 public override void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers)
 {
     selection.ApplyToTilemap(TilePos, application.CurrentTilemap, ((Modifiers & ModifierType.ControlMask) == 0));
 }