int UnitInd; //index of the next unit in one cell of gameobjects grid

        #endregion Fields

        #region Constructors

        internal NearObjectsIterator(GameVector Center, float Radius, ArrayList[,] gameObjects)
        {
            this.gameObjects = gameObjects;
            this.Radius = Radius;
            UpdateCenter(Center);
            Reset();
        }
Exemplo n.º 2
0
        public override void Init(int PlayerNumber, IGame Game)
        {
            if (PlayerNumber == 0) sign = 1;
            else sign = -1;
            AngleForward=1.57f*(1-sign);
            base.Init(PlayerNumber, Game);

            cruisers= CreateSquadron();
            corvettes= CreateSquadron();

            destroyers= CreateSquadron();

            for (int i = 0; i < friends.Count; i++)
            {
                if (friends[i].Type == ShipTypes.Cruiser) cruisers.AddUnit(friends[i]);
                else
                {
                    if (friends[i].Type == ShipTypes.Destroyer)
                    {

                        destroyers.AddUnit(friends[i]);
                    }
                    else
                    {

                        corvettes.AddUnit(friends[i]);
                    }
                }
            }
            center = cruisers.formation.GetMassCenter();
            cruisers.SetFormationTypeLine(600);
            destroyers.SetFormationTypeBar(10,200,150);
            corvettes.SetFormationTypeLine(600);

            corvettes.ArrayOrder(center-GameVector.UnitX*1000*sign, AngleForward);
            cruisers.ArrayOrder(center, AngleForward);
            destroyers.ArrayOrder(center-GameVector.UnitX * 2000*sign, AngleForward);

            timer = new Timer(3);

            Stage = 0;
        }
Exemplo n.º 3
0
 public Unit(ShipTypes ShipType, string Name, GameVector Position, GameVector Size, DerivativeControlledParameter Speed,
     DerivativeControlledParameter RotationSpeed,
     DerivativeControlledParameter RotationAngle, Gun Gun, float HP, int team, Shots shots, float BlowDamage, float BlowRadius)
 {
     shipType = ShipType;
     blowDamage = BlowDamage;
     blowRadius = BlowRadius;
     name = Name;
     position = Position;
     size = Size;
     speed = Speed;
     rotationSpeed = RotationSpeed;
     rotationAngle = RotationAngle;
     gun = Gun;
     gun.owner = this;
     this.hp = HP;
     this.team = team;
     maxTimeAfterDeath = 5 * 0.2f;
     timeAfterDeath = 0;
     IsAliveInPrevLoop = true;
     this.shots = Core.shots;
 }
 public void GetNearObjects(GameVector Position, float Radius, out List<Unit> NearUnits, out List<Shots.Shot> NearShots)
 {
     NearUnits = new List<Unit>();
     NearShots = new List<Shots.Shot>();
     int RadiusLogic = (int)(Radius / cellSize) + 1;// (int)(CruiserSize.Y / (border / (float)gameObjectsCCells)) + 1;
     int X = GetLogicCoo(Position.X);
     int Y = GetLogicCoo(Position.Y);
     //if (RadiusLogic == 0 && (GetLogicCoo(X + 10) != X || GetLogicCoo(X - 10) != X || GetLogicCoo(Y + 10) != Y || GetLogicCoo(Y - 10) != Y))
     //{
     //    RadiusLogic++;
     //}
     int minX, minY, maxX, maxY;
     minX = (int)Math.Min(Math.Max(X - RadiusLogic, 0), gameObjectsCCells - 1);
     minY = (int)Math.Min(Math.Max(Y - RadiusLogic, 0), gameObjectsCCells - 1);
     maxX = (int)Math.Min(Math.Max(X + RadiusLogic, 0), gameObjectsCCells - 1);
     maxY = (int)Math.Min(Math.Max(Y + RadiusLogic, 0), gameObjectsCCells - 1);
     int i, j, k;
     for (i = minX; i <= maxX; i++)
         for (j = minY; j <= maxY; j++)
         {
             for (k = 0; k < gameObjects[i, j].Count; k++)
             {
                 Unit nearUnit = gameObjects[i, j][k] as Unit;
                 if (nearUnit != null)
                 {
                     NearUnits.Add(nearUnit);
                 }
                 else
                 {
                     Shots.Shot nearShot = gameObjects[i, j][k] as Shots.Shot;
                     if (nearShot != null)
                     {
                         NearShots.Add(nearShot);
                     }
                 }
             }
         }
 }
Exemplo n.º 5
0
 /// <summary>
 /// finds distance square between two points
 /// </summary>
 /// <param name="pt1">first operand</param>
 /// <param name="pt2">second operand</param>
 /// <returns>float distance square</returns>
 public static float DistanceSquared(GameVector pt1, GameVector pt2)
 {
     return (pt2 - pt1).LengthSquared();
 }
Exemplo n.º 6
0
 public void Update()
 {
     lifeTime -= Core.Timing.DeltaTime;
     PrevPos = pos;
     pos += direction * Core.Timing.DeltaTime;
 }
Exemplo n.º 7
0
 /// <summary>
 /// mulls GameVector with specified matrix
 /// </summary>
 /// <param name="vec"></param>
 /// <param name="matrix"></param>
 /// <returns></returns>
 public static GameVector Mull(GameVector vec, Matrix matrix)
 {
     return new GameVector(
         matrix.values[0, 0] * vec.X + matrix.values[1, 0] * vec.Y + matrix.values[2, 0],
         matrix.values[0, 1] * vec.X + matrix.values[1, 1] * vec.Y + matrix.values[2, 1]);
 }
Exemplo n.º 8
0
 /// <summary>
 /// calculates rotated vector
 /// </summary>
 /// <param name="Vector">vector to rotate</param>
 /// <param name="Angle">angle in radians to rotate CCW</param>
 /// <returns>rotated vector</returns>
 public static GameVector Rotate(GameVector Vector, float Angle)
 {
     return new GameVector((float)(Vector.X * Math.Cos(Angle) - Vector.Y * Math.Sin(Angle)), (float)(Vector.X * Math.Sin(Angle) + Vector.Y * Math.Cos(Angle)));
 }
Exemplo n.º 9
0
 public void HitSomebody(GameVector where)
 {
     hitSomebody = true;
 }
Exemplo n.º 10
0
 /// <summary>
 /// value is constant vector
 /// </summary>
 /// <param name="value">value vector</param>
 public RelativeVector(GameVector value)
 {
     constValue = value;
     mode = Modes.ConstVector;
 }
Exemplo n.º 11
0
 public override void CreatePositions(GameVector CenterPosition, float Angle)
 {
     if (subordinates.Count > 0)
     {
         rotationAngle = Angle;
         GameVector center = CenterPosition;
         DefineLinesFormation(Angle);
         int CLines = (subordinates.Count - 1) / cUnitsInLine + 1;
         int ind = 0;
         for (int currLine = 0; currLine < CLines; currLine++)
         {
             for (int currColumn = 0; currColumn < cUnitsInLine && ind < subordinates.Count; currColumn++)
             {
                 subordinates[ind].Position =
                     new RelativeVector(center -
                     LinesPosDifference * (currLine - CLines * 0.5f + 0.5f) +
                     NearUnitsPosDifference * (currColumn - cUnitsInLine * 0.5f + 0.5f));
                 ind++;
             }
         }
         SortUnitsByNearanceToPositions();
     }
 }
