1

okay so I am trying to make a game like ludo, with pygame. When I run it on windows the player (blue dot) doesn't move farther than the first line, but if I run it in linux works fine. It draws the circle depending on the players position but it doesn't print it if the position is above or equal to 7.

here is the code of the game (sorry for the bad coding, thanks!!):

import random
import pygame

pygame.init()

black = ( 0, 0, 0)
white = ( 255, 255, 255)
blue = ( 0, 0, 255)

#cambia esta variable para cambiar la posicion de inicio
pos = 0

screenw = 600
screenh = 750
screen = pygame.display.set_mode((screenw,screenh))
cellsize = 75

tablero = ([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])

preg = (['tema: texto', 'S.O.', 'Edit texto', 'redes', 'edit imagen sonido y video', 'Edit hojas CÁLCULO', 'comodin para tema imagen', 'Infografía', 'Mapa conceptual', 'línea del tiempo', 'Captura de pantalla', 'Editar imagen', 'comodin para tema sonido', 'PODCAST PRESENTANDOSE', 'soundtrack (youtube .mp3)', 'Descargar de Ivoox', 'Editor sonido u editor online de extras', 'Descarga de soundsnap', 'comodin para tema video', 'VIDEO (youtube mp3)', 'Screen video & Desktop', 'Screen Brower Tab', 'Webcam recording presentandose', 'Editar video u editor online', 'comodin para tema paginas web', 'Full screen captura', 'Editor webpage / editor online', 'Cuaderno digital', 'HTML webpage', 'Firma en correo', 'has llegado al final!'])

dado = 0

tablero[pos] = 1


#draw the board
def tabla():
    pygame.draw.rect(screen, white, (cellsize, cellsize*6, cellsize, cellsize), 3)
    pygame.draw.rect(screen, white, (cellsize*6, cellsize, cellsize, cellsize), 3)
    for x in range(1, 8):
        for y in range(1, 7):
            pygame.draw.line(screen, white, ( x*cellsize, cellsize), ( x*cellsize, cellsize*6))
            pygame.draw.line(screen, white, ( cellsize, y*cellsize), ( cellsize*7, y*cellsize))
            pygame.display.update()

x = 0
clock = pygame.time.Clock()


#main loop
while x != 30 or pos >= 32:
    clock.tick(10)
    
    #draw the board
    tabla()

    #throw a dice 
    print("presione enter para lanzar dado")
    input()
    dado = random.randint(1, 6)
    print("dado", dado)

    screen.fill(black)
    tabla()
 
    #remove the player and update the position
    tablero[pos] = 0
    preg[pos] = ' '
    pos += dado

    if pos >= 32:
        pos = 32
        tablero[pos] = 1
        print("enhorabuena, has ganado!! Puedes pedir tu punto extra de la evaluacion a Monica")
    #update the position
    tablero[pos] = 1
    print(tablero)
    print(pos)
    
    #this part isn't finished
    if pos == 4:
        for p in range(1, 7):
            if preg[p] == ' ':
                screen.fill(black)
                tabla()
                print("elige una pregunta del bloque anterior antes de continuar")
                pos += 7

    #draw the circle that simbolices the player depending on the position
    #this is where I get the problem
    if pos >= pos and pos < 7:
        screen.fill(black)
        tabla()
        pygame.draw.circle(screen, blue, ((cellsize*pos) + (cellsize/2), (cellsize*5 + (cellsize/2))), cellsize/3)

    elif pos >= 7 and pos < 13:
        screen.fill(black)
        tabla()
        pygame.draw.circle(screen, blue, ((cellsize*(pos-6)) + (cellsize/2), (cellsize*4 + (cellsize/2))), cellsize/3)

    elif pos >= 13 and pos < 19:
        screen.fill(black)
        tabla()
        pygame.draw.circle(screen, blue, ((cellsize*(pos-12)) + (cellsize/2), (cellsize*3 + (cellsize/2))), cellsize/3)

    elif pos >= 19 and pos < 25:
        screen.fill(black)
        tabla()
        pygame.draw.circle(screen, blue, ((cellsize*(pos-18)) + (cellsize/2), (cellsize*2 + (cellsize/2))), cellsize/3)

    elif pos >= 25 and pos < 32:
        screen.fill(black)
        tabla()
        pygame.draw.circle(screen, blue, ((cellsize*(pos-24)) + (cellsize/2), (cellsize + (cellsize/2))), cellsize/3)

    #print a question from a list depending on the player's position
    print("preg:", preg[pos - 1])

    #add 1 to the loop
    x += 1

1 Answers1

1

You have to handle the events in the application loop. See pygame.event.get() respectively pygame.event.pump():

For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system.

while x != 30 or pos >= 32:
    clock.tick(10)
    pygame.event.pump()

    # [...]
Rabbid76
  • 202,892
  • 27
  • 131
  • 174