예제 #1
0
        public void CalculateTransforms_BeforeCollisionCheck()
        {
            SceneGraph graph = BuildSceneGraph();
            Vector2 parentPosition = new Vector2(32, 64);
            GameObject obj = new GameObject();
            obj.Position = parentPosition;
            obj.NoClip = false;
            obj.SetCollisionSize(16, 16);

            Vector2 childPosition = new Vector2(96, 128);
            GameObject childObj = new GameObject();
            childObj.Position = childPosition;
            childObj.NoClip = false;
            childObj.SetCollisionSize(16, 16);

            obj.AddChild(childObj);

            GameObjectCounter collisionObj = new GameObjectCounter();
            collisionObj.Position = parentPosition + childPosition;
            collisionObj.NoClip = false;
            collisionObj.SetCollisionSize(16, 16);

            graph.Add(obj);
            graph.Add(collisionObj);
            graph.Update();

            Assert.That(collisionObj.Stats.CollisionCount, Is.EqualTo(1));
        }
예제 #2
0
        public void CenterPoint()
        {
            GameObject obj = new GameObject() { Position = new Vector2(32f, 32f) };
            obj.SetDrawSize(128, 256);

            //Center point is half of draw size
            Assert.That(obj.CenterPoint, Is.EqualTo(new Vector2(64f, 128f)));
        }
        public override void GameObject_ObjectCollision(GameObject sender, GameObjectCollisionEventArgs e)
        {
            GameObjectCounter obj = new GameObjectCounter();
            obj.NoClip = true;
            obj.Position = this.Position;
            SceneGraph.Add(obj);

            base.GameObject_ObjectCollision(sender, e);
        }
예제 #4
0
        public void CenterPoint_NotAffectedByPosition()
        {
            GameObject obj = new GameObject()
            {
                Position = new Vector2(500f, 500f)
            };

            obj.SetDrawSize(64, 64);

            //Center point is not affected by position
            Assert.That(obj.CenterPoint, Is.EqualTo(new Vector2(32f, 32f)));
        }
예제 #5
0
 public void AbsolutePosition_RespectsParentRotation()
 {
     GameObject obj = new GameObject()
     {
         Rotation = MathHelper.Pi
     };
     GameObject child = new GameObject()
     {
         Position = new Vector2(32, 32)
     };
     obj.AddChild(child);
     Vector2 expected = new Vector2(-32f, -32f);
     float precision  = .00001f;
     Assert.That(child.AbsolutePosition, Is.Not.EqualTo(child.Position));
     Assert.That(MathFunctions.FloatEquivalent(child.AbsolutePosition.X, expected.X, precision));
     Assert.That(MathFunctions.FloatEquivalent(child.AbsolutePosition.Y, expected.Y, precision));
 }
예제 #6
0
        public void CalculateTransforms()
        {
            SceneGraph graph = BuildSceneGraph();
            Vector2 parentPosition = new Vector2(32, 64);
            GameObject obj = new GameObject();
            obj.Position = parentPosition;

            Vector2 childPosition = new Vector2(96, 128);
            GameObject childObj = new GameObject();
            childObj.Position = childPosition;

            obj.AddChild(childObj);
            graph.Add(obj);
            graph.Update();

            Assert.That(childObj.Position, Is.EqualTo(childPosition));
            Assert.That(childObj.AbsolutePosition, Is.EqualTo(parentPosition + childPosition));
        }
예제 #7
0
        public void CollisionBounds_SetToAbsolutePosition()
        {
            GameObject obj = new GameObject();
            obj.Position = new Vector2(32f, 64f);
            GameObject child = new GameObject();
            child.Position = new Vector2(32f, 32f);
            obj.AddChild(child);
            Vector2 expected = new Vector2(64f, 96f);

            //verify child absolute position
            Assert.That(child.AbsolutePosition, Is.EqualTo(expected));

            //Collision bounds should be based off of AbsolutePosition
            Assert.That(child.CollisionBounds.X, Is.EqualTo(child.AbsolutePosition.X));
            Assert.That(child.CollisionBounds.Y, Is.EqualTo(child.AbsolutePosition.Y));

            //Collision bounds should not be based off of Relateive Position
            Assert.That(child.CollisionBounds.X, Is.Not.EqualTo(child.Position.X));
            Assert.That(child.CollisionBounds.Y, Is.Not.EqualTo(child.Position.Y));
        }
예제 #8
0
        public void DrawBounds()
        {
            GameObject obj = new GameObject();
            obj.SetDrawSize(16, 32);
            obj.Position = new Vector2(128, 256);

            BoundingBox box = obj.DrawBounds();
            Vector3 expectedMin = new Vector3(obj.AbsolutePosition, 0);
            Vector3 expectedMax = new Vector3(obj.AbsolutePosition, 0);
            expectedMax.X += obj.DrawSize.Width;
            expectedMax.Y += obj.DrawSize.Height;
            Assert.That(box.Min, Is.EqualTo(expectedMin));
            Assert.That(box.Max, Is.EqualTo(expectedMax));

            //Rectangle bounds = new Rectangle( obj.DrawBounds.Min;
            //Assert.That(bounds.Width, Is.EqualTo(16));
            //Assert.That(bounds.Height, Is.EqualTo(32));
            //Assert.That(bounds.X, Is.EqualTo(128));
            //Assert.That(bounds.Y, Is.EqualTo(256));
        }
