Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://www.reddit.com/r/LocalLLaMA/comments/1j7j6cg/comment/mgxbpxa/
- # Create an interactive action game. The player character will need to face multiple opponents with silly/creative names. These characters, including the player, should be represented in a way that is unique to other characters.
- # The game should have combat. Every time the player defeats one enemy character, a new enemy character should be introduced, slightly harder than the previous one, and with a unique style of attacking. The player character should be movable through the WASD keys W=up, A=left S=down D=right. The player should be able to ‘attack’ using the space key. There should be a visual associated with all actions, same goes for the enemy.
- # The enemy should steadily move towards the player, occasionally attacking. There should be a visual queue (use Pygame shapes to make this) for when the player attacks and when the enemy attacks.
- # The player should not ‘die’ instantly if hit, there should be health, attack, damage to this game. You may implement it however you see fit.
- # There should be a visual representation of the player and the enemies, all unique, as well as visual representation of the ‘attacks’. The visuals cannot be provided externally through png files so you need to make them yourself out of basic shapes of different colors in a way that conveys what is happening.
- # Use Python, specifically the PyGame module, in order to make this game. Make it stylish and colorful. The background should reflect a scene of some sort
- import pygame
- import random
- # Initialize Pygame
- pygame.init()
- # Screen dimensions
- screen_width = 800
- screen_height = 600
- screen = pygame.display.set_mode((screen_width, screen_height))
- pygame.display.set_caption("Silly Showdown!")
- # Colors
- white = (255, 255, 255)
- black = (0, 0, 0)
- red = (255, 0, 0)
- green = (0, 255, 0)
- blue = (0, 0, 255)
- yellow = (255, 255, 0)
- purple = (128, 0, 128)
- # Player class
- class Player(pygame.sprite.Sprite):
- def __init__(self):
- super().__init__()
- self.image = pygame.Surface([50, 50])
- self.image.fill(blue)
- self.rect = self.image.get_rect()
- self.rect.center = (screen_width // 2, screen_height - 50)
- self.speed = 5
- self.health = 100
- self.attack = 10
- self.attacking = False
- self.attack_timer = 0
- def update(self):
- keys = pygame.key.get_pressed()
- if keys[pygame.K_w]:
- self.rect.y -= self.speed
- if keys[pygame.K_s]:
- self.rect.y += self.speed
- if keys[pygame.K_a]:
- self.rect.x -= self.speed
- if keys[pygame.K_d]:
- self.rect.x += self.speed
- # Keep player within screen bounds
- self.rect.x = max(0, min(self.rect.x, screen_width - self.rect.width))
- self.rect.y = max(0, min(self.rect.y, screen_height - self.rect.height))
- if self.attacking:
- self.attack_timer += 1
- if self.attack_timer > 5:
- self.attacking = False
- self.attack_timer = 0
- def attack_visual(self):
- pygame.draw.line(screen, red, self.rect.center, (self.rect.center[0] + 60, self.rect.center[1]), 5)
- # Enemy classes
- class Enemy(pygame.sprite.Sprite):
- def __init__(self, name, health, attack, speed, color, attack_style):
- super().__init__()
- self.name = name
- self.health = health
- self.attack = attack
- self.speed = speed
- self.color = color
- self.attack_style = attack_style
- self.image = pygame.Surface([40, 40])
- self.image.fill(self.color)
- self.rect = self.image.get_rect()
- self.rect.x = random.randint(0, screen_width - self.rect.width)
- self.rect.y = 50
- self.attacking = False
- self.attack_timer = 0
- def update(self, player):
- # Move towards player
- if player.rect.x > self.rect.x:
- self.rect.x += self.speed
- elif player.rect.x < self.rect.x:
- self.rect.x -= self.speed
- if player.rect.y > self.rect.y:
- self.rect.y += self.speed
- elif player.rect.y < self.rect.y:
- self.rect.y -= self.speed
- # Attack logic
- if not self.attacking and random.randint(0, 100) < 2: # 2% chance to attack
- self.attacking = True
- self.attack_timer = 0
- if self.attacking:
- self.attack_timer += 1
- if self.attack_timer > 10:
- self.attacking = False
- self.attack_timer = 0
- return True # Return True to indicate attack happened
- return False
- def attack_visual(self):
- if self.attack_style == "wave":
- pygame.draw.circle(screen, red, self.rect.center, 20, 2)
- elif self.attack_style == "beam":
- pygame.draw.line(screen, red, self.rect.center, (self.rect.center[0] - 60, self.rect.center[1]), 5)
- elif self.attack_style == "spin":
- pygame.draw.circle(screen, red, self.rect.center, 30, 1)
- # Enemy list and difficulty progression
- enemies_data = [
- ("Sir Reginald Fluffbottom", 50, 5, 2, green, "wave"),
- ("Madame Gigglesnort", 75, 8, 3, purple, "beam"),
- ("Captain Calico Chaos", 100, 12, 4, yellow, "spin"),
- ("Professor Bumblebrook", 125, 15, 5, red, "wave"),
- ("The Grand Poobah", 150, 20, 6, black, "beam")
- ]
- # Game loop
- def main():
- player = Player()
- player_group = pygame.sprite.Group()
- player_group.add(player)
- enemy = None
- enemy_group = pygame.sprite.Group()
- enemy_index = 0
- font = pygame.font.Font(None, 36)
- game_over_font = pygame.font.Font(None, 72)
- running = True
- game_over = False
- def spawn_enemy():
- nonlocal enemy, enemy_index
- if enemy_index < len(enemies_data):
- enemy_name, health, attack, speed, color, attack_style = enemies_data[enemy_index]
- enemy = Enemy(enemy_name, health, attack, speed, color, attack_style)
- enemy_group.add(enemy)
- enemy_index += 1
- spawn_enemy()
- while running:
- 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 player.attacking:
- player.attacking = True
- player.attack_timer = 0
- if not game_over:
- player.update()
- if enemy:
- attack_happened = enemy.update(player)
- if attack_happened:
- # Check for collision and apply damage
- if pygame.sprite.collide_rect(player, enemy):
- player.health -= enemy.attack
- print(f"Player hit! Health: {player.health}")
- if pygame.sprite.collide_rect(player, enemy) and player.attacking:
- enemy.health -= player.attack
- print(f"{enemy.name} hit! Health: {enemy.health}")
- if enemy.health <= 0:
- print(f"You defeated {enemy.name}!")
- enemy.kill()
- enemy = None
- spawn_enemy()
- # Check for player death
- if player.health <= 0:
- game_over = True
- print("Game Over!")
- # Draw everything
- screen.fill(white) # Background color
- # Draw background elements (e.g., hills, trees)
- pygame.draw.rect(screen, green, (0, screen_height - 100, screen_width, 100)) # Ground
- pygame.draw.rect(screen, blue, (0, screen_height - 200, screen_width, 100)) # Water
- player_group.draw(screen)
- enemy_group.draw(screen)
- if player.attacking:
- player.attack_visual()
- if enemy and enemy.attacking:
- enemy.attack_visual()
- # Display health
- health_text = font.render(f"Health: {player.health}", True, black)
- screen.blit(health_text, (10, 10))
- else:
- # Game Over screen
- screen.fill(black)
- game_over_text = game_over_font.render("Game Over!", True, red)
- game_over_rect = game_over_text.get_rect(center=(screen_width // 2, screen_height // 2))
- screen.blit(game_over_text, game_over_rect)
- pygame.display.flip()
- pygame.time.Clock().tick(60)
- pygame.quit()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement