0

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)
ArCh6'HA
  • 1
  • 1
  • What is your code purpose? When you say `the sprite isn't jumping` what do you mean? or in other words - what is the output you get and what is the expected output? What Python version is this? – Or b May 19 '22 at 21:49
  • 1
    I want the sprite to jump automatically checking when checking for collisions, jumping is false as long as the sprite is not touching the platforms, the expected output is a sprite jumping auto checking for collisions on a platform, also, this is on replit – ArCh6'HA May 20 '22 at 12:23

0 Answers0