飞机大战制作笔记2

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)


  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值