예제 #1
0
        private static float CornerContactTime(AbsObject primaryObj, AbsObject contactedObject)
        {
            // Console.WriteLine("  CornerContactTime called!");

            float   minTime            = -1;
            Vector2 velocity           = primaryObj.Velocity - contactedObject.Velocity;
            Vector2 unitVelocity       = Vector2.Normalize(velocity);
            Boolean immediateCollision = BorderlessIntersects(contactedObject.Hitbox.Value, new BoundingBox(new Vector3(primaryObj.Hitbox.Value.Min.X + unitVelocity.X,
                                                                                                                        primaryObj.Hitbox.Value.Min.Y + unitVelocity.Y, 0), new Vector3(primaryObj.Hitbox.Value.Max.X + unitVelocity.X, primaryObj.Hitbox.Value.Max.Y + unitVelocity.Y, 0)));

            if (immediateCollision)
            {
                minTime = 0;

                // Console.WriteLine("   Immediate collision detected!");
            }
            else
            {
                List <Ray> rays = GetRays(primaryObj.Hitbox.Value.GetCorners(), velocity);
                foreach (Ray ray in rays)
                {
                    float?time = BorderlessIntersects(ray, contactedObject.Hitbox.Value);
                    if (time != null && time > 0 && (time < minTime || minTime < 0))
                    {
                        minTime = (Single)time;
                    }
                }
            }

            // Console.WriteLine("   minTime = " + minTime);

            return(minTime);
        }
        public void Update_Platforms(Layer layer, Camera camera)
        {
            //updte camera position, then use distance travelled to lower platform density logarithmicly
            distance_travelled += Math.Abs(camera_position.Y - camera.Position.Y);
            camera_position     = camera.Position;
            current_density     = starting_density - (int)(Math.Log((distance_travelled + 1), 2) + (distance_travelled / 250));
            current_density     = (int)((-.001 * distance_travelled) + starting_density);

            // https://stackoverflow.com/questions/1582285/how-to-remove-elements-from-a-generic-list-while-iterating-over-it
            if (Remove_Platforms(layer.Objects))
            {
                layer.Objects.Add(Valid_Keystone(layer.Objects));
            }

            while (layer.Objects.Count < current_density)
            {
                PlatformObject new_platform = Valid_Platform(layer.Objects);
                layer.Objects.Add(new_platform);
            }
            updates++;
            if (updates % 1000 == 0)
            {
                AbsObject temp = Select_Item(layer.Objects);
                layer.Objects.Add(temp);
            }
        }
예제 #3
0
        private static void SideCollide(DoodleObject avatar, AbsObject obj, bool[] directionsBlocked)
        {
            if (obj is ItemObject)
            {
                switch (((ItemObject)obj).State)
                {
                case "speed":
                    avatar.powerState = new SpeedState(avatar);
                    break;

                case "jump":
                    avatar.powerState = new DoubleState(avatar);
                    break;

                case "propeller":

                    break;

                default:
                    break;
                }
            }
            else
            {
                avatar.ObjectsToNotCollide.Add(obj);
            }
        }
예제 #4
0
 private static void BottomCollide(ItemObject item, AbsObject obj, bool[] directionsBlocked, AudioManager audio)
 {
     if (obj is BlockObject || obj is PlatformObject)
     {
         item._velocity.Y     = 0;
         directionsBlocked[2] = true;
         if (item.State == "star")
         {
             item._velocity.Y = -1;
         }
     }
     else if (obj is MiscObject)
     {
         if (((MiscObject)obj).Type == "pipe_head")
         {
             item._velocity.Y     = 0;
             directionsBlocked[2] = true;
             if (item.State == "star")
             {
                 item._velocity.Y = -1;
             }
         }
         else
         {
             item.ObjectsToNotCollide.Add(obj);
         }
     }
     else if (obj is MarioObject)
     {
         if (item.State == "coin")
         {
             audio.PlaySound("coin");
         }
         else if (item.State == "1up")
         {
             audio.PlaySound("oneUp");
         }
         item.Hitbox     = new BoundingBox(new Vector3(0), new Vector3(0));
         item.deleteThis = true;
         item.isVisible  = false;
     }
     else if (obj is DoodleObject)
     {
         if (item.State == "speed" || item.State == "jump")
         {
             audio.PlaySound("potion");
         }
         item.Hitbox     = new BoundingBox(new Vector3(0), new Vector3(0));
         item.deleteThis = true;
         item.isVisible  = false;
     }
     else
     {
         item.ObjectsToNotCollide.Add(obj);
     }
 }
