Fixed edgecase when mouse is held-down outside of window.
This commit is contained in:
10
conway.py
10
conway.py
@@ -108,8 +108,9 @@ class Board:
|
||||
def fill_crowding(self):
|
||||
for row in self.matrix:
|
||||
for cell in row:
|
||||
crowding_number = self.calculate_crowding_number(cell.position, XYPair(1,1))
|
||||
cell.set_crowding_number(crowding_number)
|
||||
cell.set_crowding_number(
|
||||
self.calculate_crowding_number(cell.position, XYPair(1,1))
|
||||
)
|
||||
|
||||
def evolve_state(self):
|
||||
#calculate crowding numbers before updating any state, otherwise you'll be unhappy
|
||||
@@ -143,7 +144,10 @@ class Board:
|
||||
x = pixel_to_index(mouse_pos[0], dimensions.x, render_info.padding.x)
|
||||
y = pixel_to_index(mouse_pos[1], dimensions.y, render_info.padding.y)
|
||||
|
||||
try:
|
||||
cell = self.matrix[y][x]
|
||||
except IndexError:
|
||||
return #this exception corresponds to the case of the mouse being held down outside the game window
|
||||
|
||||
if not self.click_state:
|
||||
if cell.state == CellStates.ALIVE:
|
||||
@@ -189,7 +193,7 @@ def main():
|
||||
|
||||
while running:
|
||||
|
||||
dt = clock.tick(60)
|
||||
dt = clock.tick(144)
|
||||
board.draw(screen)
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user