getFacingCoord can now return non-relative coords
This commit is contained in:
parent
107bd0d8f7
commit
269e376756
@ -2,7 +2,6 @@ from pathlib import Path
|
|||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
# TODO: Add getters to retrieve relative coords
|
|
||||||
from entities.Enums import Rotations, Movement
|
from entities.Enums import Rotations, Movement
|
||||||
|
|
||||||
|
|
||||||
@ -65,6 +64,15 @@ class Entity(pygame.sprite.Sprite):
|
|||||||
self.rect.x = coords[0] * self.rect.w + self.mapOffset
|
self.rect.x = coords[0] * self.rect.w + self.mapOffset
|
||||||
self.rect.y = coords[1] * self.rect.h
|
self.rect.y = coords[1] * self.rect.h
|
||||||
|
|
||||||
|
def translateToAbsolute(self, offset=(0, 0)):
|
||||||
|
"""
|
||||||
|
Returns entities' absolute coords after applying a non-relative offset.
|
||||||
|
|
||||||
|
:param offset: Offset tuple
|
||||||
|
:return: Position tuple of (x,y)
|
||||||
|
"""
|
||||||
|
return self.rect.x + offset[0] * self.rect.w, self.rect.y + offset[1] * self.rect.h
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def setNewId():
|
def setNewId():
|
||||||
"""
|
"""
|
||||||
@ -97,19 +105,31 @@ class Entity(pygame.sprite.Sprite):
|
|||||||
rect = image.get_rect()
|
rect = image.get_rect()
|
||||||
return image, rect
|
return image, rect
|
||||||
|
|
||||||
def getFacingCoord(self):
|
def getFacingCoord(self, screenRelative=True):
|
||||||
"""
|
"""
|
||||||
Get coordinates forward to the player.
|
Gets coordinates forward to the player.
|
||||||
:return: Position tuple
|
|
||||||
|
:param screenRelative: If true, the method returns absolute coords
|
||||||
|
:return: Position tuple of (x,y) coords
|
||||||
"""
|
"""
|
||||||
if self.rotation.value == Rotations.NORTH.value:
|
if screenRelative:
|
||||||
return self.rect.x, self.rect.y - self.rect.h
|
if self.rotation.value == Rotations.NORTH.value:
|
||||||
elif self.rotation.value == Rotations.SOUTH.value:
|
return self.translateToAbsolute((0, -1))
|
||||||
return self.rect.x, self.rect.y + self.rect.h
|
elif self.rotation.value == Rotations.SOUTH.value:
|
||||||
elif self.rotation.value == Rotations.EAST.value:
|
return self.translateToAbsolute((0, 1))
|
||||||
return self.rect.x + self.rect.h, self.rect.y
|
elif self.rotation.value == Rotations.EAST.value:
|
||||||
elif self.rotation.value == Rotations.WEST.value:
|
return self.translateToAbsolute((1, 0))
|
||||||
return self.rect.x - self.rect.h, self.rect.y
|
elif self.rotation.value == Rotations.WEST.value:
|
||||||
|
return self.translateToAbsolute((-1, 0))
|
||||||
|
else:
|
||||||
|
if self.rotation.value == Rotations.NORTH.value:
|
||||||
|
return self.x, self.y - 1
|
||||||
|
elif self.rotation.value == Rotations.SOUTH.value:
|
||||||
|
return self.x, self.y + 1
|
||||||
|
elif self.rotation.value == Rotations.EAST.value:
|
||||||
|
return self.x + 1, self.y
|
||||||
|
elif self.rotation.value == Rotations.WEST.value:
|
||||||
|
return self.x - 1, self.y
|
||||||
|
|
||||||
def move(self, movement):
|
def move(self, movement):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user