Helicopter angle,movement size changes

This commit is contained in:
Yadciel 2023-04-24 13:50:48 +02:00
parent bb5a1b03d6
commit cad6758f1c
4 changed files with 27 additions and 4 deletions

View File

@ -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

View File

@ -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()

View File

@ -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):

View File

@ -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