S
S
s1vemod2021-11-23 17:54:42
pygame
s1vemod, 2021-11-23 17:54:42

How to implement gravity and collision with such a structure?

Good afternoon, I'm trying to implement collision and gravity in pygame, I decided to try to write all this on classes and ran into a misunderstanding of the implementation.

I am attaching the code:
https://github.com/s1veme/game-bomber

In the bomber/scenes.py file , I have a MainScene class , which is the main scene of the game.
I'm trying to implement gravity in this particular class, because I believe that this is the responsibility of this class.

If I implemented a simple fall down by adding y to the Player class every second, then there is trouble with collisions.

Can you please tell me how to implement the collision? Am I correct in my responsibility?
When falling, the player should collide with the floor and stop, the same should happen if the player tries to go to the right or left.

I would be grateful if you tell me what can be changed in the classes and how to implement a collision.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Chetchasov, 2022-03-05
@TalismanChet

take the Rect of the bomb image and for each point of this Rect top_left, top_right, top, left, right, bottom_left, bottom_left, center check the collide with, for example, the earth or character Rect with Rect.collidepoint(point) -> bool will return True on collision

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question