예제 #9
0
        public void SpawnAtMe_Position()
        {
            SceneGraph graph = BuildSceneGraph();
            Vector2 objPosition = new Vector2(32, 64);
            GameObjectCounter obj = new GameObjectCounter();
            obj.Position = objPosition;

            GameObject childObj = new GameObject();
            childObj.Position = new Vector2(16, 16);
            childObj.SceneGraph = graph;
            obj.AddChild(childObj);

            graph.Add(obj);
            graph.Update();

            GameObjectCounter spawn = new GameObjectCounter();
            childObj.SpawnAtMe(spawn);

            graph.Update();

            Assert.That(spawn.Position, Is.EqualTo(childObj.AbsolutePosition));
            Assert.That(spawn.Position, Is.EqualTo(new Vector2(48f, 80f)));
        }
예제 #10
0
        public void LockToMap_BeforeCollisionCheck()
        {
            SceneGraph graph = BuildSceneGraph();
            GameObjectCounter obj = new GameObjectCounter();
            obj.NoClip = false;
            obj.Position = new Vector2(0, 0);
            obj.SetCollisionSize(16, 16);
            graph.Add(obj);

            GameObject offScreen = new GameObject();
            offScreen.NoClip = false;
            offScreen.Position = new Vector2(-32, -32);
            offScreen.SetCollisionSize(16, 16);
            graph.Add(offScreen);

            //LockToMap should be called before collision checking
            graph.Update();

            Assert.That(obj.Stats.CollisionCount, Is.EqualTo(1));
        }
예제 #11
0
        public void LockToMap_OnlyFirstLevelNodes()
        {
            SceneGraph graph = BuildSceneGraph();
            GameObject obj = new GameObject();
            obj.NoClip = false;
            obj.Position = new Vector2(32, 32);
            obj.SetCollisionSize(16, 16);
            graph.Add(obj);

            Vector2 offScreenPosition = new Vector2(-300, -300);
            GameObject offScreen = new GameObject();
            offScreen.NoClip = false;
            offScreen.Position = offScreenPosition;
            offScreen.SetCollisionSize(16, 16);

            obj.AddChild(offScreen);

            graph.Update();

            Assert.That(offScreen.AbsolutePosition, Is.EqualTo(offScreenPosition + obj.Position));
            Assert.That(offScreen.Position, Is.EqualTo(offScreenPosition));
        }
예제 #12
0
        public virtual void LockToObject(GameObject obj, IMap activeMap)
        {
            Position = obj.AbsolutePosition - new Vector2(ViewportRectangle.Width / 2, ViewportRectangle.Height / 2);

            //position.X = (obj.AbsolutePosition.X + obj.DrawSize.Width / 2) * Zoom
            //                - (ViewportRectangle.Width / 2);
            //position.Y = (obj.AbsolutePosition.Y + obj.DrawSize.Height / 2) * Zoom
            //                - (ViewportRectangle.Height / 2);
            //Position = position;
            //LockToMap(activeMap);
        }
예제 #13
0
        public void Intersects()
        {
            GameObject obj1 = new GameObject() { NoClip = false };
            obj1.SetCollisionSize(32, 32);
            GameObject obj2 = new GameObject() { NoClip = false };
            obj2.SetCollisionSize(32, 32);

            Assert.That(obj1.Intersects(obj2));
            Assert.That(obj2.Intersects(obj1));
        }
예제 #14
0
        public void Intersects_False()
        {
            GameObject obj1 = new GameObject() { NoClip = false };
            obj1.SetCollisionSize(32, 32);
            obj1.Position = new Vector2(128f, 128f);
            GameObject obj2 = new GameObject() { NoClip = false };
            obj2.SetCollisionSize(32, 32);
            obj2.Position = new Vector2(32f, 32f);

            Assert.That(!obj1.Intersects(obj2));
            Assert.That(!obj2.Intersects(obj1));
        }
예제 #15
0
        public void Intersects_CallOnCollision()
        {
            GameObjectCounter obj1 = new GameObjectCounter() { NoClip = false };
            obj1.SetCollisionSize(32, 32);
            GameObject obj2 = new GameObject() { NoClip = false };
            obj2.SetCollisionSize(32, 32);

            obj1.OnObjectCollision(obj2);

            Assert.That(obj1.Stats.CollisionCount, Is.EqualTo(1));
        }
예제 #16
0
 public void MoveUp()
 {
     GameObject obj = new GameObject();
     obj.MoveUp();
     Assert.That(obj.Velocity, Is.EqualTo(-Vector2.UnitY));
 }
