Пример #1
0
        public Player(char[,] mapObstacles, Color playerColor)
        {
            color         = playerColor;
            speed         = 12.0f;
            direction     = PlayerDirection.UP;
            isHumanPlayer = false;
            isAlive       = true;

            trailHistory = new List <TrailSector>();

            currentTrail = new TrailSector(direction, color);
            SetBeginningPos(mapObstacles);
            //SetDirection(mapObstacles);

            directionChanged = false;
        }
Пример #2
0
        public void createNewTrail()
        {
            currentTrail.isCurrentTrail   = false;
            currentTrail.isFirstOnHistory = true;

            TrailSector firstOnHistory = trailHistory.Find(i => i.isFirstOnHistory);

            if (firstOnHistory != null)
            {
                firstOnHistory.isFirstOnHistory = false;
            }

            trailHistory.Add(currentTrail);

            currentTrail = new TrailSector(direction, color);
            currentTrail.beginningPoint = currentTrail.endPoint = position;
        }
Пример #3
0
        public static bool CollideWithTrail(Player player, TrailSector trailSector)
        {
            float obstacle_x1 = 0, obstacle_x2 = 0, obstacle_y1 = 0, obstacle_y2 = 0;

            switch (trailSector.direction)
            {
            case PlayerDirection.LEFT:
                obstacle_x1 = (float)trailSector.beginningPoint.X - TrailSector.TRAIL_DEPTH;
                obstacle_x2 = (float)trailSector.beginningPoint.X + TrailSector.TRAIL_DEPTH;

                obstacle_y2 = (float)trailSector.beginningPoint.Z;
                obstacle_y1 = (float)trailSector.endPoint.Z;
                break;

            case PlayerDirection.RIGHT:
                obstacle_x1 = (float)trailSector.beginningPoint.X - TrailSector.TRAIL_DEPTH;
                obstacle_x2 = (float)trailSector.beginningPoint.X + TrailSector.TRAIL_DEPTH;

                obstacle_y1 = (float)trailSector.beginningPoint.Z;
                obstacle_y2 = (float)trailSector.endPoint.Z;
                break;

            case PlayerDirection.UP:
                obstacle_x1 = (float)trailSector.beginningPoint.X;
                obstacle_x2 = (float)trailSector.endPoint.X;

                obstacle_y1 = (float)trailSector.beginningPoint.Z - TrailSector.TRAIL_DEPTH;
                obstacle_y2 = (float)trailSector.endPoint.Z + TrailSector.TRAIL_DEPTH;
                break;

            case PlayerDirection.DOWN:
                obstacle_x2 = (float)trailSector.beginningPoint.X;
                obstacle_x1 = (float)trailSector.endPoint.X;

                obstacle_y1 = (float)trailSector.beginningPoint.Z - TrailSector.TRAIL_DEPTH;
                obstacle_y2 = (float)trailSector.endPoint.Z + TrailSector.TRAIL_DEPTH;
                break;
            }

            Rectangle trailRect = new Rectangle(obstacle_x1, obstacle_x2, obstacle_y1, obstacle_y2);

            return(trailRect.CollideWithRectancle(player.hitBox));
        }