예제 #5
0
 private void SideCollide(AbsObject obj)
 {
     if (obj is PlatformObject)
     {
         Console.WriteLine("platform on platform detected");
     }
     else
     {
         _objectsToNotCollide.Add(obj);
     }
 }
예제 #6
0
        public static Collision.CollisionType GetCollisionType(AbsObject primaryObj, AbsObject collidedObj)
        {
            // Console.WriteLine("   CollisionType called!");

            CollisionType type;
            Boolean       top    = primaryObj.Hitbox.Value.Min.Y - collidedObj.Hitbox.Value.Max.Y >= 0;
            Boolean       bottom = primaryObj.Hitbox.Value.Max.Y - collidedObj.Hitbox.Value.Min.Y <= 0;
            Boolean       right  = primaryObj.Hitbox.Value.Max.X - collidedObj.Hitbox.Value.Min.X <= 0;
            Boolean       left   = primaryObj.Hitbox.Value.Min.X - collidedObj.Hitbox.Value.Max.X >= 0;

            if (top)
            {
                type = CollisionType.TSide;
                if (right)
                {
                    type = CollisionType.TRCorner;
                }
                else if (left)
                {
                    type = CollisionType.TLCorner;
                }
            }
            else if (bottom)
            {
                type = CollisionType.BSide;
                if (right)
                {
                    type = CollisionType.BRCorner;
                }
                else if (left)
                {
                    type = CollisionType.BLCorner;
                }
            }
            else
            {
                if (right)
                {
                    type = CollisionType.RSide;
                }
                else
                {
                    type = CollisionType.LSide;
                }
            }

            // Console.WriteLine("    Collision type = " + type);

            return(type);
        }
예제 #7
0
 private void TopCollide(AbsObject obj)
 {
     if (obj is DoodleObject)
     {
         _stoodOn = true;
     }
     else if (obj is ItemObject || obj is EnemyObject)
     {
         // No collision response
     }
     else
     {
         _objectsToNotCollide.Add(obj);
     }
 }
예제 #8
0
        private static void TopCollide(AbsAvatarObject avatar, AbsObject obj, bool[] directionsBlocked)
        {
            if (obj is BlockObject || obj is PlatformObject)
            {
                avatar._velocity.Y = 0;
                avatar.Displace(0, 0.5f);
                directionsBlocked[0] = true;
            }
            else if (obj is EnemyObject)
            {
                avatar.TakeDamage();
                avatar.ObjectsToNotCollide.Add(obj);
            }
            else if (obj is ItemObject)
            {
                switch (((ItemObject)obj).State)
                {
                case "super":
                    avatar.Super();
                    avatar.hud.ChangeScore(1000);
                    break;

                case "fire":
                    avatar.Fire();
                    avatar.hud.ChangeScore(1000);
                    break;

                case "coin":
                    avatar.hud.GetCoin();
                    break;

                case "star":
                    avatar.hud.ChangeScore(1000);
                    break;

                case "1up":
                    avatar.hud.ChangeLife(1);
                    break;

                default:
                    break;
                }
            }
            else
            {
                avatar.ObjectsToNotCollide.Add(obj);
            }
        }
예제 #9
0
        private static float CollisionTime(AbsObject obj1, AbsObject obj2)
        {
            // Console.WriteLine("  CornerContactTime 1 called!");

            float minTime = CornerContactTime(obj1, obj2);

            // Console.WriteLine("  CornerContactTime 2 called!");

            float time = CornerContactTime(obj2, obj1);

            if (time >= 0 && time < minTime)
            {
                minTime = time;
            }
            return(minTime);
        }
예제 #10
0
 private static void SideCollide(EnemyObject enemy, AbsObject obj, bool[] directionsBlocked)
 {
     if (obj is BlockObject)
     {
         if (Collision.GetCollisionType(enemy, obj) == Collision.CollisionType.RSide)
         {
             if (!directionsBlocked[1])
             {
                 directionsBlocked[1] = true;
                 enemy._velocity.X   *= -1;
             }
         }
         else
         {
             if (!directionsBlocked[3])
             {
                 directionsBlocked[3] = true;
                 enemy._velocity.X   *= -1;
             }
         }
         Console.WriteLine("Post side collision x velocity: " + enemy.Velocity.X);
     }
     else if (obj is MiscObject)
     {
         if (((MiscObject)obj).Type == "pipe_head" || ((MiscObject)obj).Type == "pipe_section")
         {
             enemy._velocity.X *= -1;
             if (Collision.GetCollisionType(enemy, obj) == Collision.CollisionType.RSide)
             {
                 directionsBlocked[1] = true;
             }
             else
             {
                 directionsBlocked[3] = true;
             }
         }
         else
         {
             enemy.ObjectsToNotCollide.Add(obj);
         }
     }
     else
     {
         enemy.ObjectsToNotCollide.Add(obj);
     }
 }
예제 #11
0
        private static void BottomCollide(DoodleObject avatar, AbsObject obj, bool[] directionsBlocked)
        {
            avatar.hasDoubleJump = true;
            if ((obj is BlockObject || obj is PlatformObject) && avatar.Velocity.Y >= 0)
            {
                avatar._velocity.Y    = 0;
                directionsBlocked[2]  = true;
                avatar.isGrounded     = true;
                avatar.groundVelocity = obj.Velocity;

                if (avatar.movementState is LeftJumpingIdleState || avatar.movementState is LeftJumpingState || avatar.movementState is LeftFallingState || avatar.movementState is LeftIdleFallingState)
                {
                    avatar.movementState = new LeftIdleState(avatar);
                }
                else if (avatar.movementState is RightJumpingIdleState || avatar.movementState is RightJumpingState || avatar.movementState is RightFallingState || avatar.movementState is RightIdleFallingState)
                {
                    avatar.movementState = new RightIdleState(avatar);
                }
            }
            else if (obj is ItemObject)
            {
                switch (((ItemObject)obj).State)
                {
                case "speed":
                    avatar.powerState = new SpeedState(avatar);
                    break;

                case "jump":
                    avatar.powerState = new DoubleState(avatar);
                    break;

                case "propeller":

                    break;

                default:
                    break;
                }
            }
            else
            {
                avatar.ObjectsToNotCollide.Add(obj);
            }
        }
예제 #12
0
 private static void TopCollide(EnemyObject enemy, AbsObject obj, bool[] directionsBlocked, AudioManager audio)
 {
     if (obj is BlockObject)
     {
         enemy._velocity.Y = 0;
         enemy.Displace(0, 0.5f);
         directionsBlocked[0] = true;
     }
     else if (obj is MarioObject)
     {
         audio.PlaySound("kick");
         enemy.TakeDamage();
         enemy.ObjectsToNotCollide.Add(obj);
     }
     else
     {
         enemy.ObjectsToNotCollide.Add(obj);
     }
 }
예제 #13
0
 public MiscObject(Vector2 startPos, ContentManager content, string type)
 {
     _opacity             = 1.0f;
     isVisible            = true;
     deleteThis           = false;
     HiddenObject         = null;
     WarpDestination      = null;
     inRange              = false;
     isTouching           = false;
     _type                = type;
     _mario               = null;
     _hiddenObj           = null;
     _spriteFactory       = new MiscSpriteFactory(content);
     _sprite              = _spriteFactory.build(type);
     _hitbox              = GetHitbox(type, startPos);
     _position            = startPos;
     _velocity            = new Vector2(0);
     _acceleration        = new Vector2(0);
     _objectsToNotCollide = new List <AbsObject>();
     _objectsToAdd        = new List <AbsObject>();
 }
