public void resolveCollision(Sprite s, Vector2 velocity)
        {
            return;

            float time     = 0.5f;
            int   i        = 1;
            bool  collides = true;

            while (i <= 5)
            {
                collides = checkPlatformCollision(s.testBox(velocity.X * time, velocity.Y * time));
                i++;
                if (collides)
                {
                    time -= 1 / (float)Math.Pow(2, i);
                }
                else
                {
                    time += 1 / (float)Math.Pow(2, i);
                }
            }
            if (time == 0.015625f)
            {
                time = 0;
            }
            s.Position += velocity * time;
            s.Speed     = s.Speed;
        }
Пример #2
0
 /* public void Update2(GameTime time, List<Action> actions)
  * {
  *   Vector2 bunnyHvec = new Vector2(0, 0);
  *   Vector2 clydeHvec = new Vector2(0, 0);
  *
  *   if (actions.Contains(Action.BunnyMoveLeft))
  *   {
  *       bunnyHvec.X = bunny.Speed;
  *   }
  *   if(actions.Contains (Action.BunnyMoveLeft)){
  *       bunnyHvec.X = -bunny.Speed ;
  *   }
  *   moveSprite(bunny, bunnyHvec);
  *   if(actions.Contains(Action.ClydeMoveLeft){
  *
  *   }
  * }*/
 public void moveSprite(Sprite sprite, Vector2 velocity)
 {
     if (checkPlatformCollision(sprite.testBox(velocity.X, velocity.Y)))
     {
         resolveCollision(sprite, velocity);
     }
     else
     {
         sprite.Position += velocity;
     }
 }
Пример #3
0
        public void resolveCollision(Sprite s, Vector2 velocity)
        {
            float time     = 0.5f;
            int   i        = 1;
            bool  collides = true;

            while (i <= 5 || collides)
            {
                collides = checkPlatformCollision(s.testBox(velocity.X * time, velocity.Y * time));
                i++;
                if (collides)
                {
                    time -= 1 / (2 ^ i);
                }
                else
                {
                    time += 1 / (2 ^ i);
                }
            }
            s.Position += velocity * time;
        }
Пример #4
0
        /* public void Update2(GameTime time, List<Action> actions)
        {
            Vector2 bunnyHvec = new Vector2(0, 0);
            Vector2 clydeHvec = new Vector2(0, 0);

            if (actions.Contains(Action.BunnyMoveLeft))
            {
                bunnyHvec.X = bunny.Speed;
            }
            if(actions.Contains (Action.BunnyMoveLeft)){
                bunnyHvec.X = -bunny.Speed ;
            }
            moveSprite(bunny, bunnyHvec);
            if(actions.Contains(Action.ClydeMoveLeft){

            }
        }*/
        public void moveSprite(Sprite sprite, Vector2 velocity)
        {
            if (checkPlatformCollision(sprite.testBox(velocity.X, velocity.Y)))
            {
                resolveCollision(sprite, velocity);
            }
            else
            {
                sprite.Position += velocity;
            }
        }
