Added requirements.txt

Fixed projectilespawn from enemys
This commit is contained in:
Christian
2024-08-26 22:03:26 +02:00
parent ae750f236d
commit 89c5dcc6d1
8 changed files with 130 additions and 19 deletions

View File

@@ -14,7 +14,7 @@ class GameObject(object):
self.image = image
self.rect:pygame.Rect
self.objects.append(self)
self.keymap = {"up":False, "down":False, "left":False, "right":False}
def get_objectinfo(self):
print(F"Gameobject-Info: \n",
@@ -38,6 +38,12 @@ class GameObject(object):
self.width = width
self.height = height
def __del__(self):
#Remove objectpoint on delete from static
if(len(self.objects) > 0):
print(F"Remove: {self}")
self.objects.remove(self)
class Player(GameObject):
def __init__(self, name, screen, pos_x, pos_y, width, height, image=None) -> None:
super().__init__(name, pos_x, pos_y, width, height, image)
@@ -49,6 +55,7 @@ class Player(GameObject):
self.kills = 0
#self._healthbar = pygame.rect.Rect((15, self.screen.get_size()[1]-50, 100, 20))
self.healthbar = interface.Healthbar(screen, "Player1", 25, screen.get_size()[1]-80, 300, 10, self.get_health())
self.keymap = {"up":False, "down":False, "left":False, "right":False}
def handle_input(self, event:pygame.event.EventType):
if(event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT):
@@ -99,7 +106,7 @@ class Player(GameObject):
projectile_width = 6
projectile_height = 10
shot = Projectile(self.name, self.pos_x+(self.width/2)-(projectile_width/2), self.pos_y-projectile_height, projectile_width, projectile_height, screen, 8)
#Maybe change this by another subroutine in Projectiles class
def firecontrol(self, screen):
if(len(Projectile.shots) > 0):
for objects in Projectile.shots:
@@ -154,6 +161,8 @@ class Enemy(GameObject):
super().__init__(name, pos_x, pos_y, width, height, image)
self.screen = screen
self.movespeed = 10
self._target_x = 0
self._target_y = 0
self.weapon:Weapons = None
def fire(self, screen):
@@ -171,8 +180,10 @@ class Enemy(GameObject):
def move(self, x=0, y=0):
if(x != 0):
self.pos_x += x
self.weapon.pos_x = self.pos_x+(self.width/2)
if(y != 0):
self.pos_y += y
def give_weapon(self, weapon):
self.weapon = weapon
@@ -235,4 +246,8 @@ class Item(GameObject):
class item_extra_life(Item):
def __init__(self, name, pos_x, pos_y, width, height, image=None) -> None:
super().__init__(name, pos_x, pos_y, width, height, image)
self.speed = 10
self.speed = 10
class barricade1(GameObject):
def __init__(self, name, pos_x, pos_y, width, height, image=None) -> None:
super().__init__(name, pos_x, pos_y, width, height, image)