Compare commits

...

5 Commits

Author SHA1 Message Date
09b34d1dbd Merge pull request 'Fahrzeug' (#2) from Fahrzeug into main
Reviewed-on: http://192.168.2.198:3000/Yadciel/LF08/pulls/2
2023-03-31 12:47:08 +02:00
Yadciel
ebfa3ca1da debug 2023-03-31 12:42:36 +02:00
Yadciel
322f808f38 Merge remote-tracking branch 'LF08/Fahrzeug' into Fahrzeug 2023-03-31 12:38:17 +02:00
Yadciel
89f820f1f7 Fahrzeug 2023-03-31 12:37:20 +02:00
Yadciel
f4fa36e941 Fahrzeug 2023-03-31 12:33:56 +02:00
3 changed files with 38 additions and 38 deletions

36
fahrzeug.py Normal file
View File

@ -0,0 +1,36 @@
import pygame
import math
class Fahrzeug(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
self.image = pygame.image.load("player.png").convert_alpha()
self.rect = self.image.get_rect(center=(x, y))
self.rect.centerx = x
self.rect.centery = y
self.speed = 2
self.dest_x = x
self.dest_y = y
self.direction = pygame.math.Vector2(0, -1)
self.angle = 0
def draw(self, win):
rotated_image = pygame.transform.rotate(self.image, self.angle)
rotated_rect = rotated_image.get_rect(center=self.rect.center)
#debug nicht anrühren
#self.angle += 1
#pygame.draw.rect(win, (255, 0, 0), rotated_rect)
win.blit(rotated_image, rotated_rect)
def update(self):
if self.rect.centerx < self.dest_x:
self.rect.centerx += self.speed
if self.rect.centerx > self.dest_x:
self.rect.centerx -= self.speed
if self.rect.centery < self.dest_y:
self.rect.centery += self.speed
if self.rect.centery > self.dest_y:
self.rect.centery -= self.speed
def dest(self, pos):
self.dest_x, self.dest_y = pos

View File

@ -1,5 +1,5 @@
import pygame import pygame
import fahrzeug
import background import background
import player import player
import sys import sys
@ -7,7 +7,7 @@ import sys
def start(): def start():
pygame.init() pygame.init()
win = pygame.display.set_mode((800, 800)) win = pygame.display.set_mode((800, 800))
player1 = player.Player(0, 0) player1 = fahrzeug.Fahrzeug(0, 0)
Erzmine = background.Erz() Erzmine = background.Erz()
Tanken = background.Tank() Tanken = background.Tank()
Ziele = background.Ziel() Ziele = background.Ziel()

View File

@ -1,36 +0,0 @@
import pygame
import math
class Player(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
self.image = pygame.image.load("player.png").convert_alpha()
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
self.speed = 2
self.dest_x = x
self.dest_y = y
self.direction = pygame.math.Vector2(1, 0)
def draw(self, win):
win.blit(self.image, self.rect)
def update(self):
if self.rect.x < self.dest_x:
self.rect.x += self.speed
if self.rect.x > self.dest_x:
self.rect.x -= self.speed
if self.rect.y < self.dest_y:
self.rect.y += self.speed
if self.rect.y > self.dest_y:
self.rect.y -= self.speed
direction = pygame.math.Vector2(self.dest_x - self.rect.centerx, self.dest_y - self.rect.centery)
#angle = -math.degrees(math.atan2(direction.y, direction.x))
#self.image = pygame.transform.rotate(self.image, angle)
self.rect = self.image.get_rect(center=self.rect.center)
self.direction = direction.normalize()
def dest(self, pos):
self.dest_x, self.dest_y = pos