I would like to know because I'm making a game in Pygmyam and would like to use this method because it looks clean and streamlined.
EXE
level = "WWWWWWWW" \ "WSSSSSSW \" WSSSSSSW \ "WSSSSSSW \" WSSSSSSW \ "WWWWWWWW \"
If you use that method, you will need to define level dimensions - LEVELWIDTH And LEVELHEIGHT, in this case 8 and 6, you can get the block on x, y with this code:
LEVELWIDTH = 8 LEVELHIGHIGHT = 6 def GetBlock (x, y): return Level [x * LEVELWIDTH + y]
Remember that the index x and y both begin with zero and finally the last item on the index The indexing method of Python length - 1.
Here is a different method I have used in such situations:
level = ['WWWWWWWW', 'WSSSSSSW', 'WSSSSSSW', ' WSSSSSSW ',' WSSSSSSW ',' WWWWWWWW ']
With this method you need to find what is the block (X, Y):
Level [x] [y]
But remember that if you want to be able to edit level, you need to create a new string for each line that you edit , Because You can not assign items to a string. Example: To set blocks on x, y with string:
level [y] = level [x] [: y] + new + level [x] [y + 1: ]
I have shown that based on the examples given in this book for more information on indexing the method and a good example of the levels used in the book. 9 is in - Star Pushar
No comments:
Post a Comment