SHARE
TWEET

Untitled

a guest Apr 18th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame
  2. import random
  3. import math
  4.  
  5.  
  6. class Character:
  7.     def __init__(self):
  8.         self.health = 100
  9.         self.health_placeholder = 100
  10.         self.func_list = [self.spell_berserk, self.spell_fierce_berserk, self.spell_light_healing]
  11.  
  12.     def spell_berserk(self):
  13.         self.min_dmg = 18
  14.         self.max_dmg = 25
  15.  
  16.         return random.randint(self.min_dmg, self.max_dmg)
  17.  
  18.     def spell_fierce_berserk(self):
  19.         self.min_dmg = 10
  20.         self.max_dmg = 35
  21.  
  22.         return random.randint(self.min_dmg, self.max_dmg)
  23.  
  24.     def spell_light_healing(self):
  25.         self.min_heal = 12
  26.         self.max_heal = 30
  27.  
  28.         return random.randint(self.min_heal, self.max_heal)
  29.  
  30.  
  31. class Bot(Character):
  32.     pass
  33.  
  34.  
  35. class Game:
  36.     def __init__(self):
  37.         pygame.init()
  38.         self.stop_game = False
  39.         self.bg_color = [211, 211, 211]
  40.         self.display_width = 600
  41.         self.display_height = 480
  42.         self.score = 0
  43.         self.fps_number = 15
  44.         self.clock = pygame.time.Clock()
  45.         self.game_display = pygame.display.set_mode((self.display_width, self.display_height))
  46.         pygame.display.set_caption('Pokemon_Battle_Game')
  47.         self.character = Character()
  48.         self.character.health = 100
  49.         self.bot = Bot()
  50.         self.health_green = pygame.Color('green')
  51.         self.health_yellow = pygame.Color('yellow')
  52.         self.health_red = pygame.Color('red')
  53.         self.border_black = pygame.Color('black')
  54.         self.btn_gray = pygame.Color('gray')
  55.         self.btn_dark_gray = pygame.Color('dark gray')
  56.         self.btn_blue = pygame.Color('blue')
  57.         self.health_color_player = None  # https://stackoverflow.com/questions/40750584/this-inspection-detects-instance-attribute-definition-outside-init-method
  58.         self.health_color_bot = None
  59.         self.spells_button = None
  60.  
  61.     def health_bar(self):
  62.         # hp bar for Character
  63.         if self.character.health > 75:
  64.             self.health_color_player = self.health_green
  65.         elif self.character.health > 49:
  66.             self.health_color_player = self.health_yellow
  67.         else:
  68.             self.health_color_player = self.health_red
  69.  
  70.         # hp bar for Bot
  71.         if self.bot.health > 75:
  72.             self.health_color_bot = self.health_green
  73.         elif self.bot.health > 49:
  74.             self.health_color_bot = self.health_yellow
  75.         else:
  76.             self.health_color_bot = self.health_red
  77.  
  78.         pygame.draw.rect(self.game_display, self.health_color_player, [50, 5, self.character.health, 25], 0)  # printing health bar
  79.         pygame.draw.rect(self.game_display, self.border_black, [50, 5, self.character.health_placeholder, 25], 1)  # printing border
  80.         pygame.draw.rect(self.game_display, self.health_color_bot, [460, 5, self.bot.health, 25], 0)  # printing health for Bot
  81.         pygame.draw.rect(self.game_display, self.border_black, [460, 5, self.bot.health_placeholder, 25], 1)  # printing border for Bot
  82.  
  83.     def display_hp(self):
  84.         font = pygame.font.SysFont("arial", 14)
  85.         text = font.render(f"{self.character.health} / 100", True, (15, 5, 25))
  86.         self.game_display.blit(text, (80, 9))
  87.         text = font.render(f"{self.bot.health} / 100", True, (15, 5, 25))
  88.         self.game_display.blit(text, (490, 9))
  89.  
  90.     def creating_characters(self):
  91.         # creating Character image
  92.         self.water_priest = pygame.image.load("images/water-mage.png")
  93.         self.game_display.blit(self.water_priest, (10, 50))
  94.         # creating Bot image character
  95.         self.dark_priest = pygame.image.load("images/dark-mage.png")
  96.         self.game_display.blit(self.dark_priest, (360, 50))
  97.  
  98.     # drawing spell buttons and hover
  99.     def spell_buttons(self):
  100.         mouse = pygame.mouse.get_pos()
  101.         click = pygame.mouse.get_pressed()
  102.         # first button
  103.         if 190+50 > mouse[0] > 190 and 5+30 > mouse[1] > 5:
  104.             pygame.draw.rect(self.game_display, self.btn_dark_gray, (190, 5, 75, 30))
  105.             if click[0] == 1:
  106.                 self.bot.health = self.bot.health - self.character.spell_berserk()
  107.                 self.character.health = self.character.health - self.character.spell_berserk()
  108.         else:
  109.             pygame.draw.rect(self.game_display, self.btn_gray, (190, 5, 75, 30))
  110.         # second button
  111.         if 270+50 > mouse[0] > 270 and 5+30 > mouse[1] > 5:
  112.             pygame.draw.rect(self.game_display, self.btn_dark_gray, (270, 5, 75, 30))
  113.             if click[0] == 1:
  114.                 self.bot.health = self.bot.health - self.character.spell_fierce_berserk()
  115.                 self.character.health = self.character.health - self.character.spell_fierce_berserk()
  116.         else:
  117.             pygame.draw.rect(self.game_display, self.btn_gray, (270, 5, 75, 30))
  118.         # third button
  119.         if 350+50 > mouse[0] > 350 and 5+30 > mouse[1] > 5:
  120.             pygame.draw.rect(self.game_display, self.btn_dark_gray, (350, 5, 75, 30))
  121.             if click[0] == 1:
  122.                 self.character.health = self.character.health + self.character.spell_light_healing()
  123.                 self.bot.health = self.bot.health + self.character.spell_light_healing()
  124.         else:
  125.             pygame.draw.rect(self.game_display, self.btn_gray, (350, 5, 75, 30))
  126.         # printing txt on spell_buttons
  127.         font = pygame.font.SysFont("arial", 13)
  128.         text = font.render(f"Berserk", True, (15, 5, 25))
  129.         self.game_display.blit(text, (210, 10))
  130.  
  131.         font = pygame.font.SysFont("arial", 13)
  132.         text = font.render(f"Fierce Berserk", True, (15, 5, 25))
  133.         self.game_display.blit(text, (272, 10))
  134.  
  135.         font = pygame.font.SysFont("arial", 13)
  136.         text = font.render(f"Light Healing", True, (15, 5, 25))
  137.         self.game_display.blit(text, (355, 10))
  138.  
  139.     def quit_button(self):
  140.         click = pygame.mouse.get_pressed()
  141.         mouse = pygame.mouse.get_pos()
  142.         if 540+55 > mouse[0] > 540 and 445+30 > mouse[1] > 445:
  143.             pygame.draw.rect(self.game_display, self.btn_blue, (540, 445, 55, 30))
  144.             if click[0] == 1:
  145.                 pygame.quit()
  146.                 quit()
  147.  
  148.         font = pygame.font.SysFont("arial", 14)
  149.         text = font.render(f"Quit", True, (15, 5, 25))
  150.         self.game_display.blit(text, (555, 450))
  151.  
  152.     # ESC to quit
  153.     def handle_keyboard_input(self):
  154.         for event in pygame.event.get():
  155.             if event.type == pygame.KEYDOWN:
  156.                 if event.type == pygame.QUIT:
  157.                     self.stop_game = True
  158.                 if event.key == pygame.K_ESCAPE:
  159.                     self.stop_game = True
  160.  
  161.     def game_over(self):
  162.         if self.character.health <= 0 \
  163.                 or self.bot.health <= 0:
  164.             self.stop_game = True
  165.             print("Game Over!")
  166.         else:
  167.             pass
  168.  
  169.     def game_loop(self):
  170.         while not self.stop_game:
  171.             self.game_display.fill(self.bg_color)
  172.             self.clock.tick(self.fps_number)
  173.             self.handle_keyboard_input()
  174.             self.health_bar()
  175.             self.display_hp()
  176.             self.creating_characters()
  177.             self.spell_buttons()
  178.             self.quit_button()
  179.             pygame.display.update()
  180.             self.game_over()
  181.  
  182.  
  183. Game().game_loop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top