Exemplo n.º 1
0
        public byte[] DrawText(string text, bool x2 = false)
        {
            using (var image = new MagickImage(MagickColors.White, 380, 400))
            {
                var x = new Drawables()
                        .FontPointSize(16)
                        .Font("Courier New")
                        .TextAntialias(true)
                        .StrokeColor(MagickColors.Black)
                        .StrokeWidth(0)
                        .FillColor(MagickColors.Black)
                        .TextAlignment(TextAlignment.Left)
                        .Text(10, 128, text)
                        .Draw(image);

                image.Trim();
                if (x2)
                {
                    image.Extent(new MagickGeometry(-10, -10, image.Width + 20, image.Height * 2 + 20), MagickColors.White);
                }
                else
                {
                    image.Extent(new MagickGeometry(-10, -10, image.Width + 20, image.Height + 20), MagickColors.White);
                }

                return(image.ToByteArray(MagickFormat.Png));
            }
        }
Exemplo n.º 2
0
        public override void ShowPreview(Renderer renderer)
        {
            var image      = state.Image(needle.Key).Clone();
            var searchArea = NeedleSearchArea(image, needle.Gravity);
            var rows       = searchArea.Item1;
            var columns    = searchArea.Item2;

            var minX = columns.Min();
            var maxX = columns.Max();
            var minY = rows.Min();
            var maxY = rows.Max();

            var preview = image;
            var rect    = new Drawables()
                          .StrokeWidth(2)
                          .StrokeColor(new MagickColor("yellow"))
                          .FillOpacity(new Percentage(0))
                          .Rectangle(minX, minY, maxX, maxY);

            preview.Draw(rect);

            if (searchResult != null)
            {
                var needleRect = new Drawables()
                                 .StrokeWidth(2)
                                 .StrokeColor(new MagickColor(searchResult.MeetsThreshold() ? "green" : "red"))
                                 .FillOpacity(new Percentage(0))
                                 .Rectangle(searchResult.Point.X, searchResult.Point.Y, searchResult.Point.X + NeedleSize, searchResult.Point.Y + NeedleSize);
                preview.Draw(needleRect);
            }

            renderer.DisplayImages(preview);
        }
Exemplo n.º 3
0
        private bool TryAddBarrier(MapTile tile, Point location)
        {
            BlockType blockType;

            switch (tile)
            {
            case MapTile.InvisibleWall:
                blockType = BlockType.InvisibleBlock;
                break;

            case MapTile.BlackBarrier:
                blockType = BlockType.BlackBarrier;
                break;

            case MapTile.InvisibleProjectileBarrier:
                blockType = BlockType.InvisibleProjectileBarrier;
                break;

            default:
                return(false);
            }

            var barrier = new Barrier(location, blockType);

            Collidables.Add(barrier);
            Drawables.Add(barrier);

            return(true);
        }
        private void DrawBboxes(byte[] photo, Bbox[] bboxes, ref Image img)
        {
            using (var image = new MagickImage(photo))
            {
                var drawables = new Drawables();
                drawables.StrokeWidth(ViewImage.Source.Height >= 1000 ? 8 : 2);
                drawables.FillColor(MagickColor.FromRgba(255, 255, 255, 0));
                drawables.StrokeColor(MagickColor.FromRgb(255, 0, 0));

                foreach (var bbox in bboxes)
                {
                    drawables.Rectangle(bbox.X,
                                        bbox.Y,
                                        bbox.X + bbox.Width,
                                        bbox.Y + bbox.Height
                                        );
                }

                image.Draw(drawables);

                using (var ms = new MemoryStream(image.ToByteArray()))
                {
                    var bitmap = new BitmapImage();
                    bitmap.BeginInit();
                    bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                    bitmap.StreamSource = ms;
                    bitmap.EndInit();
                    img.Source = bitmap;
                }
            }
        }
Exemplo n.º 5
0
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            Hero          player        = (Hero)engine.GetEntity("Player");
            KeyboardState keyboardState = Keyboard.GetState();

            if (KeyboardExtensions.GetKeyDownState(keyboardState, Keys.S, this, true) &&
                Entity.IntersectsWith(this, null, player, "Shadow", gameTime))
            {
                if (CurrentDrawableState != "Open")
                {
                    Random random = new Random();

                    CurrentDrawableState = "Open";
                    Drawables.ResetState("Open", gameTime);

                    for (int i = 0; i < 10; i++)
                    {
                        Coin coin = new Coin(this.Pos.X, this.Pos.Y, 100, (CoinType)random.Next(3));
                        coin.Pos.X += (float)((random.NextDouble() - 0.5) * 100);
                        coin.Pos.Y += (float)((random.NextDouble() - 0.5) * 100);

                        engine.AddEntity(coin);
                    }
                }
            }
        }
