rric

leise_gleitet_der_wald

Dec 12th, 2023 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. # Eine Menge an Bäumen ziehen vorbei ...
  2. # Copyright 2023 Roland Richter                        [Mu: Pygame Zero]
  3.  
  4. import random
  5.  
  6. # Erzeuge ein rechteckiges 800×500 Fenster
  7. TITLE = "Leise gleitet der Wald"
  8. WIDTH = 800
  9. HEIGHT = 500
  10. frame_count = 0
  11.  
  12. # Erzeuge die Positionen, an denen Bäume gemalt werden:
  13. # - horizontal alle 80 Pixel
  14. # - vertikal zwischen 440 und 460
  15. # PROBIERE, mehr Bäume hinzu zu fügen, und die Bäume enger zueinander zu stellen
  16. wood = []
  17. for num in range(12):
  18.     tree_x = 80 * num
  19.     tree_y = random.randint(440, 460)
  20.     wood.append((tree_x, tree_y))
  21.  
  22.  
  23. def draw():
  24.     global frame_count
  25.     frame_count += 1
  26.  
  27.     screen.fill("skyblue2")
  28.  
  29.     # Male Schnee in den unteren Teil des Fensters
  30.     screen.draw.filled_rect(Rect((0, 0.8 * HEIGHT), (WIDTH, 0.2 * HEIGHT)), "snow")
  31.  
  32.     # Male die Sonne
  33.     screen.draw.filled_circle((150, 70), 45, "yellow")
  34.  
  35.     # Male alle Bäume in der "Wald"-Liste
  36.     for tree_pos in wood:
  37.         draw_tree(tree_pos)
  38.  
  39.  
  40. def update():
  41.     global wood
  42.  
  43.     # ⭠: flieg nach links = alle Bäume rücken 3 Pixel nach RECHTS
  44.     if keyboard.left:
  45.         wood = [(pos[0] + 3, pos[1]) for pos in wood]
  46.     # ⭢: flieg nach rechts = alle Bäume rücken 3 Pixel nach LINKS
  47.     elif keyboard.right:
  48.         wood = [(pos[0] - 3, pos[1]) for pos in wood]
  49.  
  50.  
  51. def draw_tree(pos):
  52.     """Male einen Baum an der gegebenen Position."""
  53.     x, y = pos
  54.     screen.blit("kenney_platformer-art-winter/tiles/pinesapling.png", (x - 35, y - 70))
  55.  
  56.  
  57. # ----------------------------------------------------------------------
  58. # This program is free software: you can redistribute it and/or modify
  59. # it under the terms of the GNU General Public License as published by
  60. # the Free Software Foundation, either version 3 of the License, or
  61. # (at your option) any later version.
  62. #
  63. # This program is distributed in the hope that it will be useful,
  64. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  65. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  66. # GNU General Public License for more details.
  67. #
  68. # You should have received a copy of the GNU General Public License
  69. # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  70.  
Advertisement
Add Comment
Please, Sign In to add comment