SHARE
TWEET

Untitled

a guest Apr 19th, 2019 70 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.         elif self.character.health <= 0:  # not negative values
  68.             self.character.health = 0
  69.         else:
  70.             self.health_color_player = self.health_red
  71.  
  72.         # hp bar for Bot
  73.         if self.bot.health > 75:
  74.             self.health_color_bot = self.health_green
  75.         elif self.bot.health > 49:
  76.             self.health_color_bot = self.health_yellow
  77.         elif self.bot.health <= 0:  # not negative values
  78.             self.bot.health = 0
  79.         else:
  80.             self.health_color_bot = self.health_red
  81.  
  82.         pygame.draw.rect(self.game_display, self.health_color_player, [50, 5, self.character.health, 25], 0)  # printing health bar
  83.         pygame.draw.rect(self.game_display, self.border_black, [50, 5, self.character.health_placeholder, 25], 1)  # printing border
  84.         pygame.draw.rect(self.game_display, self.health_color_bot, [460, 5, self.bot.health, 25], 0)  # printing health for Bot
  85.         pygame.draw.rect(self.game_display, self.border_black, [460, 5, self.bot.health_placeholder, 25], 1)  # printing border for Bot
  86.  
  87.     def display_hp(self):
  88.         font = pygame.font.SysFont("arial", 14)
  89.         text = font.render(f"{self.character.health} / 100", True, (15, 5, 25))
  90.         self.game_display.blit(text, (80, 9))
  91.         text = font.render(f"{self.bot.health} / 100", True, (15, 5, 25))
  92.         self.game_display.blit(text, (490, 9))
  93.  
  94.     def creating_characters(self):
  95.         # creating Character image
  96.         self.water_priest = pygame.image.load("images/water-mage.png")
  97.         self.game_display.blit(self.water_priest, (10, 50))
  98.         # creating Bot image character
  99.         self.dark_priest = pygame.image.load("images/dark-mage.png")
  100.         self.game_display.blit(self.dark_priest, (360, 50))
  101.  
  102.     # drawing spell buttons and hover
  103.     def spell_buttons(self):
  104.         mouse = pygame.mouse.get_pos()
  105.         click = pygame.mouse.get_pressed()
  106.         # first button
  107.         if 190+50 > mouse[0] > 190 and 5+30 > mouse[1] > 5:
  108.             pygame.draw.rect(self.game_display, self.btn_dark_gray, (190, 5, 75, 30))
  109.             if click[0] == 1:
  110.                 self.bot.health = self.bot.health - self.character.spell_berserk()
  111.                 self.character.health = self.character.health - self.character.spell_berserk()
  112.         else:
  113.             pygame.draw.rect(self.game_display, self.btn_gray, (190, 5, 75, 30))
  114.         # second button
  115.         if 270+50 > mouse[0] > 270 and 5+30 > mouse[1] > 5:
  116.             pygame.draw.rect(self.game_display, self.btn_dark_gray, (270, 5, 75, 30))
  117.             if click[0] == 1:
  118.                 self.bot.health = self.bot.health - self.character.spell_fierce_berserk()
  119.                 self.character.health = self.character.health - self.character.spell_fierce_berserk()
  120.         else:
  121.             pygame.draw.rect(self.game_display, self.btn_gray, (270, 5, 75, 30))
  122.         # third button
  123.         if 350+50 > mouse[0] > 350 and 5+30 > mouse[1] > 5:
  124.             pygame.draw.rect(self.game_display, self.btn_dark_gray, (350, 5, 75, 30))
  125.             if click[0] == 1:
  126.                 self.character.health = self.character.health + self.character.spell_light_healing()
  127.                 self.bot.health = self.bot.health + self.character.spell_light_healing()
  128.         else:
  129.             pygame.draw.rect(self.game_display, self.btn_gray, (350, 5, 75, 30))
  130.         # printing txt on spell_buttons
  131.         font = pygame.font.SysFont("arial", 13)
  132.         text = font.render(f"Berserk", True, (15, 5, 25))
  133.         self.game_display.blit(text, (210, 10))
  134.  
  135.         font = pygame.font.SysFont("arial", 13)
  136.         text = font.render(f"Fierce Berserk", True, (15, 5, 25))
  137.         self.game_display.blit(text, (272, 10))
  138.  
  139.         font = pygame.font.SysFont("arial", 13)
  140.         text = font.render(f"Light Healing", True, (15, 5, 25))
  141.         self.game_display.blit(text, (355, 10))
  142.  
  143.     def quit_button(self):
  144.         click = pygame.mouse.get_pressed()
  145.         mouse = pygame.mouse.get_pos()
  146.         if 540+55 > mouse[0] > 540 and 445+30 > mouse[1] > 445:
  147.             pygame.draw.rect(self.game_display, self.btn_blue, (540, 445, 55, 30))
  148.             if click[0] == 1:
  149.                 pygame.quit()
  150.                 quit()
  151.  
  152.         font = pygame.font.SysFont("arial", 14)
  153.         text = font.render(f"Quit", True, (15, 5, 25))
  154.         self.game_display.blit(text, (555, 450))
  155.  
  156.     # ESC to quit
  157.     def handle_keyboard_input(self):
  158.         for event in pygame.event.get():
  159.             if event.type == pygame.KEYDOWN:
  160.                 if event.type == pygame.QUIT:
  161.                     self.stop_game = True
  162.                 if event.key == pygame.K_ESCAPE:
  163.                     self.stop_game = True
  164.  
  165.     def game_over(self):
  166.         if self.character.health <= 0 \
  167.                 or self.bot.health <= 0:
  168.             self.stop_game = False
  169.             print("Game Over!")
  170.         else:
  171.             pass
  172.  
  173.     def game_loop(self):
  174.         while not self.stop_game:
  175.             self.game_display.fill(self.bg_color)
  176.             self.clock.tick(self.fps_number)
  177.             self.handle_keyboard_input()
  178.             self.health_bar()
  179.             self.display_hp()
  180.             self.creating_characters()
  181.             self.spell_buttons()
  182.             self.quit_button()
  183.             pygame.display.update()
  184.             self.game_over()
  185.  
  186.  
  187. 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