예제 #14
0
        //check the bounding box of the platform to be added vs all the current platforms
        private bool Check_Location(AbsObject to_be_added, List <AbsObject> absObjects)
        {
            bool result = true;
            int  i      = 0;
            //absObject's hitbox is nullable (i think thats right, its of type BoundingBox?, not
            //BoundingBox, hence the needed casts)
            BoundingBox checked_hitbox = (BoundingBox)to_be_added.Hitbox;

            //loop while true and i less than count
            while (result && i < absObjects.Count)
            {
                //result is made true when there is no intersect, false when there is, stoppping the loop
                result = !(checked_hitbox.Intersects((BoundingBox)absObjects[i].Hitbox));
                i     += 1;
            }
            if (i > absObjects.Count)
            {
                Console.WriteLine("could not find non-colliding pllatform space");
            }

            return(result);
        }
예제 #15
0
 private static void BottomCollide(EnemyObject enemy, AbsObject obj, bool[] directionsBlocked)
 {
     if (obj is BlockObject)
     {
         enemy._velocity.Y    = 0;
         directionsBlocked[2] = true;
     }
     else if (obj is MiscObject)
     {
         if (((MiscObject)obj).Type == "pipe_head")
         {
             enemy._velocity.Y    = 0;
             directionsBlocked[2] = true;
         }
         else
         {
             enemy.ObjectsToNotCollide.Add(obj);
         }
     }
     else
     {
         enemy.ObjectsToNotCollide.Add(obj);
     }
 }
예제 #16
0
 private static void SideCollide(ItemObject item, AbsObject obj, bool[] directionsBlocked, AudioManager audio)
 {
     if (obj is BlockObject || obj is PlatformObject)
     {
         if (Collision.GetCollisionType(item, obj) == Collision.CollisionType.RSide)
         {
             if (!directionsBlocked[1])
             {
                 directionsBlocked[1] = true;
                 item._velocity.X    *= -1;
             }
         }
         else
         {
             if (!directionsBlocked[3])
             {
                 directionsBlocked[3] = true;
                 item._velocity.X    *= -1;
             }
         }
         Console.WriteLine("Post side collision x velocity: " + item.Velocity.X);
     }
     else if (obj is MiscObject)
     {
         if (((MiscObject)obj).Type == "pipe_head" || ((MiscObject)obj).Type == "pipe_section")
         {
             item._velocity.X *= -1;
             if (Collision.GetCollisionType(item, obj) == Collision.CollisionType.RSide)
             {
                 directionsBlocked[1] = true;
             }
             else
             {
                 directionsBlocked[3] = true;
             }
         }
         else
         {
             item.ObjectsToNotCollide.Add(obj);
         }
     }
     else if (obj is MarioObject)
     {
         if (item.State == "coin")
         {
             audio.PlaySound("coin");
         }
         else if (item.State == "1up")
         {
             audio.PlaySound("oneUp");
         }
         item.Hitbox     = new BoundingBox(new Vector3(0), new Vector3(0));
         item.deleteThis = true;
         item.isVisible  = false;
     }
     else if (obj is DoodleObject)
     {
         if (item.State == "speed" || item.State == "jump")
         {
             audio.PlaySound("potion");
         }
         item.Hitbox     = new BoundingBox(new Vector3(0), new Vector3(0));
         item.deleteThis = true;
         item.isVisible  = false;
     }
     else
     {
         item.ObjectsToNotCollide.Add(obj);
     }
 }
