andere Straßen bearbeitet und id System überarbeitet
This commit is contained in:
parent
8369f3d4de
commit
742c168916
BIN
Planung/Street Plan Skizze.jpg
Normal file
BIN
Planung/Street Plan Skizze.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 MiB |
BIN
code/__pycache__/setup.cpython-310.pyc
Normal file
BIN
code/__pycache__/setup.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
87
code/setup.py
Normal file
87
code/setup.py
Normal file
|
@ -0,0 +1,87 @@
|
|||
import pygame
|
||||
import sprites
|
||||
|
||||
def setup_streets():
|
||||
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
|
||||
street_4 = sprites.Streets(950, 200, 850, 4) # Street 2 Bottom Line
|
||||
street_5 = sprites.Streets(0, 750, 850, 4) # Street 5 Top Line
|
||||
street_6 = sprites.Streets(950, 750, 850, 4) # Street 6 Top Line
|
||||
street_7 = sprites.Streets(0, 850, 1800, 4) # Street 5/6 Bottom Line
|
||||
street_8 = sprites.Streets(850, 200, 4, 554) # Street 4 Left Line
|
||||
street_9 = sprites.Streets(950, 200, 4, 554) # Street 4 Right Line
|
||||
street_10 = sprites.Streets(850, 0, 4, 104) # Street 3 Left Line
|
||||
street_11 = sprites.Streets(950, 0, 4, 104) # Street 3 Right Line
|
||||
|
||||
streets_list = [street_1, street_2, street_3, street_4, street_5, street_6, street_7, street_8, street_9, street_10, street_11]
|
||||
|
||||
return streets_list
|
||||
|
||||
|
||||
def setup_lanterns_detectors_new(SCREEN_WIDTH):
|
||||
lantern_list = []
|
||||
detectors_list = []
|
||||
|
||||
# Street 1
|
||||
for y_pos in range(75, 226, 150):
|
||||
x_pos = 25
|
||||
id = 1
|
||||
while x_pos <= 825:
|
||||
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 y_pos in range(75, 226, 150):
|
||||
x_pos = 975
|
||||
id = 1
|
||||
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 4
|
||||
for x_pos in range(825, 976, 150):
|
||||
y_pos = 325
|
||||
id = 1
|
||||
while y_pos <= 625:
|
||||
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
|
||||
|
||||
# Street 5
|
||||
for y_pos in range(725, 976, 150):
|
||||
x_pos = 25
|
||||
id = 1
|
||||
while x_pos <= 825:
|
||||
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")
|
||||
detectors_list.append(detector)
|
||||
x_pos += 100
|
||||
id += 1
|
||||
|
||||
# Street 6
|
||||
for y_pos in range(725, 976, 150):
|
||||
x_pos = 975
|
||||
id = 1
|
||||
while x_pos <= 1775:
|
||||
lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_6")
|
||||
lantern_list.append(lantern)
|
||||
detector = sprites.Detectors(x_pos, y_pos, 75, 90, id, street="street_6")
|
||||
detectors_list.append(detector)
|
||||
x_pos += 100
|
||||
id += 1
|
||||
|
||||
return lantern_list, detectors_list
|
|
@ -1,46 +1,31 @@
|
|||
import pygame
|
||||
import sprites
|
||||
|
||||
import setup
|
||||
|
||||
pygame.init()
|
||||
|
||||
SCREEN_WIDTH = 1280
|
||||
SCREEN_HEIGHT = 720
|
||||
SCREEN_WIDTH = 1800
|
||||
SCREEN_HEIGHT = 1000
|
||||
|
||||
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
player = pygame.sprite.GroupSingle()
|
||||
player.add(sprites.Player())
|
||||
|
||||
streets = pygame.sprite.Group()
|
||||
street_1 = sprites.Streets(0, 100, SCREEN_WIDTH, 4)
|
||||
street_2 = sprites.Streets(0, 200, SCREEN_WIDTH, 4)
|
||||
streets.add(street_1)
|
||||
streets.add(street_2)
|
||||
streets_list = setup.setup_streets()
|
||||
|
||||
lanterns = pygame.sprite.Group()
|
||||
lantern_list = []
|
||||
detectors = pygame.sprite.Group()
|
||||
detectors_list = []
|
||||
id = 1
|
||||
|
||||
for y_pos in range(50, 251, 200):
|
||||
x_pos = 100
|
||||
while x_pos < SCREEN_WIDTH:
|
||||
lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id)
|
||||
lantern_list.append(lantern)
|
||||
detector = sprites.Detectors(x_pos, y_pos, 133, 300, id)
|
||||
detectors_list.append(detector)
|
||||
x_pos += 150
|
||||
id += 1
|
||||
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)
|
||||
|
||||
if __name__ == "__main__":
|
||||
run = True
|
||||
|
@ -48,7 +33,6 @@ if __name__ == "__main__":
|
|||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
|
||||
screen.fill("Grey")
|
||||
detectors.draw(screen)
|
||||
|
@ -64,10 +48,13 @@ if __name__ == "__main__":
|
|||
collisions = pygame.sprite.spritecollide(player.sprite, detectors, False)
|
||||
for detector in collisions:
|
||||
for lantern in lanterns:
|
||||
if lantern.id == detector.id - 1 and lantern.id is not 8 or lantern.id == detector.id + 1 and lantern.id is not 8:
|
||||
lantern.light_up(176, 179, 0)
|
||||
if lantern.id == detector.id:
|
||||
lantern.light_up(255, 255, 0)
|
||||
if lantern.street == detector.street:
|
||||
if lantern.id == detector.id - 1 or lantern.id == detector.id + 1:
|
||||
lantern.light_up(176, 179, 0, 255)
|
||||
if lantern.id == detector.id - 2 or lantern.id == detector.id + 2:
|
||||
lantern.light_up(176, 179, 0, 128)
|
||||
if lantern.id == detector.id:
|
||||
lantern.light_up(255, 255, 0, 255)
|
||||
|
||||
|
||||
if pygame.sprite.spritecollide(player.sprite, streets, False):
|
||||
|
|
|
@ -10,22 +10,22 @@ 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 = (0, 150))
|
||||
|
||||
|
||||
self.walking_speed = 5
|
||||
|
||||
def player_inputs(self):
|
||||
key = pygame.key.get_pressed()
|
||||
if key[pygame.K_a]:
|
||||
self.rect.x -= 3
|
||||
self.rect.x -= self.walking_speed
|
||||
self.image = self.player_direction[1]
|
||||
if key[pygame.K_d]:
|
||||
self.rect.x += 3
|
||||
self.rect.x += self.walking_speed
|
||||
self.image = self.player_direction[0]
|
||||
if key[pygame.K_s]:
|
||||
self.rect.y += 3
|
||||
self.rect.y += self.walking_speed
|
||||
if key[pygame.K_w]:
|
||||
self.rect.y -= 3
|
||||
self.rect.y -= self.walking_speed
|
||||
|
||||
def get_last_position(self):
|
||||
self.last_position = self.rect.topleft
|
||||
|
@ -33,9 +33,17 @@ class Player(pygame.sprite.Sprite):
|
|||
def set_back(self):
|
||||
self.rect.topleft = self.last_position
|
||||
|
||||
def left_screen(self):
|
||||
if self.rect.x > 1860:
|
||||
self.rect.x = -60
|
||||
if self.rect.x < -60:
|
||||
self.rect.x = 1860
|
||||
|
||||
def update(self):
|
||||
self.get_last_position()
|
||||
self.player_inputs()
|
||||
self.left_screen()
|
||||
|
||||
|
||||
|
||||
class Streets(pygame.sprite.Sprite):
|
||||
|
@ -46,23 +54,27 @@ 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):
|
||||
def __init__(self, left, top, width, height, id, street):
|
||||
super().__init__()
|
||||
self.image = pygame.Surface([width, height])
|
||||
self.image.fill((0, 0, 0))
|
||||
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
|
||||
|
||||
def light_up(self, r, g, b):
|
||||
self.image.fill((r, g, b))
|
||||
def light_up(self, r, g, b, oppacity):
|
||||
self.image.fill((r, g, b, oppacity))
|
||||
|
||||
def reset_light(self):
|
||||
self.image.fill((0, 0, 0))
|
||||
|
||||
class Detectors(pygame.sprite.Sprite):
|
||||
def __init__(self, left, top, width, height, id):
|
||||
def __init__(self, left, top, width, height, id, street):
|
||||
super().__init__()
|
||||
self.image = pygame.Surface([width, height])
|
||||
self.image.fill("Grey")
|
||||
self.image = pygame.Surface([width, height], pygame.SRCALPHA)
|
||||
|
||||
self.image.fill((0, 0, 0, 0))
|
||||
#pygame.draw.rect(self.image, "White", self.image.get_rect(), 1) # Zum Debuggen eine Umrandung
|
||||
self.rect = self.image.get_rect(center=(left, top))
|
||||
self.id = id
|
||||
self.street = street
|
||||
|
|
6
code/tempCodeRunnerFile.py
Normal file
6
code/tempCodeRunnerFile.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
if lantern.id == detector.id - 1 or lantern.id == detector.id + 1:
|
||||
lantern.light_up(176, 179, 0, 255)
|
||||
if lantern.id == detector.id - 2 or lantern.id == detector.id + 2:
|
||||
lantern.light_up(176, 179, 0, 128)
|
||||
if lantern.id == detector.id:
|
||||
lantern.light_up(255, 255, 0, 255)
|
Loading…
Reference in a new issue