Пример #1
0
        private void HaveAttacked(SolidBody attacked, Vec2 position, float angle, IBullet bullet)
        {
            PointF locationObject = attacked.Shape.Location;
            ulong  idParent       = (Parent as Weapon).Owner.ID;

            float newDistance = VectorMethod.DefineDistance(position, new Vec2(locationObject.X, locationObject.Y));

            Parent.Model.AddOutgoingMessage(new MakedShot(idParent, angle, newDistance));

            if (attacked == null)
            {
                return;
            }

            var damageMsg = new GotDamage(idParent, bullet.Damage);

            attacked.Parent.Update(damageMsg);

            //определяем убили ли мы противника
            Healthy healthyAttacked = attacked.Parent.Components.GetComponent <Healthy>();

            if (healthyAttacked == null)
            {
                return;
            }
            //если убили засчитываем фраг
            if (healthyAttacked.HP < bullet.Damage)
            {
                (Parent as Weapon).Owner.Update(new MakedKill(idParent));
            }
        }
Пример #2
0
        private Segment CreateRayForShot(Vec2 positionGamer, float angle, float distance)
        {
            var segment = new Segment();

            //начальная точка выстрела
            segment.P1 = positionGamer;

            var sweepVector = VectorMethod.RotateVector(angle, distance);

            //конечная точка выстрела
            segment.P2 = new Vec2
            {
                X = positionGamer.X + sweepVector.X,
                Y = positionGamer.Y + sweepVector.Y
            };

            return(segment);
        }
Пример #3
0
        private void Handler_MakeShot(IMessage msg)
        {
            try
            {
                SolidBody BodyHolder = (Parent as Weapon).Owner?.Components?.GetComponent <SolidBody>();
                if (BodyHolder == null)
                {
                    Log.AddNewRecord("Ошибка получения держателя оружия");
                    return;
                }
                Vec2 position = (Vec2)BodyHolder.Body.GetPosition();

                //получаем патрон
                IBullet bullet = magazin.GetBullet();
                if (bullet == null)
                {
                    return;
                }

                //определяем угол
                float angle = VectorMethod.DefineAngle(position, new Vec2(msg.Location.X, msg.Location.Y));

                var rayOfShot = CreateRayForShot(position, angle, bullet.Distance);

                var attackedObject = DefineDamagedSolidBody(rayOfShot, (Parent as Weapon).Owner.ID);

                if (attackedObject == null)
                {
                    NotAttacked(angle, bullet.Distance);
                }
                else
                {
                    HaveAttacked(attackedObject, position, angle, bullet);
                }
            }
            catch (Exception e)
            {
                Log.AddNewRecord(e.ToString());
            }
        }
Пример #4
0
        private RectangleF CreateAndAddNewUniqueShape(List <RectangleF> occupiedArea, SizeF sizeObject)
        {
            RectangleF newShape;
            bool       haveIntersection;

            do
            {
                haveIntersection = false;
                newShape         = new RectangleF(VectorMethod.CreateRandPosition(LengthOfSideMap), sizeObject);

                foreach (var shape in occupiedArea)
                {
                    if (shape.IntersectsWith(newShape))
                    {
                        haveIntersection = true;
                        break;
                    }
                }
            } while (haveIntersection);

            occupiedArea.Add(newShape);

            return(newShape);
        }