「北海道大戦」カテゴリーアーカイブ

【北海道大戦2021】リンク情報のチェック

https://github.com/takishita2nd/HokkaidoWar/tree/2021_develop

そういえば、まだデータのチェックやっていなかったな、と思って、

こんなコードを書きました。

    protected override void OnUpdated()
    {
        asd.Vector2DF pos = asd.Engine.Mouse.Position;

        var maps = Singleton.FieldMap.GetAllMaps();
        foreach(var map in maps)
        {
            if(map == null)
            {
                continue;
            }

            if(map.IsOnMouse(pos))
            {
                map.GetCity().PaintAttackColor();
                foreach(var linkedMap in map.GetLinkdMap())
                {
                    linkedMap.GetCity().PaintDeffenceColor();
                }
                break;
            }
            else
            {
                map.GetCity().ClearPaint();
            }
        }

都市間のリンクデータを確認するプログラムです。

こんな感じで確認しました。

まぁ、手ででーたを入力していたわけで、

データミスが一箇所見つかりました。

めんどくさいことだけど、放置するともっとめんどくさいことになるから、めんどくさくてもやらなくちゃ行けないのです。

【北海道大戦2021】タイトル画面の作成

ロードボタンは何も実装していないので、何も置きませんが、

新規ゲームを選択すると、フェードイン、フェードアウトがかかって前回まで作成した画面に遷移します。

    class TitleScene : asd.Scene
    {
        private asd.Layer2D layer = null;
        private asd.TextureObject2D _newgame = null;
        private asd.TextureObject2D _load = null;

        private asd.Texture2D newgame1Image = asd.Engine.Graphics.CreateTexture2D("newgame1.png");
        private asd.Texture2D newgame2Image = asd.Engine.Graphics.CreateTexture2D("newgame2.png");
        private asd.Texture2D load1Image = asd.Engine.Graphics.CreateTexture2D("load1.png");
        private asd.Texture2D load2Image = asd.Engine.Graphics.CreateTexture2D("load2.png");

        private const int buttonWidth = 330;
        private const int buttonHeight = 80;

        public TitleScene()
        {
        }

        protected override void OnRegistered()
        {
            layer = new asd.Layer2D();
            AddLayer(layer);

            // 下地
            var background = new asd.GeometryObject2D();
            layer.AddObject(background);
            var bgRect = new asd.RectangleShape();
            bgRect.DrawingArea = new asd.RectF(0, 0, 1900, 1000);
            background.Shape = bgRect;

            // 北海道の背景
            var hokkaido = new asd.TextureObject2D();
            hokkaido.Texture = asd.Engine.Graphics.CreateTexture2D("101.png");
            hokkaido.Scale = new asd.Vector2DF(1.5f, 1.5f);
            layer.AddObject(hokkaido);

            // タイトル
            var title = new asd.TextureObject2D();
            title.Texture = asd.Engine.Graphics.CreateTexture2D("title.png");
            title.Position = new asd.Vector2DF(250, 200);
            layer.AddObject(title);

            // 新規ゲームボタン
            _newgame = new asd.TextureObject2D();
            _newgame.Texture = newgame1Image;
            _newgame.Position = new asd.Vector2DF(150, 450);
            layer.AddObject(_newgame);

            // ロードボタン
            _load = new asd.TextureObject2D();
            _load.Texture = load1Image;
            _load.Position = new asd.Vector2DF(500, 450);
            layer.AddObject(_load);
        }

        protected override void OnUpdated()
        {
            asd.Vector2DF pos = asd.Engine.Mouse.Position;

            if(isOnMouse(pos, _newgame))
            {
                _newgame.Texture = newgame2Image;
            }
            else
            {
                _newgame.Texture = newgame1Image;
            }

            if (isOnMouse(pos, _load))
            {
                _load.Texture = load2Image;
            }
            else
            {
                _load.Texture = load1Image;
            }

            if (asd.Engine.Mouse.LeftButton.ButtonState == asd.ButtonState.Push)
            {
                if (isOnMouse(pos, _newgame))
                {
                    var scene = new MainScene();
                    asd.Engine.ChangeSceneWithTransition(scene, new asd.TransitionFade(1.5f, 1.5f));
                }
            }
        }

        private bool isOnMouse(asd.Vector2DF pos, asd.TextureObject2D button)
        {
            if (pos.X > button.Position.X && pos.X < button.Position.X + buttonWidth
                && pos.Y > button.Position.Y && pos.Y < button.Position.Y + buttonHeight)
            {
                return true;
            }
            return false;
        }
    }

【北海道大戦2021】都市データを表示。

都市データの入力が終わりまして、

画面に都市の情報を表示させてみたいと思います。

今までの実装では

こんな感じになってました。

テキストだけを表示させている、と言う状態です。

これでは見づらいので、表示ウィンドウを作りたいと思います。

    class InfomationWindow
    {
        private TextObject2D _valueText;
        private GeometryObject2D _windowBox;
        private GeometryObject2D[] _geometryObj = new GeometryObject2D[4];
        private RectangleShape _rect;
        private LineShape[] _line = new LineShape[4];
        private const int rectWidth = 250;
        private const int rectHeight = 70;
        private const int xPositionOffset = 10;

        public InfomationWindow()
        {
        }

        public void AddLayer(Layer2D layer)
        {
            _windowBox = new GeometryObject2D();
            _windowBox.DrawingPriority = 10;
            _windowBox.Color = new Color(255, 255, 255, 255);
            _rect = new RectangleShape();
            layer.AddObject(_windowBox);

            for(int i = 0; i < 4; i++)
            {
                _geometryObj[i] = new GeometryObject2D();
                _geometryObj[i].DrawingPriority = 10;
                _geometryObj[i].Color = new Color(0, 0, 0, 255);
                _line[i] = new LineShape();
                _line[i].Thickness = 5;
                _geometryObj[i].Shape = _line[i];
                layer.AddObject(_geometryObj[i]);
            }

            _valueText = new TextObject2D();
            _valueText.Font = Singleton.Font;
            _valueText.DrawingPriority = 20;
            layer.AddObject(_valueText);
        }

        public void ShowText(Vector2DF pos, string text)
        {
            _rect.DrawingArea = new RectF(pos.X, pos.Y, rectWidth, rectHeight);
            _windowBox.Shape = _rect;
            _line[0].StartingPosition = new Vector2DF(pos.X, pos.Y);
            _line[0].EndingPosition = new Vector2DF(pos.X + rectWidth, pos.Y);
            _line[1].StartingPosition = new Vector2DF(pos.X + rectWidth, pos.Y);
            _line[1].EndingPosition = new Vector2DF(pos.X + rectWidth, pos.Y + rectHeight);
            _line[2].StartingPosition = new Vector2DF(pos.X + rectWidth, pos.Y + rectHeight);
            _line[2].EndingPosition = new Vector2DF(pos.X, pos.Y + rectHeight);
            _line[3].StartingPosition = new Vector2DF(pos.X, pos.Y + rectHeight);
            _line[3].EndingPosition = new Vector2DF(pos.X, pos.Y);
            _valueText.Text = text;
            _valueText.Position = new Vector2DF(pos.X + xPositionOffset, pos.Y);
        }

        public void AppendText(Vector2DF pos, string text)
        {
            _valueText.Text += text;
            _valueText.Position = new Vector2DF(pos.X + xPositionOffset, pos.Y);
        }
    }

画面に白い四角形を描画し、それに追加して、四辺に線を書きました。

あ、そうだ、タイトル画面作らないと。

次回はタイトル画面作ります。

【北海道大戦2021】マップの配置

https://github.com/takishita2nd/HokkaidoWar/tree/2021_develop

jsonファイルのデータを元に、都市を画面に配置していきます。

            // マップの配置
            foreach (var c in gameData.Battle.GetAliveCityList())
            {
                var maps = c.GetMaps();
                foreach (var m in maps)
                {
                    m.AddLayer(layer);
                }
            }

ここは前回と変わらず。

ただ、表示する■のサイズや座標の計算処理は変えています。

そして、その都市同士のリンクを示す選も描画していきます。

            // リンクの描画
            for (int i = 1; i <= gameData.MapData.citydata.Length; i++)
            {
                var m = Singleton.FieldMap.GetMap(i);
                foreach (var linkedMap in m.GetLinkdMap())
                {
                    if(m.Id < linkedMap.Id)
                    {
                        var geometryObject = new asd.GeometryObject2D();
                        geometryObject.Color = new asd.Color(0, 0, 255);
                        geometryObject.DrawingPriority = 5;
                        var linkLine = new asd.LineShape();
                        linkLine.StartingPosition = new asd.Vector2DF(m.CenterX, m.CenterY);
                        linkLine.EndingPosition = new asd.Vector2DF(linkedMap.CenterX, linkedMap.CenterY);
                        linkLine.Thickness = 2;
                        geometryObject.Shape = linkLine;
                        layer.AddObject(geometryObject);
                    }
                }
            }

さて、後はデータを入力していくだけの力仕事だ。

がんばります。

【北海道大戦2021】マップの作成

とりあえず、マップを配置。

https://github.com/takishita2nd/HokkaidoWar/tree/2021_develop

こちらのサイトのフリー素材を使用しました。

https://map.finemakeyuri.com/map/101.html

マップデータはこんな感じで作成しようと思います。(データは仮)

{
    "citydata":[
        {
            "id" : 1,
            "name" : "礼文",
            "population" : 2576,
            "money" : 0,
            "point" : { "x" :21, "y" :0 },
            "link" : [2, 3]
        },
        {
            "id" : 2,
            "name" : "利尻",
            "population" : 2087,
            "money" : 0,
            "point" : { "x" :21, "y" :0 },
            "link" : [1, 3]
        },
        {
            "id" : 3,
            "name" : "利尻富士",
            "population" : 2519,
            "money" : 0,
            "point" : { "x" :21, "y" :0 },
            "link" : [1, 2]
        }
    ]
}

これを「Jsonをクラスで貼り付け」すれば、適切なクラスを作成してくれます。

    public class MapData
    {
        public Citydata[] citydata { get; set; }
    }

    public class Citydata
    {
        public int id { get; set; }
        public string name { get; set; }
        public int population { get; set; }
        public int money { get; set; }
        public Point point { get; set; }
        public int[] link { get; set; }
    }

    public class Point
    {
        public int x { get; set; }
        public int y { get; set; }
    }

これでJsonの読み込みはできるはず。

        private const string _filename = "hokkaido.json";
        public static MapData Load()
        {
            string json;
            using (var stream = new StreamReader(_filename, true))
            {
                json = stream.ReadToEnd();
            }
            return JsonConvert.DeserializeObject<MapData>(json);
        }

そして、下地の北海道の描画。

        public MainScene()
        {
        }

        protected override void OnRegistered()
        {
            layer = new asd.Layer2D();
            AddLayer(layer);

            // 下地
            var background = new asd.GeometryObject2D();
            layer.AddObject(background);
            var bgRect = new asd.RectangleShape();
            bgRect.DrawingArea = new asd.RectF(0, 0, 1900, 1000);
            background.Shape = bgRect;
            var hokkaido = new asd.TextureObject2D();
            hokkaido.Texture = asd.Engine.Graphics.CreateTexture2D("101.png");
            hokkaido.Scale = new asd.Vector2DF(1.5f, 1.5f);
            layer.AddObject(hokkaido);

さて、次はマップに都市を貼り付けるのをやっていきます。

【北海道大戦2021】開発計画

前回とは以下の点を変更したいと思います。

マップをタイルを並べて作成→地図上に都市を配置して隣接関係を線で結ぶ。

データの持ち方は後々考える。

人口データは2021年度のデータを使用します。

お金的なものを導入したい。

例えば小さな村でもお金があれば戦力補強できるような仕組みにしたい。

どのデータを使用するかは検討します。

このページに財政状況がわかるデータがありました。

http://www.pref.hokkaido.lg.jp/ss/scs/zaisei/shi-zaisei-2-2.htm

【北海道大戦】札幌強すぎ問題

マップを修正して。札幌を9区に分けてみました。

これで単純計算で札幌の戦力が1/9になったはずですが、

都市間のリンクがぐちゃぐちゃになりまして、それをできる限り修正してみたらかなりいびつな形になっちゃいました。

まあいいや。

今後はリアル北海道地図でやりたいなぁ。

【北海道大戦】バトルシーンの画面を作成する

前回までの状況はこちら。

最新ソースはこちら(gitHub)。

https://github.com/takishita2nd/HokkaidoWar

バトルシーンの画面を作成していきます。

とは言っても部品を配置しているだけですが。

    class BattleScene : asd.Scene
    {
        private asd.TextObject2D _label = null;
        private asd.TextObject2D _attackCity = null;
        private asd.TextObject2D _deffenceCity = null;
        private asd.TextureObject2D _image_gu_attack = null;
        private asd.TextureObject2D _image_choki_attack = null;
        private asd.TextureObject2D _image_par_attack = null;
        private asd.TextureObject2D _image_gu_deffence = null;
        private asd.TextureObject2D _image_choki_deffence = null;
        private asd.TextureObject2D _image_par_deffence = null;
        private asd.TextObject2D _attackParam = null;
        private asd.TextObject2D _deffenceParam = null;

        public BattleScene()
        {

        }

        protected override void OnRegistered()
        {
            var layer = new asd.Layer2D();
            AddLayer(layer);

            // 下地
            var background = new asd.GeometryObject2D();
            layer.AddObject(background);
            var bgRect = new asd.RectangleShape();
            bgRect.DrawingArea = new asd.RectF(0, 0, 1800, 1000);
            background.Shape = bgRect;

            _label = new asd.TextObject2D();
            _label.Font = Singleton.GetLargeFont();
            _label.Text = "VS";
            _label.Position = new asd.Vector2DF(470, 400);
            layer.AddObject(_label);

            _attackCity = new asd.TextObject2D();
            _attackCity.Font = Singleton.GetLargeFont();
            _attackCity.Text = "札幌";
            _attackCity.Position = new asd.Vector2DF(450, 150);
            layer.AddObject(_attackCity);

            _deffenceCity = new asd.TextObject2D();
            _deffenceCity.Font = Singleton.GetLargeFont();
            _deffenceCity.Text = "小樽";
            _deffenceCity.Position = new asd.Vector2DF(450, 650);
            layer.AddObject(_deffenceCity);

            _attackParam = new asd.TextObject2D();
            _attackParam.Font = Singleton.GetLargeFont();
            _attackParam.Text = "戦闘力:10000";
            _attackParam.Position = new asd.Vector2DF(700, 650);
            layer.AddObject(_attackParam);

            _deffenceParam = new asd.TextObject2D();
            _deffenceParam.Font = Singleton.GetLargeFont();
            _deffenceParam.Text = "戦闘力:8000";
            _deffenceParam.Position = new asd.Vector2DF(700, 150);
            layer.AddObject(_deffenceParam);

            _image_gu_attack = new asd.TextureObject2D();
            _image_gu_attack.Texture = Singleton.GetImageGu();
            _image_gu_attack.Position = new asd.Vector2DF(300, 500);
            layer.AddObject(_image_gu_attack);

            _image_choki_attack = new asd.TextureObject2D();
            _image_choki_attack.Texture = Singleton.GetImageChoki();
            _image_choki_attack.Position = new asd.Vector2DF(450, 500);
            layer.AddObject(_image_choki_attack);

            _image_par_attack = new asd.TextureObject2D();
            _image_par_attack.Texture = Singleton.GetImagePar();
            _image_par_attack.Position = new asd.Vector2DF(600, 500);
            layer.AddObject(_image_par_attack);

            _image_gu_deffence = new asd.TextureObject2D();
            _image_gu_deffence.Texture = Singleton.GetImageGu();
            _image_gu_deffence.Position = new asd.Vector2DF(300, 250);
            layer.AddObject(_image_gu_deffence);

            _image_choki_deffence = new asd.TextureObject2D();
            _image_choki_deffence.Texture = Singleton.GetImageChoki();
            _image_choki_deffence.Position = new asd.Vector2DF(450, 250);
            layer.AddObject(_image_choki_deffence);

            _image_par_deffence = new asd.TextureObject2D();
            _image_par_deffence.Texture = Singleton.GetImagePar();
            _image_par_deffence.Position = new asd.Vector2DF(600, 250);
            layer.AddObject(_image_par_deffence);
        }

        protected override void OnUpdated()
        {

        }
    }

シンプルだけどまぁいいでしょう。

グー・チョキ・パーは絵文字が使えないっぽいので、絵文字を拡大してスクリーンショットで画像を作成しています。

次回は実際にシーンの切り替えをやってみます。