Erweiterung um Scene 3 und 4
This commit is contained in:
parent
d1fcc7142b
commit
8e4283a936
BIN
code/__pycache__/functions.cpython-310.pyc
Normal file
BIN
code/__pycache__/functions.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -96,3 +96,39 @@ def scene_2(screen, detectors, streets, lanterns, player):
|
|||
|
||||
if pygame.sprite.spritecollide(player.sprite, streets, False):
|
||||
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()
|
214
code/setup.py
214
code/setup.py
|
@ -2,6 +2,89 @@ import pygame
|
|||
import sprites
|
||||
|
||||
def setup_streets_scene_1():
|
||||
street_1 = sprites.Streets(0, 450, 850, 4) # Street 1 Top Line
|
||||
street_2 = sprites.Streets(0, 550, 850, 4) # Street 1 Bottomm Line
|
||||
street_3 = sprites.Streets(950, 450, 850, 4) # Street 2 Left Line
|
||||
street_4 = sprites.Streets(950, 550, 850, 4) # Street 2 Right Line
|
||||
street_5 = sprites.Streets(850, 0, 4, 454) # Street 3 Left Line
|
||||
street_6 = sprites.Streets(950, 0, 4, 454) # Street 3 Right Line
|
||||
street_7 = sprites.Streets(850, 550, 4, 450) # Street 5/6 Bottom Line
|
||||
street_8 = sprites.Streets(950, 550, 4, 450) # Street 4 Left Line
|
||||
|
||||
streets_list = [street_1, street_2, street_3, street_4, street_5, street_6, street_7, street_8]
|
||||
|
||||
return streets_list
|
||||
|
||||
def setup_lanterns_detectors_scene_1():
|
||||
|
||||
lantern_list = []
|
||||
detectors_list = []
|
||||
|
||||
# intersection 1
|
||||
cross_lantern_1 = sprites.Lanterns(825, 425, 25, 25, id=1, street="street_1", crossing_id=1)
|
||||
cross_lantern_2 = sprites.Lanterns(975, 425, 25, 25, id=1, street="street_2", crossing_id=1)
|
||||
cross_lantern_3 = sprites.Lanterns(975, 575, 25, 25, id=1, street="street_3", crossing_id=1)
|
||||
cross_lantern_4 = sprites.Lanterns(825, 575, 25, 25, id=1, street="street_4", crossing_id=1)
|
||||
cross_detector_1 = sprites.Detectors(900, 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 y_pos in range(425, 576, 150):
|
||||
print("street 1")
|
||||
x_pos = 725
|
||||
id = 2
|
||||
while x_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, 75, 90, id, street="street_1")
|
||||
detectors_list.append(detector)
|
||||
x_pos -= 100
|
||||
id += 1
|
||||
|
||||
# Street 2
|
||||
for x_pos in range(825, 976, 150):
|
||||
y_pos = 325
|
||||
id = 2
|
||||
while y_pos >= 25:
|
||||
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):
|
||||
print("street 1")
|
||||
x_pos = 1075
|
||||
id = 2
|
||||
while x_pos <= 1775:
|
||||
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
|
||||
|
||||
# Street 4
|
||||
for x_pos in range(825, 976, 150):
|
||||
y_pos = 675
|
||||
id = 2
|
||||
while y_pos <= 975:
|
||||
lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_4")
|
||||
lantern_list.append(lantern)
|
||||
detector = sprites.Detectors(x_pos, y_pos, 200, 75, id, street="street_4")
|
||||
detectors_list.append(detector)
|
||||
print(y_pos)
|
||||
y_pos += 100
|
||||
id += 1
|
||||
|
||||
return lantern_list, detectors_list
|
||||
|
||||
def setup_streets_scene_2():
|
||||
street_1 = sprites.Streets(0, 100, 850, 4) # Street 1 Top Line
|
||||
street_2 = sprites.Streets(0, 200, 850, 4) # Street 1 Bottomm Line
|
||||
street_3 = sprites.Streets(950, 100, 850, 4) # Street 2 Top Line
|
||||
|
@ -19,7 +102,7 @@ def setup_streets_scene_1():
|
|||
return streets_list
|
||||
|
||||
|
||||
def setup_lanterns_detectors_scene_1():
|
||||
def setup_lanterns_detectors_scene_2():
|
||||
lantern_list = []
|
||||
detectors_list = []
|
||||
|
||||
|
@ -91,7 +174,7 @@ def setup_lanterns_detectors_scene_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
|
||||
# Crossing 2
|
||||
cross_lantern_5 = sprites.Lanterns(825, 725, 25, 25, id=6, street="street_4", crossing_id=2)
|
||||
cross_lantern_6 = sprites.Lanterns(825, 875, 25, 25, id=9, street="street_5", crossing_id=2)
|
||||
cross_lantern_7 = sprites.Lanterns(975, 725, 25, 25, id=1, street="street_6", crossing_id=2)
|
||||
|
@ -103,50 +186,49 @@ def setup_lanterns_detectors_scene_1():
|
|||
|
||||
return lantern_list, detectors_list
|
||||
|
||||
def setup_streets_scene_2():
|
||||
street_1 = sprites.Streets(0, 450, 850, 4) # Street 1 Top Line
|
||||
street_2 = sprites.Streets(0, 550, 850, 4) # Street 1 Bottomm Line
|
||||
street_3 = sprites.Streets(950, 450, 850, 4) # Street 2 Top Line
|
||||
street_4 = sprites.Streets(950, 550, 850, 4) # Street 2 Bottom Line
|
||||
street_5 = sprites.Streets(850, 0, 4, 454) # Street 3 Left Line
|
||||
street_6 = sprites.Streets(950, 0, 4, 454) # Street 3 Right Line
|
||||
street_7 = sprites.Streets(850, 550, 4, 450) # Street 5/6 Bottom Line
|
||||
street_8 = sprites.Streets(950, 550, 4, 450) # Street 4 Left Line
|
||||
|
||||
streets_list = [street_1, street_2, street_3, street_4, street_5, street_6, street_7, street_8]
|
||||
def setup_streets_scene_3():
|
||||
street_1 = sprites.Streets(100, 0, 4, 1000) # Street 1/2 Left Line
|
||||
street_2 = sprites.Streets(200, 0, 4, 454) # Street 2 Right Line
|
||||
street_3 = sprites.Streets(200, 550, 4, 450) # Street 1 Right Line
|
||||
street_4 = sprites.Streets(200, 450, 1600, 4) # Street 3 Top Line
|
||||
street_5 = sprites.Streets(200, 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_2():
|
||||
|
||||
def setup_lanterns_detectors_scene_3():
|
||||
|
||||
lantern_list = []
|
||||
detectors_list = []
|
||||
|
||||
# intersection 1
|
||||
cross_lantern_1 = sprites.Lanterns(825, 425, 25, 25, id=1, street="street_1", crossing_id=1)
|
||||
cross_lantern_2 = sprites.Lanterns(975, 425, 25, 25, id=1, street="street_2", crossing_id=1)
|
||||
cross_lantern_3 = sprites.Lanterns(975, 575, 25, 25, id=1, street="street_3", crossing_id=1)
|
||||
cross_lantern_4 = sprites.Lanterns(825, 575, 25, 25, id=1, street="street_4", crossing_id=1)
|
||||
cross_detector_1 = sprites.Detectors(900, 500, 260, 260, crossing_id=1)
|
||||
cross_lantern_1 = sprites.Lanterns(225, 425, 25, 25, id=1, street="street_3", crossing_id=1)
|
||||
cross_lantern_2 = sprites.Lanterns(225, 575, 25, 25, id=1, street="street_1", crossing_id=1)
|
||||
cross_lantern_3 = sprites.Lanterns(75, 425, 25, 25, id=1, street="street_2", crossing_id=1)
|
||||
cross_lantern_4 = sprites.Lanterns(75, 575, 25, 25, id=1, street="street_1", crossing_id=1)
|
||||
cross_detector_1 = sprites.Detectors(150, 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 y_pos in range(425, 576, 150):
|
||||
print("street 1")
|
||||
x_pos = 725
|
||||
for x_pos in range(75, 226, 150):
|
||||
y_pos = 675
|
||||
id = 2
|
||||
while x_pos >= 25:
|
||||
while y_pos <= 975:
|
||||
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")
|
||||
detector = sprites.Detectors(x_pos, y_pos, 200, 75, id, street="street_1")
|
||||
detectors_list.append(detector)
|
||||
x_pos -= 100
|
||||
print(y_pos)
|
||||
y_pos += 100
|
||||
id += 1
|
||||
|
||||
# Street 2
|
||||
for x_pos in range(825, 976, 150):
|
||||
for x_pos in range(75, 226, 150):
|
||||
y_pos = 325
|
||||
id = 2
|
||||
while y_pos >= 25:
|
||||
|
@ -160,8 +242,7 @@ def setup_lanterns_detectors_scene_2():
|
|||
|
||||
# Street 3
|
||||
for y_pos in range(425, 576, 150):
|
||||
print("street 1")
|
||||
x_pos = 1075
|
||||
x_pos = 325
|
||||
id = 2
|
||||
while x_pos <= 1775:
|
||||
lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_3")
|
||||
|
@ -171,20 +252,79 @@ def setup_lanterns_detectors_scene_2():
|
|||
x_pos += 100
|
||||
id += 1
|
||||
|
||||
# Street 4
|
||||
for x_pos in range(825, 976, 150):
|
||||
y_pos = 675
|
||||
return lantern_list, detectors_list
|
||||
|
||||
def setup_streets_scene_4():
|
||||
street_1 = sprites.Streets(200, 100, 1600, 4) # Street 1 Top Line
|
||||
street_2 = sprites.Streets(200, 200, 1600, 4) # Street 1 Bottom Line
|
||||
street_3 = sprites.Streets(200, 750, 1600, 4) # Street 2 Top Line
|
||||
street_4 = sprites.Streets(100, 850, 1600, 4) # Street 2 Bottom Linee
|
||||
street_5 = sprites.Streets(200, 200, 4, 550) # Street 3 right middle Line
|
||||
street_6 = sprites.Streets(100, 0, 4, 850) # Street 3 Left Line
|
||||
street_7 = sprites.Streets(200, 0, 4, 100) # Street 3 right top Line
|
||||
|
||||
|
||||
|
||||
streets_list = [street_1, street_2, street_3, street_4, street_5, street_6, street_7]
|
||||
|
||||
return streets_list
|
||||
|
||||
def setup_lanterns_detectors_scene_4():
|
||||
|
||||
lantern_list = []
|
||||
detectors_list = []
|
||||
|
||||
# Intersection 1
|
||||
cross_lantern_1 = sprites.Lanterns(225, 725, 25, 25, id=1, street="street_2", crossing_id=1)
|
||||
cross_lantern_2 = sprites.Lanterns(225, 875, 25, 25, id=1, street="street_2", crossing_id=1)
|
||||
cross_lantern_3 = sprites.Lanterns(75, 725, 25, 25, id=6, street="street_3", crossing_id=1)
|
||||
cross_lantern_4 = sprites.Lanterns(75, 875, 25, 25, id=6, street="street_3", crossing_id=1)
|
||||
cross_detector_1 = sprites.Detectors(150, 800, 260, 260, crossing_id=1)
|
||||
|
||||
# Intersection 2
|
||||
cross_lantern_5 = sprites.Lanterns(225, 75, 25, 25, id=1, street="street_1", crossing_id=2)
|
||||
cross_lantern_6 = sprites.Lanterns(225, 225, 25, 25, id=1, street="street_1", crossing_id=2)
|
||||
cross_lantern_7 = sprites.Lanterns(75, 75, 25, 25, id=1, street="street_3", crossing_id=2)
|
||||
cross_lantern_8 = sprites.Lanterns(75, 225, 25, 25, id=1, street="street_3", crossing_id=2)
|
||||
cross_detector_2 = sprites.Detectors(150, 150, 260, 260, crossing_id=2)
|
||||
|
||||
lantern_list.extend([cross_lantern_1, cross_lantern_2, cross_lantern_3, cross_lantern_4, cross_lantern_5, cross_lantern_6, cross_lantern_7, cross_lantern_8])
|
||||
detectors_list.extend([cross_detector_1, cross_detector_2])
|
||||
|
||||
# Street 1
|
||||
for y_pos in range(75, 226, 150):
|
||||
x_pos = 325
|
||||
id = 2
|
||||
while y_pos <= 975:
|
||||
lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_4")
|
||||
while x_pos <= 1775:
|
||||
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_4")
|
||||
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 y_pos in range(725, 876, 150):
|
||||
x_pos = 325
|
||||
id = 2
|
||||
while x_pos <= 1775:
|
||||
lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_2")
|
||||
lantern_list.append(lantern)
|
||||
detector = sprites.Detectors(x_pos, y_pos, 75, 90, id, street="street_2")
|
||||
detectors_list.append(detector)
|
||||
x_pos += 100
|
||||
id += 1
|
||||
|
||||
# Street 3
|
||||
for x_pos in range(75, 226, 150):
|
||||
y_pos = 325
|
||||
id = 2
|
||||
while y_pos <= 625:
|
||||
lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_3")
|
||||
lantern_list.append(lantern)
|
||||
detector = sprites.Detectors(x_pos, y_pos, 200, 75, id, street="street_3")
|
||||
detectors_list.append(detector)
|
||||
print(y_pos)
|
||||
y_pos += 100
|
||||
id += 1
|
||||
|
||||
|
||||
|
||||
return lantern_list, detectors_list
|
||||
|
||||
|
|
|
@ -16,9 +16,16 @@ player.add(sprites.Player())
|
|||
|
||||
streets_scene_1 = pygame.sprite.Group()
|
||||
streets_list_scene_1 = setup.setup_streets_scene_1()
|
||||
|
||||
streets_scene_2 = pygame.sprite.Group()
|
||||
streets_list_scene_2 = setup.setup_streets_scene_2()
|
||||
|
||||
streets_scene_3 = pygame.sprite.Group()
|
||||
streets_list_scene_3 = setup.setup_streets_scene_3()
|
||||
|
||||
streets_scene_4 = pygame.sprite.Group()
|
||||
streets_list_scene_4 = setup.setup_streets_scene_4()
|
||||
|
||||
|
||||
lanterns_scene_1 = pygame.sprite.Group()
|
||||
detectors_scene_1 = pygame.sprite.Group()
|
||||
|
@ -28,6 +35,15 @@ lanterns_scene_2 = pygame.sprite.Group()
|
|||
detectors_scene_2 = pygame.sprite.Group()
|
||||
lantern_list_scene_2, detectors_list_scene_2 = setup.setup_lanterns_detectors_scene_2()
|
||||
|
||||
lanterns_scene_3 = pygame.sprite.Group()
|
||||
detectors_scene_3 = pygame.sprite.Group()
|
||||
lantern_list_scene_3, detectors_list_scene_3 = setup.setup_lanterns_detectors_scene_3()
|
||||
|
||||
lanterns_scene_4 = pygame.sprite.Group()
|
||||
detectors_scene_4 = pygame.sprite.Group()
|
||||
lantern_list_scene_4, detectors_list_scene_4 = setup.setup_lanterns_detectors_scene_4()
|
||||
|
||||
|
||||
current_scene = "scene_1"
|
||||
|
||||
for item in lantern_list_scene_1:
|
||||
|
@ -36,6 +52,7 @@ for item in detectors_list_scene_1:
|
|||
detectors_scene_1.add(item)
|
||||
for item in streets_list_scene_1:
|
||||
streets_scene_1.add(item)
|
||||
|
||||
for item in streets_list_scene_2:
|
||||
streets_scene_2.add(item)
|
||||
for item in lantern_list_scene_2:
|
||||
|
@ -43,6 +60,20 @@ for item in lantern_list_scene_2:
|
|||
for item in detectors_list_scene_2:
|
||||
detectors_scene_2.add(item)
|
||||
|
||||
for item in streets_list_scene_3:
|
||||
streets_scene_3.add(item)
|
||||
for item in lantern_list_scene_3:
|
||||
lanterns_scene_3.add(item)
|
||||
for item in detectors_list_scene_3:
|
||||
detectors_scene_3.add(item)
|
||||
|
||||
for item in streets_list_scene_4:
|
||||
streets_scene_4.add(item)
|
||||
for item in lantern_list_scene_4:
|
||||
lanterns_scene_4.add(item)
|
||||
for item in detectors_list_scene_4:
|
||||
detectors_scene_4.add(item)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -56,6 +87,10 @@ if __name__ == "__main__":
|
|||
functions.scene_1(screen, detectors_scene_1, streets_scene_1, lanterns_scene_1, player)
|
||||
if current_scene == "scene_2":
|
||||
functions.scene_2(screen, detectors_scene_2, streets_scene_2, lanterns_scene_2, player)
|
||||
if current_scene == "scene_3":
|
||||
functions.scene_2(screen, detectors_scene_3, streets_scene_3, lanterns_scene_3, player)
|
||||
if current_scene == "scene_4":
|
||||
functions.scene_2(screen, detectors_scene_4, streets_scene_4, lanterns_scene_4, player)
|
||||
|
||||
current_scene = player.sprite.left_scene(current_scene)
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ class Player(pygame.sprite.Sprite):
|
|||
self.player_direction = [player_right, player_left]
|
||||
|
||||
self.image = self.player_direction[0]
|
||||
self.rect = self.image.get_rect(center = (0, 150))
|
||||
self.rect = self.image.get_rect(center = (900, 500))
|
||||
|
||||
self.walking_speed = 10
|
||||
|
||||
|
@ -40,20 +40,38 @@ class Player(pygame.sprite.Sprite):
|
|||
self.rect.x = 1860
|
||||
|
||||
def left_scene(self, current_scene):
|
||||
if current_scene == "scene_1" and self.rect.y <= -80:
|
||||
self.rect.x = 900
|
||||
self.rect.y = 1050
|
||||
return "scene_2"
|
||||
if current_scene == "scene_2" and self.rect.y >= 1080:
|
||||
if current_scene == "scene_1" and self.rect.y >= 1080:
|
||||
self.rect.x = 900
|
||||
self.rect.y = -80
|
||||
return "scene_2"
|
||||
if current_scene == "scene_1" and self.rect.x <= -80:
|
||||
self.rect.x = 1880
|
||||
return "scene_3"
|
||||
if current_scene == "scene_2" and self.rect.y <= -80:
|
||||
self.rect.x = 900
|
||||
self.rect.y = 1050
|
||||
return "scene_1"
|
||||
if current_scene == "scene_2" and self.rect.x <= -80:
|
||||
self.rect.x = 1800
|
||||
return "scene_4"
|
||||
if current_scene == "scene_3" and self.rect.x >= 1880:
|
||||
self.rect.x = -80
|
||||
return "scene_1"
|
||||
if current_scene == "scene_3" and self.rect.y >= 1080:
|
||||
self.rect.y = -80
|
||||
return "scene_4"
|
||||
if current_scene == "scene_4" and self.rect.x >= 1880:
|
||||
self.rect.x = -80
|
||||
return "scene_2"
|
||||
if current_scene == "scene_4" and self.rect.y <= -80:
|
||||
self.rect.y = 1080
|
||||
return "scene_3"
|
||||
return current_scene
|
||||
|
||||
def update(self):
|
||||
self.get_last_position()
|
||||
self.player_inputs()
|
||||
self.left_screen()
|
||||
# self.left_screen()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue