Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
import pygame
import random
pygame.init()
clock = pygame.time.Clock()

screen = pygame.display.set_mode((1000,600))
pygame.display.set_caption("Flappy bird")

bird_image = pygame.image.load("FLAPPY.png")
wall_image = pygame.image.load("ENEMY.png")
bird_image = pygame.transform.scale(bird_image, (80,60))
bird_rect = bird_image.get_rect()
bird_rect.center= (300, 300)
bird_speed = 0
gravity = 0.5
jump = 1

wall_group = pygame.sprite.Group
spawn_wall_event = pygame.USEREVENT
pygame.time.set_timer(spawn_wall_event, 3000)

class Wall(pygame.sprite.Sprite):
    def __init__(self, pos, image ): 
          super().__init__()
          self.image = image
          self.rect = self.image.get_rect()
          self.rect.center = pos
    def update(self):
        self.rect.x-=10

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
               running = False
        if event.type == spawn_wall_event:
            wall=Wall((650, random.randint(0, 20)), wall_image)
            wall_group.add(wall)
    keys = pygame.key.get_pressed()
    if keys[pygame.K_SPACE]:
        bird_speed-=jump
    bird_speed+=gravity
    bird_rect.centery+=int(bird_speed)

    screen.fill((15,60,200))
    screen.blit(bird_image, bird_rect)
    wall_group.draw(screen)
    wall_group.update()

    pygame.display.flip()
    clock.tick(60)


What I have tried:

I tried to run the code. But it gave me the error: AbstractGroup.draw() missing 1 required positional argument: 'surface'
Posted
Updated 16-Jul-23 2:04am
Comments
Richard MacCutchan 16-Jul-23 3:47am    
You need to check the documentation for the classes that you asre using. The error message should help to point you to the call that is failing. You can then trace through the code with the debugger to find out exactly what is missing.

We can't tell - we have no idea where in your code the error is occuring.

So start with the error message - it will tell you the file in which the error occurred and the line number it was found on. Most text / code editors use CTRL+G to go directly to a line number so it should be easy to find.

The use the python debugger to look at your code while it is running: pdb — The Python Debugger — Python 3.11.4 documentation[^]
Put a breakpoint on the line that you found gives the error, and look at all the variables involved.

Sorry, but we can't do that for you!
 
Share this answer
 
Look at the documentation at pygame.sprite.AbstractGroup[^]. The painting surface is the second parameter, the first being the this reference to the current object. So you just need to pass the correct reference in your call to:
Python
wall_group.draw(screen)
.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900