小编Kla*_*adu的帖子

Pygame碰撞Bug

我对pygame很新,遇到了一个我无法自行解决的错误.我正在尝试编写Flappy Bird游戏.问题是碰撞检测有效,但它也与我的精灵混淆.如果我设法在比赛时遇到第一个障碍,那么差距将随机重置.但差距应始终相同,只是在另一个位置.如果我删除碰撞检测,它完全正常.有任何想法吗?

import pygame    
import random      

randomy = random.randint(-150, 150)

class Bird(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.Surface((25,25))
        self.image.fill((255,255,255))
        self.rect = self.image.get_rect()
        self.rect.center = (100, 200)
        self.velocity = 0.05
        self.acceleration =0.4

    def update(self):
        self.rect.y += self.velocity
        self.velocity += self.acceleration
        if self.rect.bottom > 590:
            self.velocity = 0
            self.acceleration = 0                                


class Pipe1(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.Surface((85, 500))
        self.image.fill((255, 255, 255))
        self.rect = self.image.get_rect()
        self.rect.center = (500, randomy)
        self.randomyupdate = random.randint(-150, 150)

    def update(self):
        self.rect.x -= 2
        if self.rect.x < …
Run Code Online (Sandbox Code Playgroud)

python pygame flappy-bird-clone

3
推荐指数
1
解决办法
137
查看次数

标签 统计

flappy-bird-clone ×1

pygame ×1

python ×1