I'd love to have Svelte in Repl.it!
@PaoloAmoroso Python Play does use the asyncio features of Python 3.
await were added in Python 3.5 (source) so you just need a version of Python greater than that (which repl.it has). If you want to use Python Play on repl.it, you just need to use a Python (3) repl and install replit-play in the package manager. Or you can just fork this repl.
And the reason for using async/await is mostly to be able to set up timers. In normal loop-based python programming, it's really annoying (especially for beginners) to make a program that changes the background to red, waits 1 second, changes to green, waits 1 second, then changes to blue and cycles back to red. In Python Play you can just do that like this:
@play.repeat_forever async def do(): play.set_backdrop('red') await play.timer(seconds=1) play.set_backdrop('green') await play.timer(seconds=1) play.set_backdrop('blue') await play.timer(seconds=1)
@yoonji1010 hey! The repl you shared with me works just fine. After you hit run, try clicking your mouse in the area of the game first and THEN pressing up or down. Sometimes the keyboard focus is still in the text editor after you hit run.
@FootSpecialist ok. I’ll just say that being nice and affirming as opposed to sarcastic and unaffirming is a vastly underrated way to be. And check the response to your comment from the person it was aimed at: wouldn’t it be better if your comments didn’t cause people to frown?
@FootSpecialist hey! I think you might have been joking around with @PYer which is cool, but in text it's a little hard to tell if you're joking or being mean. It's okay if someone that likes Python doesn't know much about pygame. I've been coding for over 10 years and I didn't know anything about pygame until a few months ago! So if you were joking please let us know and if you weren't, please try to be nicer since we're all learning here :)
Hey @vitorcurado, looks like you're using Play and the pong tutorial I wrote! Cool! I'd love to offer some help here. In programming, it's helpful to break down what you want.
First, we need the text you want to display, something like "You lost :(". To do that, you can add this line of code near the beginning of your program:
losing_text = play.new_text('You lost :(', font_size=120)
Try it out and see if the text shows up. If the text is showing up, it will stay on the screen even when you start the game, which isn't what we want. So for now we should hide the text with the hide command:
losing_text = play.new_text('You lost :(', font_size=120) losing_text.hide()
We'll bring it back when we detect the player loses.
Second, you want to know when the player loses. How do you detect when the player loses? In most pong games, the player loses when the ball goes past the player's paddle or past the edge of the screen. How do we translate this into code?
To check for a condition, Python's
if statement is what you want. You can do something like this:
# check to see if the ball has gone past the right of the screen @play.repeat_forever async def check_losing(): if ball.x > play.screen.right: losing_text.show()
This will repeatedly check if the ball's
x position (its horizontal position) is bigger than (
>) the position of right of the screen. If it is, we'll show the losing text we made earlier. Try it out, does it work?
Once it's working, the third thing you said you want to do is wait three seconds. In Python Play, there's a special command to wait called the timer. You use it like this:
# check to see if the ball has gone past the right of the screen @play.repeat_forever async def check_losing(): if ball.x > play.screen.right: losing_text.show() await play.timer(seconds=3)
But what do we want to have happen after three seconds? We want to hide the losing text and put the ball back in the middle of the screen. You can do that with two more commands, like this:
# check if the ball has passed the right of the screen @play.repeat_forever async def check_losing(): if ball.x > play.screen.right: losing_text.show() await play.timer(seconds=3) losing_text.hide() ball.go_to(x=0, y=0) # go back to the center of the screen
And that's it! I think this should do what you want. Check this repl I made for you with the new code. I hope this helps!
Hey I tried remaking this project with the Python Play library that we just released on repl.it. Here it is: https://repl.it/@glench/DVD-Logo-screensaver-remake
It also chooses a random color to change to once it bounces off an edge.
@DavideRosa Works fine in Safari and Chrome (although video won't play probably due to 3rd-party cookies being disabled).
However, when I go to http://remiexample--daviderosa.repl.co/__repl it works in Safari but then fails when I tried to fork it. In Chrome when I go to the __repl url it fails both viewing your project and forking my own version.
@DavideRosa oh huh! I have the most recent Chrome (beta) and Safari and my internet is fast. In Chrome I have 3rd party cookies disabled and in Safari I have what looks like default setting of cookies enabled from websites I visit.