Pong
- 4 Devlogs
- 7 Total hours
A desktop ping pong game made in Python.
A desktop ping pong game made in Python.
It’s done!!!
The game is finally done after hours of work. There is a complete main menu now, with 3 different modes to choose from. ‘Normal’ - normal pong, nothing much else to say. ‘Speed’ - every time the ball collides with something (the wall or a paddle), its speed increases by a certain factor until someone scores a point, after which it is reset back to its original value. ‘Large Paddles’ - just gives each player larger paddles, nothing more than that. I added an AI (always paddle 2) just in case people wanted to play by themselves. It simply follows the y value of the ball (as long as its heading towards the paddle and past half of the screen). I had to change the size of the AI’s paddle in the ‘Large Paddles’ game or else it would’ve been impossible to score (still larger than the other gamemodes). I also decreased its speed. It SHOULD be possible for anyone to beat the AI in all three gamemodes, I did it myself. But, if people have trouble with it, I’ll try and balance it a bit more. Toggling on the AI uses simple states like I did for the gamemodes, ai_state = "false/true", and changing the value depending on what ‘button’ the user clicks. I wish I could get the text for the gamemodes ON the button/rectangle, but the Turtle library makes ts too difficult for no reason. Since you can’t exactly make buttons with Turtle, I added a click sound when each rectangle is pressed so it feels like you’re actually doing something (pygame my beloved). I have had lots of fun with this project and wish to make more games in Python!
So many functions…
The Work So Far:
The base game is entirely done. The paddles move, the ball moves, and there’s a scoring system. Turns out I didn’t have to do anything advanced to fix the issue with the ball, just needed to use time.sleep to make the frames more consistent. I’ve started on the main menu (works by using game_state values to switch between the games), currently it only brings you to the base game. I’m going to work on other variations soon.
Next Course of Action:
More variations to the basic pong game. Maybe polish the GUI up a bit more, I don’t know.
We’ve got some movement!!
The Work So Far:
The paddles can now move! The left paddle is controlled using ‘W’ and ‘S’ and the right paddle is controlled using the ‘Up’ and ‘Down’ arrow keys. Originally, my basic movement functions only allowed for one paddle to move at a time, which was not ideal. The movement was also very choppy (moving about 15 pixels per key press). So, I made a dictionary of all the possible key presses (false means the key is not touched and true means its being held down), created press/release functions which change the value of the key presses in the dictionary accordingly, and added event listeners. These event listeners were .onkeypress and .onkeyrelease. They execute movement functions the moment a key is pressed/released (def pad_move(): if keys_pressed["w"]: y = pad_1.ycor() y += 5 pad_1.sety(y)). I used the function .ontimer to loop the movement function every 16 milliseconds, making the paddles move smoother.
I added boundaries to the window so the ball didn’t fly into oblivion. At one point, I accidentally made the balls too fast (literally saw them for a second and then they were gone). Lowkey want to incorporate that into one of the modes I’ll make in the future. There are also boundaries for the paddles so they don’t go too far off the screen. I did these through a bunch of compound conditionals (I love logic so much dude).
Next Course of Action:
Sometimes, when the ball moves across the screen, it slows down considerably and doesn’t speed back up until it collides with either the walls or the paddles. Thinking of making a function like I did with the paddles to see if it’ll fix it. Haven’t seen any other issues but that. Need to work on the point system and probably a start menu to choose the different modes.
Wanted to continue my Python journey here on Stardance (been doing a bunch of stuff for Beest) so I decided to make a game.
The Work So Far:
Nothing much, made the window for the Pong game using the turtle library in Python. I’ve only used pygame so far for an MP3 player so its nice to use another library. Named the window ‘Pong’ (cuz what else would I name it?). Made both paddles and the ball using .shape. I wanted to make the paddles have rounded edges but I’ll have to figure that out later.
Next Course of Action:
Making the paddles and ball move. I wanted to add an animated background, too. Maybe add some special modes to change up the gameplay.