+ 2

How to make a variable updates itself constantly in pygame? (Making a ball not able to reach a certain height)

So basically I have this code #---------------Configuration statements------------------------------ import pygame import time pygame.init() display_width = 600 display_height = 600 gameDisplay=pygame.display.set_mode((display_width,display_height)) pygame.display.set_caption('Jump') clock = pygame.time.Clock() #-------------colors--------------- black = ((0,0,0)) white=((255,255,255)) #------------Moving objects : circle---------------------------------- x_circle = 50 y_circle = 500 y_circle_change= 0 orientationState = int(0) #0 for idle, 1 for upwards, 2 for downwards radius_circle = 20 def cercle(color,x_circle,y_circle,radius_circle): pygame.draw.circle(gameDisplay,color,[x_circle,y_circle],radius_circle) #_________Static objects : square----------------------------------- crashed = False while not crashed: for event in pygame.event.get(): if event.type == pygame.QUIT: crashed = True if event.type == pygame.KEYDOWN: if event.key==pygame.K_SPACE: y_circle_change = 10 orientationState = int(1) if event.type==pygame.KEYUP: if y_circle<=500 : y_circle_change = 10 orientationState=int(2) if y_circle>=500: orientationState = int(0) if y_circle>=500: y_circle_change = 0 y_circle = 500 orientationState = int(0) if orientationState is int(1): y_circle -= y_circle_change if orientationState is int(2): y_circle+=y_circle_change elif orientationState is int(0): y_circle+=0 pygame.display.update() clock.tick(60) gameDisplay.fill(white) cercle(black,x_circle,y_circle,50) What I am trying to do here is to prevent the circle, which is actually a ball, to be lower than a certain height, what it does instead is it let the ball fall but when I do press

8th May 2018, 1:44 AM
Louis Couture
Louis Couture - avatar
2 Réponses
0
You are using somekind of engine for your program if I'm not mistaking? Well, sorry for not answering your question, I don't even know the engine you're using. But to avoid having troubles like these, consider writing your own code/engine, because it is way easier for debugging, for a very simple reason - you know what your code contains and you will fix bugs way easier. With every engine/library like this, you need to take a course or something in order to master it, and that doesn't give you much experience in programming... I have a similar ball physics code written in java, which works pretty well as far as I remember... Let me know if you need help....
9th May 2018, 9:13 AM
Robert Sokolov
Robert Sokolov - avatar
0
I am not using any engine just the standard python software and the pygame library
11th May 2018, 7:39 PM
Louis Couture
Louis Couture - avatar