Beispiel #1
0
        //--------------------------------------------------------------------------------------------------------------------
        // - Spawn Actor Onto Map
        //--------------------------------------------------------------------------------------------------------------------
        public bool Join(Actor actor, int x, int y)
        {
            // Cannot join an occupied space
            if (!Occupied(x, y))
            {
                ObjectBuffer.Add(actor);
                actor.Environment = this;
                actor.Position    = new Vector3f(x, y, Height(x, y));
            }

            return(false);
        }
Beispiel #2
0
        //--------------------------------------------------------------------------------------------------------------------
        // - Place Tile At [X,Y]
        //--------------------------------------------------------------------------------------------------------------------
        // Places a tile on top of the top-most tile already located ay (X, Y), if one is present
        //--------------------------------------------------------------------------------------------------------------------
        public bool Place(Tile tile, int x, int y)
        {
            // Confirm the requested position is within the bounds of the map
            if (x >= 0 && x < Width && y >= 0 && y < Length)
            {
                float z = 0;

                // Find the top-most tile at [X, Y] ...
                if (Tiles[x, y].Any())
                {
                    Tile top = Tiles[x, y].Last();

                    // Set the incoming tile's Z-coodinate to the Z + Height of the top-most tile
                    z = top.Position.Z + top.Height();

                    // Acquire the top-most tile's occupant, if present, which should be an non-tile; then, set the top-most
                    // tile's occupant to this new tile
                    tile.Occupant = top.Occupant;
                    top.Occupant  = tile;

                    // If this tile did gain an occupant, raise it's Z-coordinate appropriately
                    if (tile.Occupant != null)
                    {
                        tile.Occupant.Position = new Vector3f(tile.Occupant.Position.X, tile.Occupant.Position.Y, tile.Occupant.Position.Z + tile.Height());
                    }
                }

                tile.Position = new Vector3f(x, y, z);
                Tiles[x, y].Add(tile);
                ObjectBuffer.Add(tile);

                // Report a successful placement
                return(true);
            }
            return(false);
        }