2023-03-31 12:33:56 +02:00
|
|
|
import pygame
|
|
|
|
import math
|
|
|
|
|
2023-04-19 08:59:00 +02:00
|
|
|
|
|
|
|
def get_angle(p1, p2):
|
|
|
|
dx = p2[0] - p1[0]
|
|
|
|
dy = p2[1] - p1[1]
|
2023-04-26 10:31:29 +02:00
|
|
|
rads = math.atan2(-dy, dx)
|
|
|
|
rads %= 2 * math.pi
|
2023-04-19 08:59:00 +02:00
|
|
|
degs = math.degrees(rads)
|
|
|
|
return degs
|
|
|
|
|
2023-04-26 10:31:29 +02:00
|
|
|
|
2023-03-31 12:33:56 +02:00
|
|
|
class Fahrzeug(pygame.sprite.Sprite):
|
|
|
|
def __init__(self, x, y):
|
|
|
|
super().__init__()
|
2023-04-19 08:59:00 +02:00
|
|
|
self.speed = 1
|
2023-03-31 12:33:56 +02:00
|
|
|
self.dest_x = x
|
|
|
|
self.dest_y = y
|
|
|
|
self.direction = pygame.math.Vector2(0, -1)
|
|
|
|
self.angle = 0
|
2023-04-19 12:23:30 +02:00
|
|
|
self.Tank = 250
|
2023-03-31 12:33:56 +02:00
|
|
|
|
|
|
|
def update(self):
|
2023-04-19 12:23:30 +02:00
|
|
|
self.move()
|
|
|
|
|
2023-04-24 13:50:48 +02:00
|
|
|
if self.rect.centerx != self.dest_x or self.rect.centery != self.dest_y:
|
2023-04-19 12:23:30 +02:00
|
|
|
if self.Tank > 0:
|
|
|
|
self.Tank -= 0.1
|
2023-04-26 10:31:29 +02:00
|
|
|
self.angle = get_angle((self.rect.centerx, self.rect.centery), (self.dest_x, self.dest_y)) - 90
|
2023-04-19 12:23:30 +02:00
|
|
|
|
2023-04-20 09:08:35 +02:00
|
|
|
def move(self):
|
|
|
|
pass
|
2023-04-19 08:59:00 +02:00
|
|
|
|
2023-04-24 13:50:48 +02:00
|
|
|
def dest(self, pos):
|
|
|
|
self.dest_x, self.dest_y = pos
|