コード例 #1
0
ファイル: UtilsDemo.cs プロジェクト: SHHSSH/Monofoxe
 public void Green(StateMachine <TestStates> stateMachine, Entity caller)
 {
     _color = Color.Green;
     if (_random.NextDouble() > 0.9)
     {
         stateMachine.ChangeState(TestStates.Blue);
         return;
     }
     if (_random.NextDouble() > 0.8)
     {
         stateMachine.ChangeState(TestStates.Red);
         return;
     }
 }
コード例 #2
0
        public SpeechBubble(Actor owner, string text)
        {
            Owner = owner;
            Text  = text;

            var r = new RandomExt();

            _wiggleys      = new Vector2[(_cornerVecticesCount + _sideVecticesCount) * 4];
            _wiggleysPhase = new double[_wiggleys.Length];

            for (var i = 0; i < _wiggleysPhase.Length; i += 1)
            {
                _wiggleysPhase[i] = r.NextDouble(Math.PI * 2);
            }

            _pos = Test.RoundVector2(Owner.Position + MainOffset);
        }
コード例 #3
0
        public Scene(Sprite map)
        {
            var texture   = map.Frames[0].Texture;
            var colorData = new Color[texture.Width * texture.Height];

            texture.GetData(colorData);             // Map loader won't support sprites on texture atlas!!!

            TileMap = new int[texture.Width, texture.Height];

            for (var y = 0; y < texture.Height; y += 1)
            {
                for (var x = 0; x < texture.Width; x += 1)
                {
                    TileMap[x, y] = 1;

                    var color = colorData[x + y * texture.Width];

                    if (CheckValue(_wall, color))
                    {
                        new Solid(new Vector2(x, y) * CellSize, Vector2.One * CellSize, SpritesDefault.Block);
                    }
                    if (CheckValue(_tree, color))
                    {
                        new Solid(new Vector2(x, y) * CellSize, Vector2.One * CellSize, SpritesDefault.Tree);
                    }
                    if (CheckValue(_player, color))
                    {
                        new Player(new Vector2(x, y) * CellSize + Vector2.One * CellSize / 2);
                    }
                    if (CheckValue(_enemy, color))
                    {
                        new Enemy(new Vector2(x, y) * CellSize + Vector2.One * CellSize / 2, CreatePath(x, y, colorData, texture.Width));
                    }
                    if (CheckValue(_sky, color))
                    {
                        TileMap[x, y] = 0;
                    }
                    if (CheckValue(_paintedTile, color))
                    {
                        TileMap[x, y] = 2;
                    }
                    if (CheckValue(_skyBorder, color))
                    {
                        new Solid(new Vector2(x, y) * CellSize, Vector2.One * CellSize);
                        TileMap[x, y] = 0;
                    }
                    if (CheckValue(_npc, color))
                    {
                        new NPC(new Vector2(x, y) * CellSize + Vector2.One * CellSize / 2, color.B);
                    }
                    if (CheckValue(_laser, color))
                    {
                        new Laser(
                            new Vector2(x, y) * CellSize + Vector2.One * CellSize / 2,
                            CreateLaserPath(x, y, colorData, texture.Width) * CellSize + Vector2.One * CellSize / 2
                            );
                    }
                    if (CheckValue(_checkpoint, color))
                    {
                        new Checkpoint(new Vector2(x, y) * CellSize + Vector2.One * CellSize / 2);
                    }
                    if (CheckValue(_dialogue, color))
                    {
                        new DialogueTrigger(new Vector2(x, y) * CellSize + Vector2.One * CellSize / 2, color.B);
                    }
                    if (CheckValue(_coin, color))
                    {
                        new Coin(new Vector2(x, y) * CellSize);
                    }
                }
            }

            var r = new RandomExt(42312342);

            for (var i = 0; i < 50; i += 1)
            {
                new Cloud(
                    new Vector2(r.Next(-400, texture.Width * CellSize), r.Next(-400, texture.Height * CellSize)),
                    r.Next(3),
                    (float)r.NextDouble(0.3, 0.7)
                    );
            }
        }
