Untitled
unknown
plain_text
2 years ago
1.6 kB
4
Indexable
>>> import pygame
import sys
# Initialize Pygame
pygame.init()
# Constants
WIDTH, HEIGHT = 800, 600
FPS = 60
WHITE = (255, 255, 255)
RED = (255, 0, 0)
# Create the game window
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Jumping Mice Game")
# Create the mouse character
mouse_width, mouse_height = 50, 50
mouse_x, mouse_y = WIDTH // 2 - mouse_width // 2, HEIGHT - mouse_height
mouse_speed = 5
is_jumping = False
jump_count = 10
# Main game loop
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
keys = pygame.key.get_pressed()
# Move the mouse left and right
if keys[pygame.K_LEFT] and mouse_x > 0:
mouse_x -= mouse_speed
if keys[pygame.K_RIGHT] and mouse_x < WIDTH - mouse_width:
mouse_x += mouse_speed
# Jumping logic
if not is_jumping:
if keys[pygame.K_SPACE]:
is_jumping = True
else:
if jump_count >= -10:
neg = 1
if jump_count < 0:
neg = -1
mouse_y -= (jump_count ** 2) * 0.5 * neg
jump_count -= 1
else:
is_jumping = False
jump_count = 10
# Draw the background and mouse
screen.fill(WHITE)
pygame.draw.rect(screen, RED, (mouse_x, mouse_y, mouse_width, mouse_height))
# Update the display
pygame.display.flip()
# Cap the frame rate
clock.tick(FPS)
Editor is loading...
Leave a Comment