""" Coin类,本程序实现由金币类。 这个角色会从右到左移动,一直到x坐标小于0后自己删除自己。 """ import time import pygame from random import randint from pygame.locals import * class Coin(pygame.sprite.Sprite): """电脑控制的AI角色类""" def __init__(self,images,screen): """ images:造型序列 screen:所在屏幕 """ pygame.sprite.Sprite.__init__(self) def setshape(self): """设置造型""" def update(self): """更新坐标""" def auto_delete(self): """到了最左边自杀""" if self.rect.left <= 0:self.kill() if __name__ == "__main__": screen = pygame.display.set_mode((960,720)) pygame.display.set_caption("闪电侠接金币的Coin类") images = [f"coin/{i}.png" for i in range(8)] images = [pygame.image.load(im) for im in images] # 帧序列 images = [pygame.transform.rotozoom(im,0,0.4) for im in images] clock = pygame.time.Clock() running = True while running: for event in pygame.event.get(): if event.type == QUIT:running=False if event.type == USEREVENT: coingroup.add(Coin(images,screen)) coingroup.update() screen.blit(bg,(0,0)) coingroup.draw(screen) pygame.display.update() pygame.quit()
如需要查看完整源代码,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)