Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.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
变量不更新Python3_Python_Python 3.x_Pygame - Fatal编程技术网

变量不更新Python3

变量不更新Python3,python,python-3.x,pygame,Python,Python 3.x,Pygame,self.p中的x和y不更新 Self.p是一个draw变量 当您使用箭头键时,它们会更改x按钮,而变量p中的x不会更改 徖 self.P = pygame.Rect(self.x, self.y, self.width, self.height) self.OB = pygame.Rect(self.oX, self.oY, self.width, self.height) 很抱歉格式化 这是我的密码: 导入pygame 导入时间 pygame.init() pygame.display.

self.p中的x和y不更新 Self.p是一个draw变量

当您使用箭头键时,它们会更改x按钮,而变量p中的x不会更改 徖

self.P = pygame.Rect(self.x, self.y, self.width, self.height)

self.OB = pygame.Rect(self.oX, self.oY, self.width, self.height)
很抱歉格式化

这是我的密码:

导入pygame
导入时间
pygame.init()
pygame.display.set_标题('Platformer'))
班级游戏:
定义初始化(自):
self.DEBUG=True
self.x=7
self.y=400
self.tX=1200
self.tY=600
自宽=40
自身高度=60
self.vel=9
self.run=True
self.isJump=False
自跳计数=10
self.clock=pygame.time.clock()
自我时钟滴答(60)
self.flag=False
self.win=pygame.display.set_模式((1200600))
self.font=pygame.font.font('freesansbold.ttf',64)
self.dieText=self.font.render('Well-crap',True,(255,0,0),(245))
self.dieRect=self.dieText.get_rect()
self.direct.center=(self.tX//2,self.tY//2)
self.die=False
self.diefag=False
self.pause=False
self.pauseFlag=False
self.pauseText=self.font.render('Pause',True,(0150150),(245))
self.pausestright=self.pauseText.get_rect()
self.tX.center=(self.tX//2150)
self.oX=400
self.oY=400
self.P=pygame.Rect(self.x、self.y、self.width、self.height)
self.OB=pygame.Rect(self.oX、self.oY、self.width、self.height)
self.pColor=(0,0,0)
self.oColor=(255,0,0)
def GameLoop(自我):
自运行时:
如果self.DEBUG==True:
打印(self.x)
打印(self.P)
打印(self.OB)
如果self.flag==False:
打印('是')
如果self.pauseFlag==True:
打印('确定')
pygame。时间。延迟(15)
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
pygame.quit()
退出
self.run==False
keys=pygame.key.get_pressed()
如果self.die==True:
self.diefag=True
如果self.pause==True:
self.pauseFlag=True
如果self.pause==False:
self.pauseFlag=False
如果键[pygame.K_p]:
self.pause=True
如果键[pygame.K_o]:
self.pause=False
如果键[pygame.K_ESCAPE]:
pygame.quit()
退出
如果self.die==False和self.pause==False:
如果self.flag==False,并且键[pygame.K_SPACE]或键[pygame.K_UP]:
self.starttime=pygame.time.get_ticks()
self.flag=True
self.isJump=True
如果self.flag==True且pygame.time.get_ticks()-self.starttime>=475:
self.flag=False
如果键[pygame.K_p]和self.pause==False和self.die==False:
self.pause=True
如果键[pygame.K_o]和self.pause==True:
self.pause=False
如果键[pygame.K_LEFT]和self.x>self.vel:
self.x-=self.vel
如果键[pygame.K_RIGHT]和self.x<1200-self.width-self.vel:
self.x+=self.vel
如果键[pygame.K_K]:
self.die=True
如果不是(self.isJump):
如果键[pygame.K_DOWN]和self.y<600-self.height-self.vel:
self.y+=0
其他:
如果self.jumpCount>=-10:
self.y-=(self.jumpCount*abs(self.jumpCount))*.55
self.jumpCount-=1
其他:
self.jumpCount=10
self.isJump=False
如果self.diefag==True:
self.win.fill((245))
如果self.pauseFlag==True:
self.win.blit(self.pauseText,self.pauseText)
pygame.draw.rect(self.win,self.oColor,(self.oX,self.oY,100200))
pygame.draw.rect(self.win,self.pColor,(self.x,self.y,self.width,self.height))
self.win.blit(self.dieText,self.dieRect)
pygame.display.update()
elif self.pauseFlag==False:
pygame.draw.rect(self.win,self.oColor,(self.oX,self.oY,100200))
pygame.draw.rect(self.win,self.pColor,(self.x,self.y,self.width,self.height))
self.win.blit(self.dieText,self.dieRect)
pygame.display.update()
elif self.diefag==False:
如果self.pauseFlag==True:
self.win.fill((245))
self.win.blit(self.pauseText,self.pauseText)
pygame.draw.rect(self.win,self.oColor,(self.oX,self.oY,100200))
pygame.draw.rect(self.win,self.pColor,(self.x,self.y,self.width,self.height))
pygame.display.update()
elif self.pauseFlag==False:
self.win.fill((245))
pygame.draw.rect(self.win,self.oColor,(self.oX,self.oY,40,60))
pygame.draw.rect(self.win,self.pColor,(self.x,self.y,self.width,self.height))
pygame.display.update()
g=游戏()
g、 GameLoop()
非常感谢您的帮助
同样很抱歉格式化

如果我没有遗漏什么,在您发布的代码中,没有地方可以让您意外更改p和OB的值

请注意,这两个变量特定于类的实例。它们是“实例变量”

我推荐 了解di