0
How to add block images instead of the rectangle in this code?
9 Answers
+ 1
What do you mean by block images and which rectangles are you talking about ? btw you should have shared the audio and image files as well (i found random image and audio myself , so i was able to play the game atleast!)
+ 1
Nafi Rahat Rahman is that rectangular shape black in color ? And you want to replace that with snake image , right?
+ 1
rough way you can do that is by slicing snk_list into 3 part. Head, body, tail. Then blit the image corresponding to each part onto the game_window. Idk if this is what you are trying to do.. but.. might as well try it. So, first create a dictionary containing image for each part. Then create a function that accept, game_window, snk_list, and snake_texture as parameter as follow (you can replace plot_snake function with this function instead)-
def draw_snake(game_window, snk_list, snake_texture):
if len(snk_list) > 1:
for x, y in snk_list[1 : len(snk_list)]:
game_window.blit(snake_texture["body"], (x, y))
tail_x, tail_y = snk_list[len(snk_list) - 1]
game_window.blit(snake_texture["tail"], (tail_x * 30, tail_y * 30))
head_x, head_y = snk_list[0]
game_window.blit(snake_texture["head"], (head_x, head_y))
p.s. This function has some bugs. I'm too lazy to fix it. But the idea is there.
0
I am talking about the snake shape which is rectangular, but I want to add custom image as snake body
0
Yes, Abhay
0
Nafi Rahat Rahman what is that snake image you are using in your code for ? Are you using it as a background image ?
0
No, I only want to change rectangular snake body by a custom image