I am making a meme guessing game in Pygame Zero where an image changes depending on the current meme that should be displayed. The problem is that despite me having the proper blitting and image loading (from my understanding) the image does not ever change.
Here is my code:
import pygame
import random
WIDTH = 1280
HEIGHT = 720
main_box = Rect(0, 0, 410, 120)
timer_box = Rect(0, 0, 240, 240)
answer_box1 = Rect(0, 0, 200, 75)
answer_box2 = Rect(0, 0, 200, 75)
answer_box3 = Rect(0, 0, 200, 75)
answer_box4 = Rect(0, 0, 200, 75)
main_box.move_ip(50, 40)
timer_box.move_ip(990, 40)
answer_box1.move_ip(150, 600)
answer_box2.move_ip(400, 600)
answer_box3.move_ip(650, 600)
answer_box4.move_ip(900, 600)
answer_boxes = [answer_box1, answer_box2, answer_box3, answer_box4]
score = 0
time_left = 10
time_deduction = 1
q1 = ["What is the name of this dog?", "Shiba", "Berkley", "Doge", "Gabe", 4]
q2 = ["What is this dog's breed?", "Doge", "Golden Retriever", "Shiba Inu", "Samoyed", 3]
questions = [q1, q2]
memes = [("gabe.png", 0), ("doge.png", 1)]
current_meme = memes[random.randint(0, len(memes) - 1)] # Initialize current_meme
which_question = current_meme[1]
question = questions[which_question]
def draw():
screen.clear()
screen.fill("light gray")
meme_image = pygame.image.load(current_meme[0]).convert_alpha()
screen.blit(meme_image, (WIDTH/2 - meme_image.get_width()/2, HEIGHT/2 - meme_image.get_height()/2))
for box in answer_boxes:
screen.draw.filled_rect(box, "orange")
screen.draw.textbox(str(time_left), timer_box, color=("black"))
screen.draw.textbox(question[0], main_box, color=("black"))
index = 1
for box in answer_boxes:
screen.draw.textbox(question[index], box, color=("black"))
index = index + 1
a
def game_over():
global question, time_left
message = "Game over. You got %s questions correct" % str(score)
question = [message, "-", "-", "-", "-", 5]
time_left = 0
def correct_answer():
global question, score, time_left, time_deduction, current_meme
score = score + 1
if questions:
question = questions.pop(0)
time_deduction = time_deduction + 1
time_left = 10 - time_deduction
else:
print("End of questions")
game_over()
def on_mouse_down(pos):
index = 1
for box in answer_boxes:
if box.collidepoint(pos):
print("Clicked on answer " + str(index))
if index == question[5]:
print("You got it correct!")
correct_answer()
else:
game_over()
index = index + 1
def update_time_left():
global time_left, update_meme
if time_left:
time_left = time_left - 1
else:
game_over()
if time_left == 0:
update_meme()
def update_meme():
global current_meme, which_question, question
meme_index = random.randint(0, len(memes) -1)
current_meme = memes[meme_index]
which_question = current_meme[1]
question = questions[which_question]
clock.schedule_interval(update_time_left, 1.0)
I attempted to blit an image to the screen that would change continually depending on the value of the current_meme variable, but instead the image did not change despite the code resulting in no errors.
Fools Gold Glisterrs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.