Erstellung/Beginn Szene 2
This commit is contained in:
parent
a2ece792f8
commit
6ce32a689d
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -58,4 +58,41 @@ def check_sensor(collisions, lanterns):
|
||||||
|
|
||||||
# Direkt zugehörige Laterne anmachen
|
# Direkt zugehörige Laterne anmachen
|
||||||
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:
|
||||||
|
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")
|
||||||
|
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()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import pygame
|
import pygame
|
||||||
import sprites
|
import sprites
|
||||||
|
|
||||||
def setup_streets():
|
def setup_streets_scene_1():
|
||||||
street_1 = sprites.Streets(0, 100, 850, 4) # Street 1 Top Line
|
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_2 = sprites.Streets(0, 200, 850, 4) # Street 1 Bottomm Line
|
||||||
street_3 = sprites.Streets(950, 100, 850, 4) # Street 2 Top Line
|
street_3 = sprites.Streets(950, 100, 850, 4) # Street 2 Top Line
|
||||||
|
@ -19,7 +19,7 @@ def setup_streets():
|
||||||
return streets_list
|
return streets_list
|
||||||
|
|
||||||
|
|
||||||
def setup_lanterns_detectors_new(SCREEN_WIDTH):
|
def setup_lanterns_detectors_scene_1(SCREEN_WIDTH):
|
||||||
lantern_list = []
|
lantern_list = []
|
||||||
detectors_list = []
|
detectors_list = []
|
||||||
|
|
||||||
|
@ -101,4 +101,18 @@ def setup_lanterns_detectors_new(SCREEN_WIDTH):
|
||||||
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])
|
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])
|
detectors_list.extend([cross_detector_1, cross_detector_2])
|
||||||
|
|
||||||
return lantern_list, detectors_list
|
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]
|
||||||
|
|
||||||
|
return streets_list
|
|
@ -14,19 +14,26 @@ clock = pygame.time.Clock()
|
||||||
player = pygame.sprite.GroupSingle()
|
player = pygame.sprite.GroupSingle()
|
||||||
player.add(sprites.Player())
|
player.add(sprites.Player())
|
||||||
|
|
||||||
streets = pygame.sprite.Group()
|
streets_scene_1 = pygame.sprite.Group()
|
||||||
streets_list = setup.setup_streets()
|
streets_list_scene_1 = setup.setup_streets_scene_1()
|
||||||
|
streets_scene_2 = pygame.sprite.Group()
|
||||||
|
streets_list_scene_2 = setup.setup_streets_scene_2()
|
||||||
|
|
||||||
lanterns = pygame.sprite.Group()
|
|
||||||
detectors = pygame.sprite.Group()
|
lanterns_scene_1 = pygame.sprite.Group()
|
||||||
lantern_list, detectors_list = setup.setup_lanterns_detectors_new(SCREEN_WIDTH)
|
detectors_scene_1 = pygame.sprite.Group()
|
||||||
|
lantern_list_scene_1, detectors_list_scene_1 = setup.setup_lanterns_detectors_scene_1(SCREEN_WIDTH)
|
||||||
|
|
||||||
|
current_scene = "scene_1"
|
||||||
|
|
||||||
for item in lantern_list:
|
for item in lantern_list_scene_1:
|
||||||
lanterns.add(item)
|
lanterns_scene_1.add(item)
|
||||||
for item in detectors_list:
|
for item in detectors_list_scene_1:
|
||||||
detectors.add(item)
|
detectors_scene_1.add(item)
|
||||||
for item in streets_list:
|
for item in streets_list_scene_1:
|
||||||
streets.add(item)
|
streets_scene_1.add(item)
|
||||||
|
for item in streets_list_scene_2:
|
||||||
|
streets_scene_2.add(item)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,25 +44,12 @@ if __name__ == "__main__":
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
run = False
|
run = False
|
||||||
|
|
||||||
screen.fill("Grey")
|
if current_scene == "scene_1":
|
||||||
detectors.draw(screen)
|
functions.scene_1(screen, detectors_scene_1, streets_scene_1, lanterns_scene_1, player)
|
||||||
streets.draw(screen)
|
if current_scene == "scene_2":
|
||||||
lanterns.draw(screen)
|
functions.scene_2(screen, detectors_scene_1, streets_scene_2, lanterns_scene_1, player)
|
||||||
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)
|
|
||||||
functions.check_sensor(collisions, lanterns)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if pygame.sprite.spritecollide(player.sprite, streets, False):
|
|
||||||
player.sprite.set_back()
|
|
||||||
|
|
||||||
|
current_scene = player.sprite.left_scene(current_scene)
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
|
|
|
@ -39,6 +39,13 @@ class Player(pygame.sprite.Sprite):
|
||||||
if self.rect.x < -60:
|
if self.rect.x < -60:
|
||||||
self.rect.x = 1860
|
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"
|
||||||
|
return current_scene
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.get_last_position()
|
self.get_last_position()
|
||||||
self.player_inputs()
|
self.player_inputs()
|
||||||
|
|
Loading…
Reference in a new issue