飞机大战制作笔记2

来源:互联网 发布:游戏源代码 知乎 编辑:程序博客网 时间:2024/04/28 19:29
1.append() 方法向列表的尾部添加一个新的元素。只接受一个参数。
  extend()方法只接受一个列表作为参数,并将该参数的每个元素都添加到原有的列表中。
 
2.索引图片列表
在某个飞机类中。。。
self.destroy_images = []self.destroy_images.extend([pygame.image.load("Images/shoot/hero_blowup_n1.png").convert_alpha(),                            pygame.image.load("Images/shoot/hero_blowup_n2.png").convert_alpha(),                            pygame.image.load("Images/shoot/hero_blowup_n3.png").convert_alpha(),                            pygame.image.load("Images/shoot/hero_blowup_n4.png").convert_alpha()])
类外
e3_destroy_index = 0 #在游戏主循环外,初始化引索值为0     ...  (下面语句均在游戏主循环内)screen.blit(each.destroy_images[e3_destroy_index], each.rect) #显示图片e3_destroy_index = (e3_destroy_index + 1) % 6 #这里是一个小技巧,这样 e3_destroy_index的值只能是0~5

3.碰撞检测 ,mask参数
首先在类中,要把设置一个mask变量,把图片中的非透明的部分设置为mask:
self.mask = pygame.mask.from_surface(self.image1)#让image1图片中,非透明的部分设置为mask,方便等下的碰撞检测使用
然后在碰撞检测方法的最后一个参数中加入“pygame.sprite.collide_mask”:
enemies_down = pygame.sprite.spritecollide(me, enemies, False, pygame.sprite.collide_mask)


  
0 0