Help with simple python project. (I’m brand new to coding or programming of any kind.) /u/Exp-Turkeys Python Education

So i just started working on a simple python project to help me learn using the module pygame, but I’m having trouble with a certain section. My current plan is to simply make my stickman jump over the rectangle that is sliding through the screen, however, I can’t seem to figure out why “stickman_run” does not reappear after it plays the jumping animation. Heres a copy of my code. Sorry if this is a dumb question.

import pygame # Define some colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) pygame.init() # Set the width and height of the screen [width, height] size = (700, 500) screen = pygame.display.set_mode(size) pygame.display.set_caption("My Game") def stickman_run(): pygame.draw.ellipse(screen, WHITE, [stickman_x, 200, 30, 30]) # Head pygame.draw.polygon(screen, WHITE, [[365, 220], [359, 260], [362, 260]]) # Body pygame.draw.polygon(screen, WHITE, [[361, 260], [362, 260], [374, 278], [372, 278]]) # Thigh 1 pygame.draw.polygon(screen, WHITE, [[372, 278], [374, 278], [362, 286], [360, 286]]) # Shin 1 pygame.draw.polygon(screen, WHITE, [[360, 260], [359, 260], [349, 290], [350, 290]]) # Leg 2 def stickman_jump(): pygame.draw.ellipse(screen, WHITE, [350, 200, 30, 30]) # Head # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() rect_x = 700 stickman_x = 350 rect_change_x = 5 # -------- Main Program Loop ----------- while not done: # --- Main event loop for event in pygame.event.get(): if event.type == pygame.QUIT: done = True # --- Game logic should go here rect_x -= 5 if rect_x < -50: rect_x = 700 if rect_x - stickman_x < 20: stickman_run = stickman_jump # --- Screen-clearing code goes here # Here, we clear the screen to white. Don't put other drawing commands # above this, or they will be erased with this command. # If you want a background image, replace this clear with blit'ing the # background image. screen.fill(BLACK) stickman_run() pygame.draw.rect(screen, WHITE, [rect_x, 250, 50, 50]) # --- Drawing code should go here # --- Go ahead and update the screen with what we've drawn. pygame.display.flip() # --- Limit to 60 frames per second clock.tick(60) # Close the window and quit. pygame.quit() 

submitted by /u/Exp-Turkeys
[link] [comments]

​r/learnpython So i just started working on a simple python project to help me learn using the module pygame, but I’m having trouble with a certain section. My current plan is to simply make my stickman jump over the rectangle that is sliding through the screen, however, I can’t seem to figure out why “stickman_run” does not reappear after it plays the jumping animation. Heres a copy of my code. Sorry if this is a dumb question. import pygame # Define some colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) pygame.init() # Set the width and height of the screen [width, height] size = (700, 500) screen = pygame.display.set_mode(size) pygame.display.set_caption(“My Game”) def stickman_run(): pygame.draw.ellipse(screen, WHITE, [stickman_x, 200, 30, 30]) # Head pygame.draw.polygon(screen, WHITE, [[365, 220], [359, 260], [362, 260]]) # Body pygame.draw.polygon(screen, WHITE, [[361, 260], [362, 260], [374, 278], [372, 278]]) # Thigh 1 pygame.draw.polygon(screen, WHITE, [[372, 278], [374, 278], [362, 286], [360, 286]]) # Shin 1 pygame.draw.polygon(screen, WHITE, [[360, 260], [359, 260], [349, 290], [350, 290]]) # Leg 2 def stickman_jump(): pygame.draw.ellipse(screen, WHITE, [350, 200, 30, 30]) # Head # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() rect_x = 700 stickman_x = 350 rect_change_x = 5 # ——– Main Program Loop ———– while not done: # — Main event loop for event in pygame.event.get(): if event.type == pygame.QUIT: done = True # — Game logic should go here rect_x -= 5 if rect_x < -50: rect_x = 700 if rect_x – stickman_x < 20: stickman_run = stickman_jump # — Screen-clearing code goes here # Here, we clear the screen to white. Don’t put other drawing commands # above this, or they will be erased with this command. # If you want a background image, replace this clear with blit’ing the # background image. screen.fill(BLACK) stickman_run() pygame.draw.rect(screen, WHITE, [rect_x, 250, 50, 50]) # — Drawing code should go here # — Go ahead and update the screen with what we’ve drawn. pygame.display.flip() # — Limit to 60 frames per second clock.tick(60) # Close the window and quit. pygame.quit() submitted by /u/Exp-Turkeys [link] [comments] 

So i just started working on a simple python project to help me learn using the module pygame, but I’m having trouble with a certain section. My current plan is to simply make my stickman jump over the rectangle that is sliding through the screen, however, I can’t seem to figure out why “stickman_run” does not reappear after it plays the jumping animation. Heres a copy of my code. Sorry if this is a dumb question.

import pygame # Define some colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) pygame.init() # Set the width and height of the screen [width, height] size = (700, 500) screen = pygame.display.set_mode(size) pygame.display.set_caption("My Game") def stickman_run(): pygame.draw.ellipse(screen, WHITE, [stickman_x, 200, 30, 30]) # Head pygame.draw.polygon(screen, WHITE, [[365, 220], [359, 260], [362, 260]]) # Body pygame.draw.polygon(screen, WHITE, [[361, 260], [362, 260], [374, 278], [372, 278]]) # Thigh 1 pygame.draw.polygon(screen, WHITE, [[372, 278], [374, 278], [362, 286], [360, 286]]) # Shin 1 pygame.draw.polygon(screen, WHITE, [[360, 260], [359, 260], [349, 290], [350, 290]]) # Leg 2 def stickman_jump(): pygame.draw.ellipse(screen, WHITE, [350, 200, 30, 30]) # Head # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() rect_x = 700 stickman_x = 350 rect_change_x = 5 # -------- Main Program Loop ----------- while not done: # --- Main event loop for event in pygame.event.get(): if event.type == pygame.QUIT: done = True # --- Game logic should go here rect_x -= 5 if rect_x < -50: rect_x = 700 if rect_x - stickman_x < 20: stickman_run = stickman_jump # --- Screen-clearing code goes here # Here, we clear the screen to white. Don't put other drawing commands # above this, or they will be erased with this command. # If you want a background image, replace this clear with blit'ing the # background image. screen.fill(BLACK) stickman_run() pygame.draw.rect(screen, WHITE, [rect_x, 250, 50, 50]) # --- Drawing code should go here # --- Go ahead and update the screen with what we've drawn. pygame.display.flip() # --- Limit to 60 frames per second clock.tick(60) # Close the window and quit. pygame.quit() 

submitted by /u/Exp-Turkeys
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *