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.
|
@ -59,3 +59,40 @@ def check_sensor(collisions, lanterns):
|
|||
# Direkt zugehörige Laterne anmachen
|
||||
if lantern.id == detector.id:
|
||||
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 sprites
|
||||
|
||||
def setup_streets():
|
||||
def setup_streets_scene_1():
|
||||
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 +19,7 @@ def setup_streets():
|
|||
return streets_list
|
||||
|
||||
|
||||
def setup_lanterns_detectors_new(SCREEN_WIDTH):
|
||||
def setup_lanterns_detectors_scene_1(SCREEN_WIDTH):
|
||||
lantern_list = []
|
||||
detectors_list = []
|
||||
|
||||
|
@ -102,3 +102,17 @@ def setup_lanterns_detectors_new(SCREEN_WIDTH):
|
|||
detectors_list.extend([cross_detector_1, cross_detector_2])
|
||||
|
||||
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.add(sprites.Player())
|
||||
|
||||
streets = pygame.sprite.Group()
|
||||
streets_list = setup.setup_streets()
|
||||
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()
|
||||
|
||||
lanterns = pygame.sprite.Group()
|
||||
detectors = pygame.sprite.Group()
|
||||
lantern_list, detectors_list = setup.setup_lanterns_detectors_new(SCREEN_WIDTH)
|
||||
|
||||
for item in lantern_list:
|
||||
lanterns.add(item)
|
||||
for item in detectors_list:
|
||||
detectors.add(item)
|
||||
for item in streets_list:
|
||||
streets.add(item)
|
||||
lanterns_scene_1 = pygame.sprite.Group()
|
||||
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_scene_1:
|
||||
lanterns_scene_1.add(item)
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
@ -37,25 +44,12 @@ if __name__ == "__main__":
|
|||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
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)
|
||||
functions.check_sensor(collisions, lanterns)
|
||||
|
||||
|
||||
|
||||
if pygame.sprite.spritecollide(player.sprite, streets, False):
|
||||
player.sprite.set_back()
|
||||
if current_scene == "scene_1":
|
||||
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_1, streets_scene_2, lanterns_scene_1, player)
|
||||
|
||||
current_scene = player.sprite.left_scene(current_scene)
|
||||
|
||||
pygame.display.update()
|
||||
clock.tick(60)
|
||||
|
|
|
@ -39,6 +39,13 @@ class Player(pygame.sprite.Sprite):
|
|||
if self.rect.x < -60:
|
||||
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):
|
||||
self.get_last_position()
|
||||
self.player_inputs()
|
||||
|
|
Loading…
Reference in a new issue