import pygame class FlappyWhatever(): FALL_DELAY = 2 HEIGHT = 700 WIDTH = 1000 def __init__(self): pygame.init() self.screen = pygame.display.set_mode((1000, 700)) self.background = pygame.image.load('background.png') self.image = pygame.image.load('player.png') self.image = pygame.transform.scale(self.image, (int(1.25*50), 50)) self.gravity = 1 self.fall_speed = 1 self.fall_delay = FlappyWhatever.FALL_DELAY self.x = 100 self.y = 100 self.running = True def game_loop(self): 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, (0,0)) keys = pygame.key.get_pressed() if keys[pygame.K_SPACE] and self.y > 0: self.fall_speed = -10 self.y -= 2 #print('SPACE KEY PRESSED') self.fall_delay -= 1 if self.fall_delay == 0: if self.y < FlappyWhatever.HEIGHT-self.image.get_height(): self.y = self.y + self.fall_speed self.fall_speed = self.fall_speed + self.gravity #print(f'y is {self.y}, fall_speed {self.fall_speed}') self.fall_delay = FlappyWhatever.FALL_DELAY self.screen.blit(self.image, (self.x, self.y)) if __name__ == '__main__': sb = FlappyWhatever() sb.game_loop()