马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这是为什么?
如果搞不明白的的话:
代码:import modules
from pygame.locals import *
def main():
modules.pygame.mixer.init()
modules.pygame.init()
x1 = ((modules.win32api.GetSystemMetrics(modules.win32con.SM_CXSCREEN)) // 2) - 1024 // 2
y1 = ((modules.win32api.GetSystemMetrics(modules.win32con.SM_CYSCREEN)) // 2) - 768 // 2
modules.os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x1,y1)
del x1
del y1
#图片存放路径
image = str('..\\image\\')
#加载各类图片
bg_images = str(image) + 'bg.png'
ban_images = image + 'ban.png'
blue_block_images = image + 'blue_block.png'
ji_images = image + 'ji.png'
hand_image = image + 'hand.cur'
icon_image = image + 'elsfk.ico'
#按照背景图片大小设置窗口大小
bg_size = width, height = 1024, 768
screen = modules.pygame.display.set_mode(bg_size)
icon = modules.pygame.image.load(icon_image).convert_alpha()
cur = modules.pygame.image.load(hand_image).convert_alpha()
modules.pygame.display.set_icon(icon)
#设置标题栏文本
modules.pygame.display.set_caption("俄罗斯方块")
#用白色填充背景,避免出现一些奇奇怪怪的渲染问题
screen.fill((255,255,255))
background = modules.pygame.image.load(bg_images).convert_alpha()
clock = modules.pygame.time.Clock()
#用于存放消息列表
msg = []
#用于存放俄罗斯方块
blocks = []
group = modules.pygame.sprite.Group()
GAMEOVER = modules.USEREVENT
GAMEPAUSE = modules.USEREVENT
running = True
if running == False:
try:
sys.exit()
except SystemExit:
pass
except:
print("出错了!")
return 0
for i in range(1):
postion = (modules.random.randint(0, width), modules.random.randint(int(-20),int(0)))
speed = [0,0]
classes = modules.classes.Block(blue_block_images,postion,speed,bg_size)
block = modules.block.Block(classes.blue_image,classes.postion,\
classes.speed,classes.bg_size)
del classes
blocks.append(block)
group.add(block)
del block
modules.pygame.display.update()
modules.pygame.display.flip()
modules.pygame.key.set_repeat(100, 100)
modules.pygame.mouse.set_pos(500,450)
bools = True
while running:
for event in modules.pygame.event.get():
if event.type == modules.pygame.QUIT:
running = False
modules.pygame.quit()
try:
modules.sys.exit()
except SystemExit:
pass
except:
print("出错了!")
return 0
elif event.type == GAMEOVER:
running = False
continue
elif event.type == modules.KEYDOWN:
if event.key == modules.K_d:
for each in group:
each.speed[0] = 1
elif event.key == modules.K_a:
for each in group:
each.speed[0] = -1
elif event.key == modules.K_s:
blocks[0].down = True
blocks[0].speed[1] = 2
elif event.key == modules.K_RCTRL:
bools = not(bools)
elif event.type == modules.KEYUP:
if event.key == modules.K_s:
blocks[0].down = False
blocks[0].speed[1] = 0
elif event.key == modules.K_d:
for each in group:
each.speed[0] = 0
elif event.key == modules.K_a:
for each in group:
each.speed[0] = 0
elif event.type == modules.MOUSEBUTTONDOWN:
bools = True
x , y = modules.pygame.mouse.get_pos()
if bools:
if y >= 700:
modules.pygame.mouse.set_pos(x,768)
y = 700
elif y <= 0:
modules.pygame.mouse.set_pos(x,0)
y = 0
if x >= 1000:
modules.pygame.mouse.set_pos(1024,y)
x = 1000
elif x <= 0:
modules.pygame.mouse.set_pos(0,y)
x = 0
screen.blit(background, (0, 0))
#modules.pygame.display.flip()
for each in blocks:
each.move()
screen.blit(each.blue_image,each.rect)
modules.pygame.display.flip()
modules.pygame.display.update()
clock.tick(30)
else:
try:
modules.sys.exit()
except SystemExit:
pass
except:
print("出错了!")
if __name__ == "__main__":
# 这样做的好处是双击打开时如果出现异常可以报告异常,而不是一闪而过!
try:
main()
except SystemExit:
pass
except:
modules.traceback.print_exc()
modules.pygame.quit()
input()
del modules
不是模块的问题,这些地方好好的
self.move = False
def move(self):
果真有问题,你有属性move和方法move,同名了,有冲突,外面调用的其实是属性move,所以会报错,你改掉其中一个名字,然后再试。
|