LF08/fahrzeug.py
2023-04-26 10:44:59 +02:00

37 lines
868 B
Python

import pygame
import math
def get_angle(p1, p2):
dx = p2[0] - p1[0]
dy = p2[1] - p1[1]
rads = math.atan2(-dy, dx)
rads %= 2 * math.pi
degs = math.degrees(rads)
return degs
class Fahrzeug(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
self.speed = 1
self.dest_x = x
self.dest_y = y
self.direction = pygame.math.Vector2(0, -1)
self.angle = 0
self.Tank = 250
def update(self):
self.move()
if self.rect.centerx != self.dest_x or self.rect.centery != self.dest_y:
if self.Tank > 0:
self.Tank -= 0.1
self.angle = get_angle((self.rect.centerx, self.rect.centery), (self.dest_x, self.dest_y)) - 90
def move(self):
pass
def dest(self, pos):
self.dest_x, self.dest_y = pos