Пример #1
0
        public override float getRotation(SpriteObjects.Ship mShip, Body otherShipsBody, float rotationWeight)
        {
            float rotationChange = 99f;

            if (otherShipsBody == null || mShip.mSpriteBody == null)
            {
                return rotationChange;
            }

            Vector2 aIShipStartPoint = mShip.mSpriteBody.Position + GravitationUtils.rotateVector(new Vector2(0, -0.6f), mShip.mSpriteBody.Rotation); //mine
            Vector2 aIShipEndPoint = aIShipStartPoint + GravitationUtils.rotateVector(new Vector2(0, -5), mShip.mSpriteBody.Rotation);

            Vector2 aIPoint = new Vector2(aIShipStartPoint.Y - aIShipEndPoint.Y, aIShipStartPoint.X - aIShipEndPoint.X);

            Vector2 otherShipStartPoint = aIShipStartPoint;
            Vector2 otherShipEndPoint = otherShipsBody.Position;

            Vector2 otherShipPoint = new Vector2(otherShipStartPoint.Y - otherShipEndPoint.Y, otherShipStartPoint.X - otherShipEndPoint.X);

            float degreeDifference = GravitationUtils.radiansToDegrees(GravitationUtils.getAngleInRadians(aIPoint, otherShipPoint));

            if(degreeDifference > -10 && degreeDifference < 10) {
                rotationChange = 0;
            } else {
                rotationChange = (degreeDifference > 0) ? rotationWeight : -rotationWeight;
            }

            //Console.WriteLine("Rotation change is ["+rotationChange+"]  current ");

            //Console.WriteLine("rotational difference between ai and player is [" + radiansToDegrees(getAngleInRadians(aIPoint, otherShipPoint)) + "]");

            return rotationChange;
        }
Пример #2
0
        public override Vector2 getDirection(SpriteObjects.Ship mShip, Body otherShipsBody, float directionWeight)
        {
            float rearRayLength = mShip.getRayCastLengths.ElementAt(4); //length of raycast at the back of the ship
            float frontRayLength = mShip.getRayCastLengths.ElementAt(0); //length of raycast at the front of the ship
            Vector2 thrust = new Vector2(0, 99);

            //if (otherShipsBody == null || mShip.mSpriteBody == null)
            //{
            //    thrust = thrust;
            //}
            //else if (otherShipsBody.Position.Equals(mShip.mSpriteBody.Position))
            //{
            //    thrust = Vector2.Zero;
            //}

            if (rearRayLength < (-SpriteObjects.Ship.BASE_SHIP_RAYCAST_LENGTH))
            {
                thrust = new Vector2(0, -directionWeight);
            }
            //else
            //{
            //    thrust = Vector2.Zero;
            //}
            if ((frontRayLength < (-SpriteObjects.Ship.BASE_SHIP_RAYCAST_LENGTH)))
            {
                thrust = Vector2.Zero;
            }

            return thrust;
        }
Пример #3
0
        public override Vector2 getDirection(SpriteObjects.Ship mShip, Body otherShipsBody, float directionWeight)
        {
            Vector2 thrust = Vector2.Zero;

            if (otherShipsBody == null || mShip.mSpriteBody == null)
            {
                thrust = Vector2.Zero;
            }
            else if (otherShipsBody.Position.Equals(mShip.mSpriteBody.Position))
            {
                thrust = Vector2.Zero;
            }
            else
            {
                Vector2 startPoint = mShip.mSpriteBody.Position + GravitationUtils.rotateVector(new Vector2(0, -0.6f), mShip.mSpriteBody.Rotation);
                Vector2 otherShipEndPoint = otherShipsBody.Position;
                double xPoints = (otherShipEndPoint.X - startPoint.X) * (otherShipEndPoint.X - startPoint.X);
                double yPoints = (otherShipEndPoint.Y - startPoint.Y) * (otherShipEndPoint.Y - startPoint.Y);
                float totalLength = (float)Math.Sqrt((xPoints + yPoints));

                //Console.WriteLine("total line length is [" + totalLength + "]");
                if (totalLength > 5)
                {
                    thrust = new Vector2(0, -directionWeight);
                }
                else
                {
                    thrust = Vector2.Zero;
                }

            }
            return thrust;
        }
        public GameConfiguration(
                                String mapName,
                                SpriteObjects.Ship playerShip,
                                SpriteObjects.Ship player2Ship)
        {
            this.mShip = playerShip;
            this.mShip2 = player2Ship;

            this.mMapName = mapName;
        }
Пример #5
0
        public AIAgent(SpriteObjects.Ship ship, World world)
        {
            this.mShip = ship;
            this.mDirection = new Vector2(0, 0);
            this.mWorld = world;

            List<behaviour> behaviours = new List<behaviour>();
            //behaviours.Add(behaviour.SeekPlayer);
            //behaviours.Add(behaviour.FireOnSight);
            //behaviours.Add(behaviour.AvoidObsticles);
            ai = new AIEngine.AIEngine(DIRECTION_WEIGHT, ROTATION_WEIGHT, behaviours);
        }
Пример #6
0
        public MainMenu(int ScreenWidth, int ScreenHeight, SoundHandler player, SpriteObjects.Ship selectedShip)
            : base(ScreenWidth, ScreenHeight)
        {
            this.mPlayer = player;
            this.mScreenWidth = ScreenWidth;
            Title = "Gravitation";

            createBackground(ref mBackground, 0.5f, 0.5f);

            this.mShip = selectedShip;

            this.createMenuButtons();
            this.detailedSelectionContainer = new MenuL2Selection();
        }
 public void Remove(QBehavior script)
 {
     Objects.Remove(script.Parent);
     if (script is IQLoad l)
     {
         LoadObjects.Remove(l);
     }
     if (script is IQStart s)
     {
         StartObjects.Remove(s);
     }
     if (script is IQFixedUpdate u)
     {
         FixedUpdateObjects.Remove(u);
     }
     if (script is IQUpdate up)
     {
         UpdateObjects.Remove(up);
     }
     if (script is IQLateUpdate late)
     {
         LateUpdateObjects.Remove(late);
     }
     if (script is IQSprite ds)
     {
         SpriteObjects.Remove(ds);
     }
     if (script is IQGui dg)
     {
         GuiObjects.Remove(dg);
     }
     if (script is IQDestroy des)
     {
         des.OnDestroy();
         DestroyObjects.Remove(des);
     }
     if (script is IQUnload un)
     {
         UnloadObjects.Remove(un);
     }
     //invokes event even if does not inherit OnDestroy
     script.DestroyEvent();
 }
 public void Add(QBehavior script)
 {
     Objects.Add(script.Parent);
     if (script is IQLoad l)
     {
         LoadObjects.Add(l);
     }
     if (script is IQStart s)
     {
         StartObjects.Add(s);
     }
     if (script is IQFixedUpdate u)
     {
         FixedUpdateObjects.Add(u);
     }
     if (script is IQUpdate up)
     {
         UpdateObjects.Add(up);
     }
     if (script is IQLateUpdate late)
     {
         LateUpdateObjects.Add(late);
     }
     if (script is IQSprite ds)
     {
         SpriteObjects.Add(ds);
     }
     if (script is IQGui dg)
     {
         GuiObjects.Add(dg);
     }
     if (script is IQDestroy des)
     {
         DestroyObjects.Add(des);
     }
     if (script is IQUnload un)
     {
         UnloadObjects.Add(un);
     }
 }
