ANOTHER racing game

Made the screen green for da grass 🙂

 #draw the grass
    screen.fill(green)

so green

Added a huge gray line on the screen(it’s the road)

#draw the road
    pygame.draw.rect(screen, gray, road)

wow so cool

ANNNND made the edge markers of the road :))

# marker size
marker_width = 10
marker_height = 50

# draw edge markers
    pygame.draw.rect(screen, yellow, left_edge_marker)
    pygame.draw.rect(screen, yellow, right_edge_marker)

RESULT:

Added the lane markers and created the player’s car

line markers

lane_marker_move_y += speed *2
    if lane_marker_move_y >= marker_height * 2:
        lane_marker_move_y = 0
        
    for y in range(marker_height * -2, HEIGHT, marker_height * 2):
        pygame.draw.rect(screen, white, (left_lane + 45, 
        y + lane_marker_move_y, marker_width, marker_height))
        
        pygame.draw.rect(screen, white, (center_lane + 45,
        y + lane_marker_move_y, marker_width, marker_height))

player car (inherits from the Vehicle class)

class PlayerVehicle(Vehicle):
    
    def __init__(self, x, y):
        image = pygame.image.load('images//car.png')
        super().__init__(image, x, y)

vehicle class

class Vehicle(pygame.sprite.Sprite):
    def __init__(self, image, x, y):
        pygame.sprite.Sprite.__init__(self)

        # scale image down to fit in the lane
        image_scale = 45 / image.get_rect().width
        new_width = image.get_rect().width * image_scale
        new_height = image.get_rect().height * image_scale
        self.image = pygame.transform.scale(image, 
        (new_width, new_height))
        
        self.rect = self.image.get_rect()
        self.rect.center = [x, y]
    

RESULT

ok that’s it byeeee

Author: Zende_

From PA. EHS 2025. Does computer programming and such. That's really it.

Leave a Reply

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