From 0967dc86e11bfae0dbffe5c34dc9a018dfb31f61 Mon Sep 17 00:00:00 2001 From: moritz Date: Sun, 7 Jul 2024 19:32:10 +0200 Subject: [PATCH] Weiter an den Kreuzungen gearbeitet --- code/__pycache__/setup.cpython-310.pyc | Bin 1829 -> 2364 bytes code/__pycache__/sprites.cpython-310.pyc | Bin 3308 -> 3384 bytes code/setup.py | 25 +++++++++++++++++++---- code/simulation.py | 2 ++ code/sprites.py | 6 ++++-- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/code/__pycache__/setup.cpython-310.pyc b/code/__pycache__/setup.cpython-310.pyc index 98da64ef030e8c2f9ea31df45bd3eef10917c6ec..7daf327a2e4da8606749b10799bb511d21e59b2e 100644 GIT binary patch delta 933 zcmZXSy>HV%6u^BSb`mFcKH8=U2}CMOtx5<|N@-VGF)$&-QVF7{=SHTGkh2Gn&P0d~ z2q~!2EifPz2^Pe{ju3wVg`tZ##!d_@jJ!*(s^r?br@P;K{@t_BAKkANci=d-0oUP= zS394}U)(V+R$!TfaRWy9lE_c^ZKDvIf-+|p@i;;cu%Lo4%BV1zEANvQa^*8}aTW66 z?cvSHU`1A9XLh>1AH^GJ;W+ktFsI<*|~8h z&T5WQJU8K0T@P=l>ut@a^`|@!oU#TZtO>Wt&X3KwFw$~M%jdMj(fmS+yIMYN@>E{b zJiTcNczV;aKnIq{ikz@TD=!@3_N?~^83G>=QJBn-z&rSk;kD!?vw@GWyk#~=%hWKA zF`Rbr$1)7A&OTTp5Pqt#i69Ii&DD>>q1NDeRdNVfUVz#0Zxz&I9!YS(con8eewz=% zFzEL>0Soq&iGs;Pyb0N07l4;ZOy2Fw59X4cSpJj9?=!C=f0^qe-cX9n!)`zFc|XZA zKk~Pu0pBW4tR0=`TuFm=8Z4*5)veOhapF8HS=mfKbS({5)8P6UZCfr_ZS+RowVtok oay6vxSyUq@vnsYx7V|~*-DqMxe%k9k@;RJPwbM@YF2DV)=V00fYdrS6{bA`(cY#wR_ zDjH(-h;Qd|NiL?mbc94A(IJj$OgQB<&T(7qk$GgR6XGsI9&Lte(%>d{I5{UBW4E19 zUQP(t1i~kP@bZsP0YcrXas;%B`XP%p?24|#3*bz0M>VL2YJXj7x{JD_g*vQ{`7K}< zp~v`!>XlBZ9ojjCyNpm|k5GtX6yqM=GQ8=HY#knzeQLSUQrCh&f)+6hp`Y%d)QqI? zeVKK^3aryNNP{mEtp1tcUE5VS7laTC{eyz);6vLY%q&p?^-PtS4eT-HTJ4z>2RyZo k_xsWp{giQE`Ui3#)Bh#**X^*4CJr?VNJvZti4DQe$N?3GFi)M>6qYEQlGqYV z*f1B)h(%(yM`oOyH@319d#u1o^YCUpw2ZXZJ|U)923gi7y@SOMIyG z5DS2u@9n;=HFh>@(nsGSVhAyet41nvrZSl%S?;xESE;mf*hp^s@VjF6!^@3a#rKx5=zm1M2s^zbNq z4{l`u0{S(4$b5Dn;L?nuXvUV$asLYhR`ov952$VE6K`^~3Tg#JVVyWBQSJn$tYSa* z`~8@LwSGUW!G7G;--7xVa_3!=CGD&$A8CMmrT=wQ>rigGQMAZ=Q-Yv&KBdxY9`;C!4X=iGB&Cck3AULc@LLg@YV$%pb(tg|pYYR0s|HId*ro*RgHfq~j=luNapYKb$9<=|b5Sr3$(=q(`fh($yJVZ$Md zgRPGl*q{@WFk(VO-y=Eb>v>XwPkmdN!_qQbD$#(!9oO;N7w4yEUIp65l$E4Bh50lh zgBUHfiB=Wv3@cI;CQfrz0aao|RYNi_ii5<{d{)Gg@<6LNp40Jq{QoQP6f`}q;Y*ncH_Y|M$gBunjOVDR=ZM4y{D1bMXQ1Exe4&SUm#(x0Sn^NEa diff --git a/code/setup.py b/code/setup.py index c1469a2..a1f05ca 100644 --- a/code/setup.py +++ b/code/setup.py @@ -27,7 +27,7 @@ def setup_lanterns_detectors_new(SCREEN_WIDTH): for y_pos in range(75, 226, 150): x_pos = 25 id = 1 - while x_pos <= 825: + while x_pos <= 725: 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") @@ -37,8 +37,8 @@ def setup_lanterns_detectors_new(SCREEN_WIDTH): # Street 2 for y_pos in range(75, 226, 150): - x_pos = 975 - id = 1 + x_pos = 1075 + id = 2 while x_pos <= 1775: lantern = sprites.Lanterns(x_pos, y_pos, 25, 25, id, street="street_2") lantern_list.append(lantern) @@ -64,7 +64,7 @@ def setup_lanterns_detectors_new(SCREEN_WIDTH): for y_pos in range(725, 976, 150): x_pos = 25 id = 1 - while x_pos <= 825: + while x_pos <= 725: 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") @@ -84,4 +84,21 @@ def setup_lanterns_detectors_new(SCREEN_WIDTH): x_pos += 100 id += 1 + # Crossing 1 + cross_lantern_1 = sprites.Lanterns(825, 225, 25, 25, id=9, street="street_1", crossing_id=1) + cross_lantern_2 = sprites.Lanterns(825, 75, 25, 25, id=9, street="street_1", crossing_id=1) + cross_lantern_3 = sprites.Lanterns(975, 225, 25, 25, id=1, street="street_2", crossing_id=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 + cross_lantern_5 = sprites.Lanterns(825, 725, 25, 25, id=9, street="street_5", crossing_id=1) + cross_lantern_6 = sprites.Lanterns(825, 875, 25, 25, id=9, street="street_5", crossing_id=1) + cross_lantern_7 = sprites.Lanterns(975, 225, 25, 25, id=1, street="street_2", crossing_id=1) + cross_lantern_8 = sprites.Lanterns(975, 75, 25, 25, id=1, street="street_2", crossing_id=1) + cross_detector_2 = sprites.Detectors(900, 150, 260, 260, crossing_id=1) + + lantern_list.extend([cross_lantern_1, cross_lantern_2, cross_lantern_3, cross_lantern_4, cross_lantern_5, cross_lantern_6]) + detectors_list.append(cross_detector_1) + return lantern_list, detectors_list \ No newline at end of file diff --git a/code/simulation.py b/code/simulation.py index 16a3927..2f38dfc 100644 --- a/code/simulation.py +++ b/code/simulation.py @@ -48,6 +48,8 @@ if __name__ == "__main__": collisions = pygame.sprite.spritecollide(player.sprite, detectors, False) for detector in collisions: for lantern in lanterns: + if detector.crossing_id == lantern.crossing_id and detector.crossing_id is not None: + lantern.light_up(255, 255, 0, 255) if lantern.street == detector.street: if lantern.id == detector.id - 1 or lantern.id == detector.id + 1: lantern.light_up(176, 179, 0, 255) diff --git a/code/sprites.py b/code/sprites.py index 76ee982..0d1a499 100644 --- a/code/sprites.py +++ b/code/sprites.py @@ -54,13 +54,14 @@ 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, street): + def __init__(self, left, top, width, height, id=None, street=None, crossing_id=None): super().__init__() 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 + self.crossing_id = crossing_id def light_up(self, r, g, b, oppacity): self.image.fill((r, g, b, oppacity)) @@ -69,7 +70,7 @@ class Lanterns(pygame.sprite.Sprite): self.image.fill((0, 0, 0)) class Detectors(pygame.sprite.Sprite): - def __init__(self, left, top, width, height, id, street): + def __init__(self, left, top, width, height, id=None, street=None, crossing_id=None): super().__init__() self.image = pygame.Surface([width, height], pygame.SRCALPHA) @@ -78,3 +79,4 @@ class Detectors(pygame.sprite.Sprite): self.rect = self.image.get_rect(center=(left, top)) self.id = id self.street = street + self.crossing_id = crossing_id