Esempio n. 1
0
        private void LoadMapAndTransition(string newMapFile, bool transition, SpawnArgs?spawnArgs = null)
        {
            Map newMap = Map.Load(AppDomain.CurrentDomain.BaseDirectory + newMapFile);

            WorldState newState =
                spawnArgs.HasValue ? new WorldState(newMap, spawnArgs.Value, transition) :
                new WorldState(newMap, new SpawnArgs(new Point(-1, -1), Direction.Down, Player), transition);

            if (transition)
            {
                _transition.TweenTo(1, TweenEaseType.Linear, 0.4);
                Coroutine.AddExisting(WaitForTransition(newState));
            }
            else
            {
                Game.CurrentState = newState;
            }
        }
Esempio n. 2
0
        private IEnumerator <ICoroutineOperation> RevealAndAnimate(int x, int y, bool updateInteract = true)
        {
            if (updateInteract)
            {
                _canInteract = false;
            }

            bool wasRevealed = Field.IsRevealed(x, y);

            Field.SetRevealed(x, y, true);

            if (!wasRevealed && Field.SurroundingNukesAt(x, y) == 0)
            {
                for (int rX = x - 1; rX <= x + 1; rX++)
                {
                    for (int rY = y - 1; rY <= y + 1; rY++)
                    {
                        if (!(rX == x && rY == y) &&
                            rX >= 0 &&
                            rY >= 0 &&
                            rX < Field.Width &&
                            rY < Field.Height &&
                            !Field[rX, rY] &&
                            !Field.IsRevealed(rX, rY))
                        {
                            Coroutine.AddExisting(RevealAndAnimate(rX, rY, false));
                            yield return(Wait.Seconds(Game, 0.03));
                        }
                    }
                }
            }

            if (updateInteract)
            {
                _canInteract = true;
            }
        }
Esempio n. 3
0
        public override void Update(double deltaTime, double totalTime, long count)
        {
            Camera.UpdatePosition(Input, LastInput);

            Vector2 viewport = new Vector2(Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Height) / (float)Game.Scale;

            if (_canInteract && !Camera.IsMoving && !Camera.JustDidPan && !Camera.JustDidZoom && LastInput.Count > 0 && Input.Count == 0)
            {
                foreach (TouchLocation location in LastInput)
                {
                    bool  setMenuTile = false;
                    Point zeroPoint   = Vector2.Transform(Vector2.Zero, Camera.Transform).ToPoint();

                    Rectangle menuRect = new Rectangle(
                        Vector2.Transform(new Vector2(MenuTile.X * (TILE_SIZE + 2), MenuTile.Y * (TILE_SIZE + 2)), Camera.TransformWithoutScale).ToPoint(),
                        new Point((int)(((TILE_SIZE + 2) * 2 + TILE_SIZE) * Camera.Zoom), (int)(TILE_SIZE * Camera.Zoom)));

                    if (menuRect.Right >= viewport.X)
                    {
                        menuRect.X -= (int)((TILE_SIZE + 2) * 2 * Camera.Zoom);
                    }

                    if (menuRect.Contains(location.Position))
                    {
                        bool explodePressed    = location.Position.X < menuRect.X + (int)(TILE_SIZE * Camera.Zoom);
                        bool flagPressed       = location.Position.X >= menuRect.X + (int)(TILE_SIZE * Camera.Zoom) && location.Position.X < menuRect.X + (int)(TILE_SIZE * Camera.Zoom) * 2;
                        bool flagvisualPressed = location.Position.X >= menuRect.X + (int)(TILE_SIZE * Camera.Zoom) * 2;

                        if (explodePressed && Field.FlagAt(MenuTile.X, MenuTile.Y) != FlagType.Flag)
                        {
                            bool anyRevealed = false;
                            int  x, y;
                            for (x = 0; x < Field.Width; x++)
                            {
                                for (y = 0; y < Field.Height; y++)
                                {
                                    if (Field.IsRevealed(x, y))
                                    {
                                        anyRevealed = true;
                                        break;
                                    }
                                }
                            }

                            if (!anyRevealed)
                            {
                                Field[MenuTile.X, MenuTile.Y] = false;
                            }

                            Coroutine.Start(OnExplodePressed);
                            Coroutine.AddExisting(RevealAndAnimate(MenuTile.X, MenuTile.Y));

                            MenuTile = new Point(-1, -1);
                        }

                        if (flagPressed)
                        {
                            if (Field.FlagAt(MenuTile.X, MenuTile.Y) != FlagType.Flag && Field.FlagsLeft > 0)
                            {
                                Field.SetFlagAt(MenuTile.X, MenuTile.Y, FlagType.Flag);
                                MenuTile = new Point(-1, -1);
                            }
                            else if (Field.FlagAt(MenuTile.X, MenuTile.Y) == FlagType.Flag)
                            {
                                Field.SetFlagAt(MenuTile.X, MenuTile.Y, FlagType.None);
                                MenuTile = new Point(-1, -1);
                            }
                        }

                        if (flagvisualPressed)
                        {
                            Field.SetFlagAt(MenuTile.X, MenuTile.Y,
                                            Field.FlagAt(MenuTile.X, MenuTile.Y) == FlagType.FlagVisual ? FlagType.None : FlagType.FlagVisual);

                            MenuTile = new Point(-1, -1);
                        }
                    }
                    else
                    {
                        int x, y;
                        for (x = 0; x < Field.Width; x++)
                        {
                            for (y = 0; y < Field.Height; y++)
                            {
                                Rectangle area = new Rectangle(
                                    Vector2.Transform(new Vector2(x * (TILE_SIZE + 2), y * (TILE_SIZE + 2)), Camera.TransformWithoutScale).ToPoint(),
                                    new Point((int)(TILE_SIZE * Camera.Zoom), (int)(TILE_SIZE * Camera.Zoom)));

                                if (area.Contains(location.Position) && !Field.IsRevealed(x, y))
                                {
                                    MenuTile    = new Point(x, y);
                                    setMenuTile = true;
                                }
                            }
                        }

                        if (!setMenuTile)
                        {
                            MenuTile = new Point(-1, -1);
                        }
                    }
                }
            }
        }