rric

quirlige_raumschiffe

Dec 15th, 2023 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.34 KB | None | 0 0
  1. # Ein Ufo im Anflug auf unseren Meeresblick ...
  2. # Copyright 2021, 2023  Roland Richter                 [Mu: Pygame Zero]
  3.  
  4. import random
  5.  
  6. # Fenstergröße 800 x 500
  7. TITLE = "Quirlige Raumschiffe"
  8. WIDTH = 800
  9. HEIGHT = 500
  10. frame_count = 0
  11.  
  12. # Die Bilder stammen von https://kenney.nl/assets/alien-ufo-pack;
  13. # alle Dateinamen wurden mit dem Befehl
  14. # for /f "Tokens=*" %f in ('dir /l/b/a-d') do (rename "%f" "%f")
  15. # in kleinbuchstaben umgewandelt
  16. ufo = Actor("kenney_alien-ufo-pack/png/shippink_manned.png", (WIDTH - 40, 140))
  17. dome = Actor("kenney_alien-ufo-pack/png/dome.png", (WIDTH - 40, 140 - 30))
  18.  
  19. # PROBIERE ein UFO in einer anderen Farbe aus; oder probiere, das Bild
  20. # des UFOs selbst zu zeichnen.
  21.  
  22. def draw():
  23.     global frame_count
  24.     frame_count += 1
  25.  
  26.     screen.fill("skyblue2")
  27.  
  28.     # Male das Meer im unteren Teil des Fensters, dahinter eine Insel
  29.     screen.draw.filled_circle((0.5 * WIDTH, HEIGHT), 0.3 * HEIGHT, "forestgreen")
  30.     screen.draw.filled_rect(
  31.         Rect((0, 0.8 * HEIGHT), (WIDTH, 0.2 * HEIGHT)), "royalblue4"
  32.     )
  33.  
  34.     # Male eine weiße Wolke ...
  35.     screen.draw.filled_circle((0.75 * WIDTH, 0.30 * HEIGHT), 42, "white")
  36.     screen.draw.filled_circle((0.72 * WIDTH, 0.31 * HEIGHT), 42, "white")
  37.     screen.draw.filled_circle((0.77 * WIDTH, 0.28 * HEIGHT), 42, "white")
  38.     screen.draw.filled_circle((0.79 * WIDTH, 0.32 * HEIGHT), 42, "white")
  39.  
  40.     # ... und die gelbe Sonne
  41.     screen.draw.filled_circle((150, 70), 45, "yellow")
  42.  
  43.     # Male einen Leuchtturm ...
  44.     screen.draw.filled_rect(Rect((0.4 * WIDTH, 0.6 * HEIGHT), (20, 80)), "whitesmoke")
  45.  
  46.     # ... mit einem Blinklicht, das zwischen rot und schwarz hin- und herspringt.
  47.     light_color = "red" if frame_count % 120 < 20 else "black"
  48.     screen.draw.filled_circle((0.4 * WIDTH + 10, 0.6 * HEIGHT), 10, light_color)
  49.  
  50.     # Zeichne das UFO mit der Hülle
  51.     ufo.draw()
  52.     dome.draw()
  53.  
  54.     # Schreibe Informationen in die linke obere Ecke
  55.     info = "frame " + str(frame_count)
  56.     screen.draw.text(info, (10, 10), color="white", fontsize=24)
  57.  
  58.  
  59. def update():
  60.     # Bewege das UFO nach rechts; ...
  61.     ufo.x += 2
  62.     # falls rechter Rand erreicht, beginne wieder am linken Rand.
  63.     if ufo.x > WIDTH:
  64.         ufo.x = 0
  65.  
  66.     # PROBIERE Lass das Ufo mit Hilfe von Zufallszahlen wackeln:
  67.     auf_ab = random.randint(-8, 8)
  68.     # QUIZ Jetzt muss 'auf_ab' die Bewegung des UFOs beeinflussen; wie?
  69.    
  70.     # QUIZ Wie kannst du hier einen zufälligen Winkel erzeugen?
  71.     winkel = 0
  72.     ufo.angle = winkel
  73.  
  74.     # Die Hülle des UFOs muss ebenfalls mitbewegt werden
  75.     dome.x = ufo.x
  76.     dome.y = ufo.y - 30
  77.     dome.angle = ufo.angle
  78.  
  79.  
  80. # ----------------------------------------------------------------------
  81. # This program is free software: you can redistribute it and/or modify
  82. # it under the terms of the GNU General Public License as published by
  83. # the Free Software Foundation, either version 3 of the License, or
  84. # (at your option) any later version.
  85. #
  86. # This program is distributed in the hope that it will be useful,
  87. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  88. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  89. # GNU General Public License for more details.
  90. #
  91. # You should have received a copy of the GNU General Public License
  92. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  93.  
Add Comment
Please, Sign In to add comment