diff --git a/gui-tests.py b/gui-tests.py index 1d1a876..091e28a 100644 --- a/gui-tests.py +++ b/gui-tests.py @@ -11,8 +11,6 @@ from direct import task from tkinter import Scale, StringVar from random import random -#TODO Klassen erstellten - def button_event_close(): print("Programm wird geschlossen") diff --git a/modules/GameObject.py b/modules/GameObject.py index 85884d6..766edbf 100644 --- a/modules/GameObject.py +++ b/modules/GameObject.py @@ -2,7 +2,6 @@ import pygame import random as rand class GameObject(): - __color = (0,0,0) _size_rect_x:int _size_rect_y:int __movespeed = int() @@ -17,7 +16,7 @@ class GameObject(): __score:int count = 0 - def __init__(self, name:str, surface, mainscreensize:tuple, posx_init:int=0, posy_init:int=0, move_speed:int=0, is_player:bool = False, is_rect:bool = True, rect_size:tuple = (10,10), image = str()) -> None: + def __init__(self, name:str, surface, mainscreensize:tuple, posx_init:int=0, posy_init:int=0, move_speed:int=0, is_player:bool = False, is_rect:bool = True, color:tuple = (0,0,0), rect_size:tuple = (10,10), image = str()) -> None: self.__name = name self._pos_x = posx_init self._pos_y = posy_init @@ -37,6 +36,7 @@ class GameObject(): self.__score = 0 self.__imagepath = image self.__imageloaded = 0 + self.__color = color def draw(self): #font = pygame.font.SysFont(None, 70) @@ -120,8 +120,8 @@ class GameObject(): class Block(GameObject): __score = int() - def __init__(self, name: str, surface, mainscreensize: tuple, posx_init: int = 0, posy_init: int = 0, move_speed: int = 0, is_player: bool = False, is_rect: bool = True, rect_size: tuple = ...) -> None: - super().__init__(name, surface, mainscreensize, posx_init, posy_init, move_speed, is_player, is_rect, rect_size) + def __init__(self, name: str, surface, mainscreensize: tuple, posx_init: int = 0, posy_init: int = 0, move_speed: int = 0, is_player: bool = False, is_rect: bool = True, color: tuple = (0, 0, 0), rect_size: tuple = (10, 10), image=str()) -> None: + super().__init__(name, surface, mainscreensize, posx_init, posy_init, move_speed, is_player, is_rect, color, rect_size, image) self.__score = rand.randint(5, 50) def set_position_player(self, pos:tuple, playermovedirection:list, debug=False): @@ -137,6 +137,7 @@ class Block(GameObject): if(playermovedirection["right"]): super().set_position((pos[0]-super().get_rect_size()[0],pos[1])) print(pos) + def test(self): print(super().get_position()) @@ -145,9 +146,8 @@ class Block(GameObject): class Player(GameObject): #Later handles the Player-Gameobject - - def __init__(self, name: str, surface, mainscreensize: tuple, posx_init: int = 0, posy_init: int = 0, move_speed: int = 0, is_player: bool = False, is_rect: bool = True, rect_size: tuple = (10, 10), image=str()) -> None: - super().__init__(name, surface, mainscreensize, posx_init, posy_init, move_speed, is_player, is_rect, rect_size, image) + def __init__(self, name: str, surface, mainscreensize: tuple, posx_init: int = 0, posy_init: int = 0, move_speed: int = 0, is_player: bool = False, is_rect: bool = True, color: tuple = (0, 0, 0), rect_size: tuple = (10, 10), image=str()) -> None: + super().__init__(name, surface, mainscreensize, posx_init, posy_init, move_speed, is_player, is_rect, color, rect_size, image) self.__mainscreensize = mainscreensize print(self.__mainscreensize) @@ -197,8 +197,8 @@ class Player(GameObject): class GOIMAGE(GameObject): - def __init__(self, name: str, surface, mainscreensize: tuple, posx_init: int = 0, posy_init: int = 0, move_speed: int = 0, is_player: bool = False, is_rect: bool = True, rect_size: tuple = (10, 10), image=str()) -> None: - super().__init__(name, surface, mainscreensize, posx_init, posy_init, move_speed, is_player, is_rect, rect_size, image) + def __init__(self, name: str, surface, mainscreensize: tuple, posx_init: int = 0, posy_init: int = 0, move_speed: int = 0, is_player: bool = False, is_rect: bool = True, color: tuple = (0, 0, 0), rect_size: tuple = (10, 10), image=str()) -> None: + super().__init__(name, surface, mainscreensize, posx_init, posy_init, move_speed, is_player, is_rect, color, rect_size, image) self.__image = pygame.image.load(image).convert() diff --git a/pygame-test.py b/pygame-test.py index 2f49c5f..480697a 100644 --- a/pygame-test.py +++ b/pygame-test.py @@ -12,6 +12,7 @@ pygame.display.set_caption("Testgame") WEISS = ( 255, 255, 255) SCHWARZ = (0,0,0) +GRUEN = (0, 255, 0) active = True @@ -73,10 +74,15 @@ def spawn_entities(x:int, list_of_objects:list): list_of_objects.append(Entity) count += 1 -player = Player("Player", MAINSCREEN, MAINSCREEN_SIZE, 10, 10, 10, is_player=False, is_rect=True, rect_size=(80,80)) +player = Player("Player", MAINSCREEN, MAINSCREEN_SIZE, 10, 10, 10, is_player=False, is_rect=True, color=(0,255,0) ,rect_size=(80,80)) goo = GOIMAGE("TESTOBJEKT", MAINSCREEN, MAINSCREEN_SIZE, 0,0,0,image="data/models/testmodel.bmp") +testlist = list() +for y in range(10): + Entity = GOIMAGE("Testobject", MAINSCREEN, MAINSCREEN_SIZE, posx_init=rand.randint(10, 600), posy_init=rand.randint(10, 600), image="data/models/testmodel.bmp") + testlist.append(Entity) + background = pygame.surface.Surface((640,480)) x = 3600 @@ -138,6 +144,10 @@ while active == True: append_follwer(xy[0], xy[1]) count_follower += 1 + for t in testlist: + t:GOIMAGE + t.draw() + #Zeichnet alle Verfolgerobjekte, sofern sie vorliegend sind #TODO: Follower sollen ab dem zweiten Objekt dem vorangegangenen Objekt folgen und nicht dem player