loop = False else: input_manager.update(event) if input_manager.x_pressed: # 1. Creat a new bullet bullet = PlayerBullet(player.x, player.y) bullet.image = pygame.image.load( "images/bullet/player/mb69bullet1.png") # 2. Add the newly created bullet into 'bullets' list # bullets.append(bullet) add(bullet) # Bullets fly # Bullets draw update() for bullet in bullets: bullet.y -= 10 for bullet in bullets: canvas.blit(bullet.image, (bullet.x - 48 / 2, bullet.y - 80 / 2)) canvas.blit(background_image, (0, 0)) render(canvas) pygame.display.flip() clock.tick(60)
SIZE = (800, 600) canvas = pygame.display.set_mode(SIZE) pygame.display.set_caption('Jet zero') # 3. Clock clock = pygame.time.Clock() loop = True input_manager = InputManager() while loop: # 1. Event processing events = pygame.event.get() for event in events: if event.type == pygame.QUIT: loop = False else: input_manager.update(event) game_object.update() # 2. Draw canvas.fill(BG) game_object.render(canvas) # 3. Flip pygame.display.flip() clock.tick(60)