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; }
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; }
static public Vector2D operator *(Vector2D A, double B) { Vector2D temp = new Vector2D(); temp.x = A.x * B; temp.y = A.y * B; return temp; }
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); }
public double Dot(Vector2D B) { return (x*B.x + y*B.y); }
public double GetDeltaAngle(Vector2D A) { return (double)GetDeltaAngle(GetAngle0To2PI(), A.GetAngle0To2PI()); }
public double GetSquaredDistanceTo(Vector2D Other) { return ((x - Other.x) * (x - Other.x) + (y - Other.y) * (y - Other.y)); }
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); }
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); }
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)); }
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); }
static public Vector2D operator /(double B, Vector2D A) { Vector2D temp = new Vector2D(); temp.x = A.x / B; temp.y = A.y / B; return temp; }
public SequenceEntity(Vector2D position, Playfield in_playfield) : base(3, in_playfield) { Position = position; }
//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; }
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; } } } }
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(); }
public void Respawn() { Random rand = new Random(); Position = new Vector2D(rand.NextDouble() * GameWidth, rand.NextDouble() * GameHeight); m_Velocity.Zero(); }
public double Cross(Vector2D B) { return x * B.y - y * B.x; }
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)); }
// 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; }
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)); }
public Vector2D GetPerpendicular() { Vector2D temp = new Vector2D(y, -x); return temp; }
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); }
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; }
public static double GetDistanceBetween(Vector2D A, Vector2D B) { return (double)System.Math.Sqrt(GetDistanceBetweenSquared(A, B)); }
public Entity(double radius, Playfield in_playfield) { levelMap = in_playfield.LevelMap; m_Radius = radius; m_Velocity = new Vector2D(60,120); }
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)); }
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; }