Last active
June 25, 2026 17:07
-
-
Save aeinbu/ec68039cb4f766927fe57f6a0a0fff40 to your computer and use it in GitHub Desktop.
Leander Stickman
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pygame, random | |
| W, H = 800, 600 | |
| class Stickman: | |
| def __init__(self): | |
| self.x = random.randint(50, W - 50) | |
| self.hp = 20 | |
| self.level = 1 | |
| self.xp = 0 | |
| def add_xp(self, a): | |
| self.xp += a | |
| if self.xp >= self.level * 10: | |
| self.level += 1 | |
| self.xp = 0 | |
| def fight(self, opponent): | |
| if abs(self.x - opponent.x) > 25: | |
| return | |
| if random.random() < 0.1: | |
| opponent.hp -= 2 | |
| self.add_xp(2) | |
| def update(self): | |
| self.x += random.randint(-2, 2) | |
| def draw(self, surface, color=(0, 0, 0)): | |
| ARM_JOINT = pygame.Vector2(self.x, 300 - 12) | |
| LEG_JOINT = pygame.Vector2(self.x, 300 - 2) | |
| LEFT_ARM = LEFT_LEG = pygame.Vector2(-10, 10) | |
| RIGHT_ARM = RIGHT_LEG = pygame.Vector2(10, 10) | |
| # Head | |
| pygame.draw.circle(surface, color, (self.x, 300 - 20), 8) | |
| # Torso | |
| pygame.draw.line(surface, color, ARM_JOINT, LEG_JOINT, 2) | |
| # Arms | |
| pygame.draw.line(surface, color, ARM_JOINT, ARM_JOINT+LEFT_ARM, 2) | |
| pygame.draw.line(surface, color, ARM_JOINT, ARM_JOINT+RIGHT_ARM, 2) | |
| # Legs | |
| pygame.draw.line(surface, color, LEG_JOINT, LEG_JOINT+LEFT_LEG, 2) | |
| pygame.draw.line(surface, color, LEG_JOINT, LEG_JOINT+RIGHT_LEG, 2) | |
| # World | |
| actors = [] | |
| selectedActor = None | |
| pygame.init() | |
| screen = pygame.display.set_mode((W, H)) | |
| clock = pygame.time.Clock() | |
| for _ in range(10): | |
| actors.append(Stickman()) | |
| # Main loop | |
| running = True | |
| while running: | |
| for event in pygame.event.get(): | |
| if event.type == pygame.QUIT: | |
| running = False | |
| if event.type == pygame.MOUSEBUTTONDOWN: | |
| mouse_x, _ = pygame.mouse.get_pos() | |
| for actor in actors: | |
| if abs(actor.x - mouse_x) < 10: | |
| selectedActor = actor | |
| for actor in actors: | |
| actor.update() | |
| for i in range(len(actors)): | |
| for j in range(i + 1, len(actors)): | |
| actors[i].fight(actors[j]) | |
| screen.fill((255, 255, 255)) | |
| for actor in actors: | |
| color = (0, 0, 0) if actor != selectedActor else (255, 0, 0) | |
| actor.draw(screen, color) | |
| pygame.display.flip() | |
| clock.tick(60) | |
| pygame.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment