Пример #1
0
 static public Vector2D operator*(Vector2D A, Vector2D B)
 {
     Vector2D temp = new Vector2D();
     temp.x = A.x * B.x;
     temp.y = A.y * B.y;
     return temp;
 }
Пример #2
0
 static public Vector2D operator *(float B, Vector2D A)
 {
     Vector2D temp = new Vector2D();
     temp.x = A.x * (double)B;
     temp.y = A.y * (double)B;
     return temp;
 }
Пример #3
0
 static public Vector2D operator *(Vector2D A, double B)
 {
     Vector2D temp = new Vector2D();
     temp.x = A.x * B;
     temp.y = A.y * B;
     return temp;
 }
Пример #4
0
 public void SetRendererPreDraw(ImageBuffer background, RendererBase rendererToDrawWith, Player playerToCenterOn)
 {
     rendererToDrawWith.PushTransform();
     Vector2D windowCenter = new Vector2D(screenWindow.Left + (screenWindow.Right - screenWindow.Left) / 2, screenWindow.Bottom + (screenWindow.Top - screenWindow.Bottom) / 2);
     Vector2D playerPos = playerToCenterOn.Position;
     Vector2D playfieldOffset = windowCenter - playerPos;
     if (playfieldOffset.x > screenWindow.Left)
     {
         playfieldOffset.x = screenWindow.Left;
     }
     if (playfieldOffset.x < -background.Width() + screenWindow.Right)
     {
         playfieldOffset.x = -background.Width() + screenWindow.Right;
     }
     if (playfieldOffset.y > screenWindow.Bottom)
     {
         playfieldOffset.y = screenWindow.Bottom;
     }
     if (playfieldOffset.y < -background.Height() + screenWindow.Top)
     {
         playfieldOffset.y = -background.Height() + screenWindow.Top;
     }
     Affine translation = Affine.NewTranslation(playfieldOffset);
     rendererToDrawWith.SetTransform(rendererToDrawWith.GetTransform() * translation);
     rendererToDrawWith.SetClippingRect(screenWindow);
 }
Пример #5
0
 public double Dot(Vector2D B)
 {
 	return (x*B.x + y*B.y);
 }
Пример #6
0
 public double GetDeltaAngle(Vector2D A)
 {
     return (double)GetDeltaAngle(GetAngle0To2PI(), A.GetAngle0To2PI());
 }
Пример #7
0
 public double GetSquaredDistanceTo(Vector2D Other)
 {
     return ((x - Other.x) * (x - Other.x) + (y - Other.y) * (y - Other.y));
 }
Пример #8
0
		public override void Update(double numSecondsPassed)
		{
            acceleration = moveDir;

            if (acceleration.x != 0 || acceleration.y != 0)
            {
                acceleration.Normalize();
                acceleration *= m_PlayerStyleSheetReference.Instance.ThrustAcceleration;
            }

			m_Velocity += acceleration * numSecondsPassed;
            m_Velocity *= m_PlayerStyleSheetReference.Instance.Friction;

            if (IsTouching(playfieldOn.key))
            {
                entityHolding = playfieldOn.key;
                hasKey = true;
            }

            if (entityHolding != null)
            {
                Vector2D newPosition = Position;
                newPosition.x += 8;
                entityHolding.Position = newPosition;
            }

			base.Update(numSecondsPassed);
		}
Пример #9
0
        public void LengthAndDistance()
        {
            Random Rand = new Random();
            Vector2D Test1 = new Vector2D(Rand.NextDouble() * 1000, Rand.NextDouble() * 1000);
            Vector2D Test2 = new Vector2D(Rand.NextDouble() * 1000, Rand.NextDouble() * 1000);
            Vector2D Test3 = Test1 + Test2;
            double Distance1 = Test2.GetLength();
            double Distance2 = Vector2D.GetDistanceBetween(Test1, Test3);

            Assert.IsTrue(Distance1 < Distance2 + .001f && Distance1 > Distance2 - .001f);
        }
