Untitled

 avatar
unknown
plain_text
13 days ago
1.3 kB
1
Indexable
import pygame

import sys


# Initialize Pygame

pygame.init()


# Constants

SCREEN_WIDTH = 800

SCREEN_HEIGHT = 600

FPS = 60


# Colors

WHITE = (255, 255, 255)

BLUE = (0, 0, 255)


# Set up the display

screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

pygame.display.set_caption("Simple Mario Game")


# Player settings

player_size = 50

player_x = SCREEN_WIDTH // 2

player_y = SCREEN_HEIGHT - player_size

player_speed = 5


# Game loop

clock = pygame.time.Clock()

while True:

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            pygame.quit()

            sys.exit()


    # Get the keys pressed

    keys = pygame.key.get_pressed()

    if keys[pygame.K_LEFT]:

        player_x -= player_speed

    if keys[pygame.K_RIGHT]:

        player_x += player_speed

    if keys[pygame.K_UP]:

        player_y -= player_speed

    if keys[pygame.K_DOWN]:

        player_y += player_speed


    # Fill the screen with white

    screen.fill(WHITE)


    # Draw the player (a simple blue square)

    pygame.draw.rect(screen, BLUE, (player_x, player_y, player_size, player_size))


    # Update the display

    pygame.display.flip()


    # Cap the frame rate

    clock.tick(FPS)
Editor is loading...
Leave a Comment