问题描述
我用python开发了一个小游戏,比如超级玛丽,在执行pygame.init()时遇到问题,下面是完整代码。
使用 Python 3.7.2 pygame 2.0.1 Ubuntu 16.04
在 vscode 中运行时,遇到以下错误:
pygame 2.0.1 (SDL 2.0.14,Python 3.7.2) Hello from the pygame community.
pygame.org/contribute.html Fatal Python error: (pygame parachute) Segmentation Fault
Current thread 0x00007f21f417d700 (most recent call first):
File "/home/zhouyou/projects/FreeTime/marie_adventure/marie.py",line 41 in mainGame
File "/home/zhouyou/projects/FreeTime/marie_adventure/marie.py",line 56 in <module> [1] 26264 abort (core dumped) /home/zhouyou/anaconda3/bin/python3.7
这是完整的代码。
import pygame
from pygame.locals import *
import sys
SCREENWIDTH = 822 # Game screen width
SCREENHEIGHT = 199 # Game screen height
FPS = 30 # The time to update the screen
class Map():
def __init__(self,x,y):
# load background image
self.backgroud = pygame.image.load("images/bg.png").convert_alpha()
self.x = x
self.y = y
def map_rolling(self):
if self.x < -790: # if the map x-axis in (-795-800),means it is still moving in the expeted range
self.x = 800
else:
self.x -= 5
def map_update(self):
SCREEN.bilt(self.backgroud,(self.x,self.y))
def mainGame():
global SCREEN,FPSCLOCK
score = 0
over = False # define the game go on or not
pygame.init()
FPSCLOCK = pygame.time.Clock() # control how long for each loops
SCREEN = pygame.dispaly.set_mode((SCREENWIDTH,SCREENHEIGHT))
pygame.display.set_caption("玛丽冒险") # title
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
FPSCLOCK.tick(FPS)
if __name__ == "__main__":
mainGame()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)