im trying to make it so when i click on the mouse an image will appear then when i click a 2nd then 3rd then 4th time, an image will appear, i want it to keep looping through the images.
i set Dimension to pygame.imgage then in my main loop, i tried to add it to an event. but nothing seemed to work when i run the code. It displays everything i need, sound as well but no image when i click. How do i fix? sorry im new.
import pygame
import SpriteSheet
pygame.init()
pygame.mixer.init()
SCREEN_WIDTH = 450
SCREEN_HEIGHT = 800
screen = pygame.display.set_mode((SCREEN_HEIGHT, SCREEN_WIDTH))
pygame.display.set_caption("Rick & Morty Clicks")
Rick_Garage = pygame.image.load('Garage_.jpeg')
PortalGun = pygame.image.load('PortalGun_.png')
Dimension = pygame.image.load('PDimension1.png')
Gunsound = pygame.mixer.Sound('PortalGunsound.mp3')
pygame.mouse.set_visible(False)
PortalGun = pygame.transform.scale(PortalGun, (200, 200))
Sprite_Sheet_image = pygame.image.load('PortalSheet.png').convert_alpha()
sprite_sheet = SpriteSheet.SpriteSheet(Sprite_Sheet_image)
BLACK = (0, 0, 0)
animation_list = []
animation_steps = 90
last_update = pygame.time.get_ticks()
animation_cooldown = 30
frame = 0
for x in range(animation_steps):
animation_list.append(sprite_sheet.get_image(x, 400, 400, BLACK))
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.MOUSEBUTTONDOWN:
screen.blit(Dimension, (0, 0))
Gunsound.play()
# Clear the screen
screen.fill((0, 0, 0))
current_time = pygame.time.get_ticks()
if current_time - last_update >= animation_cooldown:
frame += 1
last_update = current_time
if frame >= len(animation_list):
frame = 0
# if pygame.mouse.get_pressed()[0]:
# screen.blit(Dimension, (0, 0))
# Blit the garage background
screen.blit(Rick_Garage, (0, 0))
screen.blit(animation_list[frame], (250, 0))
# Get the mouse position
pos = pygame.mouse.get_pos()
# Blit the PortalGun image at the mouse position
screen.blit(PortalGun, pos)
# Update the display
pygame.display.update()
pygame.quit()