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


Messages In This Thread
Doodle Jump - by Dafteaser - Apr-25-2020, 01:18 PM
RE: Doodle Jump - by michael1789 - Apr-25-2020, 09:49 PM
RE: Doodle Jump - by lolloiltizio - May-25-2020, 09:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] infinity jump problem augusto_A 3 1,635 May-27-2023, 01:17 AM
Last Post: deanhystad
  pygame double jump problem Yegor123 3 2,624 May-02-2023, 09:34 PM
Last Post: sudoku6
  [PyGame] Problems with jump code in pygame Joningstone 4 5,423 Aug-23-2021, 08:23 PM
Last Post: deanhystad
  [PyGame] Having 4 players(Sprites) all being able to jump ElijahCastle 5 4,055 May-07-2019, 05:04 PM
Last Post: SheeppOSU
  Doodle Jump themed game! georgecoopers 1 5,845 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