Advertisement
alexshaff

GEMMA 3 27B INTERACTIVE GAME

Mar 12th, 2025
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.58 KB | None | 0 0
  1. # https://www.reddit.com/r/LocalLLaMA/comments/1j7j6cg/comment/mgxbpxa/
  2. # 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.
  3. # 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.
  4. # 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.
  5. # 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.
  6. # 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.
  7. # 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
  8.  
  9. import pygame
  10. import random
  11.  
  12. # Initialize Pygame
  13. pygame.init()
  14.  
  15. # Screen dimensions
  16. screen_width = 800
  17. screen_height = 600
  18. screen = pygame.display.set_mode((screen_width, screen_height))
  19. pygame.display.set_caption("Silly Showdown!")
  20.  
  21. # Colors
  22. white = (255, 255, 255)
  23. black = (0, 0, 0)
  24. red = (255, 0, 0)
  25. green = (0, 255, 0)
  26. blue = (0, 0, 255)
  27. yellow = (255, 255, 0)
  28. purple = (128, 0, 128)
  29.  
  30. # Player class
  31. class Player(pygame.sprite.Sprite):
  32. def __init__(self):
  33. super().__init__()
  34. self.image = pygame.Surface([50, 50])
  35. self.image.fill(blue)
  36. self.rect = self.image.get_rect()
  37. self.rect.center = (screen_width // 2, screen_height - 50)
  38. self.speed = 5
  39. self.health = 100
  40. self.attack = 10
  41. self.attacking = False
  42. self.attack_timer = 0
  43.  
  44. def update(self):
  45. keys = pygame.key.get_pressed()
  46. if keys[pygame.K_w]:
  47. self.rect.y -= self.speed
  48. if keys[pygame.K_s]:
  49. self.rect.y += self.speed
  50. if keys[pygame.K_a]:
  51. self.rect.x -= self.speed
  52. if keys[pygame.K_d]:
  53. self.rect.x += self.speed
  54.  
  55. # Keep player within screen bounds
  56. self.rect.x = max(0, min(self.rect.x, screen_width - self.rect.width))
  57. self.rect.y = max(0, min(self.rect.y, screen_height - self.rect.height))
  58.  
  59. if self.attacking:
  60. self.attack_timer += 1
  61. if self.attack_timer > 5:
  62. self.attacking = False
  63. self.attack_timer = 0
  64.  
  65. def attack_visual(self):
  66. pygame.draw.line(screen, red, self.rect.center, (self.rect.center[0] + 60, self.rect.center[1]), 5)
  67.  
  68. # Enemy classes
  69. class Enemy(pygame.sprite.Sprite):
  70. def __init__(self, name, health, attack, speed, color, attack_style):
  71. super().__init__()
  72. self.name = name
  73. self.health = health
  74. self.attack = attack
  75. self.speed = speed
  76. self.color = color
  77. self.attack_style = attack_style
  78. self.image = pygame.Surface([40, 40])
  79. self.image.fill(self.color)
  80. self.rect = self.image.get_rect()
  81. self.rect.x = random.randint(0, screen_width - self.rect.width)
  82. self.rect.y = 50
  83. self.attacking = False
  84. self.attack_timer = 0
  85.  
  86. def update(self, player):
  87. # Move towards player
  88. if player.rect.x > self.rect.x:
  89. self.rect.x += self.speed
  90. elif player.rect.x < self.rect.x:
  91. self.rect.x -= self.speed
  92. if player.rect.y > self.rect.y:
  93. self.rect.y += self.speed
  94. elif player.rect.y < self.rect.y:
  95. self.rect.y -= self.speed
  96.  
  97. # Attack logic
  98. if not self.attacking and random.randint(0, 100) < 2: # 2% chance to attack
  99. self.attacking = True
  100. self.attack_timer = 0
  101.  
  102. if self.attacking:
  103. self.attack_timer += 1
  104. if self.attack_timer > 10:
  105. self.attacking = False
  106. self.attack_timer = 0
  107. return True # Return True to indicate attack happened
  108.  
  109. return False
  110.  
  111. def attack_visual(self):
  112. if self.attack_style == "wave":
  113. pygame.draw.circle(screen, red, self.rect.center, 20, 2)
  114. elif self.attack_style == "beam":
  115. pygame.draw.line(screen, red, self.rect.center, (self.rect.center[0] - 60, self.rect.center[1]), 5)
  116. elif self.attack_style == "spin":
  117. pygame.draw.circle(screen, red, self.rect.center, 30, 1)
  118.  
  119. # Enemy list and difficulty progression
  120. enemies_data = [
  121. ("Sir Reginald Fluffbottom", 50, 5, 2, green, "wave"),
  122. ("Madame Gigglesnort", 75, 8, 3, purple, "beam"),
  123. ("Captain Calico Chaos", 100, 12, 4, yellow, "spin"),
  124. ("Professor Bumblebrook", 125, 15, 5, red, "wave"),
  125. ("The Grand Poobah", 150, 20, 6, black, "beam")
  126. ]
  127.  
  128. # Game loop
  129. def main():
  130. player = Player()
  131. player_group = pygame.sprite.Group()
  132. player_group.add(player)
  133.  
  134. enemy = None
  135. enemy_group = pygame.sprite.Group()
  136. enemy_index = 0
  137.  
  138. font = pygame.font.Font(None, 36)
  139. game_over_font = pygame.font.Font(None, 72)
  140.  
  141. running = True
  142. game_over = False
  143.  
  144. def spawn_enemy():
  145. nonlocal enemy, enemy_index
  146. if enemy_index < len(enemies_data):
  147. enemy_name, health, attack, speed, color, attack_style = enemies_data[enemy_index]
  148. enemy = Enemy(enemy_name, health, attack, speed, color, attack_style)
  149. enemy_group.add(enemy)
  150. enemy_index += 1
  151.  
  152. spawn_enemy()
  153.  
  154. while running:
  155. for event in pygame.event.get():
  156. if event.type == pygame.QUIT:
  157. running = False
  158. if event.type == pygame.KEYDOWN:
  159. if event.key == pygame.K_SPACE and not player.attacking:
  160. player.attacking = True
  161. player.attack_timer = 0
  162.  
  163. if not game_over:
  164. player.update()
  165.  
  166. if enemy:
  167. attack_happened = enemy.update(player)
  168. if attack_happened:
  169. # Check for collision and apply damage
  170. if pygame.sprite.collide_rect(player, enemy):
  171. player.health -= enemy.attack
  172. print(f"Player hit! Health: {player.health}")
  173.  
  174. if pygame.sprite.collide_rect(player, enemy) and player.attacking:
  175. enemy.health -= player.attack
  176. print(f"{enemy.name} hit! Health: {enemy.health}")
  177. if enemy.health <= 0:
  178. print(f"You defeated {enemy.name}!")
  179. enemy.kill()
  180. enemy = None
  181. spawn_enemy()
  182.  
  183. # Check for player death
  184. if player.health <= 0:
  185. game_over = True
  186. print("Game Over!")
  187.  
  188. # Draw everything
  189. screen.fill(white) # Background color
  190.  
  191. # Draw background elements (e.g., hills, trees)
  192. pygame.draw.rect(screen, green, (0, screen_height - 100, screen_width, 100)) # Ground
  193. pygame.draw.rect(screen, blue, (0, screen_height - 200, screen_width, 100)) # Water
  194.  
  195. player_group.draw(screen)
  196. enemy_group.draw(screen)
  197.  
  198. if player.attacking:
  199. player.attack_visual()
  200. if enemy and enemy.attacking:
  201. enemy.attack_visual()
  202.  
  203. # Display health
  204. health_text = font.render(f"Health: {player.health}", True, black)
  205. screen.blit(health_text, (10, 10))
  206.  
  207. else:
  208. # Game Over screen
  209. screen.fill(black)
  210. game_over_text = game_over_font.render("Game Over!", True, red)
  211. game_over_rect = game_over_text.get_rect(center=(screen_width // 2, screen_height // 2))
  212. screen.blit(game_over_text, game_over_rect)
  213.  
  214. pygame.display.flip()
  215. pygame.time.Clock().tick(60)
  216.  
  217. pygame.quit()
  218.  
  219. if __name__ == "__main__":
  220. main()
  221.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement