Quiero dibujar círculos sobre una tablero de juego. Utilicé una función para transformar las coordenadas en la lista en coordenadas en píxeles que funcionó bien con un tablero de juego más grande. Sin embargo ahora ella le da esto:
La bola blanca, que debía estar en el medio, está en la parte inferior izquierda.
Aqui esta el codigo para dibujar:
for sailor in sailors:
x = sailor.x
y = sailor.y
print(x,y)
centerx, centery = translateBoardToPixelCoord(x, y)
print(centerx, centery)
if sailor.player == 'white' or sailor.player == 'black':
if sailor.player == 'white':
tileColor = WHITE
else:
tileColor = BLACK
print(DISPLAYSURF, tileColor, (centerx, centery), int(SPACESIZE / 2) - 4)
pygame.draw.circle(DISPLAYSURF, tileColor, (centerx, centery -100), int(SPACESIZE / 2) - 4)
Y aqui el codigo para transformar coordenadas tabulares en coordenadas de píxeles.
def translateBoardToPixelCoord(x, y):
return XMARGIN + x * SPACESIZE + int(SPACESIZE / 2), YMARGIN + y * SPACESIZE + int(SPACESIZE / 2)
Aquí están todas las constantes :
FPS = 10 # frames per second to update the screen
WINDOWWIDTH = 640 # width of the program's window, in pixels
WINDOWHEIGHT = 480 # height in pixels
SPACESIZE = 50 # width & height of each space on the board, in pixels
BOARDWIDTH = 11 # how many columns of spaces on the game board
BOARDHEIGHT = 3 # how many rows of spaces on the game board
EARTHWIDTH = 11
EARTHHEIGHT = 1
WHITE_TILE = 'WHITE_TILE' # an arbitrary but unique value
BLACK_TILE = 'BLACK_TILE' # an arbitrary but unique value
EMPTY_SPACE = 'EMPTY_SPACE' # an arbitrary but unique value
HINT_TILE = 'HINT_TILE' # an arbitrary but unique value
ANIMATIONSPEED = 25 # integer from 1 to 100, higher is faster animation
# Amount of space on the left & right side (XMARGIN) or above and below
# (YMARGIN) the game board, in pixels.
XMARGIN = int((WINDOWWIDTH - (BOARDWIDTH * SPACESIZE)) / 2)
YMARGIN = int((WINDOWHEIGHT - (BOARDHEIGHT * SPACESIZE)) / 2)
Y aqui esta lo que me contesta el console:
C:\Users\antoi\Documents\Programming\projects\Videogames>python projet_ambroise.py
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
[['EMPTY_SPACE', 'EMPTY_SPACE', 'EMPTY_SPACE'], ['EMPTY_SPACE', 'EMPTY_SPACE', 'EMPTY_SPACE'], ['EMPTY_SPACE', 'EMPTY_SPACE', 'EMPTY_SPACE'], ['EMPTY_SPACE', 'EMPTY_SPACE', 'EMPTY_SPACE'], ['EMPTY_SPACE', 'EMPTY_SPACE', 'EMPTY_SPACE'], ['EMPTY_SPACE', 'EMPTY_SPACE', 'EMPTY_SPACE'], ['EMPTY_SPACE', 'EMPTY_SPACE', 'EMPTY_SPACE'], ['EMPTY_SPACE', 'EMPTY_SPACE', 'EMPTY_SPACE'], ['EMPTY_SPACE', 'EMPTY_SPACE', 'EMPTY_SPACE'], ['EMPTY_SPACE', 'EMPTY_SPACE', 'EMPTY_SPACE'], ['EMPTY_SPACE', 'EMPTY_SPACE', 'EMPTY_SPACE']]
([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2])
11
(1, 6)
(120, 490)
(<Surface(640x480x32 SW)>, (0, 0, 0), (120, 490), 21)
(1, 6)
(120, 490)
(<Surface(640x480x32 SW)>, (0, 0, 0), (120, 490), 21)
(1, 6)
(120, 490)
(<Surface(640x480x32 SW)>, (255, 255, 255), (120, 490), 21)
(1, 6)
(120, 490)
(<Surface(640x480x32 SW)>, (255, 255, 255), (120, 490), 21)
¿Ya no son adecuados los márgenes?