public PlayingState()
        {
            background = new SpriteGameObject("spr_Background", 0, "", 0, 80);
            this.Add(background);
            Cursor cursor = new Cursor(2);

            map = new MapV2(scale, new Point(50, 50));
            world.Add(map);

            player = new BaseEntity("spr_Humanoid", scale, map.RandomFreePositionInMap(), map, world, true, cursor);
            //Buffs player because else it is to hard
            player.movementSpeed *= 3;
            player.maxHealth     *= 4;
            player.health        *= 4;

            world.Add(player);
            //Adds enemies
            for (int i = 0; i < map.Columns / 5; i++)
            {
                world.Add(new BaseEntity("spr_Humanoid", scale, map.RandomFreePositionInMap(), map, world, false, player));
            }
            this.Add(world);
            this.Add(new MiniMap(map, player, world, new Point(42, 42), 1, MiniMap.ViewLoc.TopRight));

            hud = new HUD(player);
            this.Add(hud);
            this.Add(cursor);
        }
Пример #2
0
        public BaseEntity(String asset, int scale, Vector2 position, MapV2 map, GameObjectList world, bool isPlayer, SpriteGameObject targetEntity) : base(asset, scale)
        {
            this.isPlayer = isPlayer;

            this.Origin = this.Center;
            Color col1 = new Color(GameEnvironment.Random.Next(0, 255), GameEnvironment.Random.Next(0, 255), GameEnvironment.Random.Next(0, 255));
            Color col2 = new Color(GameEnvironment.Random.Next(0, 255), GameEnvironment.Random.Next(0, 255), GameEnvironment.Random.Next(0, 255));

            changedSprite = new Texture2D(GameEnvironment.Graphics, sprite.Sprite.Width, sprite.Sprite.Height);
            changedSprite.SetData <Color>(Custom.ColorSprite(sprite.Sprite, col1, col2));

            this.position      = position;
            this.map           = map;
            this.pathfindingAI = new PathfindingAI();
            this.targetEntity  = targetEntity;
            this.world         = world;

            this.movementSpeed  *= scale;
            this.health          = maxHealth;
            this.primaryAttack   = new Sword(scale, this, targetEntity, attack);
            this.secondaryAttack = new Bolt(scale, this, targetEntity, attack, map);
            world.Add(primaryAttack);
            world.Add(secondaryAttack);
        }
Пример #3
0
        public Vector2[] findPath(MapV2 map, SpriteGameObject obj, SpriteGameObject targetObj)
        {
            Point startPoint    = map.GridLoc(obj);
            Point endPoint      = map.GridLoc(targetObj);
            int   maxPathRadius = 20,
                  pathLength    = 0;

            Vector2[] path = new Vector2[0];
            //Check if player is in range
            if ((endPoint - startPoint).ToVector2().Length() < maxPathRadius)
            {
                //Initialize map
                int[,] gridMap = new int[map.Columns, map.Rows];
                //Create gridMap which stores the distance each tile is from the obj
                gridMap[startPoint.X, startPoint.Y] = 1;
                for (int i = 1; (i <= maxPathRadius) && (pathLength == 0); i++)
                {
                    //loop through grid
                    for (int x = Math.Max(0, startPoint.X - maxPathRadius); x < Math.Min(map.Columns, startPoint.X + maxPathRadius); x++)
                    {
                        for (int y = Math.Max(0, startPoint.Y - maxPathRadius); y < Math.Min(map.Rows, startPoint.Y + maxPathRadius); y++)
                        {
                            if (gridMap[x, y] == i)
                            {
                                //North
                                if (map.Get(x, y - 1) is Floor && gridMap[x, y - 1] == 0)
                                {
                                    gridMap[x, y - 1] = i + 1;
                                }
                                //West
                                if (map.Get(x - 1, y) is Floor && gridMap[x - 1, y] == 0)
                                {
                                    gridMap[x - 1, y] = i + 1;
                                }
                                //South
                                if (map.Get(x, y + 1) is Floor && gridMap[x, y + 1] == 0)
                                {
                                    gridMap[x, y + 1] = i + 1;
                                }
                                //East
                                if (map.Get(x + 1, y) is Floor && gridMap[x + 1, y] == 0)
                                {
                                    gridMap[x + 1, y] = i + 1;
                                }
                                //Path found?
                                if (x == endPoint.X && y == endPoint.Y)
                                {
                                    pathLength = i;
                                }
                            }
                        }
                    }
                }

                //Create shortest path
                Point   pathSpot = endPoint;
                Point[] gridPath = new Point[pathLength];
                if (pathLength > 0)
                {
                    gridPath[pathLength - 1] = endPoint;
                    for (int dist = pathLength - 1; dist > 0; dist += 0)
                    {
                        //North West South East
                        if (pathSpot.Y > 0 && gridMap[pathSpot.X, pathSpot.Y - 1] <= dist && gridMap[pathSpot.X, pathSpot.Y - 1] != 0)
                        {
                            pathSpot.Y--;
                            dist--;
                            gridPath[dist] = pathSpot;
                        }
                        if (pathSpot.X > 0 && gridMap[pathSpot.X - 1, pathSpot.Y] <= dist && gridMap[pathSpot.X - 1, pathSpot.Y] != 0)
                        {
                            pathSpot.X--;
                            dist--;
                            gridPath[dist] = pathSpot;
                        }
                        if (pathSpot.Y + 1 < map.Rows && gridMap[pathSpot.X, pathSpot.Y + 1] <= dist && gridMap[pathSpot.X, pathSpot.Y + 1] != 0)
                        {
                            pathSpot.Y++;
                            dist--;
                            gridPath[dist] = pathSpot;
                        }
                        if (pathSpot.X + 1 < map.Columns && gridMap[pathSpot.X + 1, pathSpot.Y] <= dist && gridMap[pathSpot.X + 1, pathSpot.Y] != 0)
                        {
                            pathSpot.X++;
                            dist--;
                            gridPath[dist] = pathSpot;
                        }
                    }
                }
                path = new Vector2[gridPath.Length];
                //Convert the gridPath locations to positions
                for (int i = 0; i < path.Length; i++)
                {
                    path[i] = gridPath[i].ToVector2() * map.CellWidth;
                }
            }
            //Return
            return(path);
        }