Advertisement
rric

flugobjekt_von_links

Oct 24th, 2023 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.03 KB | None | 0 0
  1. # Ein UFO im Anflug auf unseren Meeresblick ...
  2. # Copyright (C) 2021, 2023  Roland Richter             [Mu: Pygame Zero]
  3.  
  4. # Erzeuge ein 800×500 Fenster mit Titel
  5. TITLE = "Flugobjekt von links ..."
  6. WIDTH = 800
  7. HEIGHT = 500
  8. frame_count = 0
  9.  
  10. ufo_x = 0
  11. ufo_y = 170
  12.  
  13.  
  14. def draw():
  15.     # Zähle die Anzahl der gezeichneten frames mit
  16.     global frame_count
  17.     frame_count += 1
  18.  
  19.     screen.fill("skyblue2")
  20.  
  21.     # Male das Meer im unteren Teil des Fensters, dahinter eine Insel
  22.     screen.draw.filled_circle((0.5 * WIDTH, HEIGHT), 0.3 * HEIGHT, "forestgreen")
  23.     screen.draw.filled_rect(
  24.         Rect((0, 0.8 * HEIGHT), (WIDTH, 0.2 * HEIGHT)), "royalblue4"
  25.     )
  26.  
  27.     # Male eine weiße Wolke ...
  28.     screen.draw.filled_circle((0.75 * WIDTH, 0.30 * HEIGHT), 42, "white")
  29.     screen.draw.filled_circle((0.72 * WIDTH, 0.31 * HEIGHT), 42, "white")
  30.     screen.draw.filled_circle((0.77 * WIDTH, 0.28 * HEIGHT), 42, "white")
  31.     screen.draw.filled_circle((0.79 * WIDTH, 0.32 * HEIGHT), 42, "white")
  32.  
  33.     # ... und die gelbe Sonne
  34.     screen.draw.filled_circle((150, 70), 45, "yellow")
  35.  
  36.     # PROBIERE, auch die Sonne zu bewegen!
  37.  
  38.     # Male einen Leuchtturm ...
  39.     screen.draw.filled_rect(Rect((0.4 * WIDTH, 0.6 * HEIGHT), (20, 80)), "whitesmoke")
  40.  
  41.     # ... mit einem Blinklicht, das zwischen rot und schwarz hin- und herspringt.
  42.     if frame_count % 120 < 20:
  43.         screen.draw.filled_circle((0.4 * WIDTH + 10, 0.6*HEIGHT), 10, "red")
  44.     else:
  45.         screen.draw.filled_circle((0.4 * WIDTH + 10, 0.6*HEIGHT), 10, "black")
  46.  
  47.     # PROBIERE, das Blinklicht schneller oder langsamer zu machen!
  48.  
  49.     # Zeichne das UFO
  50.     draw_ufo()
  51.  
  52.  
  53. def update():
  54.     global ufo_x, ufo_y
  55.  
  56.     # Bewege das UFO nach rechts; ...
  57.     ufo_x += 2
  58.     # falls rechter Rand erreicht, beginne wieder am linken Rand.
  59.     if ufo_x > WIDTH:
  60.         ufo_x = 0
  61.  
  62.     # PROBIERE, das Ufo von rechts nach links fliegen zu lassen!
  63.  
  64.  
  65. def draw_ufo():
  66.     # Male den Antrieb des UFOs (gelb-rote Ionenstrahlen), ...
  67.     if frame_count % 4 == 0:
  68.         screen.draw.filled_circle((ufo_x, ufo_y+40), 15, "red")
  69.         screen.draw.filled_circle((ufo_x, ufo_y+40), 10, "yellow")
  70.  
  71.     # ... und das UFO selbst.
  72.     screen.draw.filled_rect(Rect((ufo_x-70, ufo_y-10), (140, 30)), "rosybrown4")
  73.     screen.draw.filled_circle((ufo_x, ufo_y), 42, "rosybrown4")
  74.  
  75.  
  76. # ----------------------------------------------------------------------
  77. # This program is free software: you can redistribute it and/or modify
  78. # it under the terms of the GNU General Public License as published by
  79. # the Free Software Foundation, either version 3 of the License, or
  80. # (at your option) any later version.
  81. #
  82. # This program is distributed in the hope that it will be useful,
  83. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  84. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  85. # GNU General Public License for more details.
  86. #
  87. # You should have received a copy of the GNU General Public License
  88. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement