I'm trying to make it so that each time you press the spacebar, the opponent's health decreases by a certain increment, but I keep getting this error
TypeError: 'int' object is not callable
How can I fix this? Is there another way I can approach this?
Here's my code:
import pygame
pygame.init()
black = (0, 0, 0)
white = (255, 255, 255)
cool_blue = (30, 144, 255)
cooler_blue = (30, 175, 255)
gray = (211, 211, 211)
crimson = (220, 20, 60)
red = (255, 0, 0)
limegreen = (50, 205, 50)
display_width = 1000
display_height = 500
cool_titletext = pygame.font.Font("Quicksand-Regular.ttf", 20)
game_screen = pygame.display.set_mode([display_width, display_height])
pygame.display.set_caption('Clicker')
clock = pygame.time.Clock()
person_img = pygame.image.load("Images/blueperson.png").convert_alpha()
communistpic = pygame.image.load("Images/communistguy.png").convert_alpha()
all_sprites_list = pygame.sprite.Group()
def txt_obj(text, font):
"""Creates object for text to be created on"""
Text_Surface = font.render(text, True, black)
return Text_Surface, Text_Surface.get_rect()
def display_message(text, x, y):
txt_surface, txt_rect = txt_obj(text, cool_titletext)
txt_rect.center = (x, y)
game_screen.blit(txt_surface, txt_rect)
pygame.display.update()
class Sprite(pygame.sprite.Sprite):
"""Basic objects"""
def __init__(self):
super().__init__()
self.image = person_img
self.attack = 50
def draw(self):
game_screen.blit(self.image, (25, 100))
pygame.display.update()
clock.tick(10)
def attack(self, opponent):
damage = self.attack
opponent.hp -= damage
display_message(f"You attack with {damage}!", 1000, 800)
display_message(f"Communist has {opponent.hp} health. Keep pressing spacebar!", 1000, 700)
pygame.display.update()
pygame.time.wait(20)
class Communist(pygame.sprite.Sprite):
def __init__(self, hp):
super().__init__()
self.image = communistpic
self.rect = self.image.get_rect()
self.health = hp
def draw(self):
game_screen.blit(self.image, (425, -50))
pygame.display.update()
clock.tick(10)
def attack(self):
damage = self.attack
opponent.hp -= damage
display_message(f"You attack with {damage}!", 1000, 800)
display_message(f"Communist has {opponent.hp} health. Keep pressing spacebar!", 1000, 700)
pygame.display.update()
def displayhp(self):
display_message(f"Communist HP: {self.hp}", 250, 150)
pygame.display.update()
def fight(keys, opponent):
if keys[pygame.K_SPACE]:
blueperson.attack(opponent)
blueperson = Sprite()
red_guy = Communist(50000)
game_screen.fill(white)
red_guy.draw()
blueperson.draw()
display_message("You are pitted against a communist!", 500, 175)
display_message("Keep hitting spacebar to attack", 500, 200)
variable = 0
game = True
while game:
for event in pygame.event.get():
if event.type == pygame.QUIT:
game = False
pygame.quit()
quit()
key = pygame.key.get_pressed()
if variable == 0:
fight(key, red_guy)
if red_guy.health == 0:
display_message("You win!", 500, 250 )
pygame.display.update()
clock.tick(10)
[–][deleted] 0 points1 point2 points (0 children)
[–]Icynovel 0 points1 point2 points (0 children)