Пример #9
0
        public override float getRotation(SpriteObjects.Ship mShip, Body otherShipsBody, float rotationWeight)
        {
            float rotationChange = 99f;
            int leftVote = 0;
            int rightVote = 0;
            List<float> rayLengths = mShip.getRayCastLengths;
            List<float> rightRayLengths = rayLengths.GetRange(1, 3);
            List<float> leftRayLengths = rayLengths.GetRange(5, 3);

            foreach (float rayLength in rightRayLengths)
            {
                if(rayLength < (-SpriteObjects.Ship.BASE_SHIP_RAYCAST_LENGTH)) {
                    leftVote++;
                }
            }

            foreach (float rayLength in leftRayLengths)
            {
                if(rayLength < (-SpriteObjects.Ship.BASE_SHIP_RAYCAST_LENGTH)) {
                    rightVote++;
                }
            }

            if (rightVote > leftVote)
            {
                rotationChange = rotationWeight;
            }
            else if (leftVote > rightVote)
            {
                rotationChange = -rotationWeight;
            }
            else
            {
                rotationChange = 99f;
            }

            return rotationChange;
        }
Пример #10
0
        public override void performAction(SpriteObjects.Ship mShip, Body otherShipsBody)
        {
            if (otherShipsBody == null || mShip.mSpriteBody == null)
            {
                return;
            }

            Vector2 aIShipStartPoint = mShip.mSpriteBody.Position + GravitationUtils.rotateVector(new Vector2(0, -0.6f), mShip.mSpriteBody.Rotation); //mine
            Vector2 aIShipEndPoint = aIShipStartPoint + GravitationUtils.rotateVector(new Vector2(0, -5), mShip.mSpriteBody.Rotation);

            Vector2 aIPoint = new Vector2(aIShipStartPoint.Y - aIShipEndPoint.Y, aIShipStartPoint.X - aIShipEndPoint.X);

            Vector2 otherShipStartPoint = aIShipStartPoint;
            Vector2 otherShipEndPoint = otherShipsBody.Position;

            Vector2 otherShipPoint = new Vector2(otherShipStartPoint.Y - otherShipEndPoint.Y, otherShipStartPoint.X - otherShipEndPoint.X);

            float degreeDifference = GravitationUtils.radiansToDegrees(GravitationUtils.getAngleInRadians(aIPoint, otherShipPoint));

            if (degreeDifference > -10 && degreeDifference < 10)
            {
                mShip.fire();
            }
        }
Пример #11
0
        private void createBackground(ref SpriteObjects.Sprite back, MapSurfacesBackgoundPicture backSpec)
        {
            Vector2 backPos = new Vector2(
                                            Convert.ToInt32(backSpec.Asset.Position.X),
                                            Convert.ToInt32(backSpec.Asset.Position.Y)
                                        );

            float backScaleX = (float)Convert.ToDecimal(backSpec.Asset.Scale.X);
            float backScaleY = (float)Convert.ToDecimal(backSpec.Asset.Scale.Y);

            float spriteRotation = (float)Convert.ToDecimal(backSpec.Asset.Rotation);

            back = new SpriteObjects.Sprite(backPos, spriteRotation);
            back.WidthScale = backScaleX;
            back.HeightScale = backScaleY;
        }
Пример #12
0
 public override void performAction(SpriteObjects.Ship mShip, Body otherShipsBody)
 {
     //no action to perform
 }
Пример #13
0
 public LocalAgent(SpriteObjects.Ship ship)
 {
     this.mShip = ship;
     this.mDirection = new Vector2(0, 0);
 }
Пример #14
0
        public void calculate(SpriteObjects.Ship mShip, Body otherShipsBody)
        {
            //loop round stores values for behaviours allowing higher weighted values
            //to be used first.
            Dictionary<int, float> possibleRotationVals = new Dictionary<int, float>();
            Dictionary<int, Vector2> possibleDirectionVals = new Dictionary<int, Vector2>();
            foreach (Behaviour b in enabledBehaviours) { //make sure behaviours are instantiated with their weights

                Vector2 thrust = b.getDirection(mShip, otherShipsBody, DIRECTION_WEIGHT);
                if(thrust.X == 0) {
                    thrust = (thrust.Y == 0) ? Vector2.Zero : mDirection + thrust;
                    possibleDirectionVals.Add(b.getWeight(), thrust);
                }

                float rotation = b.getRotation(mShip, otherShipsBody, ROTATION_WEIGHT);
                possibleRotationVals.Add(b.getWeight(), rotation);
                b.performAction(mShip, otherShipsBody);
            }

            foreach(int weight in possibleDirectionVals.Keys.OrderByDescending(x => x)) {
                if (possibleDirectionVals[weight].Y > 0)
                {
                    continue;
                }
                mDirection = possibleDirectionVals[weight];
                break;
            }

            foreach (int weight in possibleRotationVals.Keys.OrderByDescending(x => x))
            {
                if (possibleRotationVals[weight] == 99)
                {
                    continue;
                }
                mRotation = possibleRotationVals[weight];
                break;
            }

            if(mRotation == 0) {
                mShip.mSpriteBody.AngularVelocity = 0;
            }

            //possibly limit direction and rotation here back down to normal levels.
        }
Пример #15
0
        private void createObsicals(ref SpriteObjects.Obstical[] obsicals, MapSurfacesAsset[] obsicalsSpec)
        {
            obsicals = new SpriteObjects.Obstical[obsicalsSpec.Length];

            for (int i = 0; i < obsicals.Length; i++)
            {
                Vector2 obsticalPos = new Vector2(
                                               Convert.ToInt32(obsicalsSpec[i].Position.X),
                                               Convert.ToInt32(obsicalsSpec[i].Position.Y)
                                           );

                Vector2 obsticalPosScale = new Vector2(
                                            (float)Convert.ToDecimal(obsicalsSpec[i].Scale.X),
                                            (float)Convert.ToDecimal(obsicalsSpec[i].Scale.Y)
                    );

                float rotation = (float)Convert.ToDecimal(obsicalsSpec[i].Rotation);

                obsicals[i] = new SpriteObjects.Obstical(mWorld, obsticalPos, obsticalPosScale, rotation);
            }
        }
Пример #16
0
 public abstract void performAction(SpriteObjects.Ship mShip, Body otherShipsBody);
Пример #17
0
        private void createWall(ref SpriteObjects.Wall wall, MapSurfacesWall wallSpec)
        {
            Vector2 wallPos = new Vector2(
                                            Convert.ToInt32(wallSpec.Asset.Position.X),
                                            Convert.ToInt32(wallSpec.Asset.Position.Y)
                                        );

            Vector2 scale = new Vector2(
                                        (float)Convert.ToDecimal(wallSpec.Asset.Scale.X),
                                        (float)Convert.ToDecimal(wallSpec.Asset.Scale.Y)
                );

            float spriteRotation = (float)Convert.ToDecimal(wallSpec.Asset.Rotation);

            wall = new SpriteObjects.Wall(mWorld, wallPos, spriteRotation);
            wall.WidthScale = scale.X;
            wall.HeightScale = scale.Y;
        }
Пример #18
0
 public abstract Vector2 getDirection(SpriteObjects.Ship mShip, Body otherShipsBody, float directionWeight);
 public ShipConfiguration(SpriteObjects.Ship mShip)
 {
     this.mShip = mShip;
 }
 public void ShipConfig(SpriteObjects.Ship playerShip, SpriteObjects.Ship player2Ship)
 {
     this.mShip = playerShip;
     this.mShip2 = player2Ship;
 }
Пример #21
0
 public override Vector2 getDirection(SpriteObjects.Ship mShip, Body otherShipsBody, float directionWeight)
 {
     return new Vector2(9, 0); ; //hack for now
 }
Пример #22
0
        private void createBackground(ref SpriteObjects.Sprite back, float scaleX, float scaleY)
        {
            Vector2 backPos = new Vector2( 0, 0);

            float backScaleX = scaleX;
            float backScaleY = scaleY;

            float spriteRotation = 0f;

            back = new SpriteObjects.Sprite(backPos, spriteRotation);
            back.WidthScale = backScaleX;
            back.HeightScale = backScaleY;
        }
Пример #23
0
 public abstract float getRotation(SpriteObjects.Ship mShip, Body otherShipsBody, float rotationWeight);
Пример #24
0
 public override float getRotation(SpriteObjects.Ship mShip, Body otherShipsBody, float rotationWeight)
 {
     return 99f; //hack for now
 }