public Projectile(Vec2f startPos, AbstractEnemy target, float d, string TexturePath)
            : base()
        {
            Target = target;
            IsAlive = true;
            Damage = d;
            sprite = new Sprite(new Texture(TexturePath));

            sprite.Position = startPos;
            ProjectileHandler.Projectiles.Add(this);
        }
        public void Update(GameTime t)
        {
            if (!Target.IsAlive)
                IsAlive = false;

            TargetPosition = (Target.Position + Target.Size / 2 - new Vec2f(sprite.Texture.Size.X, sprite.Texture.Size.Y) / 2);

            sprite.Position = (Vec2f)sprite.Position + (TargetPosition - (Vec2f)sprite.Position).GetNormalized() * MovementSpeed * t.EllapsedTime.Milliseconds;

            if(TargetPosition.Distance(sprite.Position)<=Help.Epsilon)
            {
                Target.DoDamage(Damage);
                IsAlive = false;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// converts point coordinates from homogeneous to normal pixel coordinates ((x,y,z)->(x/z, y/z))
        /// </summary>
        /// <param name="src">Input vector of N-dimensional points.</param>
        /// <returns>Output vector of N-1-dimensional points.</returns>
        public static Vec2f[] ConvertPointsFromHomogeneous(IEnumerable<Vec3f> src)
        {
            if (src == null)
                throw new ArgumentNullException("src");

            Vec3f[] srcA = EnumerableEx.ToArray(src);
            Vec2f[] dstA = new Vec2f[srcA.Length];
            NativeMethods.calib3d_convertPointsFromHomogeneous_array1(srcA, dstA, srcA.Length);
            return dstA;
        }
Ejemplo n.º 4
0
 public static extern void core_Mat_push_back_Vec2f(IntPtr self, Vec2f v);
Ejemplo n.º 5
0
        private int Run(string[] args)
        {
            cmd = Command.None;

            opt = new OptionSet()
            {
                {"h|?|help", "show this message", v => cmd = Command.Help },
                {"f=|font=", "generate the specifed {font}", v => { fontName = v; cmd = Command.Build;} },
                {"o=|output=", "output atlas {file}[.atlas]", v => outFile = v },
                {"c=|char-set=", "character {set} to use", v => charSets.Add(v) },
                {"i=|image-path=", "directory {path} of png images to add", v => { imagePath = v; cmd = Command.Build; } },
                {"l|list-sets", "list available character sets", v => cmd = Command.List },
                {"v|verbose", "enable maximum verbosity", v => verbose = v != null },
                {"m|make-sprite", "make an associated sprite", v => makeSprite = v != null },
                {"p=|plugin", "execute module plugin in {assembly}", v => { pluginPath = v; cmd = Command.Plugin; } },
                {"C|console-mode", "run in interactive console mode", v => cmd = Command.Console },
                {"plugin-module=", "optional plugin module {name}", v => pluginName = v },
                {"power-two", "force atlas dimensions to be a power of 2", v => powTwo = v != null},
                {"max-size=", "maximum texture {size} in pixels [2048]", v => int.TryParse(v, out maxSize) },
                {"multi-texture", "enable multi-texture support", v => multiTexture = v != null},
                {"font-size=", "font {size}", v => float.TryParse(v, out fontSize) },
                {"font-bold", "use bold font", v => fontBold = v != null},
                {"font-italic", "use italic font", v => fontItalic = v != null},
                {"force-space", "force a space glyph", v => forceSpace = v != null},
                {"sprite-rate=", "sprite play back {speed} in frames per second", v => { float r; if (float.TryParse(v, out r)) sprite.Rate = r; }},
                {"sprite-overflow=", "sprite action after playing last {frame} (Hold|Loop)", v => sprite.Overflow = (OverflowAction)Enum.Parse(typeof(OverflowAction), v) },
                {"glyph-align=", "the {layout} of each glyph (BestFit|Grid)", v => alignment = (GlyphAlignment)Enum.Parse(typeof(GlyphAlignment), v) },
                {"glyph-space=", "the {space} between glyphs in pixels", v => int.TryParse(v, out spacing)},
                {"image-start=", "image starting {index}", v => int.TryParse(v, out startCode)},
                {"image-recurse", "search sub directories when adding images", v => recurseDir = v != null},
                {"image-center", "center all image glyphs", v => centerImages = v != null},
                {"image-origin=", "{\"x, y\"} offset of all image glyphs", v => imageOrigin = Transpose.FromString<Vec2f>(v)},
            };

            try
            {
                var param = opt.Parse(args);

                switch (cmd)
                {
                    case Command.List:
                        WriteSets();
                        return 0;

                    case Command.None:
                    case Command.Help:
                        WriteHelp();
                        return 1;

                    case Command.Plugin:
                        ExecutePlugin(param);
                        break;

                    case Command.Build:
                        Validate();
                        Process();
                        break;

                    case Command.Console:
                        new Interactive(this).Run();
                        break;
                }
            }
            catch (Exception e)
            {
                WriteError(e);
                return 2;
            }

            return 0;
        }
        /// <summary>
        /// checks if the mouse is within the sprite
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static bool MouseIn(Sprite sprite)
        {
            Vec2f v = new Vec2f(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y);
            Vec2f spriteSize = new Vec2f(sprite.Texture.Size.X * sprite.Scale.X, sprite.Texture.Size.Y * sprite.Scale.Y);

            if (v.X < sprite.Position.X || v.X > sprite.Position.X + spriteSize.X)
                return false;

            if (v.Y < sprite.Position.Y || v.Y > sprite.Position.Y + spriteSize.Y)
                return false;

            return true;
        }
        /// <summary>
        /// updates the mouse controller
        /// </summary>
        public static void Update()
        {
            Vector2i v = Mouse.GetPosition(window);
            MousePosition = new Vec2f(v.X, v.Y);

            for (int i = 0; i < isPressed.Length; ++i)
            {

                if (!isPressed[i] && Mouse.IsButtonPressed(Cast((MouseButton)i)))
                {
                    isPressed[i] = Mouse.IsButtonPressed((Mouse.Button)i);
                    MouseButtonEventArgs e = new MouseButtonEventArgs();
                    e.Button = (MouseButton)i;
                    e.Position.X = Mouse.GetPosition(window).X;
                    e.Position.Y = Mouse.GetPosition(window).Y;
                    OnButtonPress(e);
                }

                isPressed[i] = Mouse.IsButtonPressed(Cast((MouseButton)i));

                if (wasPressed[i] && !isPressed[i])
                {
                    MouseButtonEventArgs e = new MouseButtonEventArgs();
                    e.Button = (MouseButton)i;
                    e.Position.X = Mouse.GetPosition(window).X;
                    e.Position.Y = Mouse.GetPosition(window).Y;
                    OnButtonRelease(e);
                }

                wasPressed[i] = isPressed[i];
            }
        }
Ejemplo n.º 8
0
 public static Vec2f Pow(Vec2f x, Veci.Vec2i y)
 {
     return new Vec2f(
         Pow(x.x, y.x),
         Pow(x.y, y.y));
 }
        public Map(Bitmap bMap)
        {
            Tiles = new Tile[bMap.Width, bMap.Height];
            for(int i = 0; i < Tiles.GetLength(0); ++i)
                for(int j = 0; j<Tiles.GetLength(1); ++j)
                {
                    if (bMap.GetPixel(i, j).Equals(white))
                    {
                        if (r.Next(10) > 7)
                            Tiles[i, j] = new Tile(false, new Vec2f(i, j) * TileSize, "Assets/Textures/tree.png");
                        else
                            Tiles[i, j] = new Tile(false, new Vec2f(i, j) * TileSize);
                    }
                    else
                    {
                        if (bMap.GetPixel(i, j).Equals(black))
                        {
                            string Path = "";

                            bool left;

                            if (i - 1 < 0)
                                left = false;
                            else
                                left = bMap.GetPixel(i - 1, j).Equals(white);

                            bool right;

                            if (i + 1 >= Tiles.GetLength(0))
                                right = false;
                            else
                                right = bMap.GetPixel(i + 1, j).Equals(white);

                            bool up;

                            if (j - 1 < 0)
                                up = false;
                            else
                                up = bMap.GetPixel(i, j - 1).Equals(white);

                            bool down;

                            if (j + 1 >= Tiles.GetLength(1))
                                down = false;
                            else
                                down = bMap.GetPixel(i, j + 1).Equals(white);

                            if (!left && !right && !up && !down)
                                Path = "Assets/Textures/ground_without_grass.png";

                            if (!left && !right && up && down)
                                Path = "Assets/Textures/ground_straight.png";

                            if (left && right && !up && !down)
                                Path = "Assets/Textures/ground_straight_2.png";

                            if (left && !right && up && !down)
                                Path = "Assets/Textures/ground_corner_left_up.png";

                            if (left && !right && !up && down)
                                Path = "Assets/Textures/ground_corner_left_down.png";

                            if (!left && right && up && !down)
                                Path = "Assets/Textures/ground_corner_right_up.png";

                            if (!left && right && !up && down)
                                Path = "Assets/Textures/ground_corner_right_down.png";

                            if (Path != "")
                                Tiles[i, j] = new Tile(true, new Vec2f(i, j) * TileSize, Path);
                        }

                        if (bMap.GetPixel(i, j).Equals(red))
                        {
                            Vec2f pos = new Vec2f(i, j) * TileSize;

                            Tiles[i, j] = new Tile(true, pos, "Assets/Textures/house_humans.png");

                            SpawnPosition = new Vec2i(i, j);
                        }

                        if(bMap.GetPixel(i, j).Equals(yellow))
                        {
                            Vec2f pos = new Vec2f(i, j) * TileSize;
                            Tiles[i, j] = new Tile(true, pos, "Assets/Textures/house.png");
                            EndPosition = new Vec2i(i, j);
                        }
                    }
                }

            Verticies = new List<Vec2f>();

            SetMovementVeticies();
        }
        public Vec2f GetValidPosition(Vec2f pos)
        {
            Vec2i tilePos = (pos / TileSize);

            try
            {
                if (Tiles[tilePos.X, tilePos.Y].IsPath)
                    throw new PathException();

                foreach(AbstractTower t in TowerHandler.Towers)
                {
                    if (((Vec2f)tilePos * TileSize) == t.Position)
                        throw new PathException();
                }
            }
            catch (IndexOutOfRangeException)
            {
                throw new PathException();
            }

            return (Vec2f)tilePos * TileSize;
        }
 public static Vec2f Cos(Vec2f radians)
 {
     return new Vec2f()
     {
         x = (float)Math.Cos(radians.x),
         y = (float)Math.Cos(radians.y)
     };
 }
Ejemplo n.º 12
0
 public void TranslateWorldPosToViewPos(Vec3d worldPos, ref Vec2f viewPos)
 {
     worldMapDlg.TranslateWorldPosToViewPos(worldPos, ref viewPos);
 }