Im making my first game on python and it was talking about adding row and coloumn counts could someone explain what that means and what does it do ?
Row Count and coloumn count
|
Row Count and coloumn count
|
|
Oct-15-2022, 06:31 PM
You will need to provide more information. The question is kinda vague.
I welcome all feedback.
The only dumb question, is one that doesn't get asked. My Github How to post code using bbtags Download my project scripts
Oct-15-2022, 09:03 PM
(This post was last modified: Oct-15-2022, 11:03 PM by Larz60+.
Edit Reason: Fixed ending quote tag
)
(Oct-15-2022, 06:31 PM)menator01 Wrote: You will need to provide more information. The question is kinda vague.So im watching this video on a tile game and he said everytime i go through one of the tiles increase that variable by one and I didnt really Understand what he was talking about. Ive also never used this type of code before so I dont understand it. here is my code for reference row_count = 0
for row in data:
col_count = 0
for tile in row:
if tile == 1:
img = pygame.transform.scale(dirt_img, (tile_size, tile_size))
img_rect = img.get_rect()
img_rect.x = col_count * tile_size
img_rect.y = row_count * tile_size
tile = (img, img_rect)
self.tile_list.append(tile)
col_count += 1
row_count += 1
world_data = [
[ 1 ,1 ,1, 1, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,1 ,1, 1, 1],
]
Oct-16-2022, 04:28 AM
world_data can be thought of as a grid, like a chessboard. "tile" is used to refer to the individual squares. A row is a group of tiles aligned in one direction, and a column is a group of tiles aligned in the other direction (often horizontal rows and vertical columns).
For your example: world_data = [ [ 1 ,1 ,1, 1, 1], [ 1 ,0, 0, 0, 1], [ 1 ,0, 0, 0, 1], [ 1 ,0, 0, 0, 1], [ 1 ,1 ,1, 1, 1], ]The first row is: [ 1 ,1 ,1, 1, 1]and the first column is [ 1, 1, 1, 1, 1 ],The way world_data is organized, it is very easy to loop through the rows, because each row is a list. row[0] = [ 1 ,1 ,1, 1, 1] row[1] = [ 1 ,0, 0, 0, 1] row[2] = [ 1 ,0, 0, 0, 1] row[3] = [ 1 ,0, 0, 0, 1] row[4] = [ 1 ,1 ,1, 1, 1],The "for row in data:" loop will run 5 times, once for each row shown above. The first time through the loop it uses row[0], the second time through the loop it uses row[1]. This continues until the last loop uses row[4]. "for tile in row:" works just like "for row in data", except this time it loops through the values in row. If row == row[1]: tile[0] = 1 tile[1] = 0 tile[2] = 0 tile[3] = 0 tile[4] = 1
Oct-18-2022, 03:52 AM
(Oct-16-2022, 04:28 AM)deanhystad Wrote: world_data can be thought of as a grid, like a chessboard. "tile" is used to refer to the individual squares. A row is a group of tiles aligned in one direction, and a column is a group of tiles aligned in the other direction (often horizontal rows and vertical columns). Thank you for the help |
|
|
Users browsing this thread: 1 Guest(s)
