python:pgzero:projekt2
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende Überarbeitung | |||
| python:pgzero:projekt2 [2023/03/16 08:18] – [Beschreibung des Programms] lutz | python:pgzero:projekt2 [2023/03/16 08:23] (aktuell) – lutz | ||
|---|---|---|---|
| Zeile 13: | Zeile 13: | ||
| [[python: | [[python: | ||
| - | <code python mario.py> | ||
| - | from random import randint | ||
| - | WIDTH = 600 | ||
| - | HEIGHT = 600 | ||
| - | score = 0 | ||
| - | |||
| - | game_over = False | ||
| - | |||
| - | mario = Actor(" | ||
| - | mario.pos = 100, 100 | ||
| - | |||
| - | coin = Actor(" | ||
| - | coin.pos = 200, 200 | ||
| - | |||
| - | def draw(): | ||
| - | screen.fill(" | ||
| - | mario.draw() | ||
| - | coin.draw() | ||
| - | screen.draw.text(" | ||
| - | |||
| - | if game_over: | ||
| - | screen.fill(" | ||
| - | screen.draw.text(" | ||
| - | |||
| - | def place_coin(): | ||
| - | coin.x = randint(20, (WIDTH-20)) | ||
| - | coin.y = randint(20, (HEIGHT-20)) | ||
| - | |||
| - | def time_up(): | ||
| - | global game_over | ||
| - | game_over = True | ||
| - | |||
| - | def update(): | ||
| - | global score | ||
| - | if keyboard.left: | ||
| - | mario.x = mario.x - 4 | ||
| - | elif keyboard.right: | ||
| - | mario.x = mario.x + 4 | ||
| - | elif keyboard.up: | ||
| - | mario.y = mario.y - 4 | ||
| - | elif keyboard.down: | ||
| - | mario.y = mario.y + 4 | ||
| - | coin_collectet = mario.colliderect(coin) | ||
| - | if coin_collectet: | ||
| - | score = score + 10 | ||
| - | place_coin() | ||
| - | |||
| - | clock.schedule(time_up, | ||
| - | place_coin() | ||
| - | </ | ||
| Mit der Zeile | Mit der Zeile | ||
python/pgzero/projekt2.1678951104.txt.gz · Zuletzt geändert: von lutz
