Python 2.7.7/Pygame - Stuck on Scrolling Random Images (pipes in flappy bird) -
i trying create pygame version of flappy bird (way more complicated thought) , stuck on making pipes generate @ random heights. help me this? create same animated want generate pipes little past right of screen , delete them little past left. when run current code pipe images on top of each other in top left corner , don't move. (the bird works though)
import pygame, random, sys pygame.init() icon = pygame.image.load('flappybirdicon.png') pygame.display.set_icon(icon) screen = pygame.display.set_mode([284, 512]) pygame.display.set_caption("flappy bird") bg = pygame.image.load('flappybirdbackground.png') bgrect = bg.get_rect() clock = pygame.time.clock() pipex = 335 class bird(pygame.sprite.sprite): def __init__(self, image, x, y): pygame.sprite.sprite.__init__(self) self.image = pygame.image.load(image) self.rect = self.image.get_rect() self.pos = [x, y] class pipe(pygame.sprite.sprite): def __init__(self, image, height): pygame.sprite.sprite.__init__(self) self.image = pygame.image.load(image) self.rect = self.image.get_rect() self.height = height self.pos = [pipex, height] def scroll(self): self.rect.move_ip(-3, 0) self.pos[0] -= 3 self.rect.center = self.pos def draw_pipes(): pipe1_height = random.randint(115, screen.get_height()) pipe1 = pipe('flappybirdpipe.png', pipe1_height) pipe2_height = 397 - pipe1_height pipe2 = pipe('flappybirdpipe2.png', pipe2_height) screen.blit(pipe1.image, pipe1.rect) screen.blit(pipe2.image, pipe2.rect) bird = bird('flappybirdbird.png', 142, 256) draw_pipes() while true: clock.tick(30) bird.pos[1] += 5 bird.rect.center = bird.pos screen.blit(bg, bgrect) pipe1.scroll() pipe2.scroll() screen.blit(bird.image, bird.rect) pygame.display.flip() event in pygame.event.get(): if event.type == pygame.quit: pygame.quit() sys.exit() elif event.type == pygame.keydown: if event.key == pygame.k_space: bird.pos[1] -= 75 elif event.type == pygame.mousebuttondown: bird.pos[1] -= 75
i'm not familiar pygame, looks you're not setting x coordinate pipes anywhere. you're setting height, never location.
it looks you're not saving pipe info anywhere, imagine code causing new pipes created/drawn every time draw_pipes() called, looks every frame.
python pygame
No comments:
Post a Comment