Erstellen Szene 8 + 9

This commit is contained in:
moritz 2024-07-11 09:41:21 +02:00
parent 41fa99c510
commit 1493ba9471
7 changed files with 182 additions and 63 deletions

View file

@ -60,26 +60,8 @@ def check_sensor(collisions, lanterns):
if lantern.id == detector.id: if lantern.id == detector.id:
lantern.light_up(255, 255, 0, 255) lantern.light_up(255, 255, 0, 255)
def scene_1(screen, detectors, streets, lanterns, player):
screen.fill("Grey")
detectors.draw(screen)
streets.draw(screen)
lanterns.draw(screen)
player.draw(screen)
player.update()
for lantern in lanterns: def scene(screen, detectors, streets, lanterns, player):
lantern.reset_light()
# Check for collision and light up corresponding lantern
collisions = pygame.sprite.spritecollide(player.sprite, detectors, False)
check_sensor(collisions, lanterns)
if pygame.sprite.spritecollide(player.sprite, streets, False):
player.sprite.set_back()#
def scene_2(screen, detectors, streets, lanterns, player):
screen.fill("Pink") screen.fill("Pink")
detectors.draw(screen) detectors.draw(screen)
streets.draw(screen) streets.draw(screen)
@ -97,38 +79,3 @@ def scene_2(screen, detectors, streets, lanterns, player):
if pygame.sprite.spritecollide(player.sprite, streets, False): if pygame.sprite.spritecollide(player.sprite, streets, False):
player.sprite.set_back() player.sprite.set_back()
def scene_3(screen, detectors, streets, lanterns, player):
screen.fill("Pink")
detectors.draw(screen)
streets.draw(screen)
lanterns.draw(screen)
player.draw(screen)
player.update()
for lantern in lanterns:
lantern.reset_light()
# Check for collision and light up corresponding lantern
collisions = pygame.sprite.spritecollide(player.sprite, detectors, False)
check_sensor(collisions, lanterns)
if pygame.sprite.spritecollide(player.sprite, streets, False):
player.sprite.set_back()
def scene_4(screen, detectors, streets, lanterns, player):
screen.fill("Pink")
detectors.draw(screen)
streets.draw(screen)
lanterns.draw(screen)
player.draw(screen)
player.update()
for lantern in lanterns:
lantern.reset_light()
# Check for collision and light up corresponding lantern
collisions = pygame.sprite.spritecollide(player.sprite, detectors, False)
check_sensor(collisions, lanterns)
if pygame.sprite.spritecollide(player.sprite, streets, False):
player.sprite.set_back()

View file

