Python Forum
[PyGame] Doodle Jump - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: [PyGame] Doodle Jump (/thread-26257.html)



Doodle Jump - Dafteaser - Apr-25-2020

Hello,
I recently started programming with Python and I started making a Doodle Jump game with PyGame.
I used a simple method to identify the collision between the character and the platform.
However, this collision isn't always identified with a platform moving up and down (horizontally).
Any ideas how to make it 100% work?
Here is my code for the character:
characterJump = 300
    if characterJump < 150:
        positionCharacterY += 2
        if rightFootCharacter[1] == height:
            characterJump = 300
        for i in range(160):   #Test if platform and character collide
            if (rightFootCharacter[0] == (platformMatrix[0][i] + imagePlateform1x)) and (rightFootCharacter[1] == imagePlateform1y):
                characterJump = 300
            
    characterJump -= 1
And this is my code for the platform:
platformUp = 400
        if platformUp < 200:
            imagePlateform1y -= 2
        if platformUp == 0:
            platformUp = 400
        if platformUp > 200:
            imagePlateform1y += 2
        
        platformUp -= 2
Thanks for the ideas Smile


RE: Doodle Jump - michael1789 - Apr-25-2020

The big tip I can offer is to use pygame sprites and pygame's collision detection.

HERE is a video from a tutorial I followed a while ago on making exactly that type of game. I would do it all largely the same if I were to do it again.

He uses pygame.sprite.spritecollide() for detection and the screen scroll happens when your player hits a certain height on the screen. When the player hits that height, all the platform sprites have a number added to their y coordinates.


RE: Doodle Jump - lolloiltizio - May-25-2020

well you can also use pygame Rect and the finction colliderect() like
character = pygame.Rect(x, y, width, height)
platform = pygame.Rect(x, y, width, height)
speed = 5 
and in the while loop:
if character.colliderect(platform):
    jump() #a function that I haven't defined wich makes the character jump
else:
    character.y += speed
Implementing this should solve your problems.

If you want to put a not defined number of platforms, than you should do something like this:

#where platforms is a list filled with platforms rects variables

for platform in platforms:
    if character.colliderect(platform):
        jump() #a function that I haven't defined wich makes the character jump
    else:
        character.y += speed
With this thing you can avoid messing up with classes for such a simple project...
for further informations about this visit the "getting projectiles in pygame" in this forum ;P