Hi I made a snake game with turtle-graphics now trying to make it with pygame.
I want help with understanding how to add background image of width=640 and height=480 to my pygame.display and how to add an image to my food which randomly appears on the screen.
Updating the UI
def _update_ui(self):
# self.display.fill(BLACK)
bg = pygame.image.load("bg.png")
self.display.blit(bg, (0, 0))
for pt in self.snake:
pygame.draw.rect(self.display, BLUE1, pygame.Rect(pt.x, pt.y, BLOCK_SIZE, BLOCK_SIZE))
pygame.draw.rect(self.display, BLUE2, pygame.Rect(pt.x + 4, pt.y + 4, 12, 12))
pygame.draw.rect(self.display, RED, pygame.Rect(self.food.x, self.food.y, BLOCK_SIZE, BLOCK_SIZE))
text = font.render("Score: " + str(self.score), True, WHITE)
self.display.blit(text, [0, 0])
pygame.display.flip()
When I add the image it does not fill the whole display of the game, a black line on right is still in the display:
For the food, I want to display anther png instead of a block of RED colour.
How to add a image which take the random x coordinate: self.food.x and y coordinate: self.food.y