Python Pygame Tutorial - Rectangle Based Collision Detection

preview_player
Показать описание
Thank you for watching my video and I really hope you found something useful.

In this episode I'm going to look examining rectangle based collision detection.

Click this link to download the images and scripts featured in this episode

... and if you have any comments then feel free but bear in mind I don't pretend to be an expert, I just enjoying using Python and Pygame.

Anthony

Downloads:

Documents:

Рекомендации по теме
Комментарии
Автор

nice and straight forward tutorials, great videos!

BigAggLP
Автор

That type of tutorials should be displayed at the top of search results :) Very useful tip, good job, keep it up !

konradpodgorski
Автор

Thank you, that's exactly what I needed :)

FiveMinuteGaming
Автор

You have made pygame so easy to use. Thank you!

trootrooper
Автор

You could technically compile this into a function (though you would need to give alot of infomation)
heres the code i used:


def checkCollision(targetX, targetY, targetWidth, targetHeight, sourceX, sourceY, sourceWidth, sourceHeight):
targetX2 = targetX + targetWidth
targetY2 = targetY + targetHeight

sourceX2 = sourceX + sourceWidth
sourceY2 = sourceY + sourceHeight
if targetX > sourceX2 or targetX2 < sourceX or targetY > sourceY2 or targetY2 < sourceY:
return False
else:
return True


# when calling the function, call it like this:
checkCollision(targetX, targetY, targetWidth, targetHeight, objectX, objectY, objectWidth, objectHeight)
# make sure to call the command in the game loop or it wont work.

metgaming
Автор

What can I say except, like and thanks for tutorial. I will use this tip to my project. ;)

szymanekk
Автор

with the same logic, how could i be true only when it is above the object?
spectacular video continues like this, thanks in advance :)

billyalani
Автор

Can you in the next time will make a video about A* alghoritm etc. this good tips to make a game with AI. ;)

szymanekk
Автор

Its lagging pretty bad on my macbook, even with just 10 stars

mason
Автор

this is so over-engineered and complex, just use pygame.Rect.colliderect(Rect)

-AWEJOKER
join shbcf.ru