public IEnumerable<WorldmapObject> GetObjectsAt(FieldPos Pos)
 {
     List<WorldmapObject> List = ObjectGrid[Pos];
     if(List == null)
         return new List<WorldmapObject> (0);
     return List;
 }
Пример #2
0
 public uint this[FieldPos Pos]
 {
     get {
         return Field[Pos];
     }
     set {
         Field[Pos] = value;
     }
 }
Пример #3
0
 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 );
 }
Пример #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);
    }
Пример #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);
 }
Пример #7
0
 public Tile GetTile(FieldPos Pos)
 {
     return Tileset.Get(this[Pos]);
 }
Пример #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);
    }
Пример #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];
        }
    }
Пример #10
0
 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]);
     }
 }
Пример #11
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;
    }
Пример #12
0
 public override void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers)
 {
     if ((selection.Width == 1) && (selection.Height == 1)) {
         FloodFill(TilePos, selection[0, 0]);
     }
 }
Пример #13
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;
     }
 }
Пример #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];
         }
     }
 }
Пример #15
0
    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;
    }
Пример #16
0
 public abstract void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers);
Пример #17
0
 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);
         }
     }
 }
Пример #18
0
    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;
    }
Пример #19
0
    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();
    }
Пример #20
0
 public bool InBounds(FieldPos pos)
 {
     return field.InBounds(pos);
 }
Пример #21
0
 public override void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers)
 {
     if(application.CurrentTilemap.InBounds(TilePos))
         brush.ApplyToTilemap(TilePos, application.CurrentTilemap);
 }
Пример #22
0
 public void Spawn(FieldPos TilemapPos)
 {
     this.TilemapPos = TilemapPos;
 }
Пример #23
0
 private void FloodFill(FieldPos pos, int new_tile)
 {
     if (Tilemap[pos] != new_tile)
         FloodFillAt(pos, Tilemap[pos], new_tile);
 }
Пример #24
0
 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);
 }
Пример #25
0
 public void ApplyToTilemap(FieldPos pos, Tilemap Tilemap)
 {
     ApplyToTilemap(pos, Tilemap, true);
 }
Пример #26
0
 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);
 }
Пример #27
0
 public int this[FieldPos pos]
 {
     get {
         return (InBounds(pos)) ? field[pos] : 0;
     }
     set {
         if(InBounds(pos))
             field[pos] = value;
     }
 }
Пример #28
0
 public override void PerformActionOnTile(FieldPos TilePos, ModifierType Modifiers)
 {
     selection.ApplyToTilemap(TilePos, application.CurrentTilemap, ((Modifiers & ModifierType.ControlMask) == 0));
 }