Python 我的角色赢了';不要下去。松鸡克隆
我的性格不会堕落。我不知道该怎么办。我的角色只会向上而不会向下。我尝试过很多事情,但似乎不知道该怎么办。我是Python新手,所以如果这是显而易见的,那么很抱歉Python 我的角色赢了';不要下去。松鸡克隆,python,python-2.7,pygame,Python,Python 2.7,Pygame,我的性格不会堕落。我不知道该怎么办。我的角色只会向上而不会向下。我尝试过很多事情,但似乎不知道该怎么办。我是Python新手,所以如果这是显而易见的,那么很抱歉 import pygame black = pygame.Color("#000000") white = pygame.Color("#FFFFFF") blue = pygame.Color("#7ec0ee") pygame.init() size = 1024,768 screen = pygame.display.set
import pygame
black = pygame.Color("#000000")
white = pygame.Color("#FFFFFF")
blue = pygame.Color("#7ec0ee")
pygame.init()
size = 1024,768
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Flappy Bird v.1b")
done = False
clock = pygame.time.Clock()
def ball(x,y):
pygame.draw.circle(screen,black,[x,y], 20)
def gameover():
text = render("Game Over!", True, black)
screen.blit(text, [150, 250])
x = 350
y = 250
x_speed = 0
y_speed = 0
ground = 480
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
y_speed = -10
if event.type == pygame.KEYUP:
if event.key == pygame.K_UP:
y_speed = 5
screen.fill(blue)
ball(x,y)
y += y_speed
if y > ground:
gameover()
y_speed = 0
pygame.display.flip()
clock.tick(60)
pygame.quit()
就像@sam pyt所说的,这似乎是一个缩进问题。我修复了间距不一致的问题,这在我这边起了作用。下面是对我有用的代码
import pygame
black = pygame.Color("#000000")
white = pygame.Color("#FFFFFF")
blue = pygame.Color("#7ec0ee")
pygame.init()
size = 1024,768
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Flappy Bird v.1b")
done = False
clock = pygame.time.Clock()
def ball(x,y):
pygame.draw.circle(screen,black,[x,y], 20)
def gameover():
text = render("Game Over!", True, black)
screen.blit(text, [150, 250])
x = 350
y = 250
x_speed = 0
y_speed = 0
ground = 480
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
y_speed = -10
if event.type == pygame.KEYUP:
if event.key == pygame.K_UP:
y_speed = 5
screen.fill(blue)
ball(x,y)
y += y_speed
if y > ground:
gameover()
y_speed = 0
pygame.display.flip()
clock.tick(60)
pygame.quit()
看看你的
pygame.KEYDOWN
check-它将pygame.K_UP
作为它的事件。key
check…@Jon似乎是故意的。不起作用,我已经试过了。你认为这可能和我的电脑有关吗?它似乎适用于我的朋友,他有类似的代码。@sam pyt是的。。。很抱歉疲惫的眼睛。。。感谢你的轻推这似乎是某种类型的缩进问题。我把它放在一个文件中,修复了缩进,它按预期工作。啊,是的,请查看您对pygame.KEYUP
事件的检查,它嵌套在pygame.KEYDOWN
的条件中。