Exemplo n.º 6
0
Arquivo: Game.cs Projeto: Vtek/Pulsar
        /// <summary>
        /// Add game module
        /// </summary>
        public Game AddModule <T>() where T : IModule
        {
            PulsarHost.Instance.Kernel.Bind <IModule> ().To <T> ().InSingletonScope();

            var module = PulsarHost.Instance.Kernel.GetService(typeof(T));

            var wasAdded = Modules.Any(x => x.GetType().IsInstanceOfType(module));

            if (wasAdded)
            {
                throw new InvalidOperationException(string.Format("Module {0} already added", module.GetType()));
            }

            if (module is GameModule)
            {
                var gm = (GameModule)module;
                gm.GlobalData = GlobalData;
                gm.TempData   = GlobalData;
            }

            Modules.Add((IModule)module);

            if (module is IDrawable)
            {
                Drawables.Add((IDrawable)module);
            }

            return(this);
        }
Exemplo n.º 7
0
        public MagickImage GetText()
        {
            var image = new MagickImage(new MagickColor(255, 255, 255, 0), 4000, 2000);

            var drawables = new Drawables()
                            //.Rotation(30)
                            .Text(0, 0, Text)
                            .TextAntialias(true)
                            .Font("CarbonRegular W00")
                            .FontPointSize(387)
                            //.FontPointSize(360)
                            //.FontPointSize(-1)
                            .TextInterlineSpacing(-50)
                            .TextKerning(20)
                            //.TextKerning(9)
                            .FillColor(TextColor)
                            .Gravity(Gravity.West);

            //return drawables;
            image.Draw(drawables);

            image.Scale(new Percentage(GetScalingFactor() * 100));
            image.Trim();
            image.Extent(Math.Max(image.Width, image.Height), Math.Max(image.Width, image.Height), Gravity.West);
            image.BorderColor = new MagickColor("transparent");
            image.Border(20);
            image.BorderColor = new MagickColor("#ffffff01");
            image.Border(1);
            //image.Write("./text-face.png");

            return(image);
        }
