diff --git a/fahrzeug.py b/fahrzeug.py index 1bf01e0..345d55e 100644 --- a/fahrzeug.py +++ b/fahrzeug.py @@ -23,7 +23,7 @@ class Fahrzeug(pygame.sprite.Sprite): def update(self): self.move() - if self.rect.centerx != self.dest_x or self.rect.centery != self.dest_y: + 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 @@ -31,6 +31,6 @@ class Fahrzeug(pygame.sprite.Sprite): def move(self): pass - def dest(self, pos): - self.dest_x, self.dest_y = pos + def dest(self, pos): + self.dest_x, self.dest_y = pos diff --git a/game.py b/game.py index 937eb87..9ff1401 100644 --- a/game.py +++ b/game.py @@ -73,6 +73,7 @@ def start(): player1.draw(win) enemy.update(player1) + enemy.dest((player1.rect.centerx,player1.rect.centery)) enemy.draw(win) pygame.display.update() diff --git a/helicopter.py b/helicopter.py index cb30921..57f978f 100644 --- a/helicopter.py +++ b/helicopter.py @@ -1,13 +1,15 @@ import pygame import player import rotor -from fahrzeug import Fahrzeug +from fahrzeug import Fahrzeug, get_angle +import time class Helicopter(Fahrzeug, pygame.sprite.Sprite): def __init__(self, x, y): super().__init__(x, y) self.image = pygame.image.load("resources/helicopter.jpg").convert_alpha() self.image = self.image.subsurface(44, 0, 44, 99) + self.image = pygame.transform.scale(self.image, (self.image.get_width()*1.2, self.image.get_height()*1.2)) self.rect = self.image.get_rect(center=(x, y)) self.rect.centerx = x self.rect.centery = y @@ -17,6 +19,8 @@ class Helicopter(Fahrzeug, pygame.sprite.Sprite): self.rect = self.image.get_rect() self.angle = 0 self.speed = 1 + self.duration_speed = 0.02 + self.start_time = time.time() def update(self, player): keys = pygame.key.get_pressed() @@ -37,6 +41,23 @@ class Helicopter(Fahrzeug, pygame.sprite.Sprite): self.dest_y += self.speed self.angle = 180 + elapsed_time = time.time() - self.start_time + if elapsed_time >= self.duration_speed: + if self.rect.centerx < player.rect.centerx: + self.rect.centerx += self.speed + if self.rect.centery < player.rect.centery: + self.rect.centery += self.speed + if self.rect.centerx > player.rect.centerx: + self.rect.centerx -= self.speed + if self.rect.centery > player.rect.centery: + self.rect.centery -= self.speed + self.start_time = time.time() + + 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 + self.rotor.update(self) def draw(self, win): diff --git a/player.py b/player.py index b4475af..597d8df 100644 --- a/player.py +++ b/player.py @@ -5,6 +5,7 @@ class Player(Fahrzeug, pygame.sprite.Sprite): def __init__(self, x, y): super().__init__(x, y) self.image = pygame.image.load("resources/player.png").convert_alpha() + self.image = pygame.transform.scale(self.image, (self.image.get_width()/1.2, self.image.get_height()/1.2)) self.rect = self.image.get_rect(center=(x, y)) self.rect.centerx = x self.rect.centery = y