0

How to add block image instead of the rectangle in this code

import pygame import random import os pygame.mixer.init() pygame.init() # Colors white = (255, 255, 255) red = (255, 0, 0) black = (0, 0, 0) screen_width = 900 screen_height = 600 game_window = pygame.display.set_mode((screen_width, screen_height)) bgimg = pygame.image.load("snake.jpg") bgimg = pygame.transform.scale(bgimg, (screen_width, screen_height)).convert_alpha() pygame.display.set_caption("SnakesWithNibir") pygame.display.update() clock = pygame.time.Clock() font = pygame.font.SysFont(None, 55) def text_screen(text, color, x, y): screen_text = font.render(text, True, color) game_window.blit(screen_text, [x, y]) def plot_snake(game_window, color, snk_list, snake_size): for x, y in snk_list: pygame.draw.rect(game_window, color, [x, y, snake_size, snake_size]) def welcome(): exit_game = False while not exit_game: game_window.fill((233, 210, 229)) text_screen("Welcome to Snakes", black, 260, 250) text_screen("Press Space Bar To Play", black, 232, 290) for event in pygame.event.get(): if event.type == pygame.QUIT: exit_game = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: pygame.mixer.music.load('back.mp3') pygame.mixer.music.play() gameloop() pygame.display.update() clock.tick(60) def gameloop(): exit_game = False game_over = False snake_x = 45 snake_y = 55 velocity_x = 0 velocity_y = 0 snk_list = [] snk_length = 1 if not os.path.exists("hiscore.txt"): with open("hiscore.txt", "w") as f: f.write("0") with open("hiscore.txt", "r") as f: hiscore = f.read() food_x = random.randint(20, screen_width / 2) # noinspection PyTypeChecker food_y = random.randint(20, screen_height / 2) score = 0 init_velocity = 5

1st Sep 2021, 1:58 PM
Nafi Rahat Rahman
1 Respuesta
+ 2
You should write your code into the code playground or some other place and then share the link of it . Right now your code is truncated due to limit of words in description .
1st Sep 2021, 2:30 PM
Abhay
Abhay - avatar