Hi, myself and two of my friends are creating a game that imitates that of Whack-a-mole. I am trying to implement code so that when I click on the mole with the mouse, the image changes to a different image, eg. the image when just moving the mouse is a mallet, and Im trying to change that when the mousebutton is clicked, the image will change to a different one, eg. mallet facing downwards as if it is hitting the mole and then revert back to the first image.
Here is mallet class and the code that's done so far:
class MalletUp(pygame.sprite.Sprite): def __init__ (self, (posX, posY)): pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load("../src/images/malletup.jpg") self.rect = self.image.get_rect() transColor = self.image.get_at((1,1)) self.image.set_colorkey(transColor) self.x = posX self.y = posY self.rect.center = (self.x, self.y) ' States for mouse click down or up ' self.noClick = 0 self.mouseRelease = 1 self.mouseClick = 2 self.mouseCounter = 3 def update(self): self.x, self.y = pygame.mouse.get_pos() self.rect.center = (self.x, self.y) ''' keys = pygame.key.get_pressed() if keys[pygame.MOUSEBUTTONUP]: self.noClick = self.mouseRelease ''' gameRunning = True while gameRunning == True: #while stay_in_loop == True: for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: self.noClick = self.mouseClick self.image = pygame.image.load("../src/images/malletdown.png") print "mouse pos:", pygame.mouse.get_pos()
Here is the mallet class being updated in the main code:
backgroundSprite.update(screen) malletSprites.clear(screen, background) ' Update mallet to the screen ' malletSprites.update() backgroundSprite.draw(screen) ' Draw the mallet to the screen ' malletSprites.draw(screen) pygame.display.flip()
We cant really do much more until we get this part working so would appreciate any help given.
-Edit- If anyone wants to see my main code class I can post all of the code.