Пример #1
0
 //updates the connected doors
 public void updateConnectedDoors(DoorDirections n, DoorDirections s, DoorDirections e, DoorDirections w)
 {
     _connectedDoors.hasNorth = _openDoors.hasNorth && n != null && n.hasSouth;
     _connectedDoors.hasSouth = _openDoors.hasSouth && s != null && s.hasNorth;
     _connectedDoors.hasEast  = _openDoors.hasEast && e != null && e.hasWest;
     _connectedDoors.hasWest  = _openDoors.hasWest && w != null && w.hasEast;
 }
Пример #2
0
 //add a shift to the queue
 public void queueShift(int index, ShiftDirection dir, DoorDirections tileDoors, bool pritority)
 {
     if (pritority)
     {
         _shiftQueue.AddFirst(new MapShift(index, dir, tileDoors));
     }
     else
     {
         _shiftQueue.AddLast(new MapShift(index, dir, tileDoors));
     }
 }
Пример #3
0
        public MapTile(Vector2 startingPosition, DoorDirections openDoors, bool visible)
            : base(startingPosition)
        {
            _openDoors = openDoors;

            _connectedDoors = new DoorDirections(false, false, false, false);

            _sprite = new StaticSprite(MapTileUtilities.appearanceStringFromDoorConfiguration(openDoors), TileSideLength, DrawLayers.GameElements.TileGround);

            _body          = new Body(Program.Objects.PhysicsWorld);
            _body.Position = startingPosition;
            _body.BodyType = BodyType.Kinematic;
            _body.UserData = this;

            MapTileUtilities.AttachFixtures(_body, _openDoors);

            _isVisible = visible;
        }
Пример #4
0
 public static StaticSprite getShiftSprite(DoorDirections d, bool visible)
 {
     if (!visible)
     {
         return(_ShiftSprites[3]);
     }
     if (d.Type == ComboType.TRIPLE)
     {
         return(_ShiftSprites[0]);
     }
     else if (d.Type == ComboType.STRAIGHT)
     {
         return(_ShiftSprites[1]);
     }
     else if (d.Type == ComboType.BENT)
     {
         return(_ShiftSprites[2]);
     }
     return(null);
 }
Пример #5
0
        public static String appearanceStringFromDoorConfiguration(DoorDirections config)
        {
            String baseName = "TileAppearance/TileAppearance_";

            if (config.Type == ComboType.TRIPLE)
            {
                return(baseName + "Triple");
            }
            else if (config.Type == ComboType.STRAIGHT)
            {
                return(baseName + "Straight");
            }
            else if (config.Type == ComboType.BENT)
            {
                return(baseName + "Bent");
            }
            else
            {
                return(null);
            }
        }
Пример #6
0
        //attaches the physics fixtures to the map tile
        public static void AttachFixtures(Body b, DoorDirections doors)
        {
            const float wallWidth    = MapTile.TileSideLength * MapTile.TileWallPercent;
            const float doorWidth    = MapTile.TileSideLength * MapTile.TileDoorPercent;
            const float halfSide     = MapTile.TileSideLength / 2.0f;
            const float sideSegWidth = (MapTile.TileSideLength - doorWidth) / 2.0f;

            if (doors.Type == ComboType.TRIPLE)
            {
                FixtureFactory.AttachRectangle(wallWidth, MapTile.TileSideLength, 1, new Vector2(-halfSide + wallWidth / 2.0f, 0), b);                        //left all
                FixtureFactory.AttachRectangle(sideSegWidth, wallWidth, 1, new Vector2(-(sideSegWidth + doorWidth) / 2.0f, -halfSide + wallWidth / 2.0f), b); //top left
                FixtureFactory.AttachRectangle(sideSegWidth, wallWidth, 1, new Vector2((sideSegWidth + doorWidth) / 2.0f, -halfSide + wallWidth / 2.0f), b);  //top right
                FixtureFactory.AttachRectangle(sideSegWidth, wallWidth, 1, new Vector2(-(sideSegWidth + doorWidth) / 2.0f, halfSide - wallWidth / 2.0f), b);  //bottom left
                FixtureFactory.AttachRectangle(sideSegWidth, wallWidth, 1, new Vector2((sideSegWidth + doorWidth) / 2.0f, halfSide - wallWidth / 2.0f), b);   //bottom right
                FixtureFactory.AttachRectangle(wallWidth, sideSegWidth, 1, new Vector2(halfSide - wallWidth / 2.0f, -(sideSegWidth + doorWidth) / 2.0f), b);  //right top
                FixtureFactory.AttachRectangle(wallWidth, sideSegWidth, 1, new Vector2(halfSide - wallWidth / 2.0f, (sideSegWidth + doorWidth) / 2.0f), b);   //right bottom
            }
            else if (doors.Type == ComboType.STRAIGHT)
            {
                FixtureFactory.AttachRectangle(wallWidth, MapTile.TileSideLength, 1, new Vector2(-halfSide + wallWidth / 2.0f, 0), b);                        //left all
                FixtureFactory.AttachRectangle(wallWidth, MapTile.TileSideLength, 1, new Vector2(halfSide - wallWidth / 2.0f, 0), b);                         //right all
                FixtureFactory.AttachRectangle(sideSegWidth, wallWidth, 1, new Vector2(-(sideSegWidth + doorWidth) / 2.0f, -halfSide + wallWidth / 2.0f), b); //top left
                FixtureFactory.AttachRectangle(sideSegWidth, wallWidth, 1, new Vector2((sideSegWidth + doorWidth) / 2.0f, -halfSide + wallWidth / 2.0f), b);  //top right
                FixtureFactory.AttachRectangle(sideSegWidth, wallWidth, 1, new Vector2(-(sideSegWidth + doorWidth) / 2.0f, halfSide - wallWidth / 2.0f), b);  //bottom left
                FixtureFactory.AttachRectangle(sideSegWidth, wallWidth, 1, new Vector2((sideSegWidth + doorWidth) / 2.0f, halfSide - wallWidth / 2.0f), b);   //bottom right
            }
            else
            {
                //bent
                FixtureFactory.AttachRectangle(wallWidth, MapTile.TileSideLength, 1, new Vector2(-halfSide + wallWidth / 2.0f, 0), b);                        //left all
                FixtureFactory.AttachRectangle(MapTile.TileSideLength, wallWidth, 1, new Vector2(0, halfSide - wallWidth / 2.0f), b);                         //bottom all
                FixtureFactory.AttachRectangle(sideSegWidth, wallWidth, 1, new Vector2(-(sideSegWidth + doorWidth) / 2.0f, -halfSide + wallWidth / 2.0f), b); //top left
                FixtureFactory.AttachRectangle(sideSegWidth, wallWidth, 1, new Vector2((sideSegWidth + doorWidth) / 2.0f, -halfSide + wallWidth / 2.0f), b);  //top right
                FixtureFactory.AttachRectangle(wallWidth, sideSegWidth, 1, new Vector2(halfSide - wallWidth / 2.0f, -(sideSegWidth + doorWidth) / 2.0f), b);  //right top
                FixtureFactory.AttachRectangle(wallWidth, sideSegWidth, 1, new Vector2(halfSide - wallWidth / 2.0f, (sideSegWidth + doorWidth) / 2.0f), b);   //right bottom
            }

            //rotate the tile
            b.Rotation = doors.tileRotation();
        }
Пример #7
0
 public static StaticSprite getOverlay(DoorDirections d)
 {
     if (d.Type == ComboType.TRIPLE)
     {
         return(_OverlaySprites[0]);
     }
     else if (d.Type == ComboType.STRAIGHT)
     {
         return(_OverlaySprites[1]);
     }
     else if (d.Type == ComboType.BENT)
     {
         return(_OverlaySprites[2]);
     }
     else if (d.Type == ComboType.SINGLE)
     {
         return(_OverlaySprites[3]);
     }
     else if (d.Type == ComboType.NONE)
     {
         return(null);
     }
     return(null);
 }
Пример #8
0
        public static DoorDirections RandomDoors()
        {
            int combo = randomDirection();

            //Prevent single doors
            while (combo == 1 || combo == 2 || combo == 4 || combo == 8)
            {
                combo = randomDirection();
            }

            bool north = (combo & 1) != 0;
            bool south = (combo & 2) != 0;
            bool east  = (combo & 4) != 0;
            bool west  = (combo & 8) != 0;

            DoorDirections newDirections = new DoorDirections(north, south, east, west);

            if (newDirections.NumberOfDoors < 2 || newDirections.NumberOfDoors > 3)
            {
                throw new Exception("Incorrect number of doors (" + newDirections.NumberOfDoors + ") returned by DoorDirections.RandomDoors()! ");
            }

            return(newDirections);
        }
Пример #9
0
        //Make the tiles
        public void StartNewGame(int gridDimension)
        {
            _gridDimension = gridDimension;

            _edgeOfMapdimesion = _gridDimension * MapTile.TileSideLength;

            _tiles = new MapTile[_gridDimension, _gridDimension];

            for (int y = 0; y < _gridDimension; y++)
            {
                for (int x = 0; x < _gridDimension; x++)
                {
                    _tiles[x, y] = new MapTile(MapTile.WorldPositionForGridCoordinates(x, y), DoorDirections.RandomDoors(), false);
                }
            }
            //initially set the overlays
            UpdateOverlays();
        }
Пример #10
0
 public MapShift(int index, ShiftDirection dir, DoorDirections newDoors)
 {
     _index    = index;
     _dir      = dir;
     _newDoors = newDoors;
 }
Пример #11
0
        //shift the row/col of tiles
        private void shiftTiles(int index, ShiftDirection dir, DoorDirections newTileDoors)
        {
            if (_isShifting)
            {
                //should never happen with the queueing now in place, but still check it to be safe
                return;
            }

            //check if the index is valid
            if (index < 0 || index >= _gridDimension)
            {
                throw new Exception("Invalid grid index passed to shiftTiles()");
            }

            //set current shift direction
            _currShiftDir   = dir;
            _currShiftIndex = index;

            Program.Objects.MainCamera.shake();

            //spawn extra enemies
            Program.Objects.EnemyDirector.OnShift();

            bool isPositiveShift = (dir == ShiftDirection.RIGHT || dir == ShiftDirection.DOWN);

            int shiftStart = isPositiveShift ? _gridDimension - 1 : 0;
            int shiftEnd   = isPositiveShift ? 0 : _gridDimension - 1;
            int shiftInc   = isPositiveShift ? -1 : 1;

            if (dir == ShiftDirection.LEFT || dir == ShiftDirection.RIGHT)
            {
                //Set all the tiles to start moving
                for (int x = 0; x < _gridDimension; x++)
                {
                    shiftTile(x, index, x - shiftInc, index);
                }

                //store the tile that is getting shifted out
                _shiftedOutTile = _tiles[shiftStart, index];

                //shift the tiles in our array to represent the new arrangement
                for (int x = shiftStart; x != shiftEnd; x += shiftInc)
                {
                    _tiles[x, index] = _tiles[x + shiftInc, index];
                }

                //set the location of the tile that was pushed in a move it into place
                //TODO: don't reassign this. pass it in.
                MapTile pushingTile = new MapTile(MapTile.WorldPositionForGridCoordinates(shiftEnd + shiftInc, index), newTileDoors, false);
                _tiles[shiftEnd, index] = pushingTile;
                shiftTile(pushingTile, shiftEnd, index);
            }
            else   //UP or DOWN
                   //Set all the tiles to start moving
            {
                for (int y = 0; y < _gridDimension; y++)
                {
                    shiftTile(index, y, index, y - shiftInc);
                }

                //store the tile that is getting shifted out
                _shiftedOutTile = _tiles[index, shiftStart];

                //shift the tiles in our array to represent the new arrangement
                for (int y = shiftStart; y != shiftEnd; y += shiftInc)
                {
                    _tiles[index, y] = _tiles[index, y + shiftInc];
                }

                //set the location of the tile that was pushed in a move it into place
                //TODO: don't reassign this. pass it in.
                MapTile pushingTile = new MapTile(MapTile.WorldPositionForGridCoordinates(index, shiftEnd + shiftInc), newTileDoors, false);
                _tiles[index, shiftEnd] = pushingTile;
                shiftTile(pushingTile, index, shiftEnd);
            }

            _shiftedOutTile.flagForDestruction(tileFinishedShifting);

            //update the overlays
            UpdateOverlays();

            _isShifting = true;
        }
Пример #12
0
 public void enqueueShift(UIButton button)
 {
     if (_pressedButton != null)
     {
         Program.Objects.Map.queueShift(_pressedButton.Index, _pressedButton.Direction, DoorDirections.RandomDoors(), false);
         _pressedButton.reset();
         _pressedButton = null;
     }
 }