Пример #10
0
 public void Rotate()
 {
     Vector2D TestVector = new Vector2D(1, 0);
     TestVector.Rotate((double)System.Math.PI / 2);
     Assert.IsTrue(TestVector.Equals(new Vector2D(0, 1), .001f));
 }
Пример #11
0
        public void GetLengthAndNormalize()
        {
            Vector2D Point3 = new Vector2D(3, -4);
            Assert.IsTrue(Point3.GetLength() > 4.999f && Point3.GetLength() < 5.001f);

            Point3.Normalize();
            Assert.IsTrue(Point3.GetLength() > 0.99f && Point3.GetLength() < 1.01f);
        }
Пример #12
0
 static public Vector2D operator /(double B, Vector2D A)
 {
     Vector2D temp = new Vector2D();
     temp.x = A.x / B;
     temp.y = A.y / B;
     return temp;
 }
Пример #13
0
 public SequenceEntity(Vector2D position, Playfield in_playfield)
     : base(3, in_playfield)
 {
     Position = position;
 }
Пример #14
0
        //updates the ANN with information from the sweepers enviroment
        public bool Update(List<Vector3> mines)
        {

            //this will store all the inputs for the NN
            List<double> inputs = new List<double>();

            //get List to closest mine
            Vector3 vClosestMine = GetClosestMine(mines);

            //normalise it
            vClosestMine.Normalize();

#if false
            // get the angle to the closest mine
            Vector3 DeltaToMine = vClosestMine - m_vPosition;
            Vector2D DeltaToMine2D = new Vector2D(DeltaToMine.x, DeltaToMine.y);
            Vector2D LookAt2D = new Vector2D(m_vLookAt.x, m_vLookAt.y);
            double DeltaAngle = LookAt2D.GetDeltaAngle(DeltaToMine2D);

            inputs.Add(DeltaAngle);
            inputs.Add(DeltaAngle);
            inputs.Add(DeltaAngle);
            inputs.Add(DeltaAngle);
#else

            //add in List to closest mine
            inputs.Add(vClosestMine.x);
            inputs.Add(vClosestMine.y);

            //add in sweepers look at List
            inputs.Add(m_vLookAt.x);
            inputs.Add(m_vLookAt.y);
#endif

            //update the brain and get feedback
            List<double> output = m_ItsBrain.Update(inputs);

            //make sure there were no errors in calculating the 
            //output
            if (output.Count < m_ItsBrain.NumOutputs)
            {
                return false;
            }

            //assign the outputs to the sweepers left & right tracks
            m_lTrack = output[0];
            m_rTrack = output[1];

            //calculate steering forces
            double RotForce = m_lTrack - m_rTrack;

            //clamp rotation
            RotForce = System.Math.Min(System.Math.Max(RotForce, -m_dMaxTurnRate), m_dMaxTurnRate);

            m_dRotation += RotForce;

            m_dSpeed = (m_lTrack + m_rTrack);

            //update Look At 
            m_vLookAt.x = (double)-System.Math.Sin(m_dRotation);
            m_vLookAt.y = (double)System.Math.Cos(m_dRotation);

            //update position
            m_vPosition += (m_vLookAt * m_dSpeed);

            //wrap around window limits
            if (m_vPosition.x > m_WindowWidth) m_vPosition.x = 0;
            if (m_vPosition.x < 0) m_vPosition.x = m_WindowWidth;
            if (m_vPosition.y > m_WindowHeight) m_vPosition.y = 0;
            if (m_vPosition.y < 0) m_vPosition.y = m_WindowHeight;

            return true;
        }
Пример #15
0
        void PlaceObjectsOnLevel()
        {
            ImageBuffer levelMap = LevelMap;
            int offset;
            byte[] buffer = levelMap.GetBuffer(out offset);

            for (int y = 0; y < levelMap.Height(); y++)
            {
                for (int x = 0; x < levelMap.Width(); x++)
                {
                    offset = levelMap.GetBufferOffsetXY(x, y);
                    switch (buffer[offset])
                    {
                        case 220:
                            // this is the sword.
                            sword = new Sword();
                            sword.Position = new Vector2D(x * 16 + 8, y * 16 + 8);
                            break;

                        case 170:
                            // this is the key.
                            key = new Key();
                            key.Position = new Vector2D(x * 16 + 8, y * 16 + 8);
                            keyStart = key.Position;
                            break;

                        case 2:
                            // this is the red player.
                            playerList[0].Position = new Vector2D(x * 16 + 8, y * 16 + 8);
                            break;

                        case 35:
                            // this is the green player.
                            playerList[1].Position = new Vector2D(x * 16 + 8, y * 16 + 8);
                            break;

                        case 251:
                            // this is the blue player.
                            playerList[2].Position = new Vector2D(x * 16 + 8, y * 16 + 8);
                            break;

                        case 5:
                            // this is the yellow player.
                            playerList[3].Position = new Vector2D(x * 16 + 8, y * 16 + 8);
                            break;

                        case 248:
                            // this is the shield.
                            shield = new Shield();
                            shield.Position = new Vector2D(x * 16 + 8, y * 16 + 8);
                            break;

                        default:
                            break;
                    }
                }
            }
        }
Пример #16
0
        public Player(int in_playerIndex, Keys in_leftKey, Keys in_rightKey,
            Keys in_downKey, Keys in_upKey, Playfield in_playfield)
			: base(26, in_playfield)
		{
            playfieldOn = in_playfield;
            playerIndex = in_playerIndex;
            leftKey = in_leftKey;
            downKey = in_rightKey;
            rightKey = in_downKey;
            upKey = in_upKey;

            int playerSequenceIndex = GetPlayerIndex();
            m_Radius = 8;
			Position = new Vector2D(GameWidth/2, GameHeight/2);
			m_Velocity.Zero();
        }
Пример #17
0
		public void Respawn()
		{
			Random rand = new Random();
			Position = new Vector2D(rand.NextDouble() * GameWidth, rand.NextDouble() * GameHeight);
            m_Velocity.Zero();			
		}
Пример #18
0
 public double Cross(Vector2D B)
 {
     return x * B.y - y * B.x;
 }
Пример #19
0
        public void ArithmaticOperations()
        {
            Vector2D Point1 = new Vector2D();
            Point1.Set(1, 1);

            Vector2D Point2 = new Vector2D();
            Point2.Set(2, 2);

            Vector2D Point3 = Point1 + Point2;
            Assert.IsTrue(Point3 == new Vector2D(3, 3));

            Point3 = Point1 - Point2;
            Assert.IsTrue(Point3 == new Vector2D(-1, -1));

            Point3 += Point1;
            Assert.IsTrue(Point3 == new Vector2D(0, 0));

            Point3 += Point2;
            Assert.IsTrue(Point3 == new Vector2D(2, 2));

            Point3 *= 6;
            Assert.IsTrue(Point3 == new Vector2D(12, 12));

            Vector2D InlineOpLeftSide = new Vector2D(5, -3);
            Vector2D InlineOpRightSide = new Vector2D(-5, 4);
            Assert.IsTrue(InlineOpLeftSide + InlineOpRightSide == new Vector2D(.0f, 1));

            Assert.IsTrue(InlineOpLeftSide - InlineOpRightSide == new Vector2D(10.0f, -7));
        }
Пример #20
0
        // are they the same within the error value?
        public bool Equals(Vector2D OtherVector, double ErrorValue)
        {
            if ((x < OtherVector.x + ErrorValue && x > OtherVector.x - ErrorValue) &&
                (y < OtherVector.y + ErrorValue && y > OtherVector.y - ErrorValue))
            {
                return true;
            }

            return false;
        }
Пример #21
0
 public void ScalerOperations()
 {
     Vector2D ScalarMultiplicationArgument = new Vector2D(5.0f, 4.0f);
     Assert.IsTrue(ScalarMultiplicationArgument * -.5 == new Vector2D(-2.5f, -2));
     Assert.IsTrue(ScalarMultiplicationArgument / 2 == new Vector2D(2.5f, 2));
     Assert.IsTrue(2 / ScalarMultiplicationArgument == new Vector2D(2.5f, 2));
     Assert.IsTrue(5 * ScalarMultiplicationArgument == new Vector2D(25, 20));
 }
