python the Flash man catch coin gif animation
闪电侠是美剧,这里是一个小游戏,操作闪电侠接不断冒出来的金币。本模块定义了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()
如需要查看完整源代码,请扫码付款:
VIP免费查看
当前隐藏内容需要支付
68元
已有3人支付
立即购买