예제 #17
0
        public void SetDrawSize()
        {
            GameObject obj = new GameObject();
            obj.Position = new Vector2(500f, 500f);
            obj.SetDrawSize(16, 32);

            Rectangle size = obj.DrawSize;
            Assert.That(size.Width, Is.EqualTo(16));
            Assert.That(size.Height, Is.EqualTo(32));
            Assert.That(size.X, Is.EqualTo(0));
            Assert.That(size.Y, Is.EqualTo(0));
        }
예제 #18
0
 void Fireball_ObjectCollision(GameObject sender, GameObjectCollisionEventArgs e)
 {
     this.Visible = false;
     this.NoClip = true;
     this.SpawnAtMe(WickedDemo.GameScreens.TestLevel.GetExplosion());
 }
예제 #19
0
 private void Character_ObjectCollision(GameObject sender, GameObjectCollisionEventArgs e)
 {
     this.Tint = Color.Red;
 }
예제 #20
0
        public void MoveUpRight()
        {
            GameObject obj = new GameObject();
            obj.MoveUp();
            obj.MoveRight();

            Vector2 expected = -Vector2.UnitY + Vector2.UnitX;
            //expected.Normalize();
            Assert.That(obj.Velocity, Is.EqualTo(expected));
        }
예제 #21
0
 public virtual void StopMovement()
 {
     GameObject obj = new GameObject();
     obj.Velocity = new Vector2(123, 456);
     obj.StopMovement();
     Assert.That(obj.Velocity, Is.EqualTo(Vector2.Zero));
 }
예제 #22
0
 public void Speed_NoNegativeValue(float speed)
 {
     GameObject obj = new GameObject();
     obj.Speed = speed;
 }
예제 #23
0
        public void Update_BeforeLockToMap()
        {
            SceneGraph graph = BuildSceneGraph();
            GameObject obj = new GameObject();
            obj.NoClip = false;
            obj.Position = new Vector2(32, 0);
            obj.Speed = 100;
            obj.Velocity = -Vector2.UnitX;

            graph.Add(obj);

            //If update is called before lock, the object will move off the map and
            //then be placed back on the map after one update
            graph.Update();

            Assert.That(obj.AbsolutePosition, Is.EqualTo(Vector2.Zero));
            Assert.That(obj.Position, Is.EqualTo(Vector2.Zero));
        }
예제 #24
0
        public void MoveDownLeft()
        {
            GameObject obj = new GameObject();
            obj.MoveDown();
            obj.MoveLeft();

            Vector2 expected = Vector2.UnitY + -Vector2.UnitX;
            //expected.Normalize();
            Assert.That(obj.Velocity, Is.EqualTo(expected));
        }
예제 #25
0
        public void Update_Moves()
        {
            GameObject obj = new GameObject() { Velocity = Vector2.UnitX };
            Vector2 initialPosition = Vector2.Zero;
            obj.Position = initialPosition;

            Vector2 expectedPosition = new Vector2(2, 0);
            obj.Update();
            Assert.That(obj.AbsolutePosition, Is.EqualTo(expectedPosition));
            Assert.That(obj.Position, Is.EqualTo(expectedPosition));
        }
예제 #26
0
        public void SetCollisionSize()
        {
            GameObject obj = new GameObject();
            obj.Position = new Vector2(32, 64);
            obj.SetCollisionSize(32, 32);

            Rectangle expected = new Rectangle(32, 64, 32, 32);
            Assert.That(obj.CollisionBounds == expected);
        }
예제 #27
0
        public virtual void LockToObject(GameObject obj, IMap activeMap)
        {
            Vector2 position = new Vector2();

            position.X = (obj.Position.X + obj.DrawSize.Width / 2 ) * _Zoom
                            - (_ViewportRectangle.Width / 2);
            position.Y = (obj.Position.Y + obj.DrawSize.Height / 2) * _Zoom
                            - (_ViewportRectangle.Height / 2);
            Position = position;
            LockToMap(activeMap);
        }
예제 #28
0
        public void Velocity_IsNormalized(float xVelocity, float yVelocity)
        {
            Vector2 velocity = new Vector2(xVelocity, yVelocity);
            Vector2 normalized = velocity;
            normalized.Normalize();

            GameObject obj = new GameObject() { Velocity = velocity };

            Assert.That(obj.Velocity, Is.EqualTo(normalized));
        }
예제 #29
0
파일: Laser.cs 프로젝트: Wydra/WickedEngine
 public Laser(GameObject source)
 {
     this.Texture = SpaceCowboy.GameScreens.TestLevel.LaserFireTexture;
     this.Source = source;
 }
예제 #30
0
        public void Velocity_IsNotZeroNormalized()
        {
            GameObject obj = new GameObject() { Velocity = Vector2.Zero };
            Assert.That(obj.Velocity, Is.EqualTo(Vector2.Zero));

            Vector2 normalizedZero = Vector2.Zero;
            normalizedZero.Normalize();

            Assert.That(obj.Velocity, Is.Not.EqualTo(normalizedZero));
        }