Added colorattribute to GameObjects class

This commit is contained in:
2024-01-20 09:36:15 +01:00
parent e595d085c6
commit 55c060559d
3 changed files with 20 additions and 12 deletions

View File

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