This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-12-21 17:53:38

Thescratch3
Scratcher
Registered: 2011-06-14
Posts: 1000+

Pong within a limit....

I need help making Pong. I wan the paddle to go to the mouse x without going outside of the lines. There is a box with the paddle in it. It goes to the mouse's x, but still is able to go outside of the box! (The box has a lining on it.) I made it so it goes back to the center if it touches the black lining, but still it doesn't look smooth or efficient. Please help!


View my projects. Or face The scratch curse! (Get it?)
http://i56.tinypic.com/2cdk8hy.png

Offline

 

#2 2011-12-21 21:45:07

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Pong within a limit....

Code:

if(mousex>maximumx)
{
     set x to (maximum)
}
else
{
     if(mousex<minimum)
     {
          set x to (minimum)
     }
     else
     {
          set x to (mouse x)
     }
}

http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#3 2011-12-22 00:44:14

Thescratch3
Scratcher
Registered: 2011-06-14
Posts: 1000+

Re: Pong within a limit....

Thanks.


View my projects. Or face The scratch curse! (Get it?)
http://i56.tinypic.com/2cdk8hy.png

Offline

 

#4 2011-12-22 04:36:43

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Pong within a limit....

Well, say the minimum x position is -150, and the maximum is 150, you'd put:

When green flag clicked
Forever
    If  x position > -150  and  150 > x position
        Set x to mouse x
    End if
End forever

Or, if you're more advanced, change the bit in the if to "150 > abs of x position"

I hope this helps!  smile


Why

Offline

 

#5 2011-12-22 07:28:17

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Pong within a limit....

RedRocker227's script works and is more concise, but it may leave the object past your barriers if the user quickly flicks their mouse left or right past them.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#6 2011-12-22 12:58:17

Thescratch3
Scratcher
Registered: 2011-06-14
Posts: 1000+

Re: Pong within a limit....

RedRocker227 wrote:

Well, say the minimum x position is -150, and the maximum is 150, you'd put:

When green flag clicked
Forever
    If  x position > -150  and  150 > x position
        Set x to mouse x
    End if
End forever

Or, if you're more advanced, change the bit in the if to "150 > abs of x position"

I hope this helps!  smile

It does, thanks for the suggestion.


View my projects. Or face The scratch curse! (Get it?)
http://i56.tinypic.com/2cdk8hy.png

Offline

 

Board footer