예제 #17
0
        private static void SideCollide(AbsAvatarObject avatar, AbsObject obj, bool[] directionsBlocked)
        {
            if (obj is BlockObject || obj is PlatformObject)
            {
                avatar._velocity.X = 0;
                if (Collision.GetCollisionType(avatar, obj) == Collision.CollisionType.RSide)
                {
                    directionsBlocked[1] = true;
                }
                else
                {
                    directionsBlocked[3] = true;
                }
                if (avatar.movementState is LeftWalkingState)
                {
                    avatar.movementState = new LeftIdleState(avatar);
                }
                else if (avatar.movementState is RightWalkingState)
                {
                    avatar.movementState = new RightIdleState(avatar);
                }
                else if (avatar.movementState is LeftJumpingState)
                {
                    avatar.movementState = new LeftJumpingIdleState(avatar);
                }
                else if (avatar.movementState is RightJumpingState)
                {
                    avatar.movementState = new RightJumpingIdleState(avatar);
                }
            }
            else if (obj is EnemyObject)
            {
                avatar.TakeDamage();
                avatar.ObjectsToNotCollide.Add(obj);
            }
            else if (obj is ItemObject)
            {
                switch (((ItemObject)obj).State)
                {
                case "super":
                    avatar.Super();
                    avatar.hud.ChangeScore(1000);
                    break;

                case "fire":
                    avatar.Fire();
                    avatar.hud.ChangeScore(1000);
                    break;

                case "coin":
                    avatar.hud.GetCoin();
                    break;

                case "star":
                    avatar.hud.ChangeScore(1000);
                    break;

                case "1up":
                    avatar.hud.ChangeLife(1);
                    break;

                default:
                    break;
                }
            }
            else if (obj is MiscObject)
            {
                if (((MiscObject)obj).Type == "pipe_head" || ((MiscObject)obj).Type == "pipe_section")
                {
                    avatar._velocity.X = 0;
                    if (Collision.GetCollisionType(avatar, obj) == Collision.CollisionType.RSide)
                    {
                        directionsBlocked[1] = true;
                    }
                    else
                    {
                        directionsBlocked[3] = true;
                    }
                    if (avatar.movementState is LeftWalkingState)
                    {
                        avatar.movementState = new LeftIdleState(avatar);
                    }
                    else if (avatar.movementState is RightWalkingState)
                    {
                        avatar.movementState = new RightIdleState(avatar);
                    }
                    else if (avatar.movementState is LeftJumpingState)
                    {
                        avatar.movementState = new LeftJumpingIdleState(avatar);
                    }
                    else if (avatar.movementState is RightJumpingState)
                    {
                        avatar.movementState = new RightJumpingIdleState(avatar);
                    }
                }
                else
                {
                    avatar.ObjectsToNotCollide.Add(obj);
                }
            }
            else
            {
                avatar.ObjectsToNotCollide.Add(obj);
            }
        }
예제 #18
0
        private static void BottomCollide(AbsAvatarObject avatar, AbsObject obj, bool[] directionsBlocked)
        {
            if (obj is BlockObject || obj is PlatformObject)
            {
                avatar._velocity.Y   = 0;
                directionsBlocked[2] = true;
                avatar.isGrounded    = true;

                if (avatar.movementState is LeftJumpingIdleState || avatar.movementState is LeftJumpingState)
                {
                    avatar.movementState = new LeftIdleState(avatar);
                }
                else if (avatar.movementState is RightJumpingIdleState || avatar.movementState is RightJumpingState)
                {
                    avatar.movementState = new RightIdleState(avatar);
                }
            }
            else if (obj is EnemyObject)
            {
                avatar._velocity.Y = -2;
                avatar.hud.ChangeScore(100);
            }
            else if (obj is ItemObject)
            {
                switch (((ItemObject)obj).State)
                {
                case "super":
                    avatar.Super();
                    avatar.hud.ChangeScore(1000);
                    break;

                case "fire":
                    avatar.Fire();
                    avatar.hud.ChangeScore(1000);
                    break;

                case "coin":
                    avatar.hud.GetCoin();
                    break;

                case "star":
                    avatar.hud.ChangeScore(1000);
                    break;

                case "1up":
                    avatar.hud.ChangeLife(1);
                    break;

                default:
                    break;
                }
            }
            else if (obj is MiscObject)
            {
                if (((MiscObject)obj).Type == "pipe_head")
                {
                    avatar._velocity.Y   = 0;
                    avatar.PipeContacted = (MiscObject)obj;
                    directionsBlocked[2] = true;
                    avatar.isGrounded    = true;

                    if (avatar.movementState is LeftJumpingIdleState || avatar.movementState is LeftJumpingState)
                    {
                        avatar.movementState = new LeftIdleState(avatar);
                    }
                    else if (avatar.movementState is RightJumpingIdleState || avatar.movementState is RightJumpingState)
                    {
                        avatar.movementState = new RightIdleState(avatar);
                    }
                }
                else
                {
                    avatar.ObjectsToNotCollide.Add(obj);
                }
            }
            else
            {
                avatar.ObjectsToNotCollide.Add(obj);
            }
        }