0

How to add block images instead of the rectangle in this code?

https://code.sololearn.com/cHk4D56YrPA7

1st Sep 2021, 2:51 PM
Nafi Rahat Rahman
9 odpowiedzi
+ 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!)
1st Sep 2021, 3:28 PM
Abhay
Abhay - avatar
+ 1
Nafi Rahat Rahman is that rectangular shape black in color ? And you want to replace that with snake image , right?
1st Sep 2021, 4:08 PM
Abhay
Abhay - avatar
+ 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.
1st Sep 2021, 5:25 PM
Shahrull Fytri
Shahrull Fytri - avatar
0
I am talking about the snake shape which is rectangular, but I want to add custom image as snake body
1st Sep 2021, 4:05 PM
Nafi Rahat Rahman
0
Yes, Abhay
1st Sep 2021, 4:10 PM
Nafi Rahat Rahman
0
Nafi Rahat Rahman what is that snake image you are using in your code for ? Are you using it as a background image ?
1st Sep 2021, 4:15 PM
Abhay
Abhay - avatar
0
No, I only want to change rectangular snake body by a custom image
1st Sep 2021, 4:18 PM
Nafi Rahat Rahman
1st Sep 2021, 4:18 PM
Nafi Rahat Rahman
1st Sep 2021, 4:31 PM
Abhay
Abhay - avatar