Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » x and y
- derpytyler911
-
Scratcher
5 posts
x and y
Is there a way to make it so a sprite can't go in a certain area? i am making a ping pong game but the ball gets trapped between the red rectangle (which takes away points) and the paddle (the rectangle that follows your mouse to hit the ball). When it gets stuck it stays in the red and gives you like -200 points. anyway to fix that?
https://scratch.mit.edu/projects/72844446/#editor
https://scratch.mit.edu/projects/72844446/#editor
Last edited by derpytyler911 (Sept. 3, 2015 01:14:47)
- JoeDerpz
-
Scratcher
3 posts
x and y
if sprites pos y < paddles pos y
change sprites pos y by -#
basically check to see if your balls position is less than your paddles if it is then move it back up a comfortable number
EDIT: sorry just realized that wont work with your gameplay so we have to also check our x pos of both objects
change sprites pos y by -#
basically check to see if your balls position is less than your paddles if it is then move it back up a comfortable number
EDIT: sorry just realized that wont work with your gameplay so we have to also check our x pos of both objects
Last edited by JoeDerpz (Sept. 3, 2015 04:41:45)
- speckosaurus
-
Scratcher
100+ posts
x and y
Is there a way to make it so a sprite can't go in a certain area? i am making a ping pong game but the ball gets trapped between the red rectangle (which takes away points) and the paddle (the rectangle that follows your mouse to hit the ball). When it gets stuck it stays in the red and gives you like -200 points. anyway to fix that?Instead of letting the ball bounce off of the red zone, when it touches red, change its position to the middle of the screen. Wait one second, then let the ball continue to move. It gives a better impression that the player has lost a life/point. This also means that because you're moving it immediately after touching the red zone, your score won't go down constantly.
https://scratch.mit.edu/projects/72844446/#editor
Your code will look something like this:
when green flag clicked
forever
if <touching [images (1) v] ?> then
change [score v] by (-1)
go to x: (0) y: (0)
end
end
For the “wait” to work, you would need this check to be in the same loop as your ball's movement. It's not necessary but it will give the player a chance to prepare for the next round.
- speckosaurus
-
Scratcher
100+ posts
x and y
It's up to you, but I also think the code for your ball's movement is more complex than it needs to be. All you really need is this:
when green flag clicked
forever
move (10) steps
if on edge, bounce
end
- Discussion Forums
- » Help with Scripts
-
» x and y