コード例 #1
0
ファイル: MPoint2Test.cs プロジェクト: Vectovox/MonoKle
 public void TestEqualsObject()
 {
     MPoint2 a = new MPoint2(5, 7);
     MPoint2 b = new MPoint2(5, 7);
     MPoint2 c = new MPoint2(4, 7);
     Assert.IsTrue(a.Equals((object)b));
     Assert.IsFalse(a.Equals((object)c));
 }
コード例 #2
0
ファイル: GraphicsManager.cs プロジェクト: Vectovox/MonoKle
 private void OnScreenSizeChanged(MPoint2 newScreenSize)
 {
     var v = this.ScreenSizeChanged;
     if(v != null)
     {
         v(this, new ScreenSizeChangedEventArgs(newScreenSize));
     }
 }
コード例 #3
0
ファイル: MPoint2Test.cs プロジェクト: Vectovox/MonoKle
 public void TestEqualsVector()
 {
     MPoint2 a = new MPoint2(5, 7);
     MPoint2 b = new MPoint2(5, 7);
     MPoint2 c = new MPoint2(4, 7);
     Assert.IsTrue(a.Equals(b));
     Assert.IsFalse(a.Equals(c));
 }
コード例 #4
0
ファイル: MouseInput.cs プロジェクト: Vectovox/MonoKle
 /// <summary>
 /// Creates a new instance of <see cref="MouseInput"/>.
 /// </summary>
 public MouseInput()
 {
     this.heldTimeByButton = new Dictionary<MouseButton, double>();
     this.previousButtons = new HashSet<MouseButton>();
     this.currentScrollDirection = MouseScrollDirection.None;
     this.previousScrollValue = 0;
     this.mousePosition = new MPoint2(0, 0);
 }
コード例 #5
0
ファイル: GraphicsManager.cs プロジェクト: Vectovox/MonoKle
 public void SetScreenSize(MPoint2 size)
 {
     this.graphicsDeviceManager.PreferredBackBufferWidth = size.X;
     this.graphicsDeviceManager.PreferredBackBufferHeight = size.Y;
     this.ScreenSize = size;          // TODO: Remove when PreparingDeviceSettings is received
     this.ScreenCenter = size / 2;    // TODO: Remove when PreparingDeviceSettings is received
     this.graphicsDeviceManager.ApplyChanges();
     this.OnScreenSizeChanged(size);
 }
コード例 #6
0
ファイル: MPoint2Test.cs プロジェクト: Vectovox/MonoKle
        public void TestConstructors()
        {
            int x = 27, y = -39;
            MPoint2 v = new MPoint2(x, y);
            Assert.AreEqual(v.X, x);
            Assert.AreEqual(v.Y, y);

            Vector2 xy = new Vector2(-57.28f, 23f);
            MPoint2 v2 = new MPoint2(xy);
            Assert.AreEqual(v2.X, (int)xy.X);
            Assert.AreEqual(v2.Y, (int)xy.Y);
        }
コード例 #7
0
ファイル: GridTest.cs プロジェクト: Vectovox/MonoKle
 public void CellRectangle_CorrectNegative()
 {
     MPoint2 point = new MPoint2(-1, -2);
     MRectangle expected = new MRectangle(-cellSize, -2 * cellSize, cellSize, cellSize);
     Assert.AreEqual(expected, grid.CellRectangle(point));
 }
コード例 #8
0
ファイル: MPoint2Test.cs プロジェクト: Vectovox/MonoKle
 public void TestTranslate()
 {
     MPoint2 orig = new MPoint2(-2, -3);
     Assert.AreEqual(orig, new MPoint2(2, 3).Translate(-4, -6));
     Assert.AreEqual(orig.Translate(new MPoint2(1, -2)), orig.Translate(1, -2));
 }
コード例 #9
0
ファイル: MPoint2Test.cs プロジェクト: Vectovox/MonoKle
 public void TestToMVector2()
 {
     int x = 23, y = -19;
     MPoint2 v = new MPoint2(x, y);
     Assert.AreEqual(new MVector2(x, y), v.ToMVector2());
 }
コード例 #10
0
ファイル: MCircleTest.cs プロジェクト: Vectovox/MonoKle
 public void SeparationVector_MPoint2_Outside_ZeroVector()
 {
     MCircle c1 = new MCircle(new MVector2(-300, 3), 2f);
     MPoint2 v = new MPoint2(0, 4);
     MVector2 separated = c1.SeparationVector(v);
     Assert.AreEqual(MVector2.Zero, separated);
 }
コード例 #11
0
ファイル: MCircleTest.cs プロジェクト: Vectovox/MonoKle
 public void SeparationVector_MPoint2_Correct()
 {
     MCircle c1 = new MCircle(new MVector2(0, 3), 2f);
     MPoint2 v = new MPoint2(0, 4);
     MVector2 separated = c1.SeparationVector(v);
     MVector2 expected = new MVector2(0, -1);
     Assert.AreEqual(expected, separated);
 }
コード例 #12
0
ファイル: MCircle.cs プロジェクト: Vectovox/MonoKle
 /// <summary>
 /// Returns the shortest vector to translate the <see cref="MCircle"/> with in order to separate from the provided <see cref="MPoint2"/>.
 /// </summary>
 /// <param name="point">The point to separate from.</param>
 /// <returns></returns>
 public MVector2 SeparationVector(MPoint2 point) => this.SeparationVector(new MCircle(point.ToMVector2(), 0));
コード例 #13
0
ファイル: GridTest.cs プロジェクト: Vectovox/MonoKle
 public void CellFromPoint_CorrectPositive()
 {
     MVector2 point = new MVector2(5, 35);
     MPoint2 expected = new MPoint2(0, 1);
     Assert.AreEqual(expected, grid.CellFromPoint(point));
 }
コード例 #14
0
ファイル: GridTest.cs プロジェクト: Vectovox/MonoKle
 public void CellFromPoint_CorrectNegative()
 {
     MVector2 point = new MVector2(-5, -35);
     MPoint2 expected = new MPoint2(-1, -2);
     Assert.AreEqual(expected, grid.CellFromPoint(point));
 }
コード例 #15
0
 /// <summary>
 /// Creates a new instance of <see cref="ScreenSizeChangedEventArgs"/>.
 /// </summary>
 /// <param name="newScreenSize">The new screen size.</param>
 public ScreenSizeChangedEventArgs(MPoint2 newScreenSize)
 {
     this.NewScreenSize = newScreenSize;
 }
コード例 #16
0
ファイル: MouseInput.cs プロジェクト: Vectovox/MonoKle
 /// <summary>
 /// Creates a new instance of <see cref="MouseInput"/> with the given screen size.
 /// </summary>
 /// <param name="screenSize"></param>
 public MouseInput(MPoint2 screenSize)
     : this()
 {
     this.ScreenSize = screenSize;
 }
コード例 #17
0
ファイル: MouseInput.cs プロジェクト: Vectovox/MonoKle
        /// <summary>
        /// Updates the component with the specified seconds since last update.
        /// </summary>
        /// <param name="seconds">The amount of seconds since last update.</param>
        public void Update(double seconds)
        {
            MouseState currentState = Mouse.GetState();

            // Buttons
            this.previousButtons.Clear();
            this.previousButtons.UnionWith(heldTimeByButton.Keys);
            this.UpdateButton(MouseButton.Left, currentState.LeftButton == ButtonState.Pressed, seconds);
            this.UpdateButton(MouseButton.Middle, currentState.MiddleButton == ButtonState.Pressed, seconds);
            this.UpdateButton(MouseButton.Right, currentState.RightButton == ButtonState.Pressed, seconds);
            this.UpdateButton(MouseButton.XButton1, currentState.XButton1 == ButtonState.Pressed, seconds);
            this.UpdateButton(MouseButton.XButton2, currentState.XButton2 == ButtonState.Pressed, seconds);

            // Scroll wheel
            if (currentState.ScrollWheelValue > previousScrollValue)
            {
                this.currentScrollDirection = MouseScrollDirection.Up;
            }
            else if (currentState.ScrollWheelValue < previousScrollValue)
            {
                this.currentScrollDirection = MouseScrollDirection.Down;
            }
            else
            {
                this.currentScrollDirection = MouseScrollDirection.None;
            }
            this.previousScrollValue = currentState.ScrollWheelValue;

            // Mouse position
            this.deltaPosition = this.mousePosition;
            if (this.VirtualMouseEnabled)
            {
                this.mousePosition += new MPoint2(currentState.X, currentState.Y);
                Mouse.SetPosition(this.ScreenSize.X / 2, ScreenSize.Y / 2);
                this.mousePosition = new MRectangleInt(ScreenSize.X, ScreenSize.Y).Clamp(this.mousePosition);
            }
            else
            {
                this.mousePosition = new MPoint2(currentState.X, currentState.Y);
            }
            this.deltaPosition = this.mousePosition - this.deltaPosition;
        }
コード例 #18
0
ファイル: Camera2D.cs プロジェクト: Vectovox/MonoKle
 /// <summary>
 /// Initiates a new instance of <see cref="Camera2D"/>.
 /// </summary>
 /// <param name="size">The <see cref="MPoint2"/> represenetation of the camera size.</param>
 public Camera2D(MPoint2 size)
 {
     this.size = size;
 }
コード例 #19
0
ファイル: MPoint2Test.cs プロジェクト: Vectovox/MonoKle
 public void TestLengthSquared()
 {
     MPoint2 v = new MPoint2(23, -19);
     Assert.AreEqual(v.Length(), Math.Sqrt(v.LengthSquared()));
 }
コード例 #20
0
ファイル: GridTest.cs プロジェクト: Vectovox/MonoKle
 public void CellRectangle_CorrectPositive()
 {
     MPoint2 point = new MPoint2(0, 1);
     MRectangle expected = new MRectangle(0, cellSize, cellSize, cellSize);
     Assert.AreEqual(expected, grid.CellRectangle(point));
 }
コード例 #21
0
ファイル: MCircleTest.cs プロジェクト: Vectovox/MonoKle
 public void Separate_MPoint2_Separated()
 {
     MCircle c1 = new MCircle(new MVector2(-64, -64), 30f);
     MPoint2 v = new MPoint2(-50, -50);
     MCircle separated = c1.Separate(v);
     Assert.IsTrue(separated.SeparationVector(v) == MVector2.Zero);
 }
コード例 #22
0
ファイル: MCircle.cs プロジェクト: Vectovox/MonoKle
 /// <summary>
 /// Separates the <see cref="MCircle"/> from the specified <see cref="MPoint2"/>, translating it with the shortest distance that makes them not intersect.
 /// </summary>
 /// <param name="point">The point to separate from.</param>
 /// <returns></returns>
 public MCircle Separate(MPoint2 point) => this.Translate(this.SeparationVector(point));