Merge remote-tracking branch 'origin/main'
commit
bc7bfc4226
|
@ -1,3 +1,4 @@
|
||||||
|
from level.elements.dynamic.PushableBoxLevelElement import PushableBoxLevelElement
|
||||||
from physics.CollisionDirection import CollisionDirection
|
from physics.CollisionDirection import CollisionDirection
|
||||||
from physics.TickData import TickData
|
from physics.TickData import TickData
|
||||||
from sprite.DynamicSprite import DynamicSprite
|
from sprite.DynamicSprite import DynamicSprite
|
||||||
|
@ -25,9 +26,36 @@ class PlayerSprite(DynamicSprite):
|
||||||
self.no_motion_since = 100
|
self.no_motion_since = 100
|
||||||
self.last_directional_input = KeyManager.KEY_RIGHT
|
self.last_directional_input = KeyManager.KEY_RIGHT
|
||||||
|
|
||||||
|
self.is_potentially_stuck = 0
|
||||||
|
|
||||||
def tick(self, tick_data: TickData):
|
def tick(self, tick_data: TickData):
|
||||||
super().tick(tick_data)
|
super().tick(tick_data)
|
||||||
|
|
||||||
|
left = self.get_collides_with_direction(CollisionDirection.LEFT)
|
||||||
|
right = self.get_collides_with_direction(CollisionDirection.RIGHT)
|
||||||
|
bottom = self.get_collides_with_direction(CollisionDirection.BOTTOM)
|
||||||
|
|
||||||
|
if self.is_potentially_stuck == 0 and left and bottom:
|
||||||
|
if left.secondary_sprite == bottom.secondary_sprite:
|
||||||
|
if isinstance(left.secondary_sprite, PushableBoxLevelElement):
|
||||||
|
self.is_potentially_stuck = 1
|
||||||
|
else:
|
||||||
|
self.is_potentially_stuck = 0
|
||||||
|
else:
|
||||||
|
self.is_potentially_stuck = 0
|
||||||
|
elif self.is_potentially_stuck == 1 and right and bottom:
|
||||||
|
if right.secondary_sprite == bottom.secondary_sprite:
|
||||||
|
if isinstance(right.secondary_sprite, PushableBoxLevelElement):
|
||||||
|
self.is_potentially_stuck = 2
|
||||||
|
else:
|
||||||
|
self.is_potentially_stuck = 0
|
||||||
|
else:
|
||||||
|
self.is_potentially_stuck = 0
|
||||||
|
|
||||||
|
if self.is_potentially_stuck == 2:
|
||||||
|
print('stuck')
|
||||||
|
self.position_scale.position = (self.position_scale.position[0] - 5, self.position_scale.position[1])
|
||||||
|
|
||||||
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_RIGHT):
|
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_RIGHT):
|
||||||
self.last_directional_input = KeyManager.KEY_RIGHT
|
self.last_directional_input = KeyManager.KEY_RIGHT
|
||||||
if self.motion[0] < self.max_motion_horizontal_via_input:
|
if self.motion[0] < self.max_motion_horizontal_via_input:
|
||||||
|
|
|
@ -47,6 +47,10 @@ class Sprite(UiElement):
|
||||||
return collision_direction
|
return collision_direction
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_all_collides_with_direction(self, direction: int) -> list[CollisionDirection]:
|
||||||
|
return [collision_direction for collision_direction in self.collides_with_elements if
|
||||||
|
collision_direction.direction == direction]
|
||||||
|
|
||||||
def tick(self, tick_data: TickData):
|
def tick(self, tick_data: TickData):
|
||||||
self.update_image(tick_data)
|
self.update_image(tick_data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue