コード例 #1
0
ファイル: ObstacleGroup.cs プロジェクト: chengyimingvb/CYMUni
 void ParseObstacle()
 {
     Obstacles.Clear();
     ObsColliders.Clear();
     ObsColliders2D.Clear();
     Obstacle[]   temps      = GetComponentsInChildren <Obstacle>();
     Collider[]   colTemps   = GetComponentsInChildren <Collider>();
     Collider2D[] colTemps2D = GetComponentsInChildren <Collider2D>();
     MainCollider   = GetComponent <Collider>();
     MainCollider2D = GetComponent <Collider2D>();
     if (temps != null)
     {
         foreach (var item in temps)
         {
             Obstacles.Add(item);
         }
     }
     if (colTemps != null)
     {
         foreach (var item in colTemps)
         {
             ObsColliders.Add(item);
         }
     }
     if (colTemps2D != null)
     {
         foreach (var item in colTemps2D)
         {
             ObsColliders2D.Add(item);
         }
     }
 }
コード例 #2
0
        public override void Update(GameTime gt)
        {
            if ((Mouse.LeftMouseDown || Mouse.RightMouseDown) && Mouse.CanPress)
            {
                Point coords = GetCoordinates(Mouse.Position);

                if (Mouse.LeftMouseDown)
                {
                    if (SpotExists(coords))
                    {
                        foreach (int[] pair in Spots)
                        {
                            if (pair[0] == coords.X && pair[1] == coords.Y)
                            {
                                Spots.Remove(pair);

                                break;
                            }
                        }
                    }
                    else
                    {
                        Spots.Add(new int[2] {
                            coords.X, coords.Y
                        });
                    }

                    Console.WriteLine("\n=========================================\nNew Spots:");
                    Spots.ForEach(x => Console.WriteLine("\t\t\t\tnew int[] { " + x[0] + ", " + x[1] + " },"));
                }
                else
                {
                    if (SpotExists(coords))
                    {
                        if (ObstacleExists(coords.X, coords.Y))
                        {
                            foreach (int[] pair in Obstacles)
                            {
                                if (pair[0] == coords.X && pair[1] == coords.Y)
                                {
                                    Obstacles.Remove(pair);

                                    break;
                                }
                            }
                        }
                        else
                        {
                            Obstacles.Add(new int[2] {
                                coords.X, coords.Y
                            });
                        }

                        Console.WriteLine("\n=========================================\nNew Obstacles:");
                        Obstacles.ForEach(x => Console.WriteLine("\t\t\t\tnew int[] { " + x[0] + ", " + x[1] + " },"));
                    }
                }
            }
        }
コード例 #3
0
 public void AddObstacle(Obstacle obstacle)
 {
     Obstacles.Add(obstacle);
     foreach (Edge edge in edges)
     {
         edge.active = false;
     }
 }
コード例 #4
0
ファイル: GameBoard.cs プロジェクト: dwsyip2/CarshoRusho
 public void RandomSpawnVehicle(PlayerVehicle p, Obstacle o)
 {
     _spawnpoints = _random.Next(0, 3);
     o.X          = positionX [_spawnpoints];
     o.Y          = UtilityFunction.InitialY;
     DifficultyHandler(p, o);
     Obstacles.Add(o);
     o.Draw();
 }
コード例 #5
0
        public void AddObstacle(Obstacle obstacle)
        {
            if (Obstacles.Any(x => x.OverlapsWith(obstacle)))
            {
                throw new Exception("Przeszkoda nakłada się na już istniejącą przeszkodę.");
            }

            Obstacles.Add(obstacle);
            GeneratePathfindingMap();
        }
コード例 #6
0
 /// <summary>
 /// Нужно больше препятствий!!!!11
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public static void SetMoreObstacles(object sender, EventArgs e)
 {
     Snake.NeedToStop = true;
     for (int i = 0; i < 30; i++)
     {
         Obstacles.Add(Circle.getRandomCircle());
     }
     PathFinder.FindRoute();
     Snake.NeedToStop = false;
 }
コード例 #7
0
        private void SpawnObstacle(object sender, EventArgs e)
        {
            Obstacle obst = new Obstacle(this);

            obst.Initialize();
            Obstacles.Add(obst);
            _obstacleContainer.Children.Add(obst.Element);
            _spawnTimer.Interval = GetObstacleSpawnTime();
            _spawnTimer.Stop();
        }
コード例 #8
0
        private void AddObstacle()
        {
            float   y = Util.Random.NextDouble() > 0.5 ? 0 : Util.Height - ObstacleTextures[0].Height - 64;
            Vector2 p = new Vector2(Util.Width - 32, y);

            Obstacles.Add(new Obstacle()
            {
                Texture  = ObstacleTextures[Util.Random.Next(0, 2)],
                Position = p
            });
        }
コード例 #9
0
    public void AddObstacle(NavMeshObstacle obstacle)
    {
        Vector2 obstacleCenter = new Vector2(obstacle.gameObject.transform.position.x, obstacle.gameObject.transform.position.y);
        Vector3 obstacleSize   = obstacle.gameObject.GetComponent <Renderer>().bounds.size;

        Rect obstacleRect = new Rect(obstacleCenter, obstacleSize);

        Obstacles.Add(obstacleRect);

        BlockedHex.UnionWith(GridHelper.BoxToHexList(obstacleCenter, obstacleSize, NavMap));
    }
コード例 #10
0
        private void AddElement(NavElement element)
        {
            if (element.NavType == NavElement.Type.Obstacle)
            {
                Obstacles.Add(element);
            }
            else if (element.NavType == NavElement.Type.Surface)
            {
                Surfaces.Add(element);
            }

            element.elementsGroupId = Id;
        }
コード例 #11
0
        // ----------------------------------------------------------------------------------------------------------------------------------------

        // Add an obstacle to the board
        public bool AddObstacle(Node NewPosition)
        {
            if (IsValidMovement(NewPosition))
            {
                BoardItem NewObstacle = new BoardItem
                {
                    Position = new Tuple <int, int>(NewPosition.X, NewPosition.Y),
                };
                BoardMatrix[NewPosition.X, NewPosition.Y] = (int)BoardPositionStatus.Obstacle;
                Obstacles.Add(NewObstacle);

                return(true);
            }
            return(false);
        }
コード例 #12
0
        // ----------------------------------------------------------------------------------------------------------------------------------------

        // Generate random obstacles
        private void GenerateRandomObstacles()
        {
            Double nObstacles = Math.Ceiling(((Size.Item1 + 1) * (Size.Item2 + 1)) * 0.2);

            while (nObstacles > 0)
            {
                Tuple <int, int> position    = RandomBoardPosition();
                BoardItem        NewObstacle = new BoardItem
                {
                    Position = position,
                };
                BoardMatrix[position.Item1, position.Item2] = (int)BoardPositionStatus.Obstacle;
                Obstacles.Add(NewObstacle);
                nObstacles--;
            }
        }
コード例 #13
0
        private void StoneEdge()
        {
            if (Obstacles == null)
            {
                Obstacles = new List <BaseObstacle>();
            }

            for (int i = 5; i < Width; i += 10)
            {
                Obstacles.Add(new Rock(new Location(i, 5), 1));
                Obstacles.Add(new Rock(new Location(i, Height - 5), 1));
            }

            for (int i = 5; i < Height; i += 10)
            {
                Obstacles.Add(new Rock(new Location(5, i), 1));
                Obstacles.Add(new Rock(new Location(Width - 5, i), 1));
            }
        }
コード例 #14
0
ファイル: Environment.cs プロジェクト: Pedrous/AutonomousCar
        private void generateEnvironment(World world, int numBoxes, Vector2 start, Vector2 destination)
        {
            Random r = new Random();

            Vector2 pos;
            float   size;
            float   orientation;

            for (int i = 0; i < numBoxes; i++)
            {
                do
                {
                    size        = (float)r.NextDouble() * 3f + 1f;
                    pos         = new Vector2((float)r.NextDouble() * GridWidth, (float)r.NextDouble() * GridHeight);
                    orientation = (float)r.NextDouble() * MathHelper.TwoPi;
                } while ((pos - start).LengthSquared() < 100f || (pos - destination).LengthSquared() < 100f || !checkObstacle(size, pos, orientation));
                Obstacles.Add(new BoxObstacle(world, size, size, pos, orientation));
            }
        }
コード例 #15
0
ファイル: Field.cs プロジェクト: Isgeny/BattleCity
        private void LoadStage()
        {
            string s = Properties.Resources.ResourceManager.GetString("Stage_" + (Stage % 71).ToString());
            int    i = 0, j = 0;

            for (int c = 0; c < s.Length; c++)
            {
                char ch = s[c];
                switch (ch)
                {
                case 'b':
                    Obstacles.Add(new Brick(GUIForm, new Rectangle(FromMatrixPos(i, j), new Size(32, 32))));
                    break;

                case 'c':
                    Obstacles.Add(new Concrete(GUIForm, new Rectangle(FromMatrixPos(i, j), new Size(32, 32))));
                    break;

                case 's':
                    Obstacles.Add(new Bush(GUIForm, new Rectangle(FromMatrixPos(i, j), new Size(32, 32))));
                    break;

                case 'w':
                    Obstacles.Add(new Water(GUIForm, new Rectangle(FromMatrixPos(i, j), new Size(32, 32))));
                    break;

                case 'i':
                    Obstacles.Add(new Ice(GUIForm, new Rectangle(FromMatrixPos(i, j), new Size(32, 32))));
                    break;

                default:
                    break;
                }
                j++;
                if (j > 25)
                {
                    i++;
                    j = 0;
                }
            }
            Obstacles.Add(new HQ(GUIForm, new Rectangle(FromMatrixPos(24, 12), new Size(64, 64))));
        }
コード例 #16
0
        // create path for PlugIn
        //
        //
        //        | gap |
        //
        //        f      b
        //        |\    /\        -
        //        | \  /  \       ^
        //        |  \/    \      |
        //        |  /\     \     |
        //        | /  \     c   top
        //        |/    \g  /     |
        //        /        /      |
        //       /|       /       V      z     y=0
        //      / |______/        -      ^
        //     /  e      d               |
        //   a/                          |
        //    |<---out-->|               o----> x
        //
        public static PolylinePathway GetTestPath()
        {
            if (TestPath == null)
            {
                const float pathRadius = 2;

                const int   pathPointCount = 7;
                const float size           = 30;
                float       top            = 2 * size;
                float       gap            = 1.2f * size;
                float       outter         = 2 * size;
                float       h          = 0.5f;
                Vector3[]   pathPoints = new Vector3[pathPointCount]
                {
                    new Vector3(h + gap - outter, 0, h + top - outter),                        // 0 a
                    new Vector3(h + gap, 0, h + top),                                          // 1 b
                    new Vector3(h + gap + (top / 2), 0, h + top / 2),                          // 2 c
                    new Vector3(h + gap, 0, h),                                                // 3 d
                    new Vector3(h, 0, h),                                                      // 4 e
                    new Vector3(h, 0, h + top),                                                // 5 f
                    new Vector3(h + gap, 0, h + top / 2)                                       // 6 g
                };

                Obstacle1.Center = Utilities.Interpolate(0.2f, pathPoints[0], pathPoints[1]);
                Obstacle2.Center = Utilities.Interpolate(0.5f, pathPoints[2], pathPoints[3]);
                Obstacle1.Radius = 3;
                Obstacle2.Radius = 5;
                Obstacles.Add(Obstacle1);
                Obstacles.Add(Obstacle2);

                Endpoint0 = pathPoints[0];
                Endpoint1 = pathPoints[pathPointCount - 1];

                TestPath = new PolylinePathway(pathPointCount,
                                               pathPoints,
                                               pathRadius,
                                               false);
            }
            return(TestPath);
        }
コード例 #17
0
        // create path for PlugIn
        //
        //
        //        | gap |
        //
        //        f      b
        //        |\    /\        -
        //        | \  /  \       ^
        //        |  \/    \      |
        //        |  /\     \     |
        //        | /  \     c   top
        //        |/    \g  /     |
        //        /        /      |
        //       /|       /       V      z     y=0
        //      / |______/        -      ^
        //     /  e      d               |
        //   a/                          |
        //    |<---out-->|               o----> x
        //
        public static PolylinePathway GetTestPath()
        {
            if (_testPath == null)
            {
                const float PATH_RADIUS = 2;

                const int   PATH_POINT_COUNT = 7;
                const float SIZE             = 30;
                const float TOP        = 2 * SIZE;
                const float GAP        = 1.2f * SIZE;
                const float OUTTER     = 2 * SIZE;
                const float H          = 0.5f;
                Vector3[]   pathPoints = new Vector3[PATH_POINT_COUNT]
                {
                    new Vector3(H + GAP - OUTTER, 0, H + TOP - OUTTER),                        // 0 a
                    new Vector3(H + GAP, 0, H + TOP),                                          // 1 b
                    new Vector3(H + GAP + (TOP / 2), 0, H + TOP / 2),                          // 2 c
                    new Vector3(H + GAP, 0, H),                                                // 3 d
                    new Vector3(H, 0, H),                                                      // 4 e
                    new Vector3(H, 0, H + TOP),                                                // 5 f
                    new Vector3(H + GAP, 0, H + TOP / 2)                                       // 6 g
                };

                Obstacle1.Center = Vector3.Lerp(pathPoints[0], pathPoints[1], 0.2f);
                Obstacle2.Center = Vector3.Lerp(pathPoints[2], pathPoints[3], 0.5f);
                Obstacle1.Radius = 3;
                Obstacle2.Radius = 5;
                Obstacles.Add(Obstacle1);
                Obstacles.Add(Obstacle2);

                Endpoint0 = pathPoints[0];
                Endpoint1 = pathPoints[PATH_POINT_COUNT - 1];

                _testPath = new PolylinePathway(pathPoints,
                                                PATH_RADIUS,
                                                false);
            }
            return(_testPath);
        }
コード例 #18
0
        public bool AddItem(Element item)
        {
            if (IsPaused)
            {
                return(false);
            }

            if (item != null)
            {
                if (item.CanAcquire)
                {
                    Items.Add(item.Id, item);
                }
                else
                {
                    Obstacles.Add(item.Id, item);
                }

                return(true);
            }

            return(false);
        }
コード例 #19
0
        private Obstacles GenerateBaseFarmObstacles()
        {
            Obstacles obstacles = new Obstacles();

            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(3.8, 3.8), 7.6, 7.6));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(1.8, 11.5), 3.6, 6));

            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(16.5, 3.8), 10.5, 7.6));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(21, 10), 1, 10));

            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(9, 12), 6, 6));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(9, 20), 2, 4));

            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(18.8, 24), 7.5, 2.5));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(20, 26), 5, 1.5));

            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(28.5, 16.5), 4, 3));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(26.5, 18.9), 1, 2.2));

            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(38, 16), 4, 10));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(28.1, 21.2), 7.5, 1.2));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(32.3, 22.5), 1, 10));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(34.8, 24), 4, 4));

            return obstacles;
        }
コード例 #20
0
        private Obstacles GenerateBaseBridgeObstacles()
        {
            Obstacles obstacles = new Obstacles();

            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(3.6, 6.3), 6.2, 11.2));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(3.6, 18.7), 6.2, 12.2));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(3.6, 31), 6.2, 11.2));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(3.2, 38.7), 7, 3));

            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(12.5, 6.3), 10, 11));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(12.5, 18.7), 10, 12.2));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(12.5, 31), 10, 11.2));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(12.5, 38.7), 10, 2.7));

            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(34, 1), 10.5, 2));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(34, 7.4), 10.5, 9.7));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(34, 18), 10.5, 10));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(34, 27.5), 10.5, 7.5));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(34, 35), 10.5, 6.5));
            obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(33, 39.5), 14, 1));

            return obstacles;
        }
コード例 #21
0
 /// <summary>
 /// Adds an obstacle
 /// </summary>
 /// <param name="x">The x coordinate</param>
 /// <param name="y">Thy y coordinate</param>
 public void AddObstacle(int x, int y) => Obstacles.Add(new Point(x, y));
コード例 #22
0
        /// <summary>
        /// Generates all the city stuff
        /// </summary>
        private void GenerateCity()
        {
            backgroundName = "City";
            Obstacles obstacles = new Obstacles();

            // Create obstacles
            for (double i = 3.5; i <= 38; i = i + 5.5)
                for (double j = 25.5; j <= 38; j = j + 5.5)
                    obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(j,i), 4, 4));

            for (double i = 25.5; i <= 38; i = i + 5.5)
                for (double j = 3.5; j <= 22; j = j + 5.5)
                    obstacles.Add(new RectangleObstacle(new HomeworkTwo.Point(j,i), 4, 4));

            // Set up workspace and generate nodes
            _workspace = new Workspace(X_MIN, X_MAX, Y_MIN, Y_MAX) { Obstacles = obstacles };
            _workspace.GenerateEvenGraph((UInt16)(X_RANGE + 1), (UInt16)(Y_RANGE + 1));

            Workspace airWorkspace = new Workspace(X_MIN, X_MAX, Y_MIN, Y_MAX) { };
            airWorkspace.GenerateEvenGraph((UInt16)(X_RANGE + 1), (UInt16)(Y_RANGE + 1));

            List<Node> groundPatrolPath = new List<Node>() {
                airWorkspace.GetNode(new HomeworkTwo.Point(1, 20)),
                airWorkspace.GetNode(new HomeworkTwo.Point(20, 20)),
                airWorkspace.GetNode(new HomeworkTwo.Point(20, 1)),
                airWorkspace.GetNode(new HomeworkTwo.Point(1, 1))};

            List<Node> airPatrolPath = new List<Node>() {
                airWorkspace.GetNode(new HomeworkTwo.Point(1, 39)),
                airWorkspace.GetNode(new HomeworkTwo.Point(39, 39)),
                airWorkspace.GetNode(new HomeworkTwo.Point(39, 1)),
                airWorkspace.GetNode(new HomeworkTwo.Point(1, 1))};

            // Create our agents
            List<RobotBase> pursuerRobots = new List<RobotBase>() {
                new GroundPursuer(GroundPursuerPatrol.TheInstance,
                    new HomeworkTwo.Point(1,1), // location
                    RADIUS, // radius
                    new Vector2D(), // intial velocity
                    MAX_SPEED * .8f, // max speed
                    new Vector2D(), // intial heading
                    MASS, // mass
                    new Vector2D(), // scale
                    TURN_RATE, // turn rate
                    MAX_FORCE, // max force
                    groundPatrolPath, // patrol path
                    _workspace, // traversability map
                    _workspace), // visibility map

                new AerialPursuer(AerialPursuerPatrol.TheInstance,
                    new HomeworkTwo.Point(1,15), // location
                    RADIUS, // radius
                    new Vector2D(), // intial velocity
                    MAX_SPEED, // max speed
                    new Vector2D(), // intial heading
                    MASS, // mass
                    new Vector2D(), // scale
                    TURN_RATE, // turn rate
                    MAX_FORCE, // max force
                    airPatrolPath, // patrol path
                    airWorkspace, // traversability map
                    airWorkspace) }; // visibility map

            List<Target> targetRobots = new List<Target>() { new Target(TargetPatrol.TheInstance,
                new HomeworkTwo.Point(30,39), // location
                RADIUS, // radius
                new Vector2D(), // intial velocity
                MAX_SPEED, // max speed
                new Vector2D(), // intial heading
                MASS, // mass
                new Vector2D(), // scale
                TURN_RATE, // turn rate
                MAX_FORCE, // max force
                new List<Node>(), // patrol path
                _workspace, // traversability map
                _workspace)}; // visibility map

            // Create our robot group with our agents
            _robotGroup = new RobotGroup(pursuerRobots, targetRobots, TIME_STEP_LENGTH, TIME_HORIZON, VISIBLITY_CRITERIA);
        }
コード例 #23
0
ファイル: ARoad.cs プロジェクト: Wedyarit/ObjectSurvival
 public void AddObstacle(AObstacle obstacle)
 {
     Obstacles.Add(obstacle);
 }
コード例 #24
0
ファイル: Environment.cs プロジェクト: Pedrous/AutonomousCar
        public ParkingEnvironment(World world) : base()
        {
            Random r = new Random();

            for (int i = 0; i < 50; i++)
            {
                if (r.NextDouble() < 0.98)
                {
                    Obstacles.Add(new BoxObstacle(world, 2 * Car.HALF_CAR_WIDTH, 2 * Car.HALF_CAR_LENGTH, new Vector2(-10 + i * 2.5f, 30)));
                }
            }
            for (int i = 0; i < 50; i++)
            {
                if (r.NextDouble() < 0.98)
                {
                    Obstacles.Add(new BoxObstacle(world, 2 * Car.HALF_CAR_WIDTH, 2 * Car.HALF_CAR_LENGTH, new Vector2(-10 + i * 2.5f, 35)));
                }
            }

            for (int i = 0; i < 20; i++)
            {
                if (r.NextDouble() < 0.98)
                {
                    Obstacles.Add(new BoxObstacle(world, 2 * Car.HALF_CAR_WIDTH, 2 * Car.HALF_CAR_LENGTH, new Vector2(20 + i * 2.5f, 60)));
                }
            }
            for (int i = 0; i < 20; i++)
            {
                if (r.NextDouble() < 0.98)
                {
                    Obstacles.Add(new BoxObstacle(world, 2 * Car.HALF_CAR_WIDTH, 2 * Car.HALF_CAR_LENGTH, new Vector2(20 + i * 2.5f, 55)));
                }
            }

            for (int i = 0; i < 40; i++)
            {
                if (r.NextDouble() < 0.98)
                {
                    Obstacles.Add(new BoxObstacle(world, 2 * Car.HALF_CAR_WIDTH, 2 * Car.HALF_CAR_LENGTH, new Vector2(80 + i * 2.5f, 60)));
                }
            }
            for (int i = 0; i < 40; i++)
            {
                if (r.NextDouble() < 0.98)
                {
                    Obstacles.Add(new BoxObstacle(world, 2 * Car.HALF_CAR_WIDTH, 2 * Car.HALF_CAR_LENGTH, new Vector2(80 + i * 2.5f, 55)));
                }
            }

            for (int i = 0; i < 40; i++)
            {
                if (r.NextDouble() < 0.95)
                {
                    Obstacles.Add(new BoxObstacle(world, 2 * Car.HALF_CAR_WIDTH, 2 * Car.HALF_CAR_LENGTH, new Vector2(-10 + i * 2.5f, 90)));
                }
            }
            for (int i = 0; i < 40; i++)
            {
                if (r.NextDouble() < 0.95)
                {
                    Obstacles.Add(new BoxObstacle(world, 2 * Car.HALF_CAR_WIDTH, 2 * Car.HALF_CAR_LENGTH, new Vector2(-10 + i * 2.5f, 85)));
                }
            }

            for (int i = 0; i < 40; i++)
            {
                if (r.NextDouble() < 0.95)
                {
                    Obstacles.Add(new BoxObstacle(world, 2 * Car.HALF_CAR_WIDTH, 2 * Car.HALF_CAR_LENGTH, new Vector2(90f + i * 2.5f, 90)));
                }
            }
            for (int i = 0; i < 40; i++)
            {
                if (r.NextDouble() < 0.95)
                {
                    Obstacles.Add(new BoxObstacle(world, 2 * Car.HALF_CAR_WIDTH, 2 * Car.HALF_CAR_LENGTH, new Vector2(92.5f + i * 2.5f, 85)));
                }
            }
        }
コード例 #25
0
ファイル: Engine.cs プロジェクト: elabbademouad/BasicSnak
        public void Move()
        {
            switch (FutureDirection)
            {
            case DirectionEnum.Left:
                if (Direction != DirectionEnum.Rigth)
                {
                    Direction = FutureDirection;
                }
                break;

            case DirectionEnum.Rigth:
                if (Direction != DirectionEnum.Left)
                {
                    Direction = FutureDirection;
                }
                break;

            case DirectionEnum.Top:
                if (Direction != DirectionEnum.Bottom)
                {
                    Direction = FutureDirection;
                }
                break;

            case DirectionEnum.Bottom:
                if (Direction != DirectionEnum.Top)
                {
                    Direction = FutureDirection;
                }
                break;
            }
            if (Root == Object)
            {
                _i++;
                CellViewModel _lastEntity;
                if (_listEntity.Count != 0)
                {
                    _lastEntity = _listEntity.Last();
                }
                else
                {
                    _lastEntity = Root;
                }

                var entity = Scene.Where(c => c.Position.X == _lastEntity.Position.X && c.Position.Y == _lastEntity.Position.Y).First();
                entity.Style = StyleEnum.Entity;
                _listEntity.Add(entity);
                Random r = new Random();
                Object       = (from c in Scene orderby r.Next() where c.Style == StyleEnum.Default select c).First();
                Object.Style = StyleEnum.Object;
                Score        = Score + 10;
                if (Speed > 120)
                {
                    Speed = Speed - 4;
                }

                if (_i == 4)
                {
                    var obstacle = (from c in Scene orderby r.Next() where c.Style == StyleEnum.Default select c).Take(4);
                    foreach (var item in obstacle)
                    {
                        item.Style = StyleEnum.Obstacle;
                        Obstacles.Add(item);
                    }
                    _i = 0;
                }
            }

            Root.Style = StyleEnum.Default;
            var _temp = Root;

            try
            {
                if (Obstacles.Contains(Root))
                {
                    throw new Exception("GameOver");
                }
                switch (Direction)
                {
                case DirectionEnum.Left:
                    Root       = Scene.Where(c => c.Position.X == Root.Position.X - 1 && c.Position.Y == Root.Position.Y).First();
                    Root.Style = StyleEnum.Entity;
                    break;

                case DirectionEnum.Rigth:
                    Root       = Scene.Where(c => c.Position.X == Root.Position.X + 1 && c.Position.Y == Root.Position.Y).First();
                    Root.Style = StyleEnum.Entity;
                    break;

                case DirectionEnum.Top:
                    Root       = Scene.Where(c => c.Position.X == Root.Position.X && c.Position.Y == Root.Position.Y - 1).First();
                    Root.Style = StyleEnum.Entity;
                    break;

                case DirectionEnum.Bottom:
                    Root       = Scene.Where(c => c.Position.X == Root.Position.X && c.Position.Y == Root.Position.Y + 1).First();
                    Root.Style = StyleEnum.Entity;
                    break;
                }
                if (_listEntity.Contains(Root))
                {
                    throw new Exception("GameOver");
                }
            }
            catch (Exception E)
            {
                if (E.Message == "GameOver")
                {
                    this.GameOver = true;
                }
                else
                {
                    switch (Direction)
                    {
                    case DirectionEnum.Left:
                        Root = Scene.Where(c => c.Position.X == 29 && c.Position.Y == Root.Position.Y).First();
                        break;

                    case DirectionEnum.Rigth:
                        Root = Scene.Where(c => c.Position.X == 0 && c.Position.Y == Root.Position.Y).First();
                        break;

                    case DirectionEnum.Top:
                        Root = Scene.Where(c => c.Position.Y == 29 && c.Position.X == Root.Position.X).First();
                        break;

                    case DirectionEnum.Bottom:
                        Root = Scene.Where(c => c.Position.Y == 0 && c.Position.X == Root.Position.X).First();
                        break;
                    }
                }
            }

            for (int i = 0; i < _listEntity.Count; i++)
            {
                var _temp2 = _listEntity[i];
                _listEntity[i].Style = StyleEnum.Default;
                _listEntity[i]       = _temp;
                _listEntity[i].Style = StyleEnum.Entity;
                _temp = _temp2;
            }
        }
コード例 #26
0
 public void AddObstacle(Cell cell)
 {
     Obstacles.Add(cell);
 }
コード例 #27
0
ファイル: MapLayer.cs プロジェクト: gon6109/sat
        /// <summary>
        /// マップのロード
        /// </summary>
        /// <param name="mapIO">マップデータ</param>
        /// <param name="initDoorID">初期ドアID</param>
        /// <param name="initSavePointID">初期セーブポイント</param>
        /// <param name="loader">ロードするオブジェクト</param>
        /// <returns></returns>
        public async Task LoadMapData(SatIO.MapIO mapIO, int initDoorID, int initSavePointID, ILoader loader)
        {
            //背景
            foreach (var item in mapIO.BackGrounds)
            {
                var backGround = await BackGround.CreateBackGroudAsync(item);

                AddObject(backGround);
                loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1);
            }

            //物理世界構築
            PhysicalWorld = new PhysicalWorld(new asd.RectF(new asd.Vector2DF(-200, -200), mapIO.Size + new asd.Vector2DF(200, 200) * 2), new asd.Vector2DF(0, 8000));

            //カメラ設定
            {
                PlayerCamera = new ScrollCamera(mapIO.CameraRestrictions);
                PlayerCamera.HomingObject = Player;
                PlayerCamera.Src          = new asd.RectI(0, 0, (int)OriginDisplaySize.X, (int)OriginDisplaySize.Y);
                PlayerCamera.MapSize      = mapIO.Size;
                AddObject(PlayerCamera);

                Camera.IsDrawn   = false;
                Camera.IsUpdated = false;
            }

            //障害物
            foreach (var item in mapIO.CollisionBoxes)
            {
                PhysicalRectangleShape temp = new PhysicalRectangleShape(PhysicalShapeType.Static, PhysicalWorld);
                temp.Density     = 1;
                temp.Restitution = 0;
                temp.Friction    = 0;
                temp.DrawingArea = new asd.RectF(item.Position, item.Size);
                Obstacles.Add(temp);
                loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1);
#if DEBUG
                asd.GeometryObject2D geometryObject = new asd.GeometryObject2D();
                geometryObject.Shape           = temp;
                geometryObject.Color           = new asd.Color(0, 0, 255, 100);
                geometryObject.DrawingPriority = 2;
                AddObject(geometryObject);
#endif
            }

            foreach (var item in mapIO.CollisionTriangles)
            {
                PhysicalTriangleShape temp = new PhysicalTriangleShape(PhysicalShapeType.Static, PhysicalWorld);
                temp.Density     = 1;
                temp.Restitution = 0;
                temp.Friction    = 0;
                var i = 0;
                foreach (var vertex in item.vertexes)
                {
                    temp.SetPointByIndex(vertex, i);
                    i++;
                }
                Obstacles.Add(temp);
                loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1);
#if DEBUG
                asd.GeometryObject2D geometryObject = new asd.GeometryObject2D();
                geometryObject.Shape           = temp;
                geometryObject.Color           = new asd.Color(0, 0, 255, 100);
                geometryObject.DrawingPriority = 2;
                AddObject(geometryObject);
#endif
            }

            //ドア
            var tempDoors = new List <Door>();
            foreach (var item in mapIO.Doors)
            {
                var door = await Door.CreateDoorAsync(item);

                door.OnLeave += OnLeave;
                AddObject(door);
                tempDoors.Add(door);
                loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1);
            }

            //マップオブジェクト
            foreach (var item in mapIO.MapObjects)
            {
                try
                {
                    var mapObject = await MapObject.CreateMapObjectAsync(item);

                    AddObject(mapObject);
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }
                loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1);
            }

            //イベントオブジェクト
            List <IActor> actors = new List <IActor>(GameScene.Players);
            foreach (var item in mapIO.EventObjects)
            {
                try
                {
                    var eventObject = await EventObject.CreateEventObjectAsync(item);

                    AddObject(eventObject);
                    actors.Add(eventObject);
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }
                loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1);
            }

            //イベント
            if (Scene is GameScene gameScene)
            {
                foreach (var item in mapIO.MapEvents)
                {
                    if (GameScene.EndEvents.Any(obj => obj.Key == gameScene.MapPath && obj.Value == item.ID))
                    {
                        continue;
                    }
                    try
                    {
                        bool isSkip = false;
                        foreach (var item2 in item.Actors.Where(obj => obj.Path != null && obj.Path.IndexOf(".pc") > -1))
                        {
                            if (!gameScene.CanUsePlayers.Any(obj => obj.Path == item2.Path))
                            {
                                isSkip = true;
                                break;
                            }
                        }
                        if (isSkip)
                        {
                            continue;
                        }
                        Object.MapEvent.MapEvent temp = await Object.MapEvent.MapEvent.CreateMapEventAsync(item, actors, PlayerCamera);

                        AddObject(temp);
                    }
                    catch (Exception e)
                    {
                        Logger.Error(e);
                    }
                    loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1);
                }
            }

            //セーブポイント
            List <SavePoint> tempSavePoints = new List <SavePoint>();
            foreach (var item in mapIO.SavePoints)
            {
                SavePoint savePoint = new SavePoint(item);
                AddObject(savePoint);
                tempSavePoints.Add(savePoint);
                loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1);
            }

            //プレイヤー初期配置
            if (initSavePointID != -1 && tempSavePoints.FirstOrDefault(savePoint => savePoint.ID == initSavePointID) != null)
            {
                Player.Position = tempSavePoints.FirstOrDefault(savePoint => savePoint.ID == initSavePointID).Position;
            }
            else if (initDoorID != -1 && tempDoors.FirstOrDefault(door => door.ID == initDoorID) != null)
            {
                Door door = tempDoors.FirstOrDefault(obj => obj.ID == initDoorID);
                Player.Position = door.Position;
                door.Come();
            }

            return;
        }
コード例 #28
0
 virtual public void AddObstacle(Obstacle obstacle)
 {
     Obstacles.Add(obstacle);
 }
コード例 #29
0
 public void AddWall(SpawnPoint s)
 {
     Obstacles.Add(s);
 }
コード例 #30
0
 public void AddMine(Mine m)
 {
     Obstacles.Add(m);
 }
コード例 #31
0
 public void AddBarrel(Barrel b)
 {
     Obstacles.Add(b);
 }
コード例 #32
0
 public void AddWall(Wall w)
 {
     Obstacles.Add(w);
 }
コード例 #33
0
    public void Load()
    {
        if (File.Exists(ActualLevel))
        {
            try
            {
                StreamReader input = new StreamReader(ActualLevel);
                string       line;
                do
                {
                    line = input.ReadLine();
                    if (line != null)
                    {
                        string[] blockData = line.Split(';');

                        string obstacleType = blockData[0].ToLower();
                        short  obstacleX    = short.Parse(blockData[1]);
                        short  obstacleY    = short.Parse(blockData[2]);

                        switch (blockData[0].ToLower())
                        {
                        case "w":     // Wall block.
                            Obstacles.Add(new Wall(obstacleX, obstacleY));
                            break;

                        case "b":     // Barrel.
                            Obstacles.Add(new Barrel(obstacleX, obstacleY));
                            break;

                        case "m":     // Mine.
                            Obstacles.Add(new Mine(obstacleX, obstacleY));
                            break;

                        case "s":     // Spawn point.
                            Obstacles.Add(new SpawnPoint(obstacleX, obstacleY));
                            break;

                        default:
                            break;
                        }
                    }
                } while (line != null);
                input.Close();
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("File not found!");
            }
            catch (PathTooLongException)
            {
                Console.WriteLine("Path too long exception!");
            }
            catch (IOException)
            {
                Console.WriteLine("Input/Output exception!");
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: " + e.Message);
            }
        }
    }