当前位置:网站首页>飞机大战碰撞检测
飞机大战碰撞检测
2022-07-27 16:17:00 【道而起】
碰撞检测
目标
- 了解碰撞检测方法
- 碰撞实现
一、了解碰撞检测方法
pygame 提供了 两个非常方便 的方法可以实现碰撞检测:
pygame.sprite.groupcollide()
- 两个精灵组 中 所有的精灵 的碰撞检测
groupcollide(group1, group2, dokill1, dokill2, collided = None) -> Sprite_dict
- 如果将 dokill 设置为 True,则 发生碰撞的精灵将被自动移除
- collided 参数是用于 计算碰撞的回调函数
- 如果没有指定,则每个精灵必须有一个 rect 属性
pygame.sprite.spritecollide()
- 判断 某个精灵 和 指定精灵组 中的精灵的碰撞
spritecollide(sprite, group, dokill, collided = None) -> Sprite_list
- 如果将 dokill 设置为 True,则 指定精灵组 中 发生碰撞的精灵将被自动移除
- collided 参数是用于 计算碰撞的回调函数
- 如果没有指定,则每个精灵必须有一个 rect 属性
- 返回 精灵组 中跟 精灵 发生碰撞的 精灵列表
二、碰撞实现
def __check_collide(self):
# 1. 子弹摧毁敌机
pygame.sprite.groupcollide(self.hero.bullets, self.enemy_group, True, True)
# 2. 敌机撞毁英雄
enemies = pygame.sprite.spritecollide(self.hero, self.enemy_group, True)
# 判断列表时候有内容
if len(enemies) > 0:
# 让英雄牺牲
self.hero.kill()
# 结束游戏
PlaneGame.__game_over()
总结
本章为飞机大战最终章,结合之前几章的内容,写到这里,飞机大战整个游戏就完成了,感兴趣的朋友自己做一遍吧!明天会将飞机大战所有实现源码整个发布出来,喜欢的朋友不要错过哦!
有哪里不足或者有更好的建议,欢迎留言吐槽,有哪里不懂的小伙伴可以私信我,我会一一答复,感谢认可,感谢支持!
边栏推荐
- Quick access to website media resources
- 低噪负离子风扇触摸IC
- Knowledge map pyhanlp realizes named body recognition (with named body recognition code)
- [mit 6.s081] LEC 9: interrupts notes
- 浴室带除雾化妆镜触摸芯片-DLT8T10S
- Set the arc button to be displayed in the middle
- INSUFFICIENT_ ACCESS_ ON_ CROSS_ REFERENCE_ ENTITY APEX / SALESFORCE
- Labels such as {@code}, {@link} and < P > in the notes
- TypeError: conv2d(): argument ‘padding‘ (position 5) must be tuple of ints, not str【报错】
- [mit 6.s081] LEC 8: page faults notes
猜你喜欢

2021.8.1 Notes database design

低噪负离子风扇触摸IC

Knowledge map pyhanlp realizes named body recognition (with named body recognition code)
![[mit 6.s081] LEC 10: multiprocessors and locking notes](/img/62/ca6362830321feaf450865132cdea9.png)
[mit 6.s081] LEC 10: multiprocessors and locking notes

File path read

虚拟偶像的歌声原来是这样生成的!

2021.7.12 internal and external connection of notes

知识图谱 — jieba、pyhanlp、smoothnlp工具实现中文分词(词性表)

阿里p8总结的10条 SQL 优化方案(非常实用)

MySQL learns the relationship between Day2 Sorting Query / aggregation function / grouping query / paging query / constraint / multiple tables
随机推荐
浴室带除雾化妆镜触摸芯片-DLT8T10S
Hbuilder submission code
Must the MySQL query column be consistent with the group by field?
The song of the virtual idol was originally generated in this way!
图文结合,完美解释MySQL逻辑备份的实现流程
Set the arc button to be displayed in the middle
USB充电式暖手宝芯片-DLTAP602SC-杰力科创
2021.8.1笔记 DBA
怎么会不喜欢呢,CI/CD中轻松发送邮件
你有没有在MySQL的order by上栽过跟头
Wechat applet obtains openid, sessionkey, unionid
Wechat applet multi file upload
[mit 6.s081] LEC 10: multiprocessors and locking notes
Part of speech list of common words
MySQL learns the relationship between Day2 Sorting Query / aggregation function / grouping query / paging query / constraint / multiple tables
[mit 6.s081] LEC 1: introduction and examples notes
「MySQL那些事」一文详解索引原理
2021.7.17笔记 mysql其他命令
2021.8.6 notes jsoup
Log4j epic loopholes, big companies like jd.com have been recruited