目标:1 使用精灵类
2 实现精灵图像的任意角度旋转
3 实现类似导弹的跟踪系统
很多文章介绍了图像的转换功能,但都是基于 Surface.blit(image,rect())这个功能。一旦使用在精灵类里,图像漫天飞舞。
偶然看到 pygame自带的chimp示例,里面打大猩猩的游戏,打中后大猩猩会旋转,巧的是,他是基于精灵的类。
经过不停的删除测试,剥离最简代码,加上之前写的文章里的跟踪弹知识,终于玩出了跟踪弹的写法。只是不明白为什么要
if not self.rotate:
self.original = self.image
self.rotate = True
这么搞一下,直接用self.orginal = self.image 图像也会漫天飞。
import os, pygame
from pygame.locals import *
import math
vect = pygame.Vector2
class Chimp(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self) # call Sprite intializer
self.image = pygame.image.load('e:/missle.png')
# colorkey = self.image.get_at((0, 1))
# self.image.set_colorkey(colorkey, RLEACCEL)
self.rect = self.image.ge