Some cleanup
This commit is contained in:
@@ -151,11 +151,8 @@ class Enemy(GameObject):
|
|||||||
self.weapon:Weapons = None
|
self.weapon:Weapons = None
|
||||||
|
|
||||||
def fire(self, screen):
|
def fire(self, screen):
|
||||||
#print("Schieße!!!!")
|
|
||||||
#shot = Projectile("Enemy", self.pos_x+(self.width/2),self.pos_y+self.height,5,10, screen, 2)
|
|
||||||
self.weapon.fire()
|
self.weapon.fire()
|
||||||
|
|
||||||
|
|
||||||
def firecontrol(self, screen):
|
def firecontrol(self, screen):
|
||||||
if(len(Projectile.shots) > 0):
|
if(len(Projectile.shots) > 0):
|
||||||
for objects in Projectile.shots:
|
for objects in Projectile.shots:
|
||||||
@@ -220,9 +217,9 @@ class Weapons(GameObject):
|
|||||||
class Item(GameObject):
|
class Item(GameObject):
|
||||||
def __init__(self, name, pos_x, pos_y, width, height, image=None) -> None:
|
def __init__(self, name, pos_x, pos_y, width, height, image=None) -> None:
|
||||||
super().__init__(name, pos_x, pos_y, width, height, image)
|
super().__init__(name, pos_x, pos_y, width, height, image)
|
||||||
self.speed = 5
|
self.speed = 2
|
||||||
|
|
||||||
def move(self, x, y):
|
def move(self, x:int, y:int):
|
||||||
self.pos_x += x
|
self.pos_x += x
|
||||||
self.pos_y += y
|
self.pos_y += y
|
||||||
|
|
||||||
|
|||||||
19
game.py
19
game.py
@@ -18,6 +18,7 @@ items = [
|
|||||||
GameObject.item_extra_life("Extra-Life", 0, 0, 30, 30, None)
|
GameObject.item_extra_life("Extra-Life", 0, 0, 30, 30, None)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
enemys_spawned = list()
|
||||||
items_spawned = list()
|
items_spawned = list()
|
||||||
|
|
||||||
#Override
|
#Override
|
||||||
@@ -30,7 +31,7 @@ def loadlevels():
|
|||||||
|
|
||||||
def item_handler(screen:pygame.Surface):
|
def item_handler(screen:pygame.Surface):
|
||||||
|
|
||||||
spawn_chance = random.randint(0, 10)
|
spawn_chance = random.randint(0, 1000)
|
||||||
print(spawn_chance)
|
print(spawn_chance)
|
||||||
if(spawn_chance == 0):
|
if(spawn_chance == 0):
|
||||||
#print("Spawne item")
|
#print("Spawne item")
|
||||||
@@ -39,13 +40,25 @@ def item_handler(screen:pygame.Surface):
|
|||||||
for item in items_spawned:
|
for item in items_spawned:
|
||||||
item:GameObject.Item
|
item:GameObject.Item
|
||||||
print(item)
|
print(item)
|
||||||
|
|
||||||
|
if(item.pos_y >= screen.get_size()[1]):
|
||||||
|
items_spawned.remove(item)
|
||||||
item.move(0, item.speed)
|
item.move(0, item.speed)
|
||||||
item.render(screen)
|
item.render(screen)
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
def spawn_item_random(screen:pygame.Surface):
|
def spawn_item_random(screen:pygame.Surface):
|
||||||
|
|
||||||
items_spawned.append(copy.deepcopy(items[0]))
|
items_spawned.append(copy.deepcopy(items[0]))
|
||||||
print("Spawn")
|
print("Spawn")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def spawn_enemys(type:object, count:int):
|
||||||
|
for i in range(count):
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
|
||||||
|
def run(screen:pygame.Surface):
|
||||||
|
screen = screen
|
||||||
|
item_handler(screen)
|
||||||
|
|
||||||
|
pass
|
||||||
50
test.py
50
test.py
@@ -113,31 +113,12 @@ while(gamestate):
|
|||||||
player2.move("right")
|
player2.move("right")
|
||||||
#print("rechts")
|
#print("rechts")
|
||||||
|
|
||||||
#image = screen.blit(testimage, (pos_x, pos_y))
|
game.run(screen)
|
||||||
|
|
||||||
mouse_pos = pygame.mouse.get_pos()
|
|
||||||
#print(int(pygame.time.get_ticks()/1000))
|
|
||||||
|
|
||||||
#print(mouse_pos)
|
|
||||||
#print(image.topleft) #Gibt die Position einen Surfaces "obenlinks" aus
|
|
||||||
#print(image.size) #Gibt die Größe eines Surfaces aus
|
|
||||||
|
|
||||||
#max = tuple(map(lambda i, j : i+j, image.topleft, image.size))
|
|
||||||
#Wenn Mausposition X-Achse innerhalb Anfangsposition+Breite
|
|
||||||
#if(mouse_pos[0] <= max[0] and mouse_pos[0] >= image.topleft[0]):
|
|
||||||
#Wenn Mausposition Y-Achse innerhalb Anfangsposition+Höhe
|
|
||||||
#if(mouse_pos[1] <= max[1] and mouse_pos[1] >= image.topleft[1]):
|
|
||||||
#print("Treffer")
|
|
||||||
#pos_x = mouse_pos[0]
|
|
||||||
#pos_y = mouse_pos[1]
|
|
||||||
healthbar1.update(player1.get_health())
|
healthbar1.update(player1.get_health())
|
||||||
healthbar1.render(screen)
|
healthbar1.render(screen)
|
||||||
player1.firecontrol(screen)
|
player1.firecontrol(screen)
|
||||||
player2.firecontrol(screen)
|
player2.firecontrol(screen)
|
||||||
game.item_handler(screen)
|
|
||||||
|
|
||||||
#print("Spieler1 Lifes: ", player1.lifes)
|
|
||||||
#print("Spieler2 Lifes: ", player2.lifes)
|
|
||||||
|
|
||||||
#TODO If Playerposition are on the same x-axis then gamble hit by 50% chance
|
#TODO If Playerposition are on the same x-axis then gamble hit by 50% chance
|
||||||
|
|
||||||
@@ -201,14 +182,8 @@ while(gamestate):
|
|||||||
seconds = milliseconds / 1000
|
seconds = milliseconds / 1000
|
||||||
now = time.time_ns()
|
now = time.time_ns()
|
||||||
|
|
||||||
#print("Playerkills 1:", player1.kills)
|
|
||||||
#print("Playerkills 2:", player2.kills)
|
|
||||||
|
|
||||||
#print(F"Player 1 Health: {player1.get_health()}")
|
|
||||||
#print(F"Player 2 Health: {player2.get_health()}")
|
|
||||||
player1.render(screen)
|
player1.render(screen)
|
||||||
player2.render(screen)
|
player2.render(screen)
|
||||||
#print(int(seconds), "\r")
|
|
||||||
|
|
||||||
rand = random.randint(0, 100)
|
rand = random.randint(0, 100)
|
||||||
for enemy in spawned_enemys:
|
for enemy in spawned_enemys:
|
||||||
@@ -242,3 +217,26 @@ while(gamestate):
|
|||||||
# print("HIIIIITTT!!!!")
|
# print("HIIIIITTT!!!!")
|
||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#image = screen.blit(testimage, (pos_x, pos_y))
|
||||||
|
|
||||||
|
#mouse_pos = pygame.mouse.get_pos()
|
||||||
|
#print(int(pygame.time.get_ticks()/1000))
|
||||||
|
|
||||||
|
#print(mouse_pos)
|
||||||
|
#print(image.topleft) #Gibt die Position einen Surfaces "obenlinks" aus
|
||||||
|
#print(image.size) #Gibt die Größe eines Surfaces aus
|
||||||
|
|
||||||
|
#max = tuple(map(lambda i, j : i+j, image.topleft, image.size))
|
||||||
|
#Wenn Mausposition X-Achse innerhalb Anfangsposition+Breite
|
||||||
|
#if(mouse_pos[0] <= max[0] and mouse_pos[0] >= image.topleft[0]):
|
||||||
|
#Wenn Mausposition Y-Achse innerhalb Anfangsposition+Höhe
|
||||||
|
#if(mouse_pos[1] <= max[1] and mouse_pos[1] >= image.topleft[1]):
|
||||||
|
#print("Treffer")
|
||||||
|
#pos_x = mouse_pos[0]
|
||||||
|
#pos_y = mouse_pos[1]
|
||||||
Reference in New Issue
Block a user