0

I'm not really sure where I'm going wrong here, but I've only been trying pygame for a day now so go easy on me! lol. It just won't show up, i have to have an attribute set wrong or missing or something, right? I have no idea.

screenw = 800
screenh = 800
speed = 1
size = (screenw, screenh)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("okay attempt number one")

#add the circle bird
birds = pygame.sprite.Group()

playerBird = Bird(PURPLE, 20, 20, 40)
playerBird.rect.x = 200
playerBird.rect.y = 200

#add circlebird to sprite list
birds.add(playerBird)

running = True
clock=pygame.time.Clock()
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        keys = pygame.key.get_pressed()
        if keys[pygame.K_LEFT]:
            playerBird.moveLeft(5)
        if keys[pygame.K_RIGHT]:
            playerBird.moveRight(5)
        if keys[pygame.K_UP]:
            speed += 0.05
        if keys[pygame.K_DOWN]:
            speed -= 0.05
        if playerBird.rect.x < 0:
            playerBird.rect.x = 0
        if playerBird.rect.x > 780:
            playerBird.rect.x = 780
        if playerBird.rect.y < 0:
            playerBird.rect.y = 0
        if playerBird.rect.y > 770:
            playerBird.rect.y = 770
        screen.fill(BLACK)
        pygame.draw.rect(screen, GREY, [0, 0, 800, 100], 0)
        pygame.draw.rect(screen, GREY, [0, 650, 800, 200], 0)
        birds.update(screen)
        birds.draw(screen)
        pygame.display.flip()
        clock.tick(30)

Edit:

Here is the Bird class, I am just piecing things together and trying to get it to even show up.

import pygame
PURPLE = (255, 0, 255)

class Bird(pygame.sprite.Sprite):
    def __init__ (self,color,width,height,speed):
        super().__init__()
        self.width = width
        self.height = height
        self.image = pygame.Surface([width, height])
        self.image.fill(PURPLE)
        self.image.set_colorkey(PURPLE)
        self.color = color
        self.speed = speed
        pygame.draw.rect(self.image, color, [400, 400,50, 50])
        self.rect = self.image.get_rect()
    def moveRight(self, pixels):
        self.rect.x += pixels
    def moveLeft(self, pixels):
        self.rect.x -= pixels
    def moveForward(self, pixels):
        self.rect.y -= pixels
    def moveBackward(self, pixels):
        self.rect.y += pixels
    def changeSpeed(self, speed):
        self.speed = speed

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    can you share the code for Bird class. – darth baba Jun 26 '21 at 13:29
  • Does this answer your question? https://stackoverflow.com/a/16186396/15751564 – darth baba Jun 26 '21 at 13:35
  • I edited the post. sorry, just realized someone commented back. You're quick! – Dalton Donovan Jun 26 '21 at 13:59
  • the link doesn't really provide any help :/ It's not that keypresses don't work, it's that the sprite won't even show up. even if I don't use screen fill or draw anything else. the resolution to that link was it just being two while loops, i only have the one loop, I just can't figure out why it won't draw? I'm gonna try blit I guess – Dalton Donovan Jun 26 '21 at 15:56

0 Answers0