Python | Making an object jump in PyGame Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of developer, what type of game he/she wants to develop using this toolkit. So, in this article, we will learn how to make an object jump using PyGame library in Python. There is basic formula from classical mechanics to make an object jump. F = 1/2 * m * v^2 Where F is the force up/down, m is the mass of the object and v is the velocity. The velocity goes down over time because when the object jumps the velocity will not increase more in this simulation. When object reaches the ground, the jump ends. If isjump variable is True or False it indicates object is jumping or not. If isjump is True, object position will be updated according to the above formula. Below is the implementation: # import pygame module in this program import pygame # activate the pygame library . # initiate pygame and give permission # to use pygame's functionality. pygame.init() # create the display surface object # of specific dimension..e(500, 500). win = pygame.display.set_mode((500, 500)) # set the pygame window name pygame.display.set_caption("Jump Game") # object current co-ordinates x = 200 y = 200 # dimensions of the object width = 30 height = 40 # Stores if player is jumping or not isjump = False # Force (v) up and mass m. v = 5 m = 1 # Indicates pygame is running run = True # infinite loop while run: # completely fill the surface object # with black colour win.fill((0, 0, 0)) # drawing object on screen which is rectangle here pygame.draw.rect(win, (255, 0, 0), (x, y, width, height)) # iterate over the list of Event objects # that was returned by pygame.event.get() method. for event in pygame.event.get(): # if event object type is QUIT # then quitting the pygame # and program both. if event.type == pygame.QUIT: # it will make exit the while loop run = False # stores keys pressed keys = pygame.key.get_pressed() if isjump == False: # if space bar is pressed if keys[pygame.K_SPACE]: # make isjump equal to True isjump = True if isjump : # calculate force (F). F = 1 / 2 * mass * velocity ^ 2. F =(1 / 2)*m*(v**2) # change in the y co-ordinate y-= F # decreasing velocity while going up and become negative while coming down v = v-1 # object reached its maximum height if v<0: # negative sign is added to counter negative velocity m =-1 # objected reaches its original state if v ==-6: # making isjump equal to false isjump = False # setting original values to v and m v = 5 m = 1 # creates time delay of 10ms pygame.time.delay(10) # it refreshes the window pygame.display.update() # closes the pygame window pygame.quit() Output : https://media.geeksforgeeks.org/wp-content/uploads/20200203223530/Jump-Game-03-02-2020-22_16_04.mp4 Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century. Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve. Last Updated : 19 Feb, 2020 Like Article Save Article Previous Python - Moving an object in PyGame Next Adding Boundary to an Object in Pygame Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Making an object jump with gravity using arcade module in Python3 Making Label Jump using PyQt5 in Python Adding Collisions Using pygame.Rect.colliderect in Pygame Making apps with Pygame Python - Moving an object in PyGame Pygame - Random Movement of Object Adding Boundary to an Object in Pygame Making a text object with VPython Jump Statements in Python PyQt5 - Jump Search Visualizer Complete Tutorials Python Crash Course Python API Tutorial: Getting Started with APIs Advanced Python Tutorials Python Automation Tutorial OpenAI Python API - Complete Guide Like R rakshitarora Follow Article Tags : Python-PyGame Technical Scripter 2019 Python Technical Scripter Practice Tags : python Additional Information Current difficulty : Hard Vote for difficulty : Easy Normal Medium Hard Expert