python mario coad
python mario coad
import sys
# Initialize Pygame
pygame.init()
# Set up display
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Mario-Like Platformer")
# Colors
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
# Player settings
player_width = 50
player_height = 50
player_x = 100
player_y = 500
player_velocity = 5
player_jump = -15
gravity = 0.8
y_velocity = 0
is_jumping = False
# Platform settings
platform_width = 800
platform_height = 50
platform_y = 550
# Game loop
while True:
screen.fill(WHITE) # Fill screen with white
# Event handling
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# Jumping mechanic
if not is_jumping:
if keys[pygame.K_SPACE]:
y_velocity = player_jump
is_jumping = True
else:
y_velocity += gravity
player_y += y_velocity