Added itemhandler to game module
This commit is contained in:
@@ -27,7 +27,7 @@ class GameObject(object):
|
||||
if(self.image is not None):
|
||||
self.rect = screen.blit(self.image, (self.pos_x, self.pos_y))
|
||||
else:
|
||||
print("Kein Image hinterlegt!")
|
||||
self.rect = pygame.draw.rect(screen, (255,0,0), (self.pos_x, self.pos_y, self.width, self.height))
|
||||
return
|
||||
|
||||
def setpos(self, pos_x, pos_y):
|
||||
@@ -220,7 +220,15 @@ class Weapons(GameObject):
|
||||
class Item(GameObject):
|
||||
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 = 5
|
||||
|
||||
def move(self, x, y):
|
||||
self.pos_x += x
|
||||
self.pos_y += y
|
||||
|
||||
pass
|
||||
|
||||
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)
|
||||
super().__init__(name, pos_x, pos_y, width, height, image)
|
||||
self.speed = 10
|
||||
31
game.py
31
game.py
@@ -7,10 +7,19 @@ import animations
|
||||
from levels import *
|
||||
import pygame
|
||||
import logger
|
||||
import random
|
||||
import copy
|
||||
|
||||
#Leveldefinitions
|
||||
levels_list.append(first_level("First Level", (500,500), 10, 2))
|
||||
|
||||
|
||||
items = [
|
||||
GameObject.item_extra_life("Extra-Life", 0, 0, 30, 30, None)
|
||||
]
|
||||
|
||||
items_spawned = list()
|
||||
|
||||
#Override
|
||||
def loadlevels():
|
||||
for level in levels_list:
|
||||
@@ -18,3 +27,25 @@ def loadlevels():
|
||||
print("LEVEL")
|
||||
print(level)
|
||||
pass
|
||||
|
||||
def item_handler(screen:pygame.Surface):
|
||||
|
||||
spawn_chance = random.randint(0, 10)
|
||||
print(spawn_chance)
|
||||
if(spawn_chance == 0):
|
||||
#print("Spawne item")
|
||||
spawn_item_random(screen)
|
||||
|
||||
for item in items_spawned:
|
||||
item:GameObject.Item
|
||||
print(item)
|
||||
item.move(0, item.speed)
|
||||
item.render(screen)
|
||||
|
||||
pass
|
||||
|
||||
def spawn_item_random(screen:pygame.Surface):
|
||||
|
||||
items_spawned.append(copy.deepcopy(items[0]))
|
||||
print("Spawn")
|
||||
pass
|
||||
|
||||
@@ -22,9 +22,9 @@ class Healthbar(UIelement):
|
||||
grundwert = self.max_health
|
||||
prozentwert = playerheatlh
|
||||
prozent = (playerheatlh/grundwert)
|
||||
print(prozent)
|
||||
print(prozentwert)
|
||||
print(playerheatlh)
|
||||
#print(prozent)
|
||||
#print(prozentwert)
|
||||
#print(playerheatlh)
|
||||
|
||||
#Update until playerhealth not zero
|
||||
if(self.health > 0):
|
||||
|
||||
Reference in New Issue
Block a user