コード例 #1
0
ファイル: Level.cs プロジェクト: BasicLich/MizJam1-5
        private void OpenDialog(Point cellClicked, Point screenPosition)
        {
            game.GameState = MizJam1Game.GameStates.OpenDialog;
            dialog         = new UIMenu(screenPosition, new Point(500, 500), true)
            {
                SpaceBetweenChildren = 5,
                Vertical             = true
            };
            Unit enemy;

            bool attackDirectly = false;

            if ((enemy = GetUnit(cellClicked)) != null && enemy.Enemy)
            {
                UIImage              attack               = new UIImage(game.Dialogs[MizJam1Game.Actions.Attack], game.SelectedDialogs[MizJam1Game.Actions.Attack]);
                Point                moveTarget           = threatenedPositions[cellClicked].From;
                MoveUnitCommand      moveUnit             = new MoveUnitCommand(this, SelectedUnit.Position, moveTarget);
                MoveAndAttackCommand moveAndAttackCommand = new MoveAndAttackCommand(moveUnit, this, SelectedUnit, enemy);
                attack.AddCommand(moveAndAttackCommand);
                dialog.AddChild(attack);
                attackDirectly = true;
            }

            if (!attackDirectly)
            {
                foreach (var threat in threatenedPositions)
                {
                    if ((enemy = GetUnit(threat.Key)) != null && enemy.Enemy)
                    {
                        UIImage             attackSelect        = new UIImage(game.Dialogs[MizJam1Game.Actions.Attack], game.SelectedDialogs[MizJam1Game.Actions.Attack]);
                        SelectAttackCommand selectAttackCommand = new SelectAttackCommand(this);
                        attackSelect.AddCommand(selectAttackCommand);
                        dialog.AddChild(attackSelect);
                        break;
                    }
                }
            }

            if (cellClicked == SelectedUnit.Position)
            {
                UIImage       defend        = new UIImage(game.Dialogs[MizJam1Game.Actions.Defend], game.SelectedDialogs[MizJam1Game.Actions.Defend]);
                DefendCommand defendCommand = new DefendCommand(this, SelectedUnit.Position);
                defend.AddCommand(defendCommand);
                dialog.AddChild(defend);
            }
            MoveUnitCommand moveCommand = null;

            if (canGoPositions.Contains(cellClicked))
            {
                UIImage move = new UIImage(game.Dialogs[MizJam1Game.Actions.Move], game.SelectedDialogs[MizJam1Game.Actions.Move]);
                moveCommand = new MoveUnitCommand(this, SelectedUnit.Position, cellClicked);
                move.AddCommand(moveCommand);
                dialog.AddChild(move);
                canGoPositions = new HashSet <Point>()
                {
                    cellClicked
                };
            }

            if (!attackDirectly)
            {
                UIImage reroll = new UIImage(game.Dialogs[MizJam1Game.Actions.Reroll], game.SelectedDialogs[MizJam1Game.Actions.Reroll]);
                if (moveCommand == null)
                {
                    moveCommand = new MoveUnitCommand(this, SelectedUnit.Position, SelectedUnit.Position);
                }
                ICommand rerollCommand = new MoveAndRerollCommand(moveCommand, this, SelectedUnit);
                reroll.AddCommand(rerollCommand);
                dialog.AddChild(reroll);
            }

            if (cellClicked == SelectedUnit.Position)
            {
                UIImage     wait        = new UIImage(game.Dialogs[MizJam1Game.Actions.Wait], game.SelectedDialogs[MizJam1Game.Actions.Wait]);
                WaitCommand waitCommand = new WaitCommand(this, cellClicked);
                wait.AddCommand(waitCommand);
                dialog.AddChild(wait);
            }

            UIImage  cancel        = new UIImage(game.Dialogs[MizJam1Game.Actions.Cancel], game.SelectedDialogs[MizJam1Game.Actions.Cancel]);
            ICommand cancelCommand = new CancelCommand(this);

            cancel.AddCommand(cancelCommand);
            dialog.AddChild(cancel);

            dialog.SetScale(3);

            if (dialog.Position.X + dialog.Size.X > 1500)
            {
                dialog.Position = new Point(screenPosition.X - dialog.Size.X, dialog.Position.Y);
            }
            if (dialog.Position.Y + dialog.Size.Y > 1080)
            {
                dialog.Position = new Point(dialog.Position.X, screenPosition.Y - dialog.Size.Y);
            }
        }
