I want a line to be drawn and rendered (for a second) when the mouse has been clicked. My example is of a game that shoots a laser or spell etc from the player to an enemy on a mouse click.
My class for the spell:
class Magic():
def __init__(self, mana=100):
self.mana = mana
self.recharge = 1
self.mana_cost = 5
def recharge_rate(self):
pass
def magic_render(self,mouse_pos):
pygame.draw.line(game_display,mg,(player.x,player.y),(mouse_pos),5)
print('fire')
My game loop:
magic = Magic()
while run_game == True: # main game loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
print('GoodBye')
run_game = False
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = pygame.mouse.get_pos()
magic.magic_render(mouse_pos)
game_display.fill(bg)
pygame.display.flip()
clock.tick(fps)
I cut out other parts of the program, but currently I can move my player around but when I click the mouse, no line is being shown, but if I remove the line game_display.fill(bg)
, then I can see the line being drawn but it stays there permanently, so I need a way it will appear for a second and still use the Magic class.