Get the block image from his repo at https://github.com/codebasics/python_projects/tree/main/1_snake_game/resources save it in the same directory as project script
import the image into the block
with
pygame.image.load() .convert()
,
Don't Forget convert() at the end
variable
block = pygame.image.load('images/block.jpeg').convert() block_x = 100 block_y = 100 surface.blit(block,(block_x, block_y))
Documentation for pygame.image.load()
is here
https://www.pygame.org/docs/ref/image.html?highlight=frombuffer
draw the block after
surface.fill((255,255,255))
.
use the blit() method to draw it on
the surface. Take the image as first argument, then x and y in (x,y)
** Make this code so if clicked, you can focus to invidiual parts like in mario chris courses
block = pygame.image.load('images/block.jpg').convert() block_x = 100 block_y = 100 surface.blit(block,(block_x,block_y)) pygame.display.flip() running = True while running: for event in pygame.event.get(): if event.type == KEYDOWN: if event.key == K_ESCAPE or event.key == K_q: running = False if event.type == QUIT: running = Falseimport pygame from pygame.locals import * if __name__ == '__main__': pygame.init() surface = pygame.display.set_mode((900,300)) surface.fill((255,255,255))