Exemplo n.º 12
0
        internal void Update()
        {
            if (hp > 0)
            {
                #region obsolete
                if (goesToPoint)
                {
                    float AngleToTgt = GetAngleTo(tgtLocation);
                    SetAngleGoingToTgt(AngleToTgt);
                    float distanceSq = GameVector.DistanceSquared(position, tgtLocation);
                    float timeToStop = speed.Value / speed.MaxDerivative;
                    float StopDistanceSq = speed.Value * timeToStop - speed.MaxDerivative * timeToStop * timeToStop / 2;
                    if (AngleClass.Distance(GetAngleTo(tgtLocation), rotationAngle.Value) < MathHelper.PiOver4 &&
                        (StopDistanceSq < GameVector.DistanceSquared(position, tgtLocation) || !stopsNearPoint))
                        SetSpeedGoingToTgt(MaxSpeed);
                    else SetSpeedGoingToTgt(0);
                    //if (distanceSq < 30*30&&speed.Value<10) { goesToPoint = false; }
                }
                #endregion
                gun.Update();
                if (rotationAngle.AimEnabled)
                {
                    float AimIsNearDecrementing;
                    //rotationAngle.RotateCCWToAngle(rotationAngle.AimedValue, out AimIsNear);
                    if (rotationAngle.RotateCCWToAngle(rotationAngle.AimedValue, out AimIsNearDecrementing))
                    {
                        if (rotationSpeed.Value < 0)
                            rotationSpeed.Derivative = rotationSpeed.MaxDerivative;
                        else
                            rotationSpeed.Derivative = rotationSpeed.MaxDerivative * AimIsNearDecrementing;
                    }
                    else
                    {
                        if (rotationSpeed.Value > 0)
                            rotationSpeed.Derivative = -rotationSpeed.MaxDerivative;
                        else
                            rotationSpeed.Derivative = -rotationSpeed.MaxDerivative * AimIsNearDecrementing;
                    }
                    //if (StopRotation && Math.Abs(rotationSpeed.Value) < 0.08f)
                    //    rotationSpeed = new DerivativeControlledParameter(0, rotationSpeed.Min, rotationSpeed.Max, rotationSpeed.MaxDerivative, false);
                }
                //rotationSpeed.Derivative *= AimIsNearDecrementing;

                rotationSpeed.Update();
                rotationAngle.Derivative = rotationSpeed.Value;
                //                rotationAngle.Derivative = (rotationAngle.AimedValue - rotationAngle.Value) * 0.05f;
                rotationAngle.Update();
                speed.Update();
                position += ForwardVector * speed.Value * Core.Timing.DeltaTime;
                isDying = false;
            }
            else
            {
                if (IsAliveInPrevLoop) isDying = true;
                else isDying = false;
                timeAfterDeath += Core.Timing.DeltaTime;
                IsAliveInPrevLoop = false;
            }
        }
Exemplo n.º 13
0
 private float GetAngleTo(GameVector Target)
 {
     return (float)Math.Atan2(Target.Y - position.Y, Target.X - position.X);
 }
Exemplo n.º 14
0
 public void GoTo(GameVector TargetLocation, bool Stop)
 {
     if (AccessDenied()) return;
     goesToPoint = true;
     stopsNearPoint = Stop;
     tgtLocation = new GameVector(TargetLocation.X, TargetLocation.Y);
 }
Exemplo n.º 15
0
 public bool IntersectsSector(GameVector pt1, GameVector pt2)
 {
     GameVector intersection;
     return this.GetRectangle().IntersectsLine(
         pt1, pt2, out intersection);
 }
Exemplo n.º 16
0
 public MiniGameInterfaces.Rectangle GetRectangle()
 {
     GameVector forward = ForwardVector;
     GameVector right = new GameVector(forward.Y, -forward.X);
     forward *= size.X * 0.5f;
     right *= size.Y * 0.5f;
     return new MiniGameInterfaces.Rectangle(forward - right + position, forward + right + position,
         -forward + right + position, -forward - right + position);
 }
Exemplo n.º 17
0
 public float AngleTo(GameVector target)
 {
     return GetAngleTo(new GameVector(target.X, target.Y));
 }
Exemplo n.º 18
0
 /// <summary>
 /// Calculates angle direction to Target vector end from this vector end
 /// </summary>
 /// <param name="Target">target vector</param>
 /// <returns>angle to target</returns>
 public float AngleTo(GameVector Target)
 {
     return (Target - this).Angle();
 }
 public void UpdateCenter(GameVector NewCenter)
 {
     Center = NewCenter;
     RadiusLogic = (int)(Radius / GameObjectsClass.cellSize) + 1;
     int X = GameObjectsClass.GetLogicCoo(Center.X);
     int Y = GameObjectsClass.GetLogicCoo(Center.Y);
     minX = (int)Math.Min(Math.Max(X - RadiusLogic, 0), GameObjectsClass.gameObjectsCCells - 1);
     minY = (int)Math.Min(Math.Max(Y - RadiusLogic, 0), GameObjectsClass.gameObjectsCCells - 1);
     maxX = (int)Math.Min(Math.Max(X + RadiusLogic, 0), GameObjectsClass.gameObjectsCCells - 1);
     maxY = (int)Math.Min(Math.Max(Y + RadiusLogic, 0), GameObjectsClass.gameObjectsCCells - 1);
 }