Пример #22
0
        public Vector2D GetPerpendicular()
        {
            Vector2D temp = new Vector2D(y, -x);

            return temp;
        }
Пример #23
0
        public void DotProduct()
        {
            Random Rand = new Random();
            Vector2D TestVector2D1 = new Vector2D(Rand.NextDouble() * 1000, Rand.NextDouble() * 1000);
            Vector2D TestVector2D2 = new Vector2D(Rand.NextDouble() * 1000, Rand.NextDouble() * 1000);
            double Cross2D = TestVector2D1.Dot(TestVector2D2);

            Vector3D TestVector3D1 = new Vector3D(TestVector2D1.x, TestVector2D1.y, 0);
            Vector3D TestVector3D2 = new Vector3D(TestVector2D2.x, TestVector2D2.y, 0);
            double Cross3D = TestVector3D1.Dot(TestVector3D2);

            Assert.IsTrue(Cross3D == Cross2D);
        }
Пример #24
0
		public virtual void Update(double numSecondsPassed)
		{
            Vector2D newPosition = m_Position + m_Velocity * numSecondsPassed;

            if (newPosition.x < GameWidth-1 && newPosition.x > 0
                && newPosition.y < GameHeight-1 && newPosition.y > 0)
            {
                if (IsCollision(newPosition))
                {
                    // first try to negate the x and check again
                    m_Velocity.x = -m_Velocity.x;
                    newPosition = m_Position + m_Velocity * numSecondsPassed;
                    if (IsCollision(newPosition))
                    {
                        // there is still a collision, negate y and try again
                        m_Velocity.x = -m_Velocity.x; // first put x back
                        m_Velocity.y = -m_Velocity.y;
                        newPosition = m_Position + m_Velocity * numSecondsPassed;
                        if (IsCollision(newPosition))
                        {
                            // still a collision try negating both
                            m_Velocity.x = -m_Velocity.x; // y is negating just need x
                            newPosition = m_Position + m_Velocity * numSecondsPassed;
                            if (IsCollision(newPosition))
                            {
                                // still a collision, don't let the player go here
                                newPosition = m_Position;
                                m_Velocity.Zero();
                            }
                        }
                    }
                }
            }

            if (newPosition.x > GameWidth)
			{
                m_Velocity.x = -m_Velocity.x;
                newPosition.x = GameWidth;
			}
            if (newPosition.x < 0)
			{
                m_Velocity.x = -m_Velocity.x;
                newPosition.x = 0;
			}
            if (newPosition.y > GameHeight)
			{
                m_Velocity.y = -m_Velocity.y;
                newPosition.y = GameHeight;
			}
            if (newPosition.y < 0)
			{
                m_Velocity.y = -m_Velocity.y;
                newPosition.y = 0;
			}

            m_Position = newPosition;
        }
Пример #25
0
 public static double GetDistanceBetween(Vector2D A, Vector2D B)
 {
     return (double)System.Math.Sqrt(GetDistanceBetweenSquared(A, B));
 }
Пример #26
0
        public Entity(double radius, Playfield in_playfield)
		{
            levelMap = in_playfield.LevelMap;
			m_Radius = radius;
			m_Velocity = new Vector2D(60,120);
		}
Пример #27
0
 public static double GetDistanceBetweenSquared(Vector2D A, Vector2D B)
 {
     return ((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
 }
Пример #28
0
        private bool IsCollision(Vector2D newPosition)
        {
            int offset;
            byte[] buffer = levelMap.GetBuffer(out offset);

            int xOnMap = ((int)(newPosition.x + .5)) / 16;
            int yOnMap = ((int)(newPosition.y + .5)) / 16;
            offset = levelMap.GetBufferOffsetXY(xOnMap, yOnMap);
            if (buffer[offset] == 0
                || !hasKey && buffer[offset] == 1)
            {
                return true;
            }

            return false;
        }