Course Content
PyGame Project: Arcade Game
PyGame Project: Arcade Game
Updating and Displaying Score and Player
In this part of your game code, we're focusing on displaying the player's score and the player character itself, then updating the game screen to show these changes. Here’s a simplified breakdown:
Displaying the Score
main_display.blit(FONT.render(str(score), True, COLOR_WHITE), (WIDTH-50, 20))
: This line takes the player's current score, converts it to a string (so it can be displayed as text), and renders it using a predefined font (FONT). The text is displayed in white (COLOR_WHITE) at a position near the top right corner of the game window (calculated by WIDTH-50, 20). This keeps the score visible to the player during the game.
Displaying the Player Character
main_display.blit(player, player_rect)
: Here, we're drawing the player's character (player) on the screen at the position defined by player_rect
. This ensures that the player sees their character and can control it during the game.
Updating the Display
pygame.display.flip()
: Finally, this command updates the entire screen with everything we've drawn so far. It essentially "flips" the display to show the new state with the updated score and player position. This happens each loop cycle, keeping the game visuals current.
Together, these steps ensure that the player always knows their score and can see their character moving around the screen, making the game interactive and engaging.
Swipe to show code editor
- Display score: use
FONT.render(str(score), True, COLOR_WHITE)
to render the score as white text andmain_display.blit
to display it near the top right corner; - Position score: place the score text at (WIDTH-50, 20), positioning it 50 pixels left from the right edge and 20 pixels down from the top of the screen;
- Show player: draw the player image at its current position with
main_display.blit(player, player_rect)
; - Update screen: refresh the entire screen to show the latest visuals with
pygame.display.flip()
.
Thanks for your feedback!
In this part of your game code, we're focusing on displaying the player's score and the player character itself, then updating the game screen to show these changes. Here’s a simplified breakdown:
Displaying the Score
main_display.blit(FONT.render(str(score), True, COLOR_WHITE), (WIDTH-50, 20))
: This line takes the player's current score, converts it to a string (so it can be displayed as text), and renders it using a predefined font (FONT). The text is displayed in white (COLOR_WHITE) at a position near the top right corner of the game window (calculated by WIDTH-50, 20). This keeps the score visible to the player during the game.
Displaying the Player Character
main_display.blit(player, player_rect)
: Here, we're drawing the player's character (player) on the screen at the position defined by player_rect
. This ensures that the player sees their character and can control it during the game.
Updating the Display
pygame.display.flip()
: Finally, this command updates the entire screen with everything we've drawn so far. It essentially "flips" the display to show the new state with the updated score and player position. This happens each loop cycle, keeping the game visuals current.
Together, these steps ensure that the player always knows their score and can see their character moving around the screen, making the game interactive and engaging.
Swipe to show code editor
- Display score: use
FONT.render(str(score), True, COLOR_WHITE)
to render the score as white text andmain_display.blit
to display it near the top right corner; - Position score: place the score text at (WIDTH-50, 20), positioning it 50 pixels left from the right edge and 20 pixels down from the top of the screen;
- Show player: draw the player image at its current position with
main_display.blit(player, player_rect)
; - Update screen: refresh the entire screen to show the latest visuals with
pygame.display.flip()
.