i was trying to make a game like pong but i cant figure out how to make the sprite glide to a random position. could someone help me
Hello, and welcome Snap!. It is recommended that you start a new topic for things like this, seeing as this topic was about helping kingico1133 in particular with their game, not help making games in general.
In answer to your question, you may want to check out the (pick random (1) to (10) block. This will produce a random number in the specified range. You can then use the glide block like so:
The numbers I used (240 and 180) are based upon the dimensions of the stage. If you want to get really fancy and allow for if the stage is changed in size (yes, that is possible to do in Snap!), try this:
Finally, if you want to get really really fancy and account for the fact that the stage's name can be changed (especially when switching languages), use this:
Remember that you can change the speed by changing the number of seconds in the glide block!
I created a separate topic for this.
I have never used the third one. Are you sure the second one doesn't update between languages?
Why don't you test it and let us know what you found.
if you have a new project in a different language and use that code, it will not work.
why are you telling us this? just use it!
Well, it depends on what you mean. If this person were to be, say, using French, their projects would start out with the stage named "scène". If they then drag my second script into Snap!, it wouldn't work. But the third script would. However, the name of the stage is saved within projects, so if you make a project using method 2, it won't break for other people... unless that other person tries to use your project as a library and to import the script into their own project.
This gave me a really good idea to create an automated game of Pong!
In fact, the other day, I built my own experiment after reading mark4sisb
's suggestion - quoted below - on using pick random (1) to (10) and glide (1) secs to x: (0) y: (0) to make a sprite move to random sides of the stage.
Quote
Here's the project I created.
I modified their block a bit to be more accurate, as it would make the sprite glide to any randomly chosen point between (-240, -180) to (240, 180) rather than just the left or right edges of the stage.
Unneeded information / My best explanation of my experiment
The project will ask you to "set your odds," this just gives you the option to set the chances (1-x, x being your response) of the "ball" being sent "out of bounds" (really just stopping at the edge) every shot.
The sprite will then glide towards a random side after a countdown and the game begins.
The sprite uses pick random (1) to (answer) to pick a random number before every shot and if the number is equal to one, the opposite "player" will "miss the ball", resulting in the side that took the shot to score.
The "ball" is tracked by pen trails: grey for the initial glide, red if it bounced off the red or left side, blue if it bounced off the blue or right side
When a point is gained, the pen trails are cleared and text will be written declaring the scoring side.
The game will go on infinitely unless the project is stopped or the tab is closed.
After each score, the side that didn't score gets the ball, and the sprite automatically glides to their edge of the screen.
I tried making it look nice with all of the pen details, and especially with the attempt at centered text, but the text block isn't working as well as I had hoped. I might make a topic for fixing that, but it's not that big of a deal anyway. Simply just a minor inconvenience.
You're free to use the code from my project however you'd like, I hope it helps!
Sorry if any of this doesn't make total sense as well, I'm writing this at about 1:00 in the morning.
Please let me know if you need anything to be clarified.