Exemplo n.º 20
0
 public override void CreatePositions(GameVector CenterPosition, float Angle)
 {
     rotationAngle = Angle;
     Line line = DefineLineFormation(rotationAngle, CenterPosition);
     CreateLinePositions(line);
     SortUnitsByNearanceToPositions();
 }
Exemplo n.º 21
0
 /// <summary>
 /// Converts vector to an outputable string
 /// Output example for GameVector(56.45f,67.96f) is "(56;68)"
 /// </summary>
 /// <param name="vec">Vector to output</param>
 /// <returns>Vector in a readable format</returns>
 public static string VectorToString(GameVector vec)
 {
     return "(" + Math.Round(vec.X) + ";" + Math.Round(vec.Y).ToString() + ")";
 }
Exemplo n.º 22
0
        public override void CreatePositions(GameVector CenterPosition, float Angle)
        {
            if (subordinates.Count > 0)
            {
                rotationAngle = Angle;
                GameVector center = CenterPosition;
                float FormationLength = heightBetweenUnits * subordinates.Count / 2;
                GameVector forward = GameVector.UnitX.Rotate(Angle);
                GameVector right = forward.Rotate(AngleClass.pi * 0.5f);
                int PositionInd;

                subordinates[0].Position = new RelativeVector(center + forward * FormationLength * 0.5f);
                for (int currPilot = 1; currPilot < subordinates.Count; currPilot += 2)
                {
                    PositionInd = currPilot / 2 + 1;
                    subordinates[currPilot].Position = new RelativeVector(center + forward * (FormationLength * 0.5f - PositionInd * heightBetweenUnits)
                        + right * (PositionInd * widthBetweenUnits));

                    if (currPilot + 1 < subordinates.Count)
                        subordinates[currPilot + 1].Position = new RelativeVector(center + forward * (FormationLength * 0.5f - PositionInd * heightBetweenUnits)
                        - right * (PositionInd * widthBetweenUnits));
                }
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Creates positions for units in this formation
 /// </summary>
 /// <param name="CenterPosition">Center of the new order</param>
 /// <param name="Angle">Forward angle of the new position</param>
 public abstract void CreatePositions(GameVector CenterPosition, float Angle);
Exemplo n.º 24
0
 /// <summary>
 /// finds a dot product of two vectors
 /// </summary>
 /// <param name="pt1">first vector</param>
 /// <param name="pt2">second vector</param>
 /// <returns>float dot product</returns>
 public static float Dot(GameVector pt1, GameVector pt2)
 {
     return pt1.X * pt2.X + pt1.Y * pt2.Y;
 }
Exemplo n.º 25
0
 private void DefineLinesFormation(float Angle)
 {
     LinesPosDifference = GameVector.UnitX.Rotate(Angle);
     NearUnitsPosDifference = LinesPosDifference.Rotate(AngleClass.pi * 0.5f);
     LinesPosDifference *= widthBetweenUnits;
     NearUnitsPosDifference *= heightBetweenUnits;
 }
Exemplo n.º 26
0
 /// <summary>
 /// normalizes a given vector
 /// </summary>
 /// <param name="pt">vector to normalize</param>
 /// <returns>normalized vector</returns>
 public static GameVector Normalize(GameVector pt)
 {
     return pt / pt.Length();
 }
Exemplo n.º 27
0
 private Line DefineLineFormation(float RotationAngle, GameVector center)
 {
     float length = distBetweenUnits * (subordinates.Count - 1);
     GameVector toVertexDir = GameVector.UnitX.Rotate(RotationAngle + AngleClass.pi * 0.5f) * 0.5f * length;
     return new Line(center + toVertexDir, center - toVertexDir);
 }
Exemplo n.º 28
0
 public Unit(ShipTypes ShipType, int Player, GameVector Position, float Angle, string Name)
 {
     shipType = ShipType;
     switch (shipType)
     {
         case ShipTypes.Destroyer:
             blowDamage = 70;
             blowRadius = 40;
             name = Name;
             position = Position;
             size = Core.DestroyerSize;
             speed = new DerivativeControlledParameter(0, 0, 20 * TimingClass.SpeedsMultiplier, 9 * TimingClass.SpeedsMultiplier, false);
             rotationSpeed = new DerivativeControlledParameter(0, -0.22f * TimingClass.SpeedsMultiplier, 0.22f * TimingClass.SpeedsMultiplier, 0.5f * TimingClass.SpeedsMultiplier, false);
             rotationAngle = new DerivativeControlledParameter(Angle, -MathHelper.Pi, MathHelper.Pi, 1000, true);
             gun = new Gun(1, 50 * TimingClass.SpeedsMultiplier, 9 / TimingClass.SpeedsMultiplier, 15);
             gun.owner = this;
             this.hp = 80;
             this.team = Player;
             maxTimeAfterDeath = 5 * 0.2f;
             timeAfterDeath = 0;
             IsAliveInPrevLoop = true;
             this.shots = Core.shots;
             break;
         case ShipTypes.Corvette:
             blowDamage = 150;
             blowRadius = 120;
             maxTimeAfterDeath = 5 * 0.2f;
             speed = new DerivativeControlledParameter(0, 0, 5 * TimingClass.SpeedsMultiplier, 1 * TimingClass.SpeedsMultiplier, false);
             rotationSpeed = new DerivativeControlledParameter(0, -0.12f * TimingClass.SpeedsMultiplier, 0.12f * TimingClass.SpeedsMultiplier, 0.39f * TimingClass.SpeedsMultiplier, false);
             gun = new Gun(1, 50 * TimingClass.SpeedsMultiplier, 18 / TimingClass.SpeedsMultiplier, 40);
             this.hp = 400;
             this.team = Player;
             IsAliveInPrevLoop = true;
             this.shots = Core.shots;
             timeAfterDeath = 0;
             name = Name;
             position = Position;
             size = Core.CorvetteSize;
             //size.Y *= 0.9f; //real object size (see texture)
             rotationAngle = new DerivativeControlledParameter(
                 Angle
                 , -MathHelper.Pi, MathHelper.Pi, 1000, true);
             gun.owner = this;
             break;
         case ShipTypes.Cruiser:
             blowDamage = 300;
             blowRadius = 150;
             maxTimeAfterDeath = 8 * 0.2f;
             speed = new DerivativeControlledParameter(0, 0, 2 * TimingClass.SpeedsMultiplier, 1.0f * TimingClass.SpeedsMultiplier, false);
             rotationSpeed = new DerivativeControlledParameter(0, -0.05f * TimingClass.SpeedsMultiplier, 0.05f * TimingClass.SpeedsMultiplier, 0.2f * TimingClass.SpeedsMultiplier, false);
             gun = new Gun(4, 50 * TimingClass.SpeedsMultiplier, 27 / TimingClass.SpeedsMultiplier, 200);
             this.hp = 800;
             this.team = Player;
             IsAliveInPrevLoop = true;
             this.shots = Core.shots;
             timeAfterDeath = 0;
             name = Name;
             position = Position;
             size = Core.CruiserSize;
             //size.X *= 0.7f; //real object size (see texture)
             //size.Y *= 0.9f; //real object size (see texture)
             rotationAngle = new DerivativeControlledParameter(
                 Angle
                 , -MathHelper.Pi, MathHelper.Pi, 1000, true);
             gun.owner = this;
             break;
     }
 }
Exemplo n.º 29
0
 public override void CreatePositions(GameVector CenterPosition, float Angle)
 {
     //nothing to do
 }
Exemplo n.º 30
0
 public Shot(GameVector Pos, GameVector Dir, float Damage, float LifeTime, Unit ParentUnit)
 {
     parent = ParentUnit;
     switch (parent.ShipType)
     {
         case ShipTypes.Destroyer:
             size = 24; break;
         case ShipTypes.Corvette:
             size = 48; break;
         case ShipTypes.Cruiser:
             size = 90; break;
         default: size = 1; break;
     }
     pos = Pos;
     PrevPos = pos;
     direction = Dir;
     damage = Damage;
     lifeTime = LifeTime;
     hitSomebody = false;
     forward = GameVector.Normalize(direction);
 }