Exemplo n.º 8
0
        public void Test_Draw()
        {
            using (IMagickImage image = new MagickImage(MagickColors.Fuchsia, 100, 100))
            {
                Drawables drawables = new Drawables()
                                      .FillColor(MagickColors.Red)
                                      .Rectangle(10, 10, 90, 90);

                IEnumerator enumerator = ((IEnumerable)drawables).GetEnumerator();
                Assert.IsTrue(enumerator.MoveNext());

                drawables.Draw(image);

                ColorAssert.AreEqual(MagickColors.Fuchsia, image, 9, 9);
                ColorAssert.AreEqual(MagickColors.Red, image, 10, 10);
                ColorAssert.AreEqual(MagickColors.Red, image, 90, 90);
                ColorAssert.AreEqual(MagickColors.Fuchsia, image, 91, 91);

                image.Draw(new Drawables()
                           .FillColor(MagickColors.Green)
                           .Rectangle(15, 15, 85, 85));

                ColorAssert.AreEqual(MagickColors.Fuchsia, image, 9, 9);
                ColorAssert.AreEqual(MagickColors.Red, image, 10, 10);
                ColorAssert.AreEqual(MagickColors.Green, image, 15, 15);
                ColorAssert.AreEqual(MagickColors.Green, image, 85, 85);
                ColorAssert.AreEqual(MagickColors.Red, image, 90, 90);
                ColorAssert.AreEqual(MagickColors.Fuchsia, image, 91, 91);
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Instantiates the cursor.
 /// Sets the cursor's layer.
 /// Offsets the cursor to be centered on it's position.
 /// </summary>
 private void CreateCursor()
 {
     _cursor       = new Sprite(Content.Load <Texture2D>("cursor"), Vector2.Zero);
     _cursor.Layer = 1.0f;
     _cursor.SetOffset(Anchor.Center);
     Drawables.Add(_cursor);
 }
Exemplo n.º 10
0
            public void ShouldDrawTheDrawables()
            {
                using (var image = new MagickImage(MagickColors.Fuchsia, 100, 100))
                {
                    var drawables = new Drawables()
                                    .FillColor(MagickColors.Red)
                                    .Rectangle(10, 10, 90, 90);

                    drawables.Draw(image);

                    ColorAssert.Equal(MagickColors.Fuchsia, image, 9, 9);
                    ColorAssert.Equal(MagickColors.Red, image, 10, 10);
                    ColorAssert.Equal(MagickColors.Red, image, 90, 90);
                    ColorAssert.Equal(MagickColors.Fuchsia, image, 91, 91);

                    image.Draw(new Drawables()
                               .FillColor(MagickColors.Green)
                               .Rectangle(15, 15, 85, 85));

                    ColorAssert.Equal(MagickColors.Fuchsia, image, 9, 9);
                    ColorAssert.Equal(MagickColors.Red, image, 10, 10);
                    ColorAssert.Equal(MagickColors.Green, image, 15, 15);
                    ColorAssert.Equal(MagickColors.Green, image, 85, 85);
                    ColorAssert.Equal(MagickColors.Red, image, 90, 90);
                    ColorAssert.Equal(MagickColors.Fuchsia, image, 91, 91);
                }
            }
Exemplo n.º 11
0
        private bool TryAddStair(MapTile tile, Point location)
        {
            BlockType blockType;

            switch (tile)
            {
            case MapTile.DungeonStairs:
                blockType = BlockType.DungeonStair;
                break;

            case MapTile.BasementStairs:
                blockType = BlockType.BasementStair;
                break;

            case MapTile.StairSpecialUp1_1:
                blockType = BlockType.StairSpecialUp1_1;
                break;

            default:
                return(false);
            }

            var stairs = new Stair(_dungeonManager, location, blockType);

            Collidables.Add(stairs);
            Drawables.Add(stairs);

            return(true);
        }
Exemplo n.º 12
0
        public byte[] Create(List <LabeleldValue> values)
        {
            var lineHeight = 12;
            var height     = values.Count * lineHeight + 4;

            using (var image = new MagickImage(new MagickColor("#56667A"), 260, height))
            {
                image.Depth = 64;

                var magic = new Drawables()
                            .FontPointSize(12)

                            .Font("Courier New")

                            .TextAlignment(TextAlignment.Left);

                for (int i = 0; i < values.Count; i++)
                {
                    magic.Text(2, 12 * (i + 1), $"{values[i].Label}: {values[i].Value}");
                }
                magic.FillColor(new MagickColor(MagickColors.White));
                magic.Draw(image);


                return(image.ToByteArray(MagickFormat.Png));
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// RemoveObject is called to remove a GameObject from the Objects list.
        /// </summary>
        public void RemoveObject(GameObject oldObject)
        {
            Objects.Remove(oldObject);

            // Adds to Drawables if drawable.
            if (oldObject is Drawable drawable)
            {
                Drawables.Remove(drawable);
            }

            // Adds to Collidables if collidable.
            if (oldObject is Collider)
            {
                Collidables.Remove(oldObject);
            }

            if (oldObject is Player)
            {
                Player = null;;
            }

            if (oldObject is Npc)
            {
                Npcs.Remove((Npc)oldObject);
            }
        }
Exemplo n.º 14
0
        private bool TryAddSpecialDoor(MapTile tile, Point location)
        {
            DoorBase  door;
            Direction direction;

            switch (tile)
            {
            case MapTile.DoorSpecialLeft2_1:
                door      = new DoorSpecialLeft2_1(_dungeonManager, location);
                direction = Direction.Left;
                break;

            case MapTile.DoorSpecialRight3_1:
                door      = new DoorSpecialRight3_1(_dungeonManager, location);
                direction = Direction.Right;
                break;

            default:
                return(false);
            }
            Doors.Add(direction, door);
            Drawables.Add(door);
            Collidables.Add(door);
            return(true);
        }
Exemplo n.º 15
0
        private bool TryAddNonStandardTiles(MapTile tile, Point location)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases (cases are covered elsewhere)
            switch (tile)
            {
            case MapTile.Key:
                Items.Add(new Key(location, this));
                break;

            case MapTile.Compass:
                Items.Add(new Compass(location));
                break;

            case MapTile.Map:
                Items.Add(new Map(location));
                break;

            case MapTile.Bow:
                Items.Add(new BowItem(location, Secondary.Bow, 10));
                break;

            case MapTile.Triforce:
                Items.Add(new Triforce(location));
                break;

            case MapTile.PushableBlock:
                var pushableBlock = new MovableBlock(location);
                Collidables.Add(pushableBlock);
                Drawables.Add(pushableBlock);
                TransitionResetables.Add(pushableBlock);
                break;

            case MapTile.SpawnEnemy:
                SpawnTiles.Add(location);
                break;

            case MapTile.Sand:
                Drawables.Add(new Overlay(location, BlockType.Sand));
                break;

            case MapTile.Heart:
                Items.Add(new HeartContainer(location, this));
                break;

            case MapTile.Boomerang:
                Items.Add(new BoomerangItem(location, this, 20));
                break;

            case MapTile.BasementBricks:
            case MapTile.BlackOverlay:
            case MapTile.None:
            case MapTile.Room2_1Block:
                break;

            default:
                return(false);
            }

            return(true);
        }
Exemplo n.º 16
0
        private bool TryAddNormalDoor(MapTile tile, Point location)
        {
            BlockType blockType;
            Direction direction;

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (tile)
            {
            case MapTile.DoorUp:
                blockType = BlockType.DoorUp;
                direction = Direction.Up;
                break;

            case MapTile.DoorDown:
                blockType = BlockType.DoorDown;
                direction = Direction.Down;
                break;

            default:
                return(false);
            }

            var door = new NormalDoor(_survivalManager, location, blockType);

            Doors.Add(direction, door);
            Drawables.Add(door);
            Collidables.Add(door);
            return(true);
        }
Exemplo n.º 17
0
        public void At(int seconds)
        {
            using (var image = new MagickImage(new MagickColor("#000000"), GraphSize, GraphSize))
            {
                image.Format = MagickFormat.Png;
                var d = new Drawables();
                d.FillColor(MagickColors.Blue);

                bool any = false;

                foreach (var point in points)
                {
                    int x = Shift(point.X + point.Vx * seconds);
                    int y = Shift(point.Y + point.Vy * seconds);

                    if (x >= 0 && y >= 0 && x <= GraphSize && y <= GraphSize)
                    {
                        any = true;
                        d.Rectangle(x, y, x + 1, y + 1);
                    }
                }

                if (any)
                {
                    image.Draw(d);
                    image.Write($@"C:\dev\aoc\2018\10\output\{seconds}.png");
                }
            }
        }
Exemplo n.º 18
0
 public override void Die()
 {
     base.Die();
     Finder.Player          = NullPlayer.Instance;
     Finder.Player.Position = this.Position;
     Drawables.Remove(this);
 }
Exemplo n.º 19
0
        /// <summary>
        /// Revives instance.
        /// </summary>
        private void Revive()
        {
            // Return if already revive.
            if (IsRevived)
            {
                return;
            }


            // Return if revive isn't possible.
            if (!CanRevive)
            {
                return;
            }


            // Revive unmanaged model.
            TaskableModel = new CubismTaskableModel(Moc);


            // Revive proxies.
            Parameters = GetComponentsInChildren <CubismParameter>();
            Parts      = GetComponentsInChildren <CubismPart>();
            Drawables  = GetComponentsInChildren <CubismDrawable>();

            Parameters.Revive(TaskableModel.UnmanagedModel);
            Parts.Revive(TaskableModel.UnmanagedModel);
            Drawables.Revive(TaskableModel.UnmanagedModel);

            CanvasInformation = new CubismCanvasInformation(TaskableModel.UnmanagedModel);

            _parameterStore = GetComponent <CubismParameterStore>();
        }
Exemplo n.º 20
0
 /// <summary>
 /// Start a draw event. Then clears subscribers.
 /// </summary>
 public void Start()
 {
     Drawables?.Invoke();
     //Drawables = null;
     Players?.Invoke();
     UIAdapter.Instance.RefreshScreen();
 }
Exemplo n.º 21
0
        public void Equip(Item item)
        {
            Unequip(item.ItemType);

            Equiped[item.ItemType] = item;
            Drawables.Union(item.Drawables);
        }
Exemplo n.º 22
0
        private static MagickImage GetCheckerBoard(int width, int height, int squareSize)
        {
            if (width == 0 || height == 0 || squareSize == 0)
            {
                return(new MagickImage());
            }
            var image = new MagickImage(MagickColors.Transparent, width, height);
            var light = MagickColor.FromRgb(150, 150, 150);
            var dark  = MagickColor.FromRgb(100, 100, 100);

            using (var tile = new MagickImage(MagickColors.Transparent, squareSize * 2, squareSize * 2)) {
                var drawable = new Drawables()
                               // Fill the background with a light color
                               .FillColor(light)
                               .Rectangle(0, 0, squareSize * 2, squareSize * 2)
                               // Create the top left square
                               .FillColor(dark)
                               .Rectangle(0, 0, squareSize, squareSize)
                               // Create the bottom right square
                               .FillColor(dark)
                               .Rectangle(squareSize, squareSize, squareSize * 2, squareSize * 2);

                tile.Draw(drawable);

                // Tile the tile on the full image
                image.Tile(tile, CompositeOperator.SrcOver);
            }
            return(image);
        }
Exemplo n.º 23
0
 public void Spin(GameTime gameTime)
 {
     if (CurrentDrawableState.Contains("Idle"))
     {
         // Reset the animations
         Drawables.ResetGroup("Body", gameTime);
         CurrentDrawableState = "Spin_" + Direction;
     }
 }
Exemplo n.º 24
0
        public void Unequip(ItemType itemType)
        {
            if (Equiped.ContainsKey(itemType))
            {
                Drawables.Remove(Equiped[itemType].Drawables);
            }

            Equiped.Remove(itemType);
        }
Exemplo n.º 25
0
        public override void Initialize()
        {
            Drawable         = Drawables.Create <DrawableTexture>();
            Drawable.Texture = Scene.ContentLoader.LoadContent <Texture>("content/planet.png");
            Size             = Drawable.Texture.Size;

            Position         = new Vec2(Game.Random.Next((int)(Scene.Window.Size.X - Size.X)), -Size.Y);
            EntityData.Speed = 50;
        }
Exemplo n.º 26
0
        /// <summary>
        /// Adds sprite to game and puts it on field on board
        /// </summary>
        /// <param name="sprite"></param>
        public void AddObject(Sprite sprite)
        {
            var spritePosition = sprite.GetPosition();

            if (IsPositionValid(spritePosition))
            {
                Drawables.Add(sprite);
                Fields[spritePosition.X, spritePosition.Y].Sprite = sprite;
            }
        }
Exemplo n.º 27
0
 protected override void DisposeManagedResources()
 {
     base.DisposeManagedResources();
     Miniature?.Dispose();
     Freehand?.Dispose();
     foreach (var drawable in Drawables)
     {
         drawable.Dispose();
     }
     Drawables.Clear();
 }
Exemplo n.º 28
0
        public Drawables GetFramePath()
        {
            var drawables = new Drawables().Path(
                new PathLineToAbs(Top, LeftTop, LeftBottom, Bottom, RightBottom, RightTop, Top));

            drawables.StrokeColor(FrameColor);
            drawables.FillColor(FillColor);
            drawables.StrokeWidth(Scale(FrameThickness));

            return(drawables);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Removes sprite from game entirely
        /// </summary>
        /// <param name="sprite"></param>
        public void RemoveObject(Sprite sprite)
        {
            var spritePosition = sprite.GetPosition();
            var spriteOnBoard  = Fields[spritePosition.X, spritePosition.Y].Sprite;

            Fields[spritePosition.X, spritePosition.Y].Sprite = null;
            if (spriteOnBoard == null || !Drawables.Remove(spriteOnBoard))
            {
                throw new Exception("No such sprite on board");
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Creates a series of 10 blocks centered on the screen.
        /// </summary>
        private void CreatePlatform()
        {
            Vector2 blockPosition = new Vector2(352f, 500f);

            for (int x = 0; x < 10; x++)
            {
                _blocks.Add(new Block(Content.Load <Texture2D>("BlockA0"), blockPosition));
                Drawables.Add(_blocks.Last());
                blockPosition.X += 64f;
            }
        }
Exemplo n.º 31
0
 public static void print(Drawables.LuaDrawable target, int x, int y, string str)
 {
     target.Console.print(x, y, str);
 }
Exemplo n.º 32
0
 public static void setDraw(Drawables.LuaDrawable target, LuaFunction draw)
 {
     if (target == null) return;
     target.LDraw = draw;
 }
Exemplo n.º 33
0
 public static void setKeyDown(Drawables.LuaDrawable target, LuaFunction keydown)
 {
     if (target == null) return;
     target.LKeyDown = keydown;
 }
Exemplo n.º 34
0
 public static void toggleDraw(Drawables.LuaDrawable target)
 {
     if (target == null) return;
     target.isActive = !target.isActive;
 }