Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Doodle Jump
#1
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
Reply
#2
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.
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] infinity jump problem augusto_A 3 1,563 May-27-2023, 01:17 AM
Last Post: deanhystad
  pygame double jump problem Yegor123 3 2,568 May-02-2023, 09:34 PM
Last Post: sudoku6
  [PyGame] Problems with jump code in pygame Joningstone 4 5,354 Aug-23-2021, 08:23 PM
Last Post: deanhystad
  [PyGame] Having 4 players(Sprites) all being able to jump ElijahCastle 5 3,999 May-07-2019, 05:04 PM
Last Post: SheeppOSU
  Doodle Jump themed game! georgecoopers 1 5,813 Apr-11-2017, 08:47 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020