当前位置:网站首页>Aircraft collision detection
Aircraft collision detection
2022-07-27 18:47:00 【Rise from the road】
collision detection
List of articles
The goal is
- Understand collision detection methods
- Collision implementation
One 、 Understand collision detection methods
pygame Provides Two are very convenient The method can realize collision detection :
pygame.sprite.groupcollide()
- Two elf groups in All the elves Collision detection based on
groupcollide(group1, group2, dokill1, dokill2, collided = None) -> Sprite_dict
- If you will dokill Set to True, be Colliding sprites will be automatically removed
- collided Parameters are used for Callback function to calculate collision
- If not specified , Then each elf must have one rect attribute
pygame.sprite.spritecollide()
- Judge Some elf and Specify the sprite group The collision of elves in
spritecollide(sprite, group, dokill, collided = None) -> Sprite_list
- If you will dokill Set to True, be Specify the sprite group in Colliding sprites will be automatically removed
- collided Parameters are used for Callback function to calculate collision
- If not specified , Then each elf must have one rect attribute
- return Spirit group Middle heel spirit There was a collision List of elves
Two 、 Collision implementation
def __check_collide(self):
# 1. The bullet destroyed the enemy plane
pygame.sprite.groupcollide(self.hero.bullets, self.enemy_group, True, True)
# 2. The enemy plane crashed the hero
enemies = pygame.sprite.spritecollide(self.hero, self.enemy_group, True)
# Judge whether there is content in the list
if len(enemies) > 0:
# Let the hero die
self.hero.kill()
# End the game
PlaneGame.__game_over()
summary
This chapter is the final chapter of the aircraft war , Combine the contents of previous chapters , Write here , The whole game is finished , Interested friends do it by themselves ! Tomorrow, all the implementation source codes of the aircraft war will be released , Don't miss your favorite friends !
Where are the deficiencies or better suggestions , Welcome to make complaints about Tucao , There is a little friend who doesn't understand can confide in me , I will answer them one by one , Thank you for your approval , Thank you for your support !
边栏推荐
- Vue uses keep alive to realize page caching
- TS study notes class
- 微信小程序微信支付概述
- 2021.7.13 note sub query
- LED学习护眼台灯触摸芯片-DLT8T10S-杰力科创
- What does the number of network request interface layers (2/3 layers) mean
- USB充电式暖手宝芯片-DLTAP602SC-杰力科创
- Wechat applet obtains openid, sessionkey, unionid
- mysql基础语句
- 2021.8.6 notes jsoup
猜你喜欢

Login page tablelayout

Why don't you like it? It's easy to send mail in ci/cd

20000 words + 30 pictures | what's the use of chatting about MySQL undo log, redo log and binlog?

2021.8.1 Notes database design

js实现简易表单验证与全选功能

2021.7.18笔记 mysql数据类型

2021.7.28笔记 事务

面试官:你觉得你最大的缺点是什么?

Uni app traversal array rendering data vertical rendering

Uni app for wechat login (to be finished)
随机推荐
Knowledge map pyhanlp realizes named body recognition (with named body recognition code)
面试官:你觉得你最大的缺点是什么?
Visual studio code installation tutorial (super detailed)
MySQL learning Day1 DDL, DML, DQL basic query
Login page tablelayout
电动加热护颈枕芯片-DLTAP703SC
1. OpenCV image basic operation
nacos显示服务注册地址错误
JPA connection database password field blob
知识图谱 — pyhanlp实现命名体识别(附命名体识别代码)
Modify placeholder style in input
2021.7.28 notes
Pandas' to_ SQL function usage
Have you ever stumbled on MySQL's order by
飞机大战碰撞检测
Vue uses keep alive to realize page caching
我人都傻了,CompletableFuture和OpenFegin一起使用竟然报错
浴室带除雾化妆镜触摸芯片-DLT8T10S
2021.7.12 internal and external connection of notes
2021.8.9 note request