python:pgzero:projekt2
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
python:pgzero:projekt2 [2021/04/26 14:09] – [Beschreibung des Programms] lutz | python:pgzero:projekt2 [2023/03/16 08:23] (aktuell) – lutz | ||
---|---|---|---|
Zeile 11: | Zeile 11: | ||
Zu nächst des gesamte Programm: | Zu nächst des gesamte Programm: | ||
- | <code python | + | [[python: |
+ | |||
+ | |||
+ | |||
+ | Mit der Zeile | ||
+ | <code python> | ||
from random import randint | from random import randint | ||
+ | </ | ||
+ | werden die Funktionen für Zufallszahlen eingebunden. | ||
+ | |||
+ | Mit | ||
+ | <code python> | ||
WIDTH = 600 | WIDTH = 600 | ||
HEIGHT = 600 | HEIGHT = 600 | ||
score = 0 | score = 0 | ||
- | |||
game_over = False | game_over = False | ||
+ | </ | ||
+ | werden einige globale Konstanten bzw. Variablen festgelegt. '' | ||
+ | |||
+ | Mit | ||
+ | <code python> | ||
mario = Actor(" | mario = Actor(" | ||
mario.pos = 100, 100 | mario.pos = 100, 100 | ||
- | |||
coin = Actor(" | coin = Actor(" | ||
coin.pos = 200, 200 | coin.pos = 200, 200 | ||
+ | </ | ||
+ | werden die Akteure des Spiels definiert. | ||
+ | <code python> | ||
def draw(): | def draw(): | ||
screen.fill(" | screen.fill(" | ||
Zeile 35: | Zeile 51: | ||
screen.fill(" | screen.fill(" | ||
screen.draw.text(" | screen.draw.text(" | ||
+ | </ | ||
+ | Mit der Funktion '' | ||
+ | |||
+ | <code python> | ||
def place_coin(): | def place_coin(): | ||
coin.x = randint(20, (WIDTH-20)) | coin.x = randint(20, (WIDTH-20)) | ||
coin.y = randint(20, (HEIGHT-20)) | coin.y = randint(20, (HEIGHT-20)) | ||
+ | </ | ||
+ | Mit der Funktion '' | ||
+ | |||
+ | <code python> | ||
def time_up(): | def time_up(): | ||
global game_over | global game_over | ||
game_over = True | game_over = True | ||
+ | </ | ||
+ | Die Funktion '' | ||
+ | |||
+ | <code python> | ||
def update(): | def update(): | ||
global score | global score | ||
Zeile 58: | Zeile 86: | ||
score = score + 10 | score = score + 10 | ||
place_coin() | place_coin() | ||
- | |||
- | clock.schedule(time_up, | ||
- | place_coin() | ||
</ | </ | ||
- | Mit der Zeile | + | Die Funktion '' |
- | <code python> | + | |
- | from random import randint | + | |
- | </ | + | |
- | werden die Funktionen für Zufallszahlen eingebunden. | + | |
+ | Mit der **if-elif**-Anweisung wird auf die Pfeiltasten der Tastatur reagiert. Die Position von Mario wird dann entsprechend verändert '' | ||
+ | |||
+ | Wenn das passiert, wird der Score erhöht und die Münze an einer anderen Stelle platziert. | ||
- | Mit | ||
<code python> | <code python> | ||
- | WIDTH = 600 | + | clock.schedule(time_up, |
- | HEIGHT = 600 | + | |
- | score = 0 | + | |
- | game_over = False | + | |
</ | </ | ||
- | werden einige globale Konstanten bzw. Variablen festgelegt. '' | ||
+ | Mit dieser Programmzeile wird festgelegt, wie lange das Programm läuft. | ||
+ | =====Erkärvideo===== | ||
- | Mit | + | {{youtube>TyWeB2UK0_4}} |
- | <code python> | + | |
- | mario = Actor(" | + | |
- | mario.pos = 100, 100 | + | |
- | coin = Actor(" | + | |
- | coin.pos = 200, 200 | + | |
- | </ | + | |
- | werden die Akteure des Spiels definiert. | + | |
- | <code python> | + | =====Aufgaben===== |
- | def draw(): | + | |
- | screen.fill(" | + | |
- | mario.draw() | + | |
- | coin.draw() | + | |
- | screen.draw.text(" | + | |
- | if game_over: | + | **Aufgabe 1** |
- | screen.fill(" | + | |
- | screen.draw.text(" | + | |
- | </ | + | |
- | Mit der Funktion '' | + | Teste den Programmcode! Verändere |
- | <code python> | + | **Aufgabe 2** |
- | def place_coin(): | + | |
- | coin.x = randint(20, (WIDTH-20)) | + | |
- | coin.y = randint(20, (HEIGHT-20)) | + | |
- | </ | + | |
- | Mit der Funktion '' | + | Erhöhe die Anzahl |
- | <code python> | + | **Aufgabe 3** |
- | def time_up(): | + | |
- | global game_over | + | |
- | game_over = True | + | |
- | </ | + | |
- | Die Funktion '' | + | Lass zusätzlich andere Münzen oder Gegenstände anzeigen, für die Mario einen anderen Score bekommt. |
+ | \\ | ||
+ | ~~DISCUSSION | Hier können Fragen zum Inhalt der Seite gestellt werden. ~~ |
python/pgzero/projekt2.1619438992.txt.gz · Zuletzt geändert: 2021/04/26 14:09 von lutz