Python / Pygame Tutorial 8 - Collision Detection

preview_player
Показать описание
In this tutorial I show you how to detect collisions with two rectangles. This is very important for creating games.

Download the starter code:

Download this code (finished):
Рекомендации по теме
Комментарии
Автор

Keep making these. It doesn't matter if you only get a few views on these videos. Just know that the people who are viewing them are actually learning something because of you and if that doesn't make you feel amazing then I don't know what does.

Thanks.

MultiSway
Автор

Please keep making these tutorials. It has helped me and a lot of other people learn pygame and python!

XxTheProElitexX
Автор

is there any other way to do this because I am making a labyrinth game and I need a way to detect every wall on it

gordanarabljenovic
Автор

The default python "IDE", IDLE (which installs along with the interpreter I believe) is what has the keyword, function, ect. highlighting.

Flyz-ejkm
Автор

Only one time this wouldn't work is if the object being collided with is significantly smaller than the moving object, and you're approaching from one side, in which case none of the four corner points would enter the area of the obstacle! I wonder if you could think of a more efficient way of programming this kind of scenario than just adding more 'test points' on the moving object?

orangeninjaMR
Автор

nice for a raspberry pi project. thanks.

qzorn
Автор

Do you have tutorial about collision detection of cuboids?

shutaosong
Автор

Hi, But doesn't pygame already do it for you ?
Rect.colliderect
test if two rectangles overlap
Rect.colliderect(Rect): return bool
Returns true if any portion of either rectangle overlap (except the top+bottom or left+right edges).

vikasmkmk
Автор

How do you make it so that it cant pass through the other object?

legoman
Автор

elif's aren't just more correct. Programs run faster if you use elif's rather than a bunch of if's

scortch
Автор

so what if i have multiple enemies and i dont want them to collide, how do i do this?

Yipper
Автор

it's an extension called pygame that makes it visual

teeboh
Автор

What is x, x1, x2, y, y1, y2 etc. defined as? I don't see an x1 equals to something

Jovahkiin
Автор

No language is visual by itself. They all need extensions/libraries to be visual.

happylittleplaces
Автор

When's the next scratch mario update?

MelodiCat