diff --git a/code/__pycache__/setup.cpython-310.pyc b/code/__pycache__/setup.cpython-310.pyc index 98da64e..7daf327 100644 Binary files a/code/__pycache__/setup.cpython-310.pyc and b/code/__pycache__/setup.cpython-310.pyc differ diff --git a/code/__pycache__/sprites.cpython-310.pyc b/code/__pycache__/sprites.cpython-310.pyc index 7c137f3..c2a3382 100644 Binary files a/code/__pycache__/sprites.cpython-310.pyc and b/code/__pycache__/sprites.cpython-310.pyc differ diff --git a/code/setup.py b/code/setup.py index c1469a2..a1f05ca 100644 --- a/code/setup.py +++ b/code/setup.py @@ -27,7 +27,7 @@ def setup_lanterns_detectors_new(SCREEN_WIDTH): for y_pos in range(75, 226, 150): x_pos = 25 id = 1 - while x_pos <= 825: + while x_pos <= 725: lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_1") lantern_list.append(lantern) detector = sprites.Detectors(x_pos, y_pos, 75, 90, id, street="street_1") @@ -37,8 +37,8 @@ def setup_lanterns_detectors_new(SCREEN_WIDTH): # Street 2 for y_pos in range(75, 226, 150): - x_pos = 975 - id = 1 + x_pos = 1075 + id = 2 while x_pos <= 1775: lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_2") lantern_list.append(lantern) @@ -64,7 +64,7 @@ def setup_lanterns_detectors_new(SCREEN_WIDTH): for y_pos in range(725, 976, 150): x_pos = 25 id = 1 - while x_pos <= 825: + while x_pos <= 725: lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_5") lantern_list.append(lantern) detector = sprites.Detectors(x_pos, y_pos, 75, 90, id, street="street_5") @@ -84,4 +84,21 @@ def setup_lanterns_detectors_new(SCREEN_WIDTH): x_pos += 100 id += 1 + # Crossing 1 + cross_lantern_1 = sprites.Lanterns(825, 225, 25, 25, id=9, street="street_1", crossing_id=1) + cross_lantern_2 = sprites.Lanterns(825, 75, 25, 25, id=9, street="street_1", crossing_id=1) + cross_lantern_3 = sprites.Lanterns(975, 225, 25, 25, id=1, street="street_2", crossing_id=1) + cross_lantern_4 = sprites.Lanterns(975, 75, 25, 25, id=1, street="street_2", crossing_id=1) + cross_detector_1 = sprites.Detectors(900, 150, 260, 260, crossing_id=1) + + # Crossing 1 + cross_lantern_5 = sprites.Lanterns(825, 725, 25, 25, id=9, street="street_5", crossing_id=1) + cross_lantern_6 = sprites.Lanterns(825, 875, 25, 25, id=9, street="street_5", crossing_id=1) + cross_lantern_7 = sprites.Lanterns(975, 225, 25, 25, id=1, street="street_2", crossing_id=1) + cross_lantern_8 = sprites.Lanterns(975, 75, 25, 25, id=1, street="street_2", crossing_id=1) + cross_detector_2 = sprites.Detectors(900, 150, 260, 260, crossing_id=1) + + lantern_list.extend([cross_lantern_1, cross_lantern_2, cross_lantern_3, cross_lantern_4, cross_lantern_5, cross_lantern_6]) + detectors_list.append(cross_detector_1) + return lantern_list, detectors_list \ No newline at end of file diff --git a/code/simulation.py b/code/simulation.py index 16a3927..2f38dfc 100644 --- a/code/simulation.py +++ b/code/simulation.py @@ -48,6 +48,8 @@ if __name__ == "__main__": collisions = pygame.sprite.spritecollide(player.sprite, detectors, False) for detector in collisions: for lantern in lanterns: + if detector.crossing_id == lantern.crossing_id and detector.crossing_id is not None: + lantern.light_up(255, 255, 0, 255) if lantern.street == detector.street: if lantern.id == detector.id - 1 or lantern.id == detector.id + 1: lantern.light_up(176, 179, 0, 255) diff --git a/code/sprites.py b/code/sprites.py index 76ee982..0d1a499 100644 --- a/code/sprites.py +++ b/code/sprites.py @@ -54,13 +54,14 @@ class Streets(pygame.sprite.Sprite): self.rect = self.image.get_rect(topleft=(left, top)) class Lanterns(pygame.sprite.Sprite): - def __init__(self, left, top, width, height, id, street): + def __init__(self, left, top, width, height, id=None, street=None, crossing_id=None): super().__init__() self.image = pygame.Surface([width, height], pygame.SRCALPHA) self.image.fill((0, 0, 0, 255)) self.rect = self.image.get_rect(center=(left, top)) self.id = id self.street = street + self.crossing_id = crossing_id def light_up(self, r, g, b, oppacity): self.image.fill((r, g, b, oppacity)) @@ -69,7 +70,7 @@ class Lanterns(pygame.sprite.Sprite): self.image.fill((0, 0, 0)) class Detectors(pygame.sprite.Sprite): - def __init__(self, left, top, width, height, id, street): + def __init__(self, left, top, width, height, id=None, street=None, crossing_id=None): super().__init__() self.image = pygame.Surface([width, height], pygame.SRCALPHA) @@ -78,3 +79,4 @@ class Detectors(pygame.sprite.Sprite): self.rect = self.image.get_rect(center=(left, top)) self.id = id self.street = street + self.crossing_id = crossing_id