A simple Pygame that has a square move and jump How does this Pygame code look? Is the run loop usually in a class? I'm a beginner and was wondering what the best format and structure is for using OOP in Pygame.

import pygame
pygame.init()

win = pygame.display.set_mode((500, 500)) 
pygame.display.set_caption("Game")


class Game:

    def __init__(self):
        self.x = 250
        self.y = 250
        self.width = 50
        self.height = 50
        self.vel = 5
        self.isJump = False
        self.jumpCount = 10

    def run(self):
        run = True
        while run:
            pygame.time.delay(30)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    run = False

            keys = pygame.key.get_pressed()

            if keys[pygame.K_LEFT] and self.x &gt; 0:
                self.x -= self.vel

            if keys[pygame.K_RIGHT] and self.x &lt; 500 - self.width:
                self.x += self.vel

            if not self.isJump:
                if keys[pygame.K_UP] and self.y &gt; 0:
                    self.y -= self.vel

                if keys[pygame.K_DOWN] and self.y &lt; 500 - self.height:
                    self.y += self.vel

                if keys[pygame.K_SPACE]:
                    self.isJump = True
            else:
                if self.jumpCount &gt;= -10:
                    self.y -= (self.jumpCount * abs(self.jumpCount)) * 0.5
                    self.jumpCount -= 1
                else:
                    self.jumpCount = 10
                    self.isJump = False

            win.fill((0, 0, 0))
            self.draw()

        pygame.quit()

    def draw(self):
        pygame.draw.rect(win, (0, 0, 255), (self.x, self.y, self.width, self.height))
        pygame.display.update()

g = Game()
g.run()
Few areas to improve:


self.vel. When I first saw this field/variable I thought: "What is that?".I guess many other people may have the same first feeling.I would rename it to an explicit and clear name: self.velocity
self.isJump and self.jumpCount violate Python naming conventions (instance variable names should be all lower case, words in an instance variable name should be separated by an underscore). Therefore, rename them to:

...
self.is_jump
self.jump_count`

run = True flag. That flag for just controlling the while loop flow is redundant.We're just starting the loop with while True: and breaking it with break.So it becomes:

def run(self):
    while True:
        pygame.time.delay(30)                
        keys = pygame.key.get_pressed()

        # handling pressed keys
        if keys ...

        win.fill((0, 0, 0))
        self.draw()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                break
    pygame.quit()