Example #1
0
        public void ProcessRoundAndSetTotalStage(Round round)
        {
            int partCount = 5;



            //shooting
            var createShells = round.turns.Select(x => x.WantsShoot && roundNumber - x.player.lastShootingRound >= 40 / SPEED_FASTER &&
                                                  (roundNumber - x.player.man.lastFreezed >= 300 / SPEED_FASTER)).ToList();//

            for (int i = 0; i < players.Count; i++)
            {
                if (createShells[i])
                {
                    var vector   = players[i].man.speedVector; //
                    var shellPos = players[i].man.position + vector.Normalized() * (5 + MAN_RADIUS);
                    _shellList.Add(new Shell
                    {
                        vectorSpeed = vector * 1000,
                        position    = shellPos,
                        Owner       = players[i]
                    });
                    players[i].lastShootingRound = roundNumber;
                }
            }


            //interpolations
            var interpolateFunctionMan = new List <InterpolationFunction>();

            _manAnimators = new List <Animator <Vector2d> >();
            _manList.ForEach(x =>
            {
                interpolateFunctionMan.Add(new InterpolationFunction(x.position, 1.0 / partCount));
                _manAnimators.Add(new Animator <Vector2d>(interpolateFunctionMan.Last().GetInterpolated, Vector2d.Zero, Vector2d.Zero, 1));
            });

            var interpolateFunctionShell = new List <InterpolationFunction>();

            _shellAnimators = new List <Animator <Vector2d> >();
            _shellList.ForEach(x =>
            {
                interpolateFunctionShell.Add(new InterpolationFunction(x.position, 1.0 / partCount));
                _shellAnimators.Add(new Animator <Vector2d>(interpolateFunctionShell.Last().GetInterpolated, Vector2d.Zero, Vector2d.Zero, 1));
            });



            //aims for man and shells
            var manSpeedsNormalized = new List <Vector2d>();
            var manAngleChange      = new List <double>();

            for (int i = 0; i < 4; i++)
            {
                var man = _manList[i];
                var pos = man.position;
                var wantsPointRelative = round.turns[i].manAim - pos;
                var nowRelative        = man.speedVector;
                var angle = wantsPointRelative.AngleDeg(nowRelative);

                manSpeedsNormalized.Add(nowRelative.Normalized());
                var goType = round.turns[i].GoType;
                if (goType == 1)
                {
                    manSpeedsNormalized[i] = manSpeedsNormalized[i] * (-1);
                }
                else if (goType == 2)
                {
                    manSpeedsNormalized[i] = manSpeedsNormalized[i].PerpendicularRight;
                }
                else if (goType == 3)
                {
                    manSpeedsNormalized[i] = manSpeedsNormalized[i].PerpendicularLeft;
                }

                if (angle > 180)
                {
                    angle = angle - 360;
                }
                manAngleChange.Add(Math.Min(0.1 / Math.PI * 180, angle));

                if ((roundNumber - man.lastFreezed < 300 / SPEED_FASTER))
                {
                    manAngleChange[i]      = 0.0001;
                    manSpeedsNormalized[i] = new Vector2d(0.000001);
                }
            }
            //var manTurnAim = round.turns.Select(turn =>
            //{

            //});
            //for (int i = 0; i < _manList.Count; i++)
            //{
            //    if ((manAims[i] - _manList[i].position).Length.DoubleLessOrEqual(0))
            //        manSpeedsNormalized.Add(Vector2d.UnitX * 0.00000001);
            //    else
            //        manSpeedsNormalized.Add((manAims[i] - _manList[i].position).Normalized());
            //}

            var shellSpeedNormalized = _shellList.Select(x => (x.vectorSpeed).Normalized()).ToList();



            var thereWasCollisionWithMan = Enumerable.Repeat(false, 10).ToList();

            //animate
            for (int partIndex = 1; partIndex <= partCount; partIndex++)
            {
                for (int i = 0; i < _shellList.Count; i++)
                {
                    _shellList[i].position += shellSpeedNormalized[i] * 10 * SPEED_FASTER / partCount;
                    interpolateFunctionShell[i].Add(_shellList[i].position);


                    var manAimed = _manList.FirstOrDefault(man => (_shellList[i].position - man.position).Length < SHELL_RADIUS + MAN_RADIUS);
                    if (manAimed != null)
                    {
                        if (roundNumber - manAimed.lastFreezed >= 300 / SPEED_FASTER)
                        {
                            manAimed.hp -= 10;
                            _shellList[i].Owner.score += 10;
                            if (manAimed.hp <= 0)
                            {
                                manAimed.hp          = 50;
                                manAimed.lastFreezed = roundNumber;
                            }
                        }

                        _shellAnimators.RemoveAt(i);
                        interpolateFunctionShell.RemoveAt(i);
                        _shellList.RemoveAt(i);
                        shellSpeedNormalized.RemoveAt(i);
                        i--;
                        continue;
                    }

                    if (_walls.Any(wall => GeomHelper.IsCircleIntersectsRect(_shellList[i].position, SHELL_RADIUS, wall)) ||
                        GeomHelper.PointInSimpleRect(_shellList[i].position, _arena) == false)
                    {
                        _shellList.RemoveAt(i);
                        _shellAnimators.RemoveAt(i);
                        interpolateFunctionShell.RemoveAt(i);
                        shellSpeedNormalized.RemoveAt(i);
                        i--;
                    }
                }

                //todo ball with wall
                var changePosition        = Enumerable.Repeat(true, 10).ToList();
                var alreadyExchangedSpeed = new List <Tuple <int, int> >();
                for (int i = 0; i < 4; i++)
                {
                    var    man      = _manList[i];
                    double manSpeed = 2.0 * SPEED_FASTER / partCount;
                    if (roundNumber - man.lastFreezed < 300 / SPEED_FASTER)
                    {
                        manSpeed = 0.000001;
                    }
                    //  bool _useDefendersSpeedIncrease, _useDefendersLimit;

                    manSpeedsNormalized[i] = manSpeedsNormalized[i].RotateDeg(manAngleChange[i] / partCount);
                    man.speedVector        = man.speedVector.RotateDeg(manAngleChange[i] / partCount);

                    if (changePosition[i])
                    {
                        #region перемещение игрока
                        var manWants = man.position + manSpeedsNormalized[i] * manSpeed;

                        //collided with man
                        for (int j = 0; j < _manList.Count; j++)
                        {
                            if (i == j)
                            {
                                continue;
                            }

                            if ((manWants - _manList[j].position).Length < MAN_RADIUS * 2)
                            {
                                thereWasCollisionWithMan[i] = thereWasCollisionWithMan[j] = true;
                                changePosition[i]           = false;

                                if (alreadyExchangedSpeed.Contains(Tuple.Create(i, j)) == false)
                                {
                                    var newSpeeds = Engine.ProcessManCollision(man.position, _manList[j].position, manSpeedsNormalized[i], manSpeedsNormalized[j]);
                                    manSpeedsNormalized[i] = newSpeeds.Item1;
                                    manSpeedsNormalized[j] = newSpeeds.Item2;
                                    alreadyExchangedSpeed.Add(Tuple.Create(i, j));
                                    alreadyExchangedSpeed.Add(Tuple.Create(j, i));
                                }
                            }
                        }

                        //collided with wall
                        if (changePosition[i])
                        {
                            double horizontalLimitLeft = 0, horizontalLimitRight = _arena.size.X;

                            if (manWants.X < horizontalLimitLeft + MAN_RADIUS || manWants.X > horizontalLimitRight - MAN_RADIUS)
                            {
                                manSpeedsNormalized[i] = new Vector2d(-manSpeedsNormalized[i].X, manSpeedsNormalized[i].Y);
                                changePosition[i]      = false;
                            }
                            if (manWants.Y < MAN_RADIUS || manWants.Y > _arena.size.Y - MAN_RADIUS)
                            {
                                manSpeedsNormalized[i] = new Vector2d(manSpeedsNormalized[i].X, -manSpeedsNormalized[i].Y);
                                changePosition[i]      = false;
                            }

                            if (_walls.Any(wall => GeomHelper.IsCircleIntersectsRect(manWants, MAN_RADIUS, wall)))
                            {
                                changePosition[i]      = false;
                                manSpeedsNormalized[i] = new Vector2d(-manSpeedsNormalized[i].X, -manSpeedsNormalized[i].Y);
                            }
                        }



                        if (changePosition[i])
                        {
                            man.position = manWants;
                        }
                        #endregion
                    }


                    interpolateFunctionMan[i].Add(man.position);
                }
            }

            round.totalStage = 1;
        }
Example #2
0
        public void DrawAll(Frame frame, double stage, double totalStage, bool humanMove, GlInput input) //todo human move??
        {
            if (allColors.Count == 0)
            {
                for (int i = 0; i <= 3; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        for (int k = 0; k < 4; k++)
                        {
                            allColors.Add(Color.FromArgb(i * 85, j * 85, k * 85));
                        }
                    }
                }
            }
            if (Debugger.IsAttached)
            {
                if (input.KeyTime(Key.Z) == 1)
                {
                    currentFieldColor = RandomColor();
                }
                if (input.KeyTime(Key.X) == 1)
                {
                    currentFieldOpacity += 0.1;
                    if (currentFieldOpacity > 1)
                    {
                        currentFieldOpacity = 0.5;
                    }
                }
                if (input.KeyTime(Key.C) == 1)
                {
                    topColorIndex++;
                    if (topColorIndex >= topColorList.Count)
                    {
                        topColorIndex = 0;
                    }
                    currentFieldColor = topColorList[topColorIndex];
                }
                if (input.KeyTime(Key.V) == 1)
                {
                    blackOpacity += 10;
                    if (blackOpacity >= 250)
                    {
                        blackOpacity = 40;
                    }
                }
                if (input.KeyTime(Key.B) == 1)
                {
                    blackOpacity = 0;
                    allColorIndex++;
                    if (allColorIndex >= allColors.Count)
                    {
                        allColorIndex = 0;
                    }
                    currentFieldColor = allColors[allColorIndex];
                }
            }

            // topColorIndex = 6;
            // currentFieldColor = topColorList[topColorIndex];
            blackOpacity        = 170;
            currentFieldOpacity = 0.90;

            //!!! будьте внимательны (ранний drawall перед любыми методами)
            int frameWidth = 112, frameHeight = 84;

            frame.CameraViewport(frameWidth, frameHeight);

            frame.Polygon(currentFieldColor, new Rect2d(0, 0, frameWidth, frameHeight)); //todo line around polygon

            var fieldCorner = new Vector2d((frameWidth - _arena.size.X - FrameworkSettings.Timeline.TileWidth) / 2, (frameHeight - _arena.size.Y) / 2);
            var lineWidth   = 0.4;

            //frame.Path(Color.Black, lineWidth, _arena + fieldCorner);
            //frame.Path(Color.Black, lineWidth, fieldCorner + new Vector2d(_arena.size.X / 2, 0), fieldCorner + new Vector2d(_arena.size.X / 2, _arena.size.Y));


            frame.SpriteCorner(ESprite.fieldPerfect, fieldCorner, sizeExact: _arena.size, opacity: currentFieldOpacity, depth: 1);
            // if (_manAnimators.Count != 0) //т е еще не было process turn
            //  {


            var blackColor = Color.FromArgb(blackOpacity, 0, 0, 0);

            frame.Polygon(blackColor, new Rect2d(0, 0, 1000, fieldCorner.Y));
            frame.Polygon(blackColor, new Rect2d(0, fieldCorner.Y, fieldCorner.X, _arena.size.Y));
            frame.Polygon(blackColor, new Rect2d(fieldCorner.X + _arena.size.X, fieldCorner.Y, 1000, _arena.size.Y));
            frame.Polygon(blackColor, new Rect2d(0, fieldCorner.Y + _arena.size.Y, 1000, 1000));


            for (int i = 0; i < _manList.Count; i++)
            {
                var man = _manList[i];
                if (i < 5)
                {
                    frame.SpriteCenter(ESprite.man03, _manAnimators[i].Get(stage) + fieldCorner, sizeOnlyWidth: 4, depth: 2, opacity: 1.0);
                }
                else
                {
                    frame.SpriteCenter(ESprite.man04, _manAnimators[i].Get(stage) + fieldCorner, sizeOnlyWidth: 4, depth: 2);
                }
                //frame.Circle(man.Color, _manAnimators[i].Get(stage) + fieldCorner, _manRadius);

                frame.TextCenter(EFont.playerNumbers, (i % 5).ToString(), _manAnimators[i].Get(stage) + fieldCorner, depth: 3);
            }

            //   var curMan = _manAnimators[6].Get(stage);



            //frame.Circle(Color.Gray, _ballAnimator.Get(stage) + fieldCorner, _ballRadius);
            if (_drawBall)
            {
                frame.SpriteCenter(ESprite.ball, _ballAnimator.Get(stage) + fieldCorner, sizeOnlyWidth: 2, depth: 2);
            }

            // }

            frame.TextBottomLeft(EFont.TeamOne, players[0].name, fieldCorner.X, fieldCorner.Y - 3); //todo framework text without declaration?
            frame.TextCustomAnchor(EFont.TeamTwo, players[1].name, 1, 1, fieldCorner.X + _arena.size.X, fieldCorner.Y - 3);

            frame.TextCustomAnchor(EFont.ScoreOne, players[0].score.ToString(), 1, 1, fieldCorner.X + _arena.size.X / 2 - 5, fieldCorner.Y - 3);
            frame.TextBottomLeft(EFont.ScoreTwo, players[1].score.ToString(), fieldCorner.X + _arena.size.X / 2 + 5, fieldCorner.Y - 3); //todo framework text without declaration?


            //frame.TextCustomAnchor(EFont.Time, roundNumber.ToString(), 0.5, 1, fieldCorner.X + _arena.size.X / 2, fieldCorner.Y - 3);


            if (GeomHelper.PointInSimpleRect(input.Mouse, _arena + fieldCorner))
            {
                var coord = input.Mouse - fieldCorner;
                var str   = string.Format("{0}  {1}", coord.X.Rounded(3), coord.Y.Rounded(3));
                frame.TextCustomAnchor(EFont.CoordsOnField, str, 0.5, 1, input.Mouse - Vector2d.UnitY * 1.5, depth: 101);
            }

            //  frame.SpriteCenter(ESprite.green, 100, 80, depth:1, sizeOnlyWidth:4);

            if (Debugger.IsAttached)
            {
                if (input.LeftMouseUp)
                {
                    var position = input.Mouse - fieldCorner;
                    if (GeomHelper.PointInSimpleRect(position, _arena))
                    {
                        _explosionStartedRound = roundNumber + 1;
                        explosionPosition      = position;
                    }
                }
            }

            if (roundNumber - _explosionStartedRound <= 2 && roundNumber >= _explosionStartedRound)
            {
                try
                {
                    frame.SpriteCenter(ESprite.explosion, explosionPosition + fieldCorner, sizeExact: new Vector2d(30), frameNumber:
                                       (int)((roundNumber - _explosionStartedRound) * 10 + stage * 10).ToRange(0, 30));
                }


                catch
                {
                }
            }

            if (_lastGoalRoundNumber != -1 && roundNumber - _lastGoalRoundNumber < _PARTY_AFTER_GOAL_TIME && roundNumber != _lastGoalRoundNumber)
            {
                frame.TextCenter(EFont.Goal, "ГОЛ !!!", fieldCorner + _arena.center, depth: 100000);
            }

            if (players.Sum(x => x.possession) > 0)
            {
                var pos = players[0].possession * 1.0 / players.Sum(x => x.possession);

                var one = (int)Math.Round(pos * 10000);
                var two = 10000 - one;

                double horsz = 0.6;
                var    rect  = new Rect2d(fieldCorner.X - horsz / 2, fieldCorner.Y + _arena.size.Y + 5.7, horsz, 2);

                frame.PolygonWithDepth(Color.FromArgb(150, 150, 150), 10, new Rect2d(fieldCorner.X, fieldCorner.Y + _arena.size.Y + 6.4, _arena.size.X, 0.6));
                frame.PolygonWithDepth(Color.FromArgb(150, 150, 150), 10, rect + Vector2d.UnitX * _arena.size.X * pos);

                //  if (this.GameFinished)
                {
                    frame.TextTopLeft(EFont.Possession, one.ToString(), fieldCorner.X, fieldCorner.Y + _arena.size.Y + 8, depth: 21);
                    frame.TextCustomAnchor(EFont.Possession, two.ToString(), 1, 0, fieldCorner.X + _arena.size.X, fieldCorner.Y + _arena.size.Y + 8, depth: 21);
                }
            }
        }