- This event has passed.
7 PM – Python Game Development – Sebastian
July 17, 2023 @ 7:00 pm - 8:00 pm
Today We Did
- Reviewed how to use Gitlab & went over homework
- Learned how to change the size of an image by scaling
- Learned how to change the position of an image with attributes
- In case you need anything, feel free to email me at sebastian@ayclogic.com
Homework
- Remember to create good commit messages when you push your homework by next Sunday.
- Homework:a) The same way we created our birds 1-3, make a fourth bird using the fourth bird image
b) For this bird, give it a variable x and y but this time it should start on the bottom right of the screen
c) Change the x and y attributes for our new bird4 so that it flies from the bottom right to the top left
Code from class:
class Birdie():
WIDTH = 1000
HEIGHT = 750
FPS = 40
def __init__(self):
pygame.init()
self.screen = pygame.display.set_mode((Birdie.WIDTH, Birdie.HEIGHT))
self.project_name = “Birdie”
pygame.display.set_caption(self.project_name)
# Loop until the user clicks the close button.
self.running = True
# Used to manage how fast the screen updates
self.clock = pygame.time.Clock()
self.background_image = pygame.image.load(“assets/background_img.png”)
self.bird1 = pygame.image.load(“assets/bird01_A.png”)
self.bird1 = pygame.transform.scale(self.bird1, (70, 50))
self.bird2 = pygame.image.load(“assets/bird02_A.png”)
self.bird2 = pygame.transform.scale(self.bird2, (140, 100))
self.bird3 = pygame.image.load(“assets/bird03_A.png”)
self.bird3 = pygame.transform.scale(self.bird3, (70, 40))
self.bird1_x = 50
self.bird1_y = 50
self.bird2_y = 200
self.bird3_x = 500
def game_loop(self):
# ——– Main Program Loop ———–
while self.running:
# — Main event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
pygame.display.flip()
self.screen.blit(self.background_image, (0, 0))
self.screen.blit(self.bird1, (self.bird1_x, self.bird1_y))
self.screen.blit(self.bird2, (100, self.bird2_y))
self.screen.blit(self.bird3, (self.bird3_x, 450))
self.bird1_x += 1
self.bird1_y += 1
self.bird2_y += 1
self.bird3_x += 5
self.clock.tick(Birdie.FPS)
current_fps = str(self.clock.get_fps())
pygame.display.set_caption(f'{self.project_name}, fps: {current_fps}’)
# Close the window and quit.
pygame.quit()
if __name__ == ‘__main__’:
sb = Birdie()
sb.game_loop()