コード例 #1
0
        public static Boundaries operator +(Boundaries b, Vector2 v)
        {
            Boundaries boundaries = new Boundaries();

            foreach (var p in b.points)
                boundaries.points.Add(p + v);

            foreach (var f in b.functions)
                if (float.IsNaN(f.a))
                    boundaries.functions.Add(new Function(f.a, f.b + v.X, f.p1 + v.Y, f.p2 + v.Y));
                else
                    boundaries.functions.Add(new Function(f.a, f.b + v.Y - f.a * v.X, f.p1 + v.X, f.p2 + v.X));

            foreach (Vector2 w in boundaries.points)
            {
                if (w.X < boundaries.min.X)
                    boundaries.min.X = w.X;
                if (w.Y < boundaries.min.Y)
                    boundaries.min.Y = w.Y;
                if (w.X > boundaries.max.X)
                    boundaries.max.X = w.X;
                if (w.Y > boundaries.max.Y)
                    boundaries.max.Y = w.Y;
            }

            return boundaries;
        }
コード例 #2
0
        public void Notice(GameMap gameMap, List <Fighter> fighters, List <Enemy> enemies)
        {
            foreach (var f in fighters)
            {
                if (!f.IsAlive)
                {
                    continue;
                }

                List <Vector2> points = new List <Vector2>();
                points.Add(Vector2.Zero);
                Vector2 v = new Vector2(f.position.X - position.X, f.position.Y - position.Y);
                if (v != Vector2.Zero)
                {
                    v.Normalize();
                }
                points.Add(new Vector2(20 * v.X, 20 * v.Y));
                boundaries = Boundaries.CreateFromPoints(points);


                Vector2 current = new Vector2(position.X, position.Y);
                bool    intersects = false;
                int     i = 0, j = 0;
                while (!current.Similar(f.position, 5) && i >= 0 && j >= 0)
                {
                    i = (int)current.GetMapPosition(gameMap).X;
                    j = (int)current.GetMapPosition(gameMap).Y;

                    foreach (var mo in gameMap[i, j].mapObjects)
                    {
                        if (mo.boundaries.Intersects(boundaries + current))
                        {
                            intersects = true;
                        }
                    }

                    if (intersects)
                    {
                        break;
                    }

                    current += v * 5;
                }

                if (!intersects)
                {
                    aware             = true;
                    this.moveStrategy = new PathFind(gameMap, fighters, enemies, this, f);
                    target            = f;
                    break;
                }
            }
        }
コード例 #3
0
        internal static Boundaries CreateFromPoints(List <Vector2> points)
        {
            Boundaries b = new Boundaries();

            foreach (Vector2 v in points)
            {
                b.points.Add(new Vector2(v.X, v.Y));
                if (v.X < b.min.X)
                {
                    b.min.X = v.X;
                }
                if (v.Y < b.min.Y)
                {
                    b.min.Y = v.Y;
                }
                if (v.X > b.max.X)
                {
                    b.max.X = v.X;
                }
                if (v.Y > b.max.Y)
                {
                    b.max.Y = v.Y;
                }
            }

            for (int i = 0; i < points.Count; i++)
            {
                float A = float.NaN, B, p1, p2;
                int   j = (i + 1 == points.Count)?0:i + 1;
                if (points[j].X == points[i].X)
                {
                    // to znaczy że to nie jest funkcja
                    p1 = (points[i].Y < points[j].Y) ? points[i].Y : points[j].Y;
                    p2 = (points[i].Y >= points[j].Y) ? points[i].Y : points[j].Y;
                    B  = points[i].X;
                }
                else
                {
                    // obliczanie wspolrzednych funkcji
                    A  = (points[j].Y - points[i].Y) / (points[j].X - points[i].X);
                    B  = (points[i].Y * points[j].X - points[j].Y * points[i].X) / (points[j].X - points[i].X);
                    p1 = (points[i].X < points[j].X) ? points[i].X : points[j].X;
                    p2 = (points[i].X >= points[j].X) ? points[i].X : points[j].X;
                }

                b.functions.Add(new Function(A, B, p1, p2));
            }


            return(b);
        }
コード例 #4
0
        public static Boundaries operator +(Boundaries b, Vector2 v)
        {
            Boundaries boundaries = new Boundaries();

            foreach (var p in b.points)
            {
                boundaries.points.Add(p + v);
            }

            foreach (var f in b.functions)
            {
                if (float.IsNaN(f.a))
                {
                    boundaries.functions.Add(new Function(f.a, f.b + v.X, f.p1 + v.Y, f.p2 + v.Y));
                }
                else
                {
                    boundaries.functions.Add(new Function(f.a, f.b + v.Y - f.a * v.X, f.p1 + v.X, f.p2 + v.X));
                }
            }


            foreach (Vector2 w in boundaries.points)
            {
                if (w.X < boundaries.min.X)
                {
                    boundaries.min.X = w.X;
                }
                if (w.Y < boundaries.min.Y)
                {
                    boundaries.min.Y = w.Y;
                }
                if (w.X > boundaries.max.X)
                {
                    boundaries.max.X = w.X;
                }
                if (w.Y > boundaries.max.Y)
                {
                    boundaries.max.Y = w.Y;
                }
            }

            return(boundaries);
        }
コード例 #5
0
        internal Boundaries Clone()
        {
            Boundaries b = new Boundaries();

            foreach (Vector2 p in points)
            {
                b.points.Add(new Vector2(p.X, p.Y));
            }

            foreach (Function f in functions)
            {
                b.functions.Add(new Function(f.a, f.b, f.p1, f.p2));
            }

            b.Min = new Vector2(Min.X, Min.Y);
            b.Max = new Vector2(Max.X, Max.Y);

            return(b);
        }
コード例 #6
0
        internal static Boundaries CreateFromPoints(List<Vector2> points)
        {
            Boundaries b = new Boundaries();

            foreach (Vector2 v in points)
            {
                b.points.Add(new Vector2(v.X, v.Y));
                if (v.X < b.min.X)
                    b.min.X = v.X;
                if (v.Y < b.min.Y)
                    b.min.Y = v.Y;
                if (v.X > b.max.X)
                    b.max.X = v.X;
                if (v.Y > b.max.Y)
                    b.max.Y = v.Y;
            }

            for (int i = 0; i < points.Count; i++)
            {
                float A = float.NaN, B, p1, p2;
                int j = (i+1==points.Count)?0:i+1;
                if (points[j].X == points[i].X)
                {
                    // to znaczy że to nie jest funkcja
                    p1 = (points[i].Y < points[j].Y) ? points[i].Y : points[j].Y;
                    p2 = (points[i].Y >= points[j].Y) ? points[i].Y : points[j].Y;
                    B = points[i].X;
                }
                else
                {
                    // obliczanie wspolrzednych funkcji
                    A = (points[j].Y - points[i].Y) / (points[j].X - points[i].X);
                    B = (points[i].Y * points[j].X - points[j].Y * points[i].X) / (points[j].X - points[i].X);
                    p1 = (points[i].X < points[j].X) ? points[i].X : points[j].X;
                    p2 = (points[i].X >= points[j].X) ? points[i].X : points[j].X;
                }

                b.functions.Add(new Function(A,B,p1,p2));
            }

            return b;
        }
コード例 #7
0
 public void Load(ContentManager content, int i, int j)
 {
     base.Load(content);
     boundaries += new Vector2(i * GameMap.TileShift.X + ((j % 2 != 0) ? GameMap.TileShift.X / 2 : 0), j * GameMap.TileShift.Y / 2);
 }
コード例 #8
0
ファイル: Fighter.cs プロジェクト: kelostrada-pjatk/minifice
        public Fighter(bool playerControlled, Vector2 position, Camera2d camera)
            : base(camera)
        {
            this.playerControlled = playerControlled;
            this.position         = position;

            // Definicja animacji postaci
            this.animation = new Animation(2, 5, Direction.Left);
            AnimationFrame mini1 = new AnimationFrame(@"Game\mini1", new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 40, 40));

            mini1.origin = new Vector2(100, 180);
            AnimationFrame mini2 = new AnimationFrame(@"Game\mini2", new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 40, 40));

            mini2.origin = new Vector2(100, 180);
            this.animation.framesLeft.Add(mini1);
            this.animation.framesLeft.Add(mini2);
            this.animation.framesRight.Add(mini1);
            this.animation.framesRight.Add(mini2);
            this.animation.framesUp.Add(mini1);
            this.animation.framesUp.Add(mini2);
            this.animation.framesDown.Add(mini1);
            this.animation.framesDown.Add(mini2);

            this.animationDeath = new Animation(20, 15, Direction.Left);

            AnimationFrame frame;

            for (int i = 1; i <= 10; i++)
            {
                frame        = new AnimationFrame(@"Game\AnimationDeath\mini1_klatka" + i.ToString(), new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 40, 40));
                frame.origin = new Vector2(100, 180);
                if (i == 10)
                {
                    for (int j = 0; j < 11; j++)
                    {
                        this.animationDeath.framesLeft.Add(frame);
                        this.animationDeath.framesRight.Add(frame);
                        this.animationDeath.framesUp.Add(frame);
                        this.animationDeath.framesDown.Add(frame);
                    }
                }
                else
                {
                    this.animationDeath.framesLeft.Add(frame);
                    this.animationDeath.framesRight.Add(frame);
                    this.animationDeath.framesUp.Add(frame);
                    this.animationDeath.framesDown.Add(frame);
                }
            }

            List <Vector2> points = new List <Vector2>();

            points.Add(new Vector2(-BoundariesSize, 0));
            points.Add(new Vector2(0, -BoundariesSize));
            points.Add(new Vector2(BoundariesSize, 0));
            points.Add(new Vector2(0, BoundariesSize));

            this.boundaries = Boundaries.CreateFromPoints(points);

            this.health       = 8;
            this.isActive     = true;
            this.speed        = 0.75f;
            this.timeLastShot = new TimeSpan();

            this.destination = new Vector2(position.X, position.Y);
        }
コード例 #9
0
        public Enemy(Vector2 position, Camera2d camera) : base(camera)
        {
            this.position = position;

            // Definicja animacji postaci
            this.animation = new Animation(2, 5, Direction.Left);
            AnimationFrame eiti1 = new AnimationFrame(@"Game\eiti1", new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 40, 40));

            eiti1.origin = new Vector2(100, 180);
            AnimationFrame eiti2 = new AnimationFrame(@"Game\eiti2", new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 40, 40));

            eiti2.origin = new Vector2(100, 180);
            this.animation.framesLeft.Add(eiti1);
            this.animation.framesLeft.Add(eiti2);
            this.animation.framesRight.Add(eiti1);
            this.animation.framesRight.Add(eiti2);
            this.animation.framesUp.Add(eiti1);
            this.animation.framesUp.Add(eiti2);
            this.animation.framesDown.Add(eiti1);
            this.animation.framesDown.Add(eiti2);

            this.animationDeath = new Animation(20, 15, Direction.Left);

            AnimationFrame frame;

            for (int i = 1; i <= 10; i++)
            {
                frame        = new AnimationFrame(@"Game\AnimationDeath\eiti1_klatka" + i.ToString(), new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 40, 40));
                frame.origin = new Vector2(100, 180);
                if (i == 10)
                {
                    for (int j = 0; j < 11; j++)
                    {
                        this.animationDeath.framesLeft.Add(frame);
                        this.animationDeath.framesRight.Add(frame);
                        this.animationDeath.framesUp.Add(frame);
                        this.animationDeath.framesDown.Add(frame);
                    }
                }
                else
                {
                    this.animationDeath.framesLeft.Add(frame);
                    this.animationDeath.framesRight.Add(frame);
                    this.animationDeath.framesUp.Add(frame);
                    this.animationDeath.framesDown.Add(frame);
                }
            }

            List <Vector2> points = new List <Vector2>();

            points.Add(new Vector2(-BoundariesSize, 0));
            points.Add(new Vector2(0, -BoundariesSize));
            points.Add(new Vector2(BoundariesSize, 0));
            points.Add(new Vector2(0, BoundariesSize));

            this.boundaries = Boundaries.CreateFromPoints(points);

            this.health       = 6;
            this.speed        = 0.55f;
            this.timeLastShot = new TimeSpan();
        }
コード例 #10
0
        internal bool Intersects(Boundaries b)
        {
            foreach (var f1 in b.functions)
            {
                foreach (var f2 in functions)
                {
                    if (float.IsNaN(f1.a) || float.IsNaN(f2.a))
                    {
                        // Ktoras z funkcji nie jest tak na prawde funkcja. Teraz przypadki
                        if (float.IsNaN(f1.a) && float.IsNaN(f2.a))
                        {
                            if (f1.b == f2.b)
                            {
                                if (f1.p2 >= f2.p1 && f2.p2 >= f1.p1)
                                {
                                    return(true);
                                }
                            }
                        }
                        if (float.IsNaN(f1.a) && !float.IsNaN(f2.a))
                        {
                            if (f1.b >= f2.p1 && f1.b <= f2.p2)
                            {
                                if (f2.func(f1.b) >= f1.p1 && f2.func(f1.b) <= f1.p2)
                                {
                                    return(true);
                                }
                            }
                        }
                        if (!float.IsNaN(f1.a) && float.IsNaN(f2.a))
                        {
                            if (f2.b >= f1.p1 && f2.b <= f1.p2)
                            {
                                if (f1.func(f2.b) >= f2.p1 && f1.func(f2.b) <= f2.p2)
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                    else if (f1.a == f2.a)
                    {
                        if (f1.b == f2.b)
                        {
                            if (f1.p2 >= f2.p1 && f2.p2 >= f1.p1)
                            {
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        float x = (f2.b - f1.b) / (f1.a - f2.a);
                        if (x >= f1.p1 && x <= f1.p2 && x >= f2.p1 && x <= f2.p2)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
コード例 #11
0
        private void Level1()
        {
            GameMap = new GameMap(150, 150);

            MapTile        t1     = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());
            MapTile        t2     = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 291, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());
            MapTile        t3     = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 317, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());
            MapObject      mo     = new MapObject();
            List <Vector2> punkty = new List <Vector2>();

            punkty.Add(new Vector2(-0.5f, 7));
            punkty.Add(new Vector2(24, 23));
            punkty.Add(new Vector2(48.5f, 7));
            punkty.Add(new Vector2(24, -2));

            mo.boundaries    = Boundaries.CreateFromPoints(punkty);
            mo.collectible   = false;
            mo.Source        = new Source(539, 0, 48, 47);
            mo.textureName   = @"Game\newtile";
            mo.throwableOver = true;
            mo.type          = new Bonus();
            mo.viewBlocking  = true;
            mo.origin        = new Vector2(0, 24);

            for (int i = 0; i < 20; i++)
            {
                for (int j = 0; j < 40; j++)
                {
                    GameMap[i + j / 2, 40 - 2 * i + j]     = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());
                    GameMap[i + j / 2 + 1, 40 - 2 * i + j] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 291, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());
                }
            }

            for (int i = 0; i < 42; i++)
            {
                GameMap[i / 2, 42 - i].mapObjects.Add(mo.Clone());
                GameMap[i / 2 + 20, 82 - i].mapObjects.Add(mo.Clone());
            }

            GameMap[20, 43].mapObjects.Add(mo.Clone());
            GameMap[21, 44].mapObjects.Add(mo.Clone());

            GameMap[20, 30].mapObjects.Add(mo.Clone());
            GameMap[1, 11].mapObjects.Add(mo.Clone());

            GameMap[4, 60] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());
            GameMap[4, 60].mapObjects.Add(mo.Clone());

            for (int i = 0; i < 70; i++)
            {
                GameMap[7, i *5] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());
            }


            GameMap[0, 0]  = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());
            GameMap[1, 1]  = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());
            GameMap[10, 2] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());
            GameMap[10, 3] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());
            GameMap[13, 2] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());
            GameMap[13, 3] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>());


            GameMap.Load(content);

            /*
             * GameMap = new GameMap(50, 100);
             *
             * for (int i = 0; i < 50; i++)
             *  for (int j = 0; j < 100; j++)
             *      GameMap.mapTiles[i][j] = new MapTile(new BackgroundSprite(@"Game\texture", new Rectangle(152, 379, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List<MapObject>());
             *
             * GameMap.Load(content);
             *
             * MapObject mo = new MapObject();
             * List<Vector2> punkty = new List<Vector2>();
             * punkty.Add(new Vector2(1, 6));
             * punkty.Add(new Vector2(4, 13));
             * punkty.Add(new Vector2(8, 13));
             * punkty.Add(new Vector2(25, 0));
             * mo.boundaries = Boundaries.CreateFromPoints(punkty);
             * mo.collectible = false;
             * mo.Source = new Source(372, 429, 30, 38);
             * mo.textureName = @"Game\texture";
             * mo.throwableOver = true;
             * mo.type = new Bonus();
             * mo.viewBlocking = true;
             * mo.origin = new Vector2(0, 24);
             * mo.Load(content);
             *
             * for (int i = 0; i < 50; i++)
             *  GameMap.mapTiles[i][10].mapObjects.Add(mo);
             *
             * mo = new MapObject();
             * punkty.Clear();
             * punkty.Add(new Vector2(40, 13));
             * punkty.Add(new Vector2(43, 13));
             * punkty.Add(new Vector2(46, 6));
             * punkty.Add(new Vector2(25, 0));
             * //punkty.Add(new Vector2(18, 2));
             * mo.boundaries = Boundaries.CreateFromPoints(punkty);
             * mo.collectible = false;
             * mo.Source = new Source(403, 429, 30, 38);
             * mo.textureName = @"Game\texture";
             * mo.throwableOver = true;
             * mo.type = new Bonus();
             * mo.viewBlocking = true;
             * mo.origin = new Vector2(-18, 24);
             * mo.Load(content);
             *
             *
             * for (int i = 0; i < 50; i++)
             *  GameMap.mapTiles[i][10].mapObjects.Add(mo);
             */
        }
