Projekt 2 - Super Mario - Quelltext

import pgzrun from random import randint WIDTH = 600 HEIGHT = 600 score = 0 game_over = False mario = Actor("mario.png") mario.pos = 100, 100 coin = Actor("money.png") coin.pos = 200, 200 def draw(): screen.fill("green") mario.draw() coin.draw() screen.draw.text("Punkte: " + str(score), color="black", topleft=(10, 10)) if game_over: screen.fill("pink") screen.draw.text("Endstand:" + str(score), topleft=(10, 10), fontsize = 60) 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, 20.0) place_coin() pgzrun.go()