@ -495,6 +495,122 @@ def setup_lanterns_detectors_scene_7():
y_pos += 100 y_pos += 100
id += 1 id += 1
return lantern_list, detectors_list
def setup_streets_scene_8():
street_1 = sprites.Streets(1700, 0, 4, 1000) # Street 1/2 Right Line
street_2 = sprites.Streets(1600, 0, 4, 454) # Street 1 Left Line
street_3 = sprites.Streets(1600, 550, 4, 450) # Street 2 Left Line
street_4 = sprites.Streets(0, 450, 1600, 4) # Street 3 Top Line
street_5 = sprites.Streets(0, 550, 1600, 4) # Street 3 Bottom Line
streets_list = [street_1, street_2, street_3, street_4, street_5]
return streets_list
def setup_lanterns_detectors_scene_8():
lantern_list = []
detectors_list = []
# intersection 1
cross_lantern_1 = sprites.Lanterns(1575, 425, 25, 25, id=1, street="street_3", crossing_id=1)
cross_lantern_2 = sprites.Lanterns(1575, 575, 25, 25, id=1, street="street_3", crossing_id=1)
cross_lantern_3 = sprites.Lanterns(1725, 425, 25, 25, id=1, street="street_1", crossing_id=1)
cross_lantern_4 = sprites.Lanterns(1725, 575, 25, 25, id=1, street="street_2", crossing_id=1)
cross_detector_1 = sprites.Detectors(1650, 500, 260, 260, crossing_id=1)
lantern_list.extend([cross_lantern_1, cross_lantern_2, cross_lantern_3, cross_lantern_4])
detectors_list.append(cross_detector_1)
# Street 1
for x_pos in range(1575, 1726, 150):
y_pos = 325
id = 2
while y_pos >= 25:
lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_1")
lantern_list.append(lantern)
detector = sprites.Detectors(x_pos, y_pos, 200, 75, id, street="street_1")
detectors_list.append(detector)
print(y_pos)
y_pos -= 100
id += 1
# Street 2
for x_pos in range(1575, 1726, 150):
y_pos = 675
id = 2
while y_pos <= 975:
lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_2")
lantern_list.append(lantern)
detector = sprites.Detectors(x_pos, y_pos, 200, 75, id, street="street_2")
detectors_list.append(detector)
print(y_pos)
y_pos += 100
id += 1
# Street 3
for y_pos in range(425, 576, 150):
x_pos = 1475
id = 2
while x_pos >= 75:
lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_3")
lantern_list.append(lantern)
detector = sprites.Detectors(x_pos, y_pos, 75, 90, id, street="street_3")
detectors_list.append(detector)
x_pos -= 100
id += 1
return lantern_list, detectors_list
def setup_streets_scene_9():
street_1 = sprites.Streets(0, 800, 1604, 4) # Street 2 Top Line
street_2 = sprites.Streets(0, 900, 1704, 4) # Street 2 Bottom Linee
street_3 = sprites.Streets(1700, 0, 4, 900) # Street 1 Right Line
street_4 = sprites.Streets(1600, 0, 4, 800) # Street 1 Left Line
streets_list = [street_1, street_2, street_3, street_4]
return streets_list
def setup_lanterns_detectors_scene_9():
lantern_list = []
detectors_list = []
cross_lantern_1 = sprites.Lanterns(1575, 775, 25, 25, id=1, street="street_1", crossing_id=1)
cross_lantern_2 = sprites.Lanterns(1725, 775, 25, 25, id=1, street="street_1", crossing_id=1)
cross_lantern_3 = sprites.Lanterns(1575, 925, 25, 25, id=1, street="street_2", crossing_id=1)
cross_lantern_4 = sprites.Lanterns(1725, 925, 25, 25, id=1, street="street_2", crossing_id=1)
cross_detector_1 = sprites.Detectors(1650, 850, 260, 260, crossing_id=1)
lantern_list.extend([cross_lantern_1, cross_lantern_2, cross_lantern_3, cross_lantern_4])
detectors_list.append(cross_detector_1)
# Street 1
for y_pos in range(775, 926, 150):
x_pos = 1475
id = 2
while x_pos >= 75:
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")
detectors_list.append(detector)
x_pos -= 100
id += 1
# Street 2
for x_pos in range(1575, 1726, 150):
y_pos = 675
id = 2
while y_pos >= 75:
lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_2")
lantern_list.append(lantern)
detector = sprites.Detectors(x_pos, y_pos, 200, 75, id, street="street_2")
detectors_list.append(detector)
y_pos -= 100
id += 1
return lantern_list, detectors_list return lantern_list, detectors_list

View file

@ -35,6 +35,12 @@ streets_list_scene_6 = setup.setup_streets_scene_6()
streets_scene_7 = pygame.sprite.Group() streets_scene_7 = pygame.sprite.Group()
streets_list_scene_7 = setup.setup_streets_scene_7() streets_list_scene_7 = setup.setup_streets_scene_7()
streets_scene_8 = pygame.sprite.Group()
streets_list_scene_8 = setup.setup_streets_scene_8()
streets_scene_9 = pygame.sprite.Group()
streets_list_scene_9 = setup.setup_streets_scene_9()
lanterns_scene_1 = pygame.sprite.Group() lanterns_scene_1 = pygame.sprite.Group()
detectors_scene_1 = pygame.sprite.Group() detectors_scene_1 = pygame.sprite.Group()
@ -64,6 +70,14 @@ lanterns_scene_7 = pygame.sprite.Group()
detectors_scene_7 = pygame.sprite.Group() detectors_scene_7 = pygame.sprite.Group()
lantern_list_scene_7, detectors_list_scene_7 = setup.setup_lanterns_detectors_scene_7() lantern_list_scene_7, detectors_list_scene_7 = setup.setup_lanterns_detectors_scene_7()
lanterns_scene_8 = pygame.sprite.Group()
detectors_scene_8 = pygame.sprite.Group()
lantern_list_scene_8, detectors_list_scene_8 = setup.setup_lanterns_detectors_scene_8()
lanterns_scene_9 = pygame.sprite.Group()
detectors_scene_9 = pygame.sprite.Group()
lantern_list_scene_9, detectors_list_scene_9 = setup.setup_lanterns_detectors_scene_9()
current_scene = "scene_1" current_scene = "scene_1"
@ -116,6 +130,20 @@ for item in lantern_list_scene_7:
for item in detectors_list_scene_7: for item in detectors_list_scene_7:
detectors_scene_7.add(item) detectors_scene_7.add(item)
for item in streets_list_scene_8:
streets_scene_8.add(item)
for item in lantern_list_scene_8:
lanterns_scene_8.add(item)
for item in detectors_list_scene_8:
detectors_scene_8.add(item)
for item in streets_list_scene_9:
streets_scene_9.add(item)
for item in lantern_list_scene_9:
lanterns_scene_9.add(item)
for item in detectors_list_scene_9:
detectors_scene_9.add(item)
if __name__ == "__main__": if __name__ == "__main__":
run = True run = True
@ -125,19 +153,23 @@ if __name__ == "__main__":
run = False run = False
if current_scene == "scene_1": if current_scene == "scene_1":
functions.scene_1(screen, detectors_scene_1, streets_scene_1, lanterns_scene_1, player) functions.scene(screen, detectors_scene_1, streets_scene_1, lanterns_scene_1, player)
if current_scene == "scene_2": if current_scene == "scene_2":
functions.scene_2(screen, detectors_scene_2, streets_scene_2, lanterns_scene_2, player) functions.scene(screen, detectors_scene_2, streets_scene_2, lanterns_scene_2, player)
if current_scene == "scene_3": if current_scene == "scene_3":
functions.scene_2(screen, detectors_scene_3, streets_scene_3, lanterns_scene_3, player) functions.scene(screen, detectors_scene_3, streets_scene_3, lanterns_scene_3, player)
if current_scene == "scene_4": if current_scene == "scene_4":
functions.scene_2(screen, detectors_scene_4, streets_scene_4, lanterns_scene_4, player) functions.scene(screen, detectors_scene_4, streets_scene_4, lanterns_scene_4, player)
if current_scene == "scene_5": if current_scene == "scene_5":
functions.scene_2(screen, detectors_scene_5, streets_scene_5, lanterns_scene_5, player) functions.scene(screen, detectors_scene_5, streets_scene_5, lanterns_scene_5, player)
if current_scene == "scene_6": if current_scene == "scene_6":
functions.scene_2(screen, detectors_scene_6, streets_scene_6, lanterns_scene_6, player) functions.scene(screen, detectors_scene_6, streets_scene_6, lanterns_scene_6, player)
if current_scene == "scene_7": if current_scene == "scene_7":
functions.scene_2(screen, detectors_scene_7, streets_scene_7, lanterns_scene_7, player) functions.scene(screen, detectors_scene_7, streets_scene_7, lanterns_scene_7, player)
if current_scene == "scene_8":
functions.scene(screen, detectors_scene_8, streets_scene_8, lanterns_scene_8, player)
if current_scene == "scene_9":
functions.scene(screen, detectors_scene_9, streets_scene_9, lanterns_scene_9, player)
current_scene = player.sprite.left_scene(current_scene) current_scene = player.sprite.left_scene(current_scene)

View file

@ -41,9 +41,11 @@ class Player(pygame.sprite.Sprite):
def left_scene(self, current_scene): def left_scene(self, current_scene):
if current_scene == "scene_1" and self.rect.y >= 1080: if current_scene == "scene_1" and self.rect.y >= 1080:
self.rect.x = 900
self.rect.y = -80 self.rect.y = -80
return "scene_2" return "scene_2"
if current_scene == "scene_1" and self.rect.x >= 1880:
self.rect.x = -80
return "scene_8"
if current_scene == "scene_1" and self.rect.x <= -80: if current_scene == "scene_1" and self.rect.x <= -80:
self.rect.x = 1880 self.rect.x = 1880
return "scene_3" return "scene_3"
@ -57,6 +59,9 @@ class Player(pygame.sprite.Sprite):
if current_scene == "scene_2" and self.rect.x <= -80: if current_scene == "scene_2" and self.rect.x <= -80:
self.rect.x = 1800 self.rect.x = 1800
return "scene_4" return "scene_4"
if current_scene == "scene_2" and self.rect.x >= 1880:
self.rect.x = -80
return "scene_9"
if current_scene == "scene_3" and self.rect.x >= 1880: if current_scene == "scene_3" and self.rect.x >= 1880:
self.rect.x = -80 self.rect.x = -80
return "scene_1" return "scene_1"
@ -90,6 +95,25 @@ class Player(pygame.sprite.Sprite):
if current_scene == "scene_7" and self.rect.x <= -80: if current_scene == "scene_7" and self.rect.x <= -80:
self.rect.x = 1880 self.rect.x = 1880
return "scene_6" return "scene_6"
if current_scene == "scene_7" and self.rect.y >= 1080:
self.rect.y = -80
return "scene_8"
if current_scene == "scene_8" and self.rect.y <= -80:
self.rect.y = 1080
return "scene_7"
if current_scene == "scene_8" and self.rect.x <= -80:
self.rect.x = 1880
return "scene_1"
if current_scene == "scene_8" and self.rect.y >= 1080:
self.rect.y = -80
return "scene_9"
if current_scene == "scene_9" and self.rect.x <= -80:
self.rect.x = 1880
self.rect.y = 795
return "scene_2"
if current_scene == "scene_9" and self.rect.y <= -80:
self.rect.y = 1080
return "scene_8"
return current_scene return current_scene
def update(self): def update(self):