Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的角色赢了';不要下去。松鸡克隆_Python_Python 2.7_Pygame - Fatal编程技术网

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

我的性格不会堕落。我不知道该怎么办。我的角色只会向上而不会向下。我尝试过很多事情,但似乎不知道该怎么办。我是Python新手,所以如果这是显而易见的,那么很抱歉

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
的条件中。