Added collision check for gameobjects
Some cleanup
This commit is contained in:
@@ -7,22 +7,37 @@ class GameObject():
|
||||
self._size = [sizex, sizey]
|
||||
self._name = name
|
||||
self._surface = surface
|
||||
self._speed:int = 0
|
||||
self._spritepath:str = ""
|
||||
self._sprite:pygame.Surface
|
||||
self._rect:pygame.rect
|
||||
self._rect:pygame.rect.RectType
|
||||
if(len(spritepath) > 0):
|
||||
self._sprite = pygame.image.load(spritepath)
|
||||
self._rect = self._sprite.get_rect()
|
||||
|
||||
|
||||
def move(self, x,y):
|
||||
self._posx += x
|
||||
self._posy += y
|
||||
|
||||
self._posy += y
|
||||
|
||||
def draw(self):
|
||||
self._rect = pygame.Surface.blit(self._surface, self._sprite, (self._posx, self._posy))
|
||||
|
||||
def check_collision(self, GameObject:pygame.rect.RectType):
|
||||
#print(self._rect)
|
||||
#print(GameObject)
|
||||
if(pygame.Rect.colliderect(self._rect, GameObject) == True):
|
||||
return True
|
||||
else: False
|
||||
|
||||
def get_position(self):
|
||||
return(self._posx, self._posy)
|
||||
return(self._posx, self._posy)
|
||||
|
||||
def get_movespeed(self):
|
||||
return self._speed
|
||||
|
||||
def set_movespeed(self, speed:int):
|
||||
self._speed = speed
|
||||
|
||||
def set_position(self, x, y):
|
||||
self._posx = x
|
||||
self._posy = y
|
||||
Reference in New Issue
Block a user