闪电侠是美剧,这里是一个小游戏,操作闪电侠接不断冒出来的金币。本模块定义了FlashMan类。这个模块能单独运行,运行后用鼠标操作闪电侠移动即可。
以下是部分代码预览:
""" FlashMan类,本程序实现闪电侠类 """ import math import time import pygame from pygame.locals import * class FlashMan(pygame.sprite.Sprite): """闪电侠类,生成后可由鼠标""" def __init__(self,rms,lms): """ rms:向右造型序列 lms:向左造型序列 """ self.shapes_right = rms self.shapes_left = lms def setshape(self): """设置造型""" def update(self): """更新坐标""" if __name__ == "__main__": screen = pygame.display.set_mode((960,720)) pygame.display.set_caption("闪电侠接金币的FlashMan类") images = [f"im1/flash{i}.png" for i in range(1,4)] images = [pygame.image.load(im) for im in images] # 向右造型序列 images_right = [pygame.transform.rotozoom(im,0,0.4) for im in images] # 向左造型序列 images_left = [pygame.transform.flip(im,True,False) for im in images_right] bg = pygame.image.load("space.png") man = FlashMan(images_right,images_left) clock = pygame.time.Clock() running = True while running: for event in pygame.event.get(): if event.type == QUIT:running=False man.update() screen.blit(bg,(0,0)) screen.blit(man.image,man.rect) pygame.display.update() pygame.quit()
如需要查看完整源代码,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)