Dateien nach "/" hochladen

This commit is contained in:
2026-09-10 13:57:49 +00:00
parent 49c80ef0ea
commit 11349988f7
3 changed files with 714 additions and 23 deletions
+27 -23
View File
@@ -14,9 +14,7 @@ class Kart:
self.position = [0, 0]
self.acceleration = acceleration
self.lastRam = 0
def __str__(self):
return "Das Kart heißt:" + self.name
self.knockback = [0, 0]
def acc(self, brk): #brk is true or false
if brk == False:
@@ -33,44 +31,50 @@ class Kart:
self.rotation += dir * self.handling
def pos(self):
# normale Eigenbewegung
self.position[0] += math.cos(math.radians(self.rotation)) * self.speed
self.position[1] += math.sin(math.radians(self.rotation)) * self.speed
# Bewegung durch Rammen
self.position[0] += self.knockback[0]
self.position[1] += self.knockback[1]
# Knockback langsam abbauen
self.knockback[0] *= 0.90
self.knockback[1] *= 0.90
if self.speed > 5:
self.speed *= 0.98
def ram(self, other):
current = time.time()
if current - self.lastRam < 1:
return
self.lastRam = current
dx = self.position[0] - other.position[0]
dy = self.position[1] - other.position[1]
dx = other.position[0] - self.position[0]
dy = other.position[1] - self.position[1]
distance = math.sqrt(dx**2 + dy**2)
if distance <= 200 and distance > 0:
if distance > 200 or distance == 0:
return
# Richtung vom anderen Kart zum eigenen Kart
direction_x = dx / distance
direction_y = dy / distance
self.lastRam = current
# Beide Karts bekommen eine schnelle Bewegung
# aufeinander zu bzw. vom Zusammenstoß weg.
ramSpeed = 12
# Richtung VOM eigenen Kart ZUM Gegner
direction_x = dx / distance
direction_y = dy / distance
self.position[0] += direction_x * ramSpeed
self.position[1] += direction_y * ramSpeed
# Das eigene Kart macht einen schnellen Satz zum Gegner
self.speed = 10
other.position[0] -= direction_x * ramSpeed
other.position[1] -= direction_y * ramSpeed
# Gegner fliegt in Bewegungsrichtung des Angreifers weg
knockbackSpeed = 18
# Zufällige Drehung wie vorher
randrot = random.randint(-20, 20)
self.rotation += randrot
other.rotation -= randrot
other.knockback[0] = direction_x * knockbackSpeed
other.knockback[1] = direction_y * knockbackSpeed
class Item: