Some more changes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import pygame
|
||||
import pygame_menu
|
||||
|
||||
pygame.init()
|
||||
MAINSCREEN = pygame.display.set_mode((640,480))
|
||||
@@ -13,13 +14,14 @@ clock = pygame.time.Clock()
|
||||
ballpos_x = 10
|
||||
ballpos_y = 10
|
||||
|
||||
class GameObjekt():
|
||||
class GameObject():
|
||||
__name = str()
|
||||
__pos_x = int()
|
||||
__pos_y = int()
|
||||
__color = (0,0,0)
|
||||
__rectobjekt = pygame.Rect
|
||||
__surface = MAINSCREEN
|
||||
__removed = False
|
||||
|
||||
__movedirection = {"up":False, "down":False, "left":False, "right":False}
|
||||
|
||||
@@ -29,10 +31,16 @@ class GameObjekt():
|
||||
self.__pos_y = posy_init
|
||||
#self.__rectobjekt = rect
|
||||
|
||||
def __del__(self):
|
||||
#print("\nKlasse gelöscht", end="\n")
|
||||
pass
|
||||
|
||||
def change_direction(self, direction:dict):
|
||||
if(direction):
|
||||
for key in self.__movedirection.keys():
|
||||
self.__movedirection[key] = False
|
||||
self.__movedirection[direction] = True
|
||||
print(self.__movedirection[direction])
|
||||
print(direction)
|
||||
pass
|
||||
|
||||
def move(self, *speed:int):
|
||||
@@ -40,62 +48,58 @@ class GameObjekt():
|
||||
#self.__rectobjekt.x += MOVE_SPEED
|
||||
|
||||
if(self.__movedirection['up']):
|
||||
self.__movedirection['down'] = False
|
||||
if(not speed): self.__pos_y -= MOVE_SPEED
|
||||
else: self.__pos_y -= speed[0]
|
||||
if(self.__pos_y <= -100):
|
||||
self.__pos_y += 580
|
||||
if(self.__movedirection['right'] or self.__movedirection['left']):
|
||||
self.__movedirection['up'] = False
|
||||
|
||||
if(self.__movedirection['down']):
|
||||
self.__movedirection['up'] = False
|
||||
elif(self.__movedirection['down']):
|
||||
if(not speed): self.__pos_y += MOVE_SPEED
|
||||
else: self.__pos_y += speed[0]
|
||||
if(self.__pos_y >= (self.__surface.get_size()[1])): self.__pos_y = -100
|
||||
if(self.__movedirection['right'] or self.__movedirection['left']):
|
||||
self.__movedirection['down'] = False
|
||||
|
||||
if(self.__movedirection['left']):
|
||||
self.__movedirection['right'] = False
|
||||
elif(self.__movedirection['left']):
|
||||
if(not speed): self.__pos_x -= MOVE_SPEED
|
||||
else: self.__pos_x -= speed[0]
|
||||
if(self.__pos_x <= -100): self.__pos_x = 680
|
||||
if(self.__movedirection['up'] or self.__movedirection['down']):
|
||||
self.__movedirection['left'] = False
|
||||
|
||||
if(self.__movedirection['right']):
|
||||
self.__movedirection['left'] = False
|
||||
elif(self.__movedirection['right']):
|
||||
if(not speed): self.__pos_x += MOVE_SPEED
|
||||
else: self.__pos_x += speed[0]
|
||||
if(self.__pos_x >= (self.__surface.get_size()[0])): self.__pos_x = -100
|
||||
if(self.__movedirection['up'] or self.__movedirection['down']):
|
||||
self.__movedirection['right'] = False
|
||||
|
||||
|
||||
print("Objekt-Koordinaten= X: "+str(self.__rectobjekt.x)+" Y: "+str(self.__rectobjekt.y), end="\r")
|
||||
|
||||
#for x in self.__movedirection.keys():
|
||||
# self.__movedirection[x] = False
|
||||
|
||||
#self.__movedirection['up'] = False
|
||||
#self.__movedirection['down'] = False
|
||||
#self.__movedirection['left'] = False
|
||||
#self.__movedirection['right'] = False
|
||||
print("Objekt-Koordinaten "+self.__name+"= X: "+str(self.__rectobjekt.x)+" Y: "+str(self.__rectobjekt.y), end="\r")
|
||||
|
||||
def draw(self):
|
||||
#font = pygame.font.SysFont(None, 70)
|
||||
#text = font.render("TEST", True, (0,0,0) )
|
||||
self.__rectobjekt = pygame.draw.rect(self.__surface, self.__color, [self.__pos_x, self.__pos_y,100,100])
|
||||
if(self.__removed == False):
|
||||
self.__rectobjekt = pygame.draw.rect(self.__surface, self.__color, [self.__pos_x, self.__pos_y,100,100])
|
||||
|
||||
def get_rect(self):
|
||||
return self.__rectobjekt
|
||||
|
||||
def collide(self, GameObject):
|
||||
#print(GameObject)
|
||||
#print(GameObject.get_rect())
|
||||
if(self.get_rect().x == GameObject.get_rect().x and self.get_rect().y == GameObject.get_rect().y):
|
||||
"""TODO: Hitbox with Objectsize"""
|
||||
print("Kollision")
|
||||
pass
|
||||
|
||||
object1 = GameObjekt("Testobject")
|
||||
def remove(self):
|
||||
print("Gameoject mit der ID " + self.__name + " gelöscht!")
|
||||
self.__removed = True
|
||||
"""TODO: Delete obeject function"""
|
||||
|
||||
|
||||
object1 = GameObject("Testobject", 50, 50)
|
||||
object2 = GameObject("Testobject2", 100, 100)
|
||||
|
||||
background = pygame.surface.Surface((640,480))
|
||||
|
||||
x = 360
|
||||
invert = False
|
||||
#Fenster-Hauptschleife
|
||||
while active == True:
|
||||
@@ -128,6 +132,14 @@ while active == True:
|
||||
|
||||
object1.draw()
|
||||
object1.move(10)
|
||||
object2.draw()
|
||||
object2.move(1)
|
||||
object2.collide(object1)
|
||||
|
||||
if(x == 0):
|
||||
#object2.remove()
|
||||
pass
|
||||
x -= 1
|
||||
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user