First devlog! It’s quite simple but it took kind of a while due to having to polish it alot.
- I first made a simple bird sprite that will be getting remade later.
- I made the
Birdclass, which is a subclass ofpygame.sprite.Sprite. It has aflap_y_delta, which is how much the bird moves upwards when it flaps, and tracks avelocityvariable that is either negative or positive and it is added to the y-coordinate of the sprite. In theupdatemethod I add the gravity, which is 1200 pixels per second, to the velocity. It also has aflap()method which sets the velocity to theflap_y_delta. Theflap_y_deltais negative (-400) because Pygame’s y-axis goes downwards as it increases. Instead of handling user input for the bird in itsupdate()method, I do it in the main event loop and just runbird.flap()because I need to only allow one press of space per keypress. This stops the user from holding the space bar to repeatedly go upwards, but it’s still spammable.- The bird also has rotation. This was quite simple. First, in the
__init__()method, I have an original image, and then theimageattribute is just a copy of the original. Then, in thedraw()method, I rotate the original image and set it to theimagevariable, which is what gets drawn to the screen. The angle is calculated bymin(90, self.velocity * 0.1), because the velocity will be very high when it is falling so it will default to 90 degrees when falling, and it is a negative value when the bird is going upwards.
- The bird also has rotation. This was quite simple. First, in the
- I made a floor sprite. Later on I put a red line on it to make sure it is repeating correctly. It will be remade later on.
- The floor was quite easy to make. Basically I make a
Floorclass as if it was a normal sprite, and the update method does 2 things: first, it’s going to move it leftwards by a set speed (200 px/s); and then it’s going to check if it has moved fully to the left of the view (self.rect.right <= 0), in which case it’s going to set its x-value to its width times 2 (self.rect.x += self.rect.width * 2), making it wrap to the right outside of the screen. In the main game class I make a sprite group of 2 floors, the second being offset by its own width to make it start to the right. This makes the floor scroll smoothly and infinitely.
It’s coming along really well!
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.