机器学习 Flappy Bird,pygame 打不开 window
Machine Learning Flappy Bird, pygame not opening window
我正在学习 Tech 和 Tim 的教程,内容是关于如何创建一个学习如何玩 flappy bird 的机器学习程序。我完成了编码,但 pygame 不会打开 window 给我看游戏。
我曾尝试移动我的命令或使用不同的变量,但其中 none 行得通。
import pygame
import neat
import time
import os
import random
pygame.font.init()
def draw(self, win):
self.img_count += 1
if self.img_count < self.ANIMATION_TIME:
self.img = self.IMGS[0]
elif self.img_count < self.ANIMATION_TIME*2:
self.img = self.IMGS[1]
elif self.img_count < self.ANIMATION_TIME*3:
self.img = self.IMGS[2]
elif self.img_count < self.ANIMATION_TIME*4:
self.img = self.IMGS[1]
elif self.img_count == self.ANIMATION_TIME*4 + 1:
self.img = self.IMGS[0]
self.img_count = 0
if self.tilt <= -80:
self.img = self.IMGS[1]
self.img_count = self.ANIMATION_TIME*2
rotated_image = pygame.transform.rotate(self.img, self.tilt)
new_rect = rotated_image.get_rect(center=self.img.get_rect(topleft = (self.x, self.y)).center)
win.blit(rotated_image, new_rect.topleft)
def draw(self, win):
win.blit(self.PIPE_TOP, (self.x, self.top))
win.blit(self.PIPE_BOTTOM, (self.x, self.bottom))
def draw(self, win):
win.blit(self.IMG, (self.x1, self.y))
win.blit(self.IMG, (self.x2, self.y))
def draw_window(win, birds, pipes, base, score):
win.blit(BG_IMG, (0,0))
for pipe in pipes:
pipe.draw(win)
text = STAT_FONT.render('Score: ' + str(score), 1, (255, 255,
win.blit(text, (WIN_WIDTH - 10 - text.get_width(), 10))
base.draw(win)
for bird in birds:
bird.draw(win)
pygame.display.update()
draw_window(win, birds, pipes, base, score
我没有收到任何错误消息。我只有这些
"/Users/ / / /Flappy Bird AI" ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 /Users/namrtashah/.vscode/extensions/ms-python.python- 2019.9.34474/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 51472 "/Users/namrtashah/Documents/Jeevan Coding /Flappy Bird AI/bird.py"
pygame 1.9.6
Hello from the pygame community. `https://www.pygame.org/contribute.html`
斜线为空,因为包含敏感信息。
我不知道这是否是您要找的,但这是我显示 pygame windows
的方式
确保在 pygame.init()
之后执行此操作
import pygame
pygame.init()
WIDTH = 500 #your width
HEIGHT = 500 #your height
window = pygame.display.set_mode((WIDTH, HEIGHT))
我正在学习 Tech 和 Tim 的教程,内容是关于如何创建一个学习如何玩 flappy bird 的机器学习程序。我完成了编码,但 pygame 不会打开 window 给我看游戏。
我曾尝试移动我的命令或使用不同的变量,但其中 none 行得通。
import pygame
import neat
import time
import os
import random
pygame.font.init()
def draw(self, win):
self.img_count += 1
if self.img_count < self.ANIMATION_TIME:
self.img = self.IMGS[0]
elif self.img_count < self.ANIMATION_TIME*2:
self.img = self.IMGS[1]
elif self.img_count < self.ANIMATION_TIME*3:
self.img = self.IMGS[2]
elif self.img_count < self.ANIMATION_TIME*4:
self.img = self.IMGS[1]
elif self.img_count == self.ANIMATION_TIME*4 + 1:
self.img = self.IMGS[0]
self.img_count = 0
if self.tilt <= -80:
self.img = self.IMGS[1]
self.img_count = self.ANIMATION_TIME*2
rotated_image = pygame.transform.rotate(self.img, self.tilt)
new_rect = rotated_image.get_rect(center=self.img.get_rect(topleft = (self.x, self.y)).center)
win.blit(rotated_image, new_rect.topleft)
def draw(self, win):
win.blit(self.PIPE_TOP, (self.x, self.top))
win.blit(self.PIPE_BOTTOM, (self.x, self.bottom))
def draw(self, win):
win.blit(self.IMG, (self.x1, self.y))
win.blit(self.IMG, (self.x2, self.y))
def draw_window(win, birds, pipes, base, score):
win.blit(BG_IMG, (0,0))
for pipe in pipes:
pipe.draw(win)
text = STAT_FONT.render('Score: ' + str(score), 1, (255, 255,
win.blit(text, (WIN_WIDTH - 10 - text.get_width(), 10))
base.draw(win)
for bird in birds:
bird.draw(win)
pygame.display.update()
draw_window(win, birds, pipes, base, score
我没有收到任何错误消息。我只有这些
"/Users/ / / /Flappy Bird AI" ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 /Users/namrtashah/.vscode/extensions/ms-python.python- 2019.9.34474/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 51472 "/Users/namrtashah/Documents/Jeevan Coding /Flappy Bird AI/bird.py"
pygame 1.9.6
Hello from the pygame community. `https://www.pygame.org/contribute.html`
斜线为空,因为包含敏感信息。
我不知道这是否是您要找的,但这是我显示 pygame windows
的方式确保在 pygame.init()
import pygame
pygame.init()
WIDTH = 500 #your width
HEIGHT = 500 #your height
window = pygame.display.set_mode((WIDTH, HEIGHT))