I am making a doodle jump game for my final project following a tutorial but I can't wrap my head around why the sprite isn't jumping. I'm confused why my sprite is not jumping. I've checked several times and changed my code over and over with no luck. My code is below and contains the full code.
def draw_window():
global blocks
WIN.blit(JUMP_BACKGROUND_IMAGE, (0, 0))
WIN.blit(sprite, (sprite_x, sprite_y - 45))
blocks = [pygame.draw.rect(WIN, BLACK, platforms[0], 0, 3)]
# print(blocks)
# for i in range(len(platforms)):
# block = pygame.draw.rect(WIN, BLACK, platforms[i], 0, 3)
# blocks.append(block)
#pygame.display.update()
def main(sprite_y, jump):
clock = pygame.time.Clock()
run = True
while run:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
print(50, jump)
sprite_y, jump = update_player(sprite_y,jump)
print(52, jump)
jump = check_collisions(blocks, jump)
draw_window()
pygame.display.flip()
pygame.quit()
def update_player(y_pos,jump):
# global jump
global y_change
jump_height = 10
gravity = 1
if jump:
print("jump")
y_change -= jump_height
jump = False
y_pos += y_change
y_change += gravity
return y_pos, jump
def check_collisions(rect_list, jump):
global sprite_x
global sprite_y
global y_change
#print(rect_list,jump, sprite_x, sprite_y, y_change)
for i in range(len(rect_list)):
if rect_list[i].colliderect([sprite_x, sprite_y, 55, 10]) and jump == False and y_change > 0:
jump = True
return jump
pygame.init()
if __name__ == "__main__":
main(sprite_y, jump)