当前位置:网站首页>飞机大战碰撞检测
飞机大战碰撞检测
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()
总结
本章为飞机大战最终章,结合之前几章的内容,写到这里,飞机大战整个游戏就完成了,感兴趣的朋友自己做一遍吧!明天会将飞机大战所有实现源码整个发布出来,喜欢的朋友不要错过哦!
有哪里不足或者有更好的建议,欢迎留言吐槽,有哪里不懂的小伙伴可以私信我,我会一一答复,感谢认可,感谢支持!
边栏推荐
- USB充电式暖手宝芯片-DLTAP602SC-杰力科创
- 内网的公司邮箱服务器怎么发外部邮件
- Vue uses keep alive to realize page caching
- [mit 6.s081] LEC 4: page tables notes
- 机器学习——SVM训练集只有一类标签数据而引发的错误
- 微信小程序微信支付概述
- 建木持续集成平台v2.5.2发布
- Why don't you like it? It's easy to send mail in ci/cd
- 2021.7.22 note constraints
- RuntimeError: output with shape [1, 256, 256] doesn‘t match the broadcast shape [3, 256, 256]【报错】
猜你喜欢

Navicat 导出表生成PDM文件

I was forced to optimize the API gateway query interface

MySQL basic statement

MySQL learning day3 multi table query / transaction / DCL

Let's move forward together, the 10th anniversary of Google play!

Idea packaging war package and war package location

阿里架构师耗时280个小时整理的1015页分布式全栈小册,轻松入手分布式系统

Run the uniapp to the mobile phone (real machine debugging)

1. OpenCV image basic operation

Use ETL tools for data migration in salesforce project
随机推荐
What should I do if MySQL master-slave replication data is inconsistent?
Build a simple knowledge question and answer system
Solution to invalid SQL Server connection to server
智能失眠治疗仪产品-DLT8P68SA-杰力科创
INSUFFICIENT_ ACCESS_ ON_ CROSS_ REFERENCE_ ENTITY APEX / SALESFORCE
MySQL学习 Day2 排序查询 / 聚合函数 /分组查询 /分页查询 /约束/多表之间的关系
[mit 6.s081] LEC 6: isolation & system call entry/exit notes
Using Jieba and pyhanlp tools to extract keyword words and sentences
修改input中placeholder样式
2021.7.31笔记 视图
What does the number of network request interface layers (2/3 layers) mean
微信小程序获取openId, sessionKey, unionId
Uni app traversal array rendering data vertical rendering
JDBC learning day1:jdbc
2021.7.28 notes
全自动吸奶器芯片-DLTAP703SD
Preliminary introduction to C miscellaneous lecture linked list
多功能无线遥控艾灸仪芯片-DLTAP703SD
机器学习分类任务效果评估指标大全(包含ROC和AUC)
机器学习——SVM训练集只有一类标签数据而引发的错误