コード例 #12
0
        internal bool Intersects(Boundaries b)
        {
            foreach (var f1 in b.functions)
                foreach (var f2 in functions)
                {
                    if (float.IsNaN(f1.a) || float.IsNaN(f2.a))
                    {
                        // Ktoras z funkcji nie jest tak na prawde funkcja. Teraz przypadki
                        if (float.IsNaN(f1.a) && float.IsNaN(f2.a))
                        {
                            if (f1.b == f2.b)
                                if (f1.p2 >= f2.p1 && f2.p2 >= f1.p1) return true;
                        }
                        if (float.IsNaN(f1.a) && !float.IsNaN(f2.a))
                        {
                            if (f1.b >= f2.p1 && f1.b <= f2.p2)
                                if (f2.func(f1.b) >= f1.p1 && f2.func(f1.b) <= f1.p2) return true;
                        }
                        if (!float.IsNaN(f1.a) && float.IsNaN(f2.a))
                        {
                            if (f2.b >= f1.p1 && f2.b <= f1.p2)
                                if (f1.func(f2.b) >= f2.p1 && f1.func(f2.b) <= f2.p2) return true;
                        }
                    }
                    else if (f1.a == f2.a)
                    {
                        if (f1.b == f2.b)
                            if (f1.p2 >= f2.p1 && f2.p2 >= f1.p1) return true;
                    }
                    else
                    {
                        float x = (f2.b - f1.b) / (f1.a - f2.a);
                        if (x >= f1.p1 && x <= f1.p2 && x >= f2.p1 && x <= f2.p2) return true;
                    }
                }

            return false;
        }
コード例 #13
0
        internal Boundaries Clone()
        {
            Boundaries b = new Boundaries();

            foreach (Vector2 p in points)
            {
                b.points.Add(new Vector2(p.X, p.Y));
            }

            foreach (Function f in functions)
            {
                b.functions.Add(new Function(f.a, f.b, f.p1, f.p2));
            }

            b.Min = new Vector2(Min.X, Min.Y);
            b.Max = new Vector2(Max.X, Max.Y);

            return b;
        }
コード例 #14
0
 public void Load(ContentManager content, int i, int j)
 {
     base.Load(content);
     boundaries += new Vector2(i * GameMap.TileShift.X + ((j % 2 != 0) ? GameMap.TileShift.X / 2 : 0), j * GameMap.TileShift.Y / 2);
 }