亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

機器學習 Flappy Bird,pygame 未打開窗口

機器學習 Flappy Bird,pygame 未打開窗口

慕婉清6462132 2022-05-19 15:55:44
我正在關注 Tech 與 Tim 的教程,內容是如何創建一個機器學習程序來學習如何玩飛揚的小鳥。我完成了編碼,但 pygame 不會打開一個窗口讓我看游戲。我試過移動我的命令或使用不同的變量,但這些都沒有奏效。import pygameimport neatimport timeimport osimport randompygame.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我沒有收到任何錯誤消息。我只有這些 pygame 1.9.6 Hello from the pygame community. `https://www.pygame.org/contribute.html`斜杠為空,因為包含敏感信息。
查看完整描述

1 回答

?
慕娘9325324

TA貢獻1783條經驗 獲得超5個贊

我不知道這是否是您正在尋找的,但這就是我顯示我的 pygame 窗口的方式


確保在之后執行此操作pygame.init()


  import pygame

  pygame.init()

  WIDTH = 500 #your width

  HEIGHT = 500 #your height

  window = pygame.display.set_mode((WIDTH, HEIGHT))


查看完整回答
反對 回復 2022-05-19
  • 1 回答
  • 0 關注
  • 173 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號