Пример #1
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;
                }
            }
        }
Пример #2
0
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, null, null, null, null, camera.get_transformation(screenManager.GraphicsDevice));

            //spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);

            //SpriteFont spriteFont = content.Load<SpriteFont>(@"Menu\menufont");
            //spriteBatch.DrawString(spriteFont, "TESTTESTTEST", new Vector2(100, 100), Color.White);
            //spriteBatch.Draw(texture, new Rectangle(100,100,1000,1000), Color.White);

            //spriteBatch.Draw(texture, new Rectangle(0, 0, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y), new Rectangle(152, 379, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y), Color.White, 0, new Vector2(), SpriteEffects.None, 0);

            GameMap.Draw(gameTime, spriteBatch);
            foreach (Fighter f in Fighters)
            {
                if ((!f.IsAlive && f.isDying) || f.IsAlive)
                {
                    f.Draw(gameTime, spriteBatch);
                }
            }
            foreach (Enemy e in Enemies)
            {
                e.Draw(gameTime, spriteBatch);
            }
            foreach (Missile m in Missiles)
            {
                m.Draw(gameTime, spriteBatch);
            }

            spriteBatch.End();

            SpriteFont font = screenManager.Font;

            // Inicjuje nowego spriteBatcha, żeby interfejs nie przesuwal sie z kamerą
            spriteBatch.Begin();

            GameInterface.Draw(spriteBatch);
            //Vector2 posClick = new Vector2(MouseCord.X - GameInterface.Width - (screenManager.Settings.Resolution.X - GameInterface.Width) / 2 + GameInterface.Width - Fighters[0].position.X, MouseCord.Y - screenManager.Settings.Resolution.Y / 2 - Fighters[0].position.Y);
            Vector2 posClick = new Vector2(MouseCord.X - GameInterface.Width - (screenManager.Settings.Resolution.X - GameInterface.Width) / 2, MouseCord.Y - screenManager.Settings.Resolution.Y / 2);

            posClick += camera.Pos;

            spriteBatch.DrawString(font, (MouseCord.X - GameInterface.Width).ToString() + "," + MouseCord.Y.ToString(), new Vector2(10, 0), Color.Red);
            spriteBatch.DrawString(font, ((int)posClick.X).ToString() + "," + ((int)posClick.Y).ToString(), new Vector2(10, 50), Color.Red);
            spriteBatch.DrawString(font, ((int)Fighters[0].position.X).ToString() + "," + ((int)Fighters[0].position.Y).ToString(), new Vector2(10, 100), Color.Red);

            spriteBatch.DrawString(font, "{" + camera.Pos.GetMapPosition(GameMap).X + "," + camera.Pos.GetMapPosition(GameMap).Y + "}", new Vector2(10, 150), Color.Purple);

            spriteBatch.DrawString(font, "{" + posClick.GetMapPosition(GameMap).X + "," + posClick.GetMapPosition(GameMap).Y + "}", new Vector2(10, 200), Color.Plum);

            spriteBatch.DrawString(font, "{" + Math.Floor(posClick.X * 2 / GameMap.TileShift.X) + "," + Math.Floor(posClick.Y * 2 / GameMap.TileShift.Y) + "}", new Vector2(10, 250), Color.Maroon);

            Vector2 test = new Vector2(47, 3);

            test.GetMapPosition(GameMap);

            spriteBatch.End();
        }
Пример #3
0
        public static IGraph CreateSimpleGraph(this GameMap gameMap, List <Fighter> fighters, List <Enemy> enemies, Vector2 start, Vector2 end)
        {
            Point  p1 = start.GetMapPosition(gameMap);
            Point  p2 = start.GetMapPosition(gameMap);
            IGraph g;

            if ((Math.Abs(p1.X - p2.X) + 4) * (Math.Abs(p1.Y - p2.Y) + 4) < 100)
            {
                g = new AdjacencyListsGraph(false, (Math.Abs(p1.X - p2.X) + 4) * (Math.Abs(p1.Y - p2.Y) + 4));
            }
            else
            {
                g = new AdjacencyListsGraph(false, 100); // TODO do poprawy
            }

            /*
             * Point sourceMap = source.GetMapPosition(gameMap);
             * Point destinationMap = source.GetMapPosition(gameMap);
             * Point shift = new Point((int)Math.Min(sourceMap.X, destinationMap.X), (int)Math.Min(sourceMap.Y, destinationMap.Y));
             *
             * IGraph g = new AdjacencyMatrixGraph(false,(int)(Math.Abs(destinationMap.X-sourceMap.X+4)*Math.Abs(destinationMap.Y-sourceMap.Y+4)));
             *
             * for (int i = -2; i < destinationMap.X - sourceMap.X + 2; i++)
             * {
             *  for (int j = -2; j < destinationMap.Y - sourceMap.Y + 2; j++)
             *  {
             *      if (shift.X+i >= 0 && shift.X+i < gameMap.width && shift.Y + j - 2 >=0 && shift.Y+j-2 < gameMap.height && gameMap[shift.X + i, shift.Y + j - 2].mapObjects.Count == 0)
             *      {
             *          //g.AddEdge((int)( j * (destinationMap.X - sourceMap.X + 4) + i ),(int)( (j - 2) * (destinationMap.X - sourceMap.X + 4) + i - 1 ));
             *      }
             *  }
             * }
             */

            return(g);
        }
        /// <summary>
        /// Aktualizacja grafu - dodawanie krawedzi
        /// Metoda rozszerzająca
        /// </summary>
        /// <param name="g">graf</param>
        /// <param name="x1">Punkt x1 (startowy)</param>
        /// <param name="y1">Punkt y1 (startowy)</param>
        /// <param name="x2">Punkt x2</param>
        /// <param name="y2">Punkt y2</param>
        /// <param name="startGraph">Gdzie na mapie zaczyna się graf</param>
        /// <param name="size">Rozmiar grafu (w ilości punktów oddalonych od siebie o VerticesDensity)</param>
        /// <param name="VerticesDensity">Oddalenie punktów od siebie nawzajem</param>
        /// <param name="gameMap">mapa</param>
        /// <param name="b">ograniczenie dla tych dwóch konkretnych punktów</param>
        private static void UpdateGraph(this IGraph g, int x1, int y1, int x2, int y2, Vector2 startGraph, Point size, float VerticesDensity, GameMap gameMap, Boundaries b)
        {
            Vector2 mapPosition1 = new Vector2(startGraph.X + x1 * VerticesDensity, startGraph.Y + y1 * VerticesDensity);
            Vector2 mapPosition2 = new Vector2(startGraph.X + x2 * VerticesDensity, startGraph.Y + y2 * VerticesDensity);
            Point mapPoint1 = mapPosition1.GetMapPosition(gameMap);
            Point mapPoint2 = mapPosition2.GetMapPosition(gameMap);
            Boundaries shift = b.Clone();
            shift += mapPosition1;
            bool intersects = false;

            foreach (MapObject mo in gameMap[mapPoint1.X, mapPoint1.Y].mapObjects)
                if (shift.Intersects(mo.boundaries)) intersects = true;
            foreach (MapObject mo in gameMap[mapPoint2.X, mapPoint2.Y].mapObjects)
                if (shift.Intersects(mo.boundaries)) intersects = true;
            if (!intersects)
                g.AddEdge(x1 + y1 * (size.X - 1), x2 + y2 * (size.X - 1));
            else
                g.DelEdge(x1 + y1 * (size.X - 1), x2 + y2 * (size.X - 1));
        }
        public static IGraph CreateSimpleGraph(this GameMap gameMap, List<Fighter> fighters, List<Enemy> enemies, Vector2 start, Vector2 end)
        {
            Point p1 = start.GetMapPosition(gameMap);
            Point p2 = start.GetMapPosition(gameMap);
            IGraph g;
            if ((Math.Abs(p1.X - p2.X) + 4) * (Math.Abs(p1.Y - p2.Y) + 4) < 100)
                g = new AdjacencyListsGraph(false, (Math.Abs(p1.X - p2.X) + 4) * (Math.Abs(p1.Y - p2.Y) + 4));
            else
                g = new AdjacencyListsGraph(false, 100); // TODO do poprawy

            /*
            Point sourceMap = source.GetMapPosition(gameMap);
            Point destinationMap = source.GetMapPosition(gameMap);
            Point shift = new Point((int)Math.Min(sourceMap.X, destinationMap.X), (int)Math.Min(sourceMap.Y, destinationMap.Y));

            IGraph g = new AdjacencyMatrixGraph(false,(int)(Math.Abs(destinationMap.X-sourceMap.X+4)*Math.Abs(destinationMap.Y-sourceMap.Y+4)));

            for (int i = -2; i < destinationMap.X - sourceMap.X + 2; i++)
            {
                for (int j = -2; j < destinationMap.Y - sourceMap.Y + 2; j++)
                {
                    if (shift.X+i >= 0 && shift.X+i < gameMap.width && shift.Y + j - 2 >=0 && shift.Y+j-2 < gameMap.height && gameMap[shift.X + i, shift.Y + j - 2].mapObjects.Count == 0)
                    {
                        //g.AddEdge((int)( j * (destinationMap.X - sourceMap.X + 4) + i ),(int)( (j - 2) * (destinationMap.X - sourceMap.X + 4) + i - 1 ));
                    }
                }
            }
            */

            return g;
        }
Пример #6
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;
                }

            }
        }
Пример #7
0
        protected Object Collision(GameMap gameMap, List <Fighter> fighters, List <Enemy> enemies)
        {
            int i = position.GetMapPosition(gameMap).X;
            int j = position.GetMapPosition(gameMap).Y;

            for (int k = -1; k <= 1; k++)
            {
                for (int l = -1; l <= 1; l++)
                {
                    if (i + k >= 0 && j + l >= 0 && i + k < gameMap.width && j + l < gameMap.height)
                    {
                        foreach (var mo in gameMap.mapTiles[i + k][j + l].mapObjects)
                        {
                            if ((j + l) % 2 == 0)
                            {
                                if (mo.boundaries.Intersects(boundaries + position))
                                {
                                    return(mo);
                                }
                            }
                            else
                            {
                                if (mo.boundaries.Intersects(boundaries + position))
                                {
                                    return(mo);
                                }
                            }
                        }
                    }
                }
            }



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

            points.Add(new Vector2(-5, -25));
            points.Add(new Vector2(5, -25));
            points.Add(new Vector2(5, 0));
            points.Add(new Vector2(-5, 0));

            b = Boundaries.CreateFromPoints(points);

            if (faction == Faction.Enemies)
            {
                foreach (Fighter f in fighters)
                {
                    //if ((boundaries + position).Intersects(f.boundaries + f.position + new Vector2(0, -15)))
                    if (f.IsAlive && (boundaries + position).Intersects(b + f.position))
                    {
                        return(f);
                    }
                }
            }

            if (faction == Faction.Fighters)
            {
                foreach (Enemy e in enemies)
                {
                    //if ((boundaries + position).Intersects(e.boundaries + e.position + new Vector2(0,-15)))
                    if (e.IsAlive && (boundaries + position).Intersects(b + e.position))
                    {
                        return(e);
                    }
                }
            }

            return(null);
        }
Пример #8
0
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, null, null, null, null, camera.get_transformation(screenManager.GraphicsDevice));

            //spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);

            //SpriteFont spriteFont = content.Load<SpriteFont>(@"Menu\menufont");
            //spriteBatch.DrawString(spriteFont, "TESTTESTTEST", new Vector2(100, 100), Color.White);
            //spriteBatch.Draw(texture, new Rectangle(100,100,1000,1000), Color.White);

            //spriteBatch.Draw(texture, new Rectangle(0, 0, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y), new Rectangle(152, 379, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y), Color.White, 0, new Vector2(), SpriteEffects.None, 0);

            GameMap.Draw(gameTime, spriteBatch);
            foreach (Fighter f in Fighters)
                if ((!f.IsAlive && f.isDying) || f.IsAlive)
                    f.Draw(gameTime, spriteBatch);
            foreach (Enemy e in Enemies)
                e.Draw(gameTime, spriteBatch);
            foreach (Missile m in Missiles)
                m.Draw(gameTime, spriteBatch);

            spriteBatch.End();

            SpriteFont font = screenManager.Font;

            // Inicjuje nowego spriteBatcha, żeby interfejs nie przesuwal sie z kamerą
            spriteBatch.Begin();

            GameInterface.Draw(spriteBatch);
            //Vector2 posClick = new Vector2(MouseCord.X - GameInterface.Width - (screenManager.Settings.Resolution.X - GameInterface.Width) / 2 + GameInterface.Width - Fighters[0].position.X, MouseCord.Y - screenManager.Settings.Resolution.Y / 2 - Fighters[0].position.Y);
            Vector2 posClick = new Vector2(MouseCord.X - GameInterface.Width - (screenManager.Settings.Resolution.X - GameInterface.Width) / 2, MouseCord.Y - screenManager.Settings.Resolution.Y / 2 );
            posClick += camera.Pos;

            spriteBatch.DrawString(font, (MouseCord.X-GameInterface.Width).ToString() + "," + MouseCord.Y.ToString(), new Vector2(10,0), Color.Red);
            spriteBatch.DrawString(font, ((int)posClick.X).ToString() + "," + ((int)posClick.Y).ToString(), new Vector2(10, 50), Color.Red);
            spriteBatch.DrawString(font, ((int)Fighters[0].position.X).ToString() + "," + ((int)Fighters[0].position.Y).ToString(), new Vector2(10, 100), Color.Red);

            spriteBatch.DrawString(font, "{" + camera.Pos.GetMapPosition(GameMap).X + "," + camera.Pos.GetMapPosition(GameMap).Y + "}", new Vector2(10, 150), Color.Purple);

            spriteBatch.DrawString(font, "{" + posClick.GetMapPosition(GameMap).X + "," + posClick.GetMapPosition(GameMap).Y + "}", new Vector2(10, 200), Color.Plum);

            spriteBatch.DrawString(font, "{" + Math.Floor(posClick.X * 2 / GameMap.TileShift.X) + "," + Math.Floor(posClick.Y * 2 / GameMap.TileShift.Y) + "}", new Vector2(10, 250), Color.Maroon);

            Vector2 test = new Vector2(47, 3);
            test.GetMapPosition(GameMap);

            spriteBatch.End();
        }