Add changes to last move detection
This commit is contained in:
parent
1edaa1f74e
commit
b12c969d14
@ -52,15 +52,11 @@ class AutomaticMovement:
|
|||||||
startingState = (self.player.rect.x - self.leftUiWidth, self.player.rect.y, self.player.rotation)
|
startingState = (self.player.rect.x - self.leftUiWidth, self.player.rect.y, self.player.rotation)
|
||||||
startingPriority = 0
|
startingPriority = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fringe.put((startingPriority, self.testCount, AStarNode(None, None, startingState)))
|
fringe.put((startingPriority, self.testCount, AStarNode(None, None, startingState)))
|
||||||
self.testCount += 1
|
self.testCount += 1
|
||||||
while True:
|
while True:
|
||||||
print("DEBUG: A* in progress")
|
print("DEBUG: A* in progress")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if fringe.empty():
|
if fringe.empty():
|
||||||
# target is unreachable
|
# target is unreachable
|
||||||
self.movesList = None
|
self.movesList = None
|
||||||
@ -74,8 +70,11 @@ class AutomaticMovement:
|
|||||||
movesList = []
|
movesList = []
|
||||||
|
|
||||||
coordsWithUiOffset = [elem.state[0] + self.leftUiWidth, elem.state[0]]
|
coordsWithUiOffset = [elem.state[0] + self.leftUiWidth, elem.state[0]]
|
||||||
if self.map.getEntityOnCoord(coordsWithUiOffset) is not None: # If goal was some entity - omit one forward movement, because player shouldn't step on entity.
|
if self.map.collision(coordsWithUiOffset[0], coordsWithUiOffset[1]): # If goal was some entity - omit one forward movement, because player shouldn't step on entity.
|
||||||
elem = elem.parent
|
elem = elem.parent
|
||||||
|
else: # debug
|
||||||
|
a = 1
|
||||||
|
a += 1
|
||||||
|
|
||||||
while elem.action is not None:
|
while elem.action is not None:
|
||||||
movesList.append(elem.action)
|
movesList.append(elem.action)
|
||||||
@ -90,7 +89,8 @@ class AutomaticMovement:
|
|||||||
# Sprawdzam czy nie jest poza mapa
|
# Sprawdzam czy nie jest poza mapa
|
||||||
coordsWithUiOffset = [newState[0] + self.leftUiWidth, newState[1]]
|
coordsWithUiOffset = [newState[0] + self.leftUiWidth, newState[1]]
|
||||||
|
|
||||||
if 0 <= newState[0] <= self.map.width - self.moveOffset and 0 <= newState[1] <= self.map.height - self.moveOffset:
|
if 0 <= newState[0] <= self.map.width - self.moveOffset and 0 <= newState[
|
||||||
|
1] <= self.map.height - self.moveOffset:
|
||||||
# if self.map.getTileOnCoord(coordsWithUiOffset) is not None:
|
# if self.map.getTileOnCoord(coordsWithUiOffset) is not None:
|
||||||
newNode = AStarNode(elem, movement, newState)
|
newNode = AStarNode(elem, movement, newState)
|
||||||
newPriority = self.priority(newNode)
|
newPriority = self.priority(newNode)
|
||||||
@ -124,11 +124,15 @@ class AutomaticMovement:
|
|||||||
(Movement.ROTATE_L, self.newStateAfterAction(elemState, Movement.ROTATE_L))]
|
(Movement.ROTATE_L, self.newStateAfterAction(elemState, Movement.ROTATE_L))]
|
||||||
|
|
||||||
stateAfterForward = self.newStateAfterAction(elemState, Movement.FORWARD)
|
stateAfterForward = self.newStateAfterAction(elemState, Movement.FORWARD)
|
||||||
if 0 <= stateAfterForward[0] <= self.map.width - self.moveOffset and 0 <= stateAfterForward[1] <= self.map.height - self.moveOffset:
|
if 0 <= stateAfterForward[0] <= self.map.width - self.moveOffset and 0 <= stateAfterForward[
|
||||||
|
1] <= self.map.height - self.moveOffset:
|
||||||
coordsWithUiOffset = [stateAfterForward[0] + self.leftUiWidth, stateAfterForward[1]]
|
coordsWithUiOffset = [stateAfterForward[0] + self.leftUiWidth, stateAfterForward[1]]
|
||||||
#facingEntity = self.map.getEntityOnCoord(coordsWithUiOffset) # TU JEST BLAD BO U CELU JEST ZAWSZE JAKIES ENTITY
|
facingEntity = self.map.getEntityOnCoord(coordsWithUiOffset)
|
||||||
facingEntity = None
|
|
||||||
if facingEntity is None:
|
if facingEntity is not None:
|
||||||
|
if facingEntity.id == self.actualTarget.id:
|
||||||
|
result.append((Movement.FORWARD, stateAfterForward))
|
||||||
|
elif not self.map.collision(coordsWithUiOffset[0], coordsWithUiOffset[1]):
|
||||||
result.append((Movement.FORWARD, stateAfterForward))
|
result.append((Movement.FORWARD, stateAfterForward))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@ -160,7 +164,8 @@ class AutomaticMovement:
|
|||||||
|
|
||||||
def priority(self, elem: AStarNode):
|
def priority(self, elem: AStarNode):
|
||||||
coordsWithUiOffset = [elem.state[0] + self.leftUiWidth, elem.state[1]]
|
coordsWithUiOffset = [elem.state[0] + self.leftUiWidth, elem.state[1]]
|
||||||
return self.approximateDistanceFromTarget(elem.state[0], elem.state[1]) + self.stepCost(self.map.getTileOnCoord(coordsWithUiOffset))
|
return self.approximateDistanceFromTarget(elem.state[0], elem.state[1]) + self.stepCost(
|
||||||
|
self.map.getTileOnCoord(coordsWithUiOffset))
|
||||||
|
|
||||||
'''
|
'''
|
||||||
state[0] - x
|
state[0] - x
|
||||||
@ -188,7 +193,6 @@ class AutomaticMovement:
|
|||||||
elif action == Movement.ROTATE_R:
|
elif action == Movement.ROTATE_R:
|
||||||
newRotation = Rotations((state[2].value + 1) % 4)
|
newRotation = Rotations((state[2].value + 1) % 4)
|
||||||
|
|
||||||
|
|
||||||
newState = (newX, newY, newRotation)
|
newState = (newX, newY, newRotation)
|
||||||
|
|
||||||
return newState
|
return newState
|
||||||
|
@ -49,7 +49,7 @@ class Game:
|
|||||||
self.lastTimePassed = self.ingameTimer.timePassed
|
self.lastTimePassed = self.ingameTimer.timePassed
|
||||||
|
|
||||||
self.moveTimer = 0
|
self.moveTimer = 0
|
||||||
self.moveTime = 300
|
self.moveTime = 100
|
||||||
|
|
||||||
|
|
||||||
self.screen = Screen(self, self.config["window"])
|
self.screen = Screen(self, self.config["window"])
|
||||||
|
Loading…
Reference in New Issue
Block a user