Hi, I'm new here, and I'm a beginner programmer.
I'm working with python and pygame library.
-Attached picture
For some reason When I try to post my prntscrn picture on paint, it doesn't show the arrow flying and the dog disappearing while the arrow still is in the air. (this happens when I click my left mouse button).
Now I want the arrow to hit the moving dog and if it hits it, let both of them disappear, how do I do that?
My problem now is that when I shoot (left mouse button), the entire game waits for the attack loop to end, and the dog disappears of screen.
I've been working on this problem a couple of months back, and now returned to try for hours with no result.
Here is my code:
import pygame
import random
# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
pygame.init()
# Set the width and height of the screen [width, height]
screen_width = 1280
screen_height = 800
screen = pygame.display.set_mode([screen_width, screen_height])
pygame.display.set_caption("Hunter")
# Loop until the user clicks the close button.
done = False
# Used to manage how fast the screen updates
clock = pygame.time.Clock()
background_image = pygame.image.load("backgroundImage.png").convert()
characterImage = pygame.image.load("Player1.png").convert()
characterImage1 = pygame.image.load("Player2.png").convert()
click_sound = pygame.mixer.Sound("shoot.ogg")
arrow = pygame.image.load("arrow.png").convert()
dog = pygame.image.load("dog.png").convert()
characterImage.set_colorkey(WHITE)
arrow.set_colorkey(WHITE)
dog.set_colorkey(WHITE)
pygame.mouse.set_visible(False)
dogX = 1200
dogY = 655
# -------- Main Program Loop -----------
while not done:
# --- Main event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
#attack animation
if event.type==pygame.MOUSEBUTTONDOWN:
click_sound.play()
arrowX = charPos[0]+20
arrowY = charPos[1]+20
for arrowPixel in range(800):
charPos = pygame.mouse.get_pos()
charX = charPos[0]
charY = charPos[1]
screen.blit(characterImage, [charX-32, charY-35])
screen.blit(background_image, [0,0])
screen.blit(characterImage1, [charPos[0], charPos[1]])
screen.blit(arrow, [arrowX, arrowY])
arrowX += 1
pygame.display.flip()
###################################################### --- Game logic should go here
###################################################### --- Drawing code should go here
screen.blit(background_image, [0,0])
# player movement
charPos = pygame.mouse.get_pos()
charX = charPos[0]
charY = charPos[1]
screen.blit(characterImage, [charX-32, charY-35])
#monsters
screen.blit(dog, [dogX, dogY])
dogX -= 1
pygame.display.flip()
clock.tick(60)
pygame.quit()
For some reason the code posted here without indentations, if I can fix this tell me and I will.