Code cleanup

Added testmodel bitmap
Added Prototype for imagemodels
This commit is contained in:
2024-01-15 22:01:13 +01:00
parent 3e56abba63
commit e01d187ea5
3 changed files with 19 additions and 10 deletions

BIN
data/models/testmodel.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -19,7 +19,7 @@ class GameObject():
__movedirection = {"up":False, "down":False, "left":False, "right":False}
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)) -> 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, rect_size:tuple = (10,10), image = str()) -> None:
self.__name = name
self.__pos_x = posx_init
self.__pos_y = posy_init
@@ -37,6 +37,14 @@ class GameObject():
self.__surface = surface
self.__mainscreensize = mainscreensize
self.__score = 0
self.__imagepath = image
self.__imageloaded = 0
if(len(self.__imagepath) > 0):
print(self.__imagepath)
test = pygame.image.load(self.__imagepath).convert()
self.__surface.blit(test, (10,10))
#self.__rectobjekt = rect

View File

@@ -22,8 +22,6 @@ clock = pygame.time.Clock()
Actually buggy if player logsin the first time, because there is no playerselected before there was an insterquery!!!
"""
#Behandelt später die Hauptschleife und Klassenobjekte
class Game():
__state = {"win":False, "lose":False, "paused":False}
@@ -77,6 +75,9 @@ def spawn_entities(x:int, list_of_objects:list):
player = Player("Player", MAINSCREEN, MAINSCREEN_SIZE, 10, 10, 10, is_player=False, is_rect=True, rect_size=(50,50))
testobj = GameObject("TESTOBJEKT", MAINSCREEN, MAINSCREEN_SIZE, 0,0,0,image="data/models/testmodel.bmp")
test = pygame.image.load("data/models/testmodel.bmp").convert()
background = pygame.surface.Surface((640,480))
@@ -89,6 +90,9 @@ count_hidden_entities = 0
count_spawend_enities = len(spawned_entities)
print("Es wurden " + str(count_spawend_enities)+ " Objekte gespawnt")
testx = 10
testy = 10
#Fenster-Hauptschleife
while active == True:
MAINSCREEN.fill((255,255,255))
@@ -110,6 +114,10 @@ while active == True:
elif (event.key == pygame.K_LEFT):
print("Keydown")
player.change_direction("left")
if(x > 0):
testx += 1
if(testx >= MAINSCREEN_SIZE[0]): testx = (0 - test.get_size()[0])
MAINSCREEN.blit(test, (testx,testy))
player.draw()
player.update_pos_lastframe(player.get_position()[0], player.get_position()[1], False)
@@ -173,13 +181,6 @@ while active == True:
y.hide()
pass
x -= 1
"""Drawing Lines test
pos = 0
for x in range(20):
pos += 60
pygame.draw.line(MAINSCREEN, (0,0,0), (pos,0),(pos,MAINSCREEN_SIZE[1]))"""
#print("Objekt-Koordinaten= X: "+str(rect1.x)+" Y: "+str(rect1.y)+"", end="\r")
#Displayflip sorgt dafür, dass das Fenster entsprechend der Tickrate aktualisiert wird