MCPcopy Index your code
hub / github.com/ndleah/python-mini-project / animatedMoves

Function animatedMoves

Chess_Game/ChessGame.py:128–146  ·  view source on GitHub ↗
(move, screen,board, clock)

Source from the content-addressed store, hash-verified

126 screen.blit(IMAGES[piece], p.Rect(c*SQ_SIZE, r*SQ_SIZE, SQ_SIZE, SQ_SIZE))
127
128def animatedMoves(move, screen,board, clock):
129 global colors
130 dR = move.endRow - move.startRow
131 dC = move.endCol - move.startCol
132 framesPerSquare = 5
133 frameCount = (abs(dR) + abs(dC)) * framesPerSquare
134 for frame in range(frameCount + 1):
135 r,c =((move.startRow + dR*frame/frameCount, move.startCol + dC*frame/frameCount))
136 drawBoard(screen)
137 drawPieces(screen, board)
138 color = colors[(move.endRow + move.endCol)%2]
139 endSquare = p.Rect(move.endCol*SQ_SIZE, move.endRow*SQ_SIZE, SQ_SIZE, SQ_SIZE)
140 p.draw.rect(screen, color, endSquare)
141 if move.pieceCaptured != "--":
142 screen.blit(IMAGES[move.pieceCaptured], endSquare)
143
144 screen.blit(IMAGES[move.pieceMoved], p.Rect(c*SQ_SIZE, r*SQ_SIZE, SQ_SIZE, SQ_SIZE))
145 p.display.flip()
146 clock.tick(60)
147
148def drawText(screen, text):
149 font = p.font.SysFont("Helvitca", 32, True, False)

Callers 1

mainFunction · 0.85

Calls 2

drawBoardFunction · 0.85
drawPiecesFunction · 0.85

Tested by

no test coverage detected