コード例 #4
0
        /// <summary>
        /// 生成拼图形状。
        /// </summary>
        public void GererateJigsawShape()
        {
            // 拼图尺寸。
            float width  = Size.Width;
            float height = Size.Height;
            // 拼图碎片的尺寸。
            float pWidth  = width / horizontalDimension;
            float pHeight = height / verticalDimension;
            // 拼图碎片的随机化尺寸。
            float rWidth = pWidth * randomization / 3;
            float rHeight = pHeight * randomization / 3;
            float x, y;

            // 最后一行节点。
            Vector2[] corners   = new Vector2[horizontalDimension + 1];
            Vector2   lastPoint = new Vector2();

            // 最后一行的边凹凸性。
            bool[] borders    = new bool[horizontalDimension + 1];
            bool   lastBorder = false;

            // 最后一行的随机数。
            float[][] values    = new float[horizontalDimension + 1][];
            float[]   lastValue = null;
            for (int i = 0; i <= this.verticalDimension; i++)
            {
                for (int j = 0; j <= this.horizontalDimension; j++)
                {
                    y = pHeight * i;
                    if (i > 0 && i < this.verticalDimension && rHeight != 0f)
                    {
                        y += (float)((RandomExt.NextDouble() * 2 - 1) * rHeight);
                    }
                    x = pWidth * j;
                    if (j > 0 && j < horizontalDimension && rWidth != 0f)
                    {
                        x += (float)((RandomExt.NextDouble() * 2 - 1) * rWidth);
                    }
                    Vector2 currentPoint = new Vector2(x, y);
                    if (i == 0)
                    {
                        corners[j] = currentPoint;
                    }
                    else if (j == 0)
                    {
                        lastPoint = currentPoint;
                    }
                    else
                    {
                        // 将拼图碎片放置在国际象棋盘上,每片会分别对应黑色和白色。
                        bool isBlack = (i + j) % 2 == 0;
                        Path path    = new Path(corners[j], isBlack);
                        // 逆时针添加边。
                        // 顶边。
                        if (i == 1)
                        {
                            path.AddLine(corners[j - 1]);
                        }
                        else
                        {
                            AddBorder(path, corners[j], corners[j - 1], !borders[j], values[j]);
                        }
                        // 左边。
                        if (j == 1)
                        {
                            path.AddLine(lastPoint);
                        }
                        else
                        {
                            AddBorder(path, corners[j - 1], lastPoint, !lastBorder, lastValue);
                        }
                        // 底边。
                        if (i == verticalDimension)
                        {
                            path.AddLine(currentPoint);
                        }
                        else
                        {
                            borders[j] = RandomExt.NextBoolean();
                            values[j]  = GenerateRandom();
                            AddBorder(path, lastPoint, currentPoint, borders[j], values[j]);
                        }
                        // 右边。
                        if (j == horizontalDimension)
                        {
                            path.AddLine(corners[j]);
                        }
                        else
                        {
                            lastBorder = RandomExt.NextBoolean();
                            lastValue  = GenerateRandom();
                            AddBorder(path, currentPoint, corners[j], lastBorder, lastValue);
                        }
                        this.paths.Add(path);
                        // 计算形状的重心。
                        Vector2 c1 = SharpDXUtility.GetCenter(corners[j - 1], corners[j], lastPoint);
                        Vector2 c2 = SharpDXUtility.GetCenter(corners[j], lastPoint, currentPoint);
                        float   w1 = SharpDXUtility.Area(corners[j - 1], corners[j], lastPoint);
                        float   w2 = SharpDXUtility.Area(corners[j], lastPoint, currentPoint);
                        path.Weight    = w1 + w2;
                        path.Center    = new Vector2((c1.X * w1 + c2.X * w2) / path.Weight, (c1.Y * w1 + c2.Y * w2) / path.Weight);
                        corners[j - 1] = lastPoint;
                        lastPoint      = currentPoint;
                        if (j == this.horizontalDimension)
                        {
                            corners[j] = currentPoint;
                        }
                    }
                }
            }
        }