Untitled
unknown
plain_text
2 months ago
5.3 kB
9
Indexable
import pygame
import sys
pygame.init()
# Screen setup
WIDTH, HEIGHT = 600, 800
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Troll Tower (Python Prototype)")
clock = pygame.time.Clock()
# Colors
WHITE = (255, 255, 255)
BLUE = (0, 100, 255)
RED = (255, 80, 80)
GREEN = (80, 255, 100)
# Player
player = pygame.Rect(300, 700, 30, 30)
velocity_y = 0
gravity = 0.5
jump_power = -10
# Platforms (x, y, width, height)
platforms = [
pygame.Rect(250, 750, 100, 10),
pygame.Rect(200, 650, 120, 10),
pygame.Rect(300, 550, 120, 10),
pygame.Rect(150, 450, 120, 10),
pygame.Rect(250, 350, 120, 10),
]
# Troll platforms (disappear when touched)
trolls = [
pygame.Rect(100, 600, 100, 10),
pygame.Rect(400, 500, 100, 10),
]
running = True
while running:
screen.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
# Movement
if keys[pygame.K_LEFT]:
player.x -= 5
if keys[pygame.K_RIGHT]:
player.x += 5
# Gravity
velocity_y += gravity
player.y += velocity_y
# Collision with platforms
for platform in platforms:
if player.colliderect(platform) and velocity_y > 0:
player.bottom = platform.top
velocity_y = jump_power
# Troll platforms logic
for troll in trolls[:]:
if player.colliderect(troll):
trolls.remove(troll) # disappear!
# Draw platforms
for platform in platforms:
pygame.draw.rect(screen, BLUE, platform)
# Draw troll blocks
for troll in trolls:
pygame.draw.rect(screen, RED, troll)
# Draw player
pygame.draw.rect(screen, GREEN, player)
pygame.display.flip()
clock.tick(60)
pygame.quit()
sys.exit()
]
]Editor is loading...
Leave a Comment