import pgzrun
from time import time
from math import pi, sin, asin, cos

WIDTH, HEIGHT = 500, 500
rechteck = Rect((0, 0), (50, 50))
nachricht = ""
punkte = 0

def skaliere_nach(wert, von_min, von_max, nach_min, nach_max):
    bereich_von = von_max - von_min
    bereich_nach = nach_max - nach_min
    return (((wert - von_min) * bereich_nach) / bereich_von) + nach_min

def sinus_oszillator(frequenz, wert_min, wert_max, zeit_versatz=0):
    t = time() + zeit_versatz
    t = t * pi * 2 * frequenz
    wert = sin(t)
    return skaliere_nach(wert, -1, 1, wert_min, wert_max)

def textnachricht(text, x=WIDTH/2, y=HEIGHT/2):
    screen.draw.text(text,
                    center=(x, y),
                    color="black",
                    fontsize=40)

def update():
    pass

def draw():
    rot = sinus_oszillator(0.1, 0, 255)
    gruen = sinus_oszillator(0.11, 0, 255)
    blau = sinus_oszillator(0.12, 0, 255)
    screen.fill((rot, gruen, blau))
    
    rot2 = 255 - rot
    gruen2 = 255 - gruen
    blau2 = 255 - blau
    
    x = sinus_oszillator(0.1, 0, WIDTH)
    y = sinus_oszillator(0.15, 0, HEIGHT)
    
    rechteck.center = (x, y)
    screen.draw.filled_rect(rechteck, (rot2, gruen2, blau2))
    
    textnachricht(nachricht)
    textnachricht("Punktestand: " + str(punkte), 100, HEIGHT-10)
    #textnachricht(f"Punktestand: {punkte}", 100, HEIGHT - 10)
    
def on_mouse_down(pos):
    global nachricht, punkte
    
    if rechteck.collidepoint(pos):
        nachricht = "Treffer!"
        punkte = punkte + 1
    else:
        nachricht = "Daneben!"
        punkte = punkte - 1

pgzrun.go( )
Zuletzt geändert: Donnerstag, 27. März 2025, 16:09