Untitled
Anonymous
plain_text
02/12/2026 7:14 PM
5.3 KB
12
Indexable
import pygame
pygame.init()
window = pygame.display.set_mode((1000, 500))
clock = pygame.time.Clock()
player_size = 40
player_x = 100
player_y = 300
player_speed_y = 0
gravity = 1
jump_strength = -15
player_rect = pygame.Rect(player_x, player_y, player_size, player_size)
plane_mode = False
fly_power = -1.2
plane_start = 2700
max_jumps = 1
jump_count = 0
platforms = [
pygame.Rect(150, 400, 120, 20),
pygame.Rect(350, 350, 120, 20),
pygame.Rect(550, 300, 120, 20),
pygame.Rect(750, 320, 120, 20),
pygame.Rect(950, 280, 120, 20),
pygame.Rect(1150, 130, 120, 20),
pygame.Rect(1350, 230, 120, 20),
pygame.Rect(1550, 320, 120, 20),
pygame.Rect(1750, 360, 120, 20),
pygame.Rect(1950, 300, 120, 20),
pygame.Rect(2150, 230, 120, 20),
pygame.Rect(2350, 140, 120, 20),
pygame.Rect(2550, 210, 120, 20),
pygame.Rect(2750, 100, 120, 20),
]
spikes = []
for x in range(0, 3000, 40):
spikes.append(pygame.Rect(x, 460, 40, 40))
font = pygame.font.SysFont("Arial", 70)
game_over = False
win = False
scroll_x = 0
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and not game_over:
if jump_count < max_jumps:
player_speed_y = jump_strength
jump_count += 1
if event.key == pygame.K_r and game_over:
player_y = 300
player_speed_y = 0
jump_count = 0
game_over = False
win = False
scroll_x = 0
player_rect.y = player_y
if not game_over:
if scroll_x > plane_start:
plane_mode = True
keys = pygame.key.get_pressed()
if plane_mode:
if keys[pygame.K_SPACE]:
player_speed_y += fly_power
player_speed_y += 0.6
player_speed_y += 0.6
else:
player_speed_y += gravity
player_y += player_speed_y
player_rect.y = player_y
if plane_mode:
plane_rect = pygame.Rect(player_rect.x, player_rect.y + 10, 50, 20)
else:
plane_rect = player_rect
on_platform = False
for plat in platforms:
plat_rect = plat.move(-scroll_x, 0)
if player_rect.colliderect(plat_rect) and player_speed_y >= 0:
player_y = plat_rect.top - player_size
player_speed_y = 0
player_rect.y = player_y
jump_count = 0
on_platform = True
for spike in spikes:
spike_rect = spike.move(-scroll_x, 0)
if player_rect.colliderect(spike_rect):
game_over = True
scroll_x += 6
if scroll_x > 5000:
win = True
game_over = True
window.fill((15, 15, 15))
if plane_mode:
plane_rect = pygame.Rect(player_rect.x, plane_rect.y + 10,50,20)
pygame.draw.rect(window, (0, 200, 255), plane_rect)
else:
pygame.draw.rect(window, (255, 100, 100), player_rect)
for plat in platforms:
pygame.draw.rect(window, (100, 255, 100), plat.move(-scroll_x, 0))
for spike in spikes:
pygame.draw.polygon(window, (255, 255, 0), [
(spike.x - scroll_x, spike.y + 40),
(spike.x + 20 - scroll_x, spike.y),
(spike.x + 40 - scroll_x, spike.y + 40)
])
if game_over:
if win:
text = font.render("YOU WIN", True, (0, 255, 0))
window.blit(text, (350, 200))
else:
text = font.render("GAME OVER R - RESTART", True, (255, 0, 0))
window.blit(text, (300, 200))
pygame.display.flip()
pygame.quit()Editor is loading...
Leave a Comment