Пример #5
0
        public void resolveCollision(Sprite s, Vector2 velocity)
        {
            float time = 0.5f;
            int i = 1;
            bool collides = true;
            while (i <= 5 || collides)
            {
                collides = checkPlatformCollision(s.testBox(velocity.X * time, velocity.Y * time));
                i++;
                if (collides)
                {
                    time -= 1 / (2 ^ i);
                }
                else
                {
                    time += 1 / (2 ^ i);
                }

            }
            s.Position += velocity * time;
        }
        public void moveSprite(Sprite sprite)
        {
            Vector2 velocity = sprite.Velocity;
            bool removed = false;
            bool removedProblem = false;
            if (solids.Contains(sprite))
            {
                removed = true;
                solids.Remove(sprite);
            }
            Sprite problem = getInitialCollision(sprite.testBox(0, 0));
            if (problem == null)
            {

            }
            else {
                solids.Remove(problem);
                removedProblem = true;
            }

            if (checkPlatformCollision(sprite.testBox(0, velocity.Y)))
            {
                resolveCollision(sprite, new Vector2(0,velocity.Y));

                sprite.Velocity = new Vector2(velocity.X, 0);

                Console.WriteLine(sprite.Velocity);
                if (velocity.Y > 0)
                {
                    //this is for ramp falling sound, fix later
                    if (velocity.Y == 0.6)
                    {
                        if (sprite.imageName == "gate_block")
                        {
                            Ramp r = (Ramp)sprite;
                            r.soundeffect.Play();
                        }
                    }
                    sprite.state = Sprite.State.Default;

                }
                else
                {

                }

            }
            else
            {
                sprite.Position += new Vector2 (0, velocity .Y);
                sprite.Update(new GameTime());
            }
            if (checkPlatformCollision(sprite.testBox(velocity.X, 0)))
            {
                resolveCollision(sprite, new Vector2(velocity.X, 0));
            }
            else
            {
                sprite.Position += new Vector2(velocity.X, 0);
                sprite.Update(new GameTime());
            }
            if (removed)
            {
                solids.Add(sprite);
            }
            if (removedProblem)
            {
                solids.Add(problem);
            }
            //sprite.Update(new GameTime());
               // sprite.Velocity = new Vector2(0.5f * sprite .Velocity .X, sprite.Velocity.Y);
        }
        public void resolveCollision(Sprite s, Vector2 velocity)
        {
            return;
            float time = 0.5f;
            int i = 1;
            bool collides = true;
            while (i <= 5 )
            {
                collides = checkPlatformCollision(s.testBox(velocity.X * time, velocity.Y * time));
                i++;
                if (collides)
                {
                    time -= 1 / (float)Math.Pow (2,i);
                }
                else
                {
                    time += 1 / (float)Math.Pow (2,i);
                }

            }
            if (time == 0.015625f)
            {
                time = 0;
            }
            s.Position += velocity * time;
            s.Speed = s.Speed;
        }
        public void moveSprite(Sprite sprite)
        {
            Vector2 velocity       = sprite.Velocity;
            bool    removed        = false;
            bool    removedProblem = false;

            if (solids.Contains(sprite))
            {
                removed = true;
                solids.Remove(sprite);
            }
            Sprite problem = getInitialCollision(sprite.testBox(0, 0));

            if (problem == null)
            {
            }
            else
            {
                solids.Remove(problem);
                removedProblem = true;
            }

            if (checkPlatformCollision(sprite.testBox(0, velocity.Y)))
            {
                resolveCollision(sprite, new Vector2(0, velocity.Y));

                sprite.Velocity = new Vector2(velocity.X, 0);

                Console.WriteLine(sprite.Velocity);
                if (velocity.Y > 0)
                {
                    //this is for ramp falling sound, fix later
                    if (velocity.Y == 0.6)
                    {
                        if (sprite.imageName == "gate_block")
                        {
                            Ramp r = (Ramp)sprite;
                            r.soundeffect.Play();
                        }
                    }
                    sprite.state = Sprite.State.Default;
                }
                else
                {
                }
            }
            else
            {
                sprite.Position += new Vector2(0, velocity.Y);
                sprite.Update(new GameTime());
            }
            if (checkPlatformCollision(sprite.testBox(velocity.X, 0)))
            {
                resolveCollision(sprite, new Vector2(velocity.X, 0));
            }
            else
            {
                sprite.Position += new Vector2(velocity.X, 0);
                sprite.Update(new GameTime());
            }
            if (removed)
            {
                solids.Add(sprite);
            }
            if (removedProblem)
            {
                solids.Add(problem);
            }
            //sprite.Update(new GameTime());
            // sprite.Velocity = new Vector2(0.5f * sprite .Velocity .X, sprite.Velocity.Y);
        }