コード例 #2
0
ファイル: MizJam1Game.cs プロジェクト: BasicLich/MizJam1-5
        protected override void LoadContent()
        {
            mapSpriteBatch    = new SpriteBatch(GraphicsDevice);
            screenSpriteBatch = new SpriteBatch(GraphicsDevice);

            mizjamHugeFont              = Content.Load <SpriteFont>("Fonts/mizjam48");
            mizjamBigFont               = Content.Load <SpriteFont>("Fonts/mizjam36");
            mizjamSmallFont             = Content.Load <SpriteFont>("Fonts/mizjam24");
            mizjamSmallFont.LineSpacing = mizjamSmallFont.LineSpacing + 5;
            whitePixel                      = Content.Load <Texture2D>("whitePixel");
            Textures[0]                     = Content.Load <Texture2D>("colored_packed");
            Textures[1]                     = Content.Load <Texture2D>("colored_transparent_packed");
            Textures[2]                     = Content.Load <Texture2D>("monochrome_packed");
            Textures[3]                     = Content.Load <Texture2D>("monochrome_transparent_packed");
            windowBorder                    = Content.Load <Texture2D>("Textures/WindowBorder");
            Dialogs[Actions.Move]           = Content.Load <Texture2D>("Textures/Dialogs/MoveDialog");
            Dialogs[Actions.Attack]         = Content.Load <Texture2D>("Textures/Dialogs/AttackDialog");
            Dialogs[Actions.Defend]         = Content.Load <Texture2D>("Textures/Dialogs/DefendDialog");
            Dialogs[Actions.Heal]           = Content.Load <Texture2D>("Textures/Dialogs/HealDialog");
            Dialogs[Actions.Reroll]         = Content.Load <Texture2D>("Textures/Dialogs/RerollDialog");
            Dialogs[Actions.Wait]           = Content.Load <Texture2D>("Textures/Dialogs/WaitDialog");
            Dialogs[Actions.Cancel]         = Content.Load <Texture2D>("Textures/Dialogs/CancelDialog");
            SelectedDialogs[Actions.Move]   = Content.Load <Texture2D>("Textures/Dialogs/MoveSelectedDialog");
            SelectedDialogs[Actions.Attack] = Content.Load <Texture2D>("Textures/Dialogs/AttackSelectedDialog");
            SelectedDialogs[Actions.Defend] = Content.Load <Texture2D>("Textures/Dialogs/DefendSelectedDialog");
            SelectedDialogs[Actions.Heal]   = Content.Load <Texture2D>("Textures/Dialogs/HealSelectedDialog");
            SelectedDialogs[Actions.Reroll] = Content.Load <Texture2D>("Textures/Dialogs/RerollSelectedDialog");
            SelectedDialogs[Actions.Wait]   = Content.Load <Texture2D>("Textures/Dialogs/WaitSelectedDialog");
            SelectedDialogs[Actions.Cancel] = Content.Load <Texture2D>("Textures/Dialogs/CancelSelectedDialog");
            TransparentTileSelect           = Content.Load <Texture2D>("Textures/TransparentTileSelect");
            SelectedUnitBorder              = Content.Load <Texture2D>("Textures/SelectedUnitBorder");
            statSlider                      = Content.Load <Texture2D>("Textures/Slider");
            statSliderPin                   = Content.Load <Texture2D>("Textures/SliderPin");
            Dice       = Content.Load <Texture2D>("Textures/Dice");
            RedDice    = Content.Load <Texture2D>("Textures/SolidRedDice");
            BlueDice   = Content.Load <Texture2D>("Textures/SolidBlueDice");
            YellowDice = Content.Load <Texture2D>("Textures/SolidYellowDice");
            LevelStart = Content.Load <Texture2D>("Textures/LevelStartBanner");
            LevelWon   = Content.Load <Texture2D>("Textures/LevelWonBanner");
            LevelLost  = Content.Load <Texture2D>("Textures/LevelLostBanner");
            YourTurn   = Content.Load <Texture2D>("Textures/YourTurnBanner");
            TheirTurn  = Content.Load <Texture2D>("Textures/TheirTurnBanner");
            GameOver   = Content.Load <Texture2D>("Textures/GameOverBanner");
            Congrats   = Content.Load <Texture2D>("Textures/CongratulationsBanner");
            AudioManager.Instance.AddSoundEffect("DiceShake", Content.Load <SoundEffect>("Audio/dieShuffle2"));
            AudioManager.Instance.AddSoundEffect("DiceThrow", Content.Load <SoundEffect>("Audio/diceThrow3"));
            AudioManager.Instance.AddSoundEffect("Hit", Content.Load <SoundEffect>("Audio/footstep_snow_000"));
            AudioManager.Instance.AddSoundEffect("MenuClick", Content.Load <SoundEffect>("Audio/back_003"));
            AudioManager.Instance.AddSoundEffect("Defend", Content.Load <SoundEffect>("Audio/impactMining_003"));
            AudioManager.Instance.AddSoundEffect("Miss", Content.Load <SoundEffect>("Audio/footstep_carpet_001"));
            AudioManager.Instance.AddSoundEffect("Walk", Content.Load <SoundEffect>("Audio/footstep_snow_001"));
            AudioManager.Instance.AddSoundEffect("Death", Content.Load <SoundEffect>("Audio/select_006"));
            AudioManager.Instance.AddSong("Song", Content.Load <Song>("Audio/2019-12-09_-_Retro_Forest_-_David_Fesliyan"));

            string[] levelFiles = Directory.GetFiles("Content/Levels");
            levels = new Level[levelFiles.Length];
            for (int i = 0; i < levelFiles.Length; i++)
            {
                XDocument levelDoc = XDocument.Parse(File.ReadAllText(levelFiles[i]));
                levels[i] = new Level(levelDoc, this);
            }
            currentLevel = levels[0];
            camera       = new Camera(1080, 1080, currentLevel.Width, currentLevel.Height);

            mainMenu = new UIContainer(Point.Zero, new Point(1920, 1080), true);
            UIMenu menu = new UIMenu(Point.Zero, new Point(1000, 600), true)
            {
                Vertical             = true,
                SpaceBetweenChildren = 50
            };
            UILabel startGame = new UILabel("START GAME", mizjamBigFont, Global.Colors.Main1)
            {
                SelectedTextColor = Global.Colors.Accent1
            };

            startGame.AddCommand(new StartGameCommand(this));
            UILabel restartLevel = new UILabel("RESTART LEVEL", mizjamBigFont, Global.Colors.Main1)
            {
                SelectedTextColor = Global.Colors.Accent1
            };

            restartLevel.AddCommand(new RestartLevelCommand(this));

            /*
             * UILabel options = new UILabel("OPTIONS", mizjamBigFont, Global.Colors.Main1) { SelectedTextColor = Global.Colors.Accent1 };
             * options.AddCommand(new OpenOptionsCommand(this));
             */
            UILabel exitGame = new UILabel("EXIT GAME", mizjamBigFont, Global.Colors.Main1)
            {
                SelectedTextColor = Global.Colors.Accent1
            };

            exitGame.AddCommand(new ExitGameCommand(this));

            menu.AddChild(startGame);
            menu.AddChild(restartLevel);
            //menu.AddChild(options);
            menu.AddChild(exitGame);

            mainMenu.AddChild(menu);

            string message = "MADE BY TOURMI\nFOR MIZ GAME JAM 1\nAUDIO ASSETS FROM KENNEY.NL\nSONG RETRO FOREST BY DAVID FESLIYAN";

            bottomLabel          = new UILabel(message, mizjamSmallFont, Global.Colors.Main1);
            bottomLabel.Position = new Point(50, 900);
            string titleText = "ROLL AND DICE";

            title          = new UILabel(titleText, mizjamHugeFont, Global.Colors.Main1);
            title.Position = new Point((1920 - mizjamHugeFont.MeasureString(titleText).ToPoint().X) / 2, 50);
            AudioManager.Instance.SetMusicVolume(0.5f);
            AudioManager.Instance.SetSoundEffectVolume(1f);
            AudioManager.Instance.PlaySong("Song");
        }