Keep ball bouncing

Discussion in 'Programming' started by OfficialVreesie, Jan 13, 2020 at 11:36 PM.

  1. OfficialVreesie

    OfficialVreesie Member

    Joined:
    Monday
    Posts:
    1
    Hi all, I have a problem.
    I created this game where I have a ball that can bounce against the walls, but I also want to keep the ball bouncing for a minimum speed, so the ball can go faster than that, but it must be bouncing a bit!

    Here is my step event code:
    //apply gravity
    yspd += grav;
    //collide on x-axis
    if place_meeting(x+xspd,y,obj_block1)
    {
    while !place_meeting(x+sign(xspd),y,obj_block1)
    {
    x += sign(xspd);
    }

    //bounce
    xspd *= -bouncedecay;
    }
    //collide on y-axis
    if place_meeting(x,y+yspd,obj_block1)
    {
    while !place_meeting(x,y+sign(yspd),obj_block1)
    {
    y += sign(yspd);
    }

    //bounce
    yspd *= -bouncedecay;
    }
    //Update positions
    x += xspd;
    y += yspd;

    Now I already tried to keep yspd > 10 and yspd < -10, but that causes the ball to freeze.

    How can I do this?
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,335
    Check if xspd and yspd are less than the minimum speed, then set them to the minimum speed if they are.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice