Closed Subisuresh321 closed 8 months ago
try adding random.seed(time.time())
before the loop to generate some randomness, by default pygbag starts games in reproducible mode.
ref : https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHASHSEED
probably would be good to add this to wiki https://pygame-web.github.io/wiki/pygbag-code/
thanks
in my game random question and answer is selected to ask 3 times...in pycharm i am getting random question out of 30 questions..but after using pygbag..i am getting the 3 same questions in same order everytime i run (not same question three time)...
the code: import pygame, asyncio import random
Initialize Pygame
pygame.init()
Set up some constants
WIDTH, HEIGHT = 800, 600 FPS = 60
Create the screen
screen = pygame.display.set_mode((WIDTH, HEIGHT))
Load the images
bg = pygame.image.load('images/restoration_photo_bot.png') bg=pygame.transform.smoothscale(bg,(800,600)) player_img = pygame.image.load('images/dora.png') player_img=pygame.transform.smoothscale(player_img,(150,150)) question_card = pygame.image.load('images/card.jpg') question_card=pygame.transform.smoothscale(question_card,(800,600)) yes_img = pygame.image.load('images/yes.png') yes_img=pygame.transform.smoothscale(yes_img,(90,90)) no_img = pygame.image.load('images/no.png') no_img=pygame.transform.smoothscale(no_img,(90,90)) start_image=pygame.image.load('images/start.png') start_image=pygame.transform.smoothscale(start_image,(50,50)) textbox_image=pygame.image.load('images/textbox.png') textbox_image=pygame.transform.smoothscale(textbox_image,(250,250))
correct
correct_image=pygame.image.load('images/verified.png') correct_image=pygame.transform.smoothscale(correct_image,(80,80)) correct_image.convert()
wrong
wrong_image=pygame.image.load('images/wrong.png') wrong_image=pygame.transform.smoothscale(wrong_image,(80,80)) wrong_image.convert()
won
won_image=pygame.image.load('images/won.jpg') won_image=pygame.transform.smoothscale(won_image,(800,600))
Set up the player
player_rect = player_img.get_rect() player_rect.topleft = (0,450)
Set up the target positions
target_positions = [pygame.Vector2(180, 360), pygame.Vector2(320, 230), pygame.Vector2(530, 120)] current_target_index = 0 speed = 1
font
font = pygame.font.Font(None, 36)
sound
pygame.mixer.music.load('sounds/bgsound.ogg') pygame.mixer.music.play(-1) won_sound=pygame.mixer.Sound('sounds/jaichu.ogg')
questions and answers
questions_answers = { "Is the sky blue?": "yes", "Can a dog fly?": "no", "Is a banana yellow?": "yes", "Do we eat with our feet?": "no", "Is water wet?": "yes", "Can cars talk?": "no", "Do you wear shoes on your hands?": "no", "Is ice cream cold?": "yes", "Can fish live outside water?": "no", "Is a pineapple blue?": "no", "Do birds swim?": "no", "Is an ant small?": "yes", "Can elephants jump?": "no", "Do we drink food?": "no", "Is a car faster than a bicycle?": "yes", "Can a cat bark?": "no", "Is chocolate sweet?": "yes", "Can a mouse roar?": "no", "Is a tomato a fruit?": "no", "Can a rabbit climb trees?": "no", "Is a strawberry red?": "yes", "Is a circle round?": "yes", "Can a bird swim?": "no", "Is a square round?": "no", "Can a fish climb a tree?": "no", "Is a triangle round?": "no", "Can a car swim?": "no", "Is a flower shape like a square?": "no", "Can a bicycle fly?": "no", "Is a star shape like a circle?": "no", "Can a teddy bear talk?": "no" } current_question = None current_answer = None questions_answers_list = list(questions_answers.items()) random.shuffle(questions_answers_list)
Set up the game loop
async def main_loop(): global current_target_index,current_answer,current_question,questions_answers_list clickable=False game_started=False running = True while running:
Draw everything
asyncio.run(main_loop())