I’m writing code for game of life logic for a platformer I’m making, but it isn’t checking every tile and only giving me one object location
<code>"<scripts.tilemap.Tilemap object at 0x000001FFBEE1DC40>"
</code>
<code>"<scripts.tilemap.Tilemap object at 0x000001FFBEE1DC40>"
</code>
"<scripts.tilemap.Tilemap object at 0x000001FFBEE1DC40>"
Here’s my game logic:
<code>def is_tile_alive(self, pos):
tile_loc = (int(pos[0] // self.tile_size), int(pos[1] // self.tile_size))
tile_key = f"{tile_loc[0]};{tile_loc[1]}"
if tile_key in self.tilemap and self.tilemap[tile_key]['type'] in ALIVE_TILE_TYPES:
print('tile is there')
return True
return False
def logic(self, pos, offset):
neighbors = 0
tile_loc = (int(pos[0] // self.tile_size), int(pos[1] // self.tile_size))
for offset in NEIGHBOR_OFFSETS:
neighbor_pos = (tile_loc[0] + offset[0], tile_loc[1] + offset[1])
if self.is_tile_alive(neighbor_pos):
print('neighbor is alive')
neighbors += 1
current_tile_alive = self.is_tile_alive(tile_loc)
if current_tile_alive and (neighbors < 2 or neighbors > 3):
load_image('tiles/ntile/ntile.png')
elif not current_tile_alive and neighbors == 3:
self.render(self.tile)
elif current_tile_alive and neighbors == 3:
pass
</code>
<code>def is_tile_alive(self, pos):
tile_loc = (int(pos[0] // self.tile_size), int(pos[1] // self.tile_size))
tile_key = f"{tile_loc[0]};{tile_loc[1]}"
if tile_key in self.tilemap and self.tilemap[tile_key]['type'] in ALIVE_TILE_TYPES:
print('tile is there')
return True
return False
def logic(self, pos, offset):
neighbors = 0
tile_loc = (int(pos[0] // self.tile_size), int(pos[1] // self.tile_size))
for offset in NEIGHBOR_OFFSETS:
neighbor_pos = (tile_loc[0] + offset[0], tile_loc[1] + offset[1])
if self.is_tile_alive(neighbor_pos):
print('neighbor is alive')
neighbors += 1
current_tile_alive = self.is_tile_alive(tile_loc)
if current_tile_alive and (neighbors < 2 or neighbors > 3):
load_image('tiles/ntile/ntile.png')
elif not current_tile_alive and neighbors == 3:
self.render(self.tile)
elif current_tile_alive and neighbors == 3:
pass
</code>
def is_tile_alive(self, pos):
tile_loc = (int(pos[0] // self.tile_size), int(pos[1] // self.tile_size))
tile_key = f"{tile_loc[0]};{tile_loc[1]}"
if tile_key in self.tilemap and self.tilemap[tile_key]['type'] in ALIVE_TILE_TYPES:
print('tile is there')
return True
return False
def logic(self, pos, offset):
neighbors = 0
tile_loc = (int(pos[0] // self.tile_size), int(pos[1] // self.tile_size))
for offset in NEIGHBOR_OFFSETS:
neighbor_pos = (tile_loc[0] + offset[0], tile_loc[1] + offset[1])
if self.is_tile_alive(neighbor_pos):
print('neighbor is alive')
neighbors += 1
current_tile_alive = self.is_tile_alive(tile_loc)
if current_tile_alive and (neighbors < 2 or neighbors > 3):
load_image('tiles/ntile/ntile.png')
elif not current_tile_alive and neighbors == 3:
self.render(self.tile)
elif current_tile_alive and neighbors == 3:
pass
This is most probably my problem
<code>if tile_key in self.tilemap and self.tilemap[tile_key]['type'] in ALIVE_TILE_TYPES:
</code>
<code>if tile_key in self.tilemap and self.tilemap[tile_key]['type'] in ALIVE_TILE_TYPES:
</code>
if tile_key in self.tilemap and self.tilemap[tile_key]['type'] in ALIVE_TILE_TYPES:
I’ve tried different ways of changing it and it changes the location but still doesn’t give me all the tile locations
New contributor
Theyocuber is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.