
-----------------------------------
jolly50
Sun Nov 04, 2007 10:19 am

My ball won't come back ~ LOL
-----------------------------------
Hey,

I'm working on some animation and i'm close to figuring it out, but i still have a while to go....


setscreen ("graphics")

var x :int

x:=0

loop


drawfilloval (x,200,100,100,brightblue)
delay (10)
drawfilloval (x,200,100,100,white)
x:=x+5

if x >maxx then
    drawfilloval (x,200,100,100,brightblue)
    delay (10)
    drawfilloval (x,200,100,100,white)
    x:=x-5
end if

end loop


I know it has something to do with the if statement....

What do i have to fix to make this work?

-----------------------------------
Clayton
Sun Nov 04, 2007 10:26 am

RE:My ball won\'t come back ~ LOL
-----------------------------------
Look closely at your if statement. If your ball goes beyond maxx, then you subtract 5 from it's x value. Afterwards, you assume you're below maxx, so you add 5 again, and this process just keeps on going in an infinite loop. Try using a velocity variable to keep track of whether you should add or subtract to your x position.

-----------------------------------
CodeMonkey2000
Sun Nov 04, 2007 1:33 pm

RE:My ball won\'t come back ~ LOL
-----------------------------------
Basically (as Clayton said) make a variable called xIncrement (this is x component if your velocity). This will initially equal 5. Your x value will increase by xIncrement every time you go through the loop. If there is a collision, xIncrement should equal the negative of itself (ie. xIncrement=xIncrement*-1). And that's it.

-----------------------------------
jolly50
Mon Nov 05, 2007 7:12 pm

RE:My ball won\'t come back ~ LOL
-----------------------------------
So... something like this?


setscreen ("graphics")

var x :int
var vx: int

x:=0
vx:=-5


loop


    drawfilloval (x,200,100,100,brightblue)
    delay (10)
    drawfilloval (x,200,100,100,white)
    x:=x+5

        if x>maxx then
        x:=x+vx
        end if
end loop


but the ball still wont come back?

-----------------------------------
HeavenAgain
Mon Nov 05, 2007 7:51 pm

RE:My ball won\'t come back ~ LOL
-----------------------------------
change your if statement to
    if x >= maxx then
        vx := -5
    elsif x 