ubuntu pygame窗口不显示
所以,我找到了一段Tech和Tim的视频,他正在创建一个flappy bird py文件。好吧,我的问题是pygame窗口在运行后没有弹出。我正在使用ubuntu 20.04..寻找解决方案,混合了我从pygame中学到的所有东西..需要帮助:(
import os
import pygame
pygame.init()
import neat
import time
import random
WIN_WIDTH = 600
WIN_HEIGHT = 800
BIRD_IMGS = [pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "bird1.png"))),pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "bird2.png"))),pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "bird3.png")))]
PIPE_IMG = pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "pipe.png")))
BASE_IMG = pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "base.png")))
BG_IMG = pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "bg.png")))
class Bird:
IMGS = BIRD_IMGS
MAX_ROTATION = 25
ROTATION_VELOCITY = 20
ANIMATION_TIME = 5
def __init__(self, x, y):
self.x = x
self.y = y
self.tilt = 0
self.tick_count = 0
self.vel = 0
self.height = self.y
self.img_count = 0
self.img = self.IMGS[0]
def jump(self):
self.vel = -10.5
self.tick_count = 0
self.height = self.y
def move(self):
self.tick_count += 1
d = self.vel * self.tick_count + 1.5*self.tick_count**2
if d >= 16:
d = 16
if d < 0:
d -= 2
self.y = self.y + d
if d < 0 or self.y < self.height + 50:
if self.tilt < self.MAX_ROTATION:
self.tilt = self.MAX_ROTATION
else:
self.tilt > -90
self.tilt -= self.ROTATION_VELOCITY
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 get_mask(self):
return pygame.mask.from_surface(self.img)
def draw_window(win, bird):
win.blit(BG_IMG, (0,0))
bird.draw(win)
pygame.display.update()
def main():
bird = Bird(200,200)
win = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
draw_window(win, bird)
pygame.quit()
quit()
main()
我得到的回溯是:
Traceback (most recent call last):
File "/home/user/Python/Flappybird-Ai/flappy_bird.py", line 98, in <module>
main()
File "/home/user/Python/Flappybird-Ai/flappy_bird.py", line 85, in main
win = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
pygame.error: No available video device
转载请注明出处:http://www.zhongtian365.com/article/20230525/1865860.html
随机推荐
-
UBUNTU中的REGEX模式仅精确匹配一个不带空格的单词
我想做一个正则表达式模式,用于ubuntu终端,从一个包含所有国家名称的文本文件中获取名称中包含多个单词的所有国家(列表如下所示):Afghanistan Albania Algeria Andorra Angola Antigua De...
-
Ubuntu Github网页上图片不显示解决方法
1. 打开终端(Ctrl + Alt + T)运行命令: sudo vi /etc/hosts 2. 把下面5个IP内容添加到打开的文件末尾(文件打开后按 i 然后就可编辑,把下面内容拷贝然后Ctrl + v粘贴), 3. 保存文件退出(...
-
Ubuntu不提供包含uint24_t类型的Clang的stdint
我需要一个3字节的无符号整数类型。当我查看clang的include path /usr/include/clang/3.5/include时,stdint提供了一个uint24_t数据类型。但是当我想使用它的时候,clang编译器抛出了一...
-
Ubuntu系统怎么设置在打开文件夹时默认显示隐藏文件?
如果只需要一次显示, 那么, 只要Ctrl+H, 即可。这里说的是每次打开文件管理时默认显示所有文件的方法。 1、点击File选项, 选择Preferences 2、在打开的对话框中勾选Show hidden and backup fi...
-
Ubuntu 20.04中找不到的Pygame示例
我想学习如何在Pygame (python3.8.5,Ubuntu 20.04)中编程。我安装了pygame,但它可以找到示例。我试图手动搜索它们,但也没有找到它们。这些示例似乎根本没有安装。这是我到目前为止所做的:由于大量失败的依赖项,尝...
-
Ubuntu系统上自定义图形化桌面时间显示的方法
尽管设置页面里已经有一些选项可以用了,这个快速教程会向你展示如何更加深入地自定义 Ubuntu 面板上的时间和日期指示器。 在开始之前,在 Ubuntu 软件中心搜索并安装 dconf Editor。然后启动该软件并按以下步骤执行: 1、...
-
Ubuntu系统更新后WiFi图标显示不正常解决方法
在Ubuntu系统中,很多用户都会在系统弹出更新提示后下载更新部分程序,但是最近有用户反映在更新完开机重启后发现WiFi图标成了一个扇形,无法搜索到信号,不能正常使用了。这是怎么回事?Ubuntu系统下更新后WiFi图标显示不正常该怎么解...
-
ubuntu修改时间、显示硬件时间、同步系统时钟(date命令使用方法)
1. date 命令主要用于显示以及修改系统时间 2. hwclock 命令用于查看设置硬件时间,以及同步硬件时间与系统时间复制代码代码如下:# 显示硬件时间hwclock /p p# 设置硬件时间hwclock -set -date="...
-
Ubuntu配置Vim及不同语法显示不同颜色操作步骤
第一步 安装vim 命令为:sudo apt-get install vim 第二步 更改vim的配置文件etc/vim 命令为:(1) cd/etc/vim (2) sudo vim vimrc 第三步 在vimrc任意地方令起一行插入...
-
ubuntu 11.10输入法图标不显示的解决方法(图文教程)
ubuntu 11.10输入法图标不显示的解决 问题: 今天更新了ubuntu。结果重启机器之后输入法的图标不显示了。 输入法的切换效果还是有的(只是不没有显示图标)。 Ubuntu11.10下ibus输入法的图标经常消失,输入中...