Fight other entities while bumping them, without any weapon
This commit is contained in:
parent
9909b12501
commit
c5e6459d37
@ -34,16 +34,18 @@ class Player(FightingEntity):
|
||||
self.current_xp += xp
|
||||
self.level_up()
|
||||
|
||||
def fight(self) -> bool:
|
||||
def check_move(self, y: int, x: int, move_if_possible: bool = False) \
|
||||
-> bool:
|
||||
"""
|
||||
Fight all f
|
||||
If the player tries to move but a fighting entity is there,
|
||||
the player fights this entity.
|
||||
It rewards some XP if it is dead.
|
||||
"""
|
||||
one_fight = False
|
||||
for entity in self.map.entities:
|
||||
if entity != self and isinstance(entity, FightingEntity) and\
|
||||
self.distance_squared(entity) <= 1:
|
||||
if entity.y == y and entity.x == x and \
|
||||
isinstance(entity, FightingEntity):
|
||||
self.hit(entity)
|
||||
one_fight = True
|
||||
if entity.dead:
|
||||
self.add_xp(randint(3, 7))
|
||||
return one_fight
|
||||
return True
|
||||
return super().check_move(y, x, move_if_possible)
|
||||
|
@ -24,7 +24,6 @@ class KeyValues(Enum):
|
||||
RIGHT = auto()
|
||||
ENTER = auto()
|
||||
SPACE = auto()
|
||||
FIGHT = auto()
|
||||
|
||||
|
||||
class Game:
|
||||
@ -89,8 +88,6 @@ class Game:
|
||||
elif key in (self.settings.KEY_UP_PRIMARY,
|
||||
self.settings.KEY_UP_SECONDARY):
|
||||
return KeyValues.UP
|
||||
elif key == self.settings.KEY_FIGHT:
|
||||
return KeyValues.FIGHT
|
||||
elif key == self.settings.KEY_ENTER:
|
||||
return KeyValues.ENTER
|
||||
elif key == ' ':
|
||||
@ -125,9 +122,6 @@ class Game:
|
||||
elif key == KeyValues.RIGHT:
|
||||
if self.player.move_right():
|
||||
self.map.tick()
|
||||
elif key == KeyValues.FIGHT:
|
||||
if self.player.fight():
|
||||
self.map.tick()
|
||||
elif key == KeyValues.SPACE:
|
||||
self.state = GameMode.MAINMENU
|
||||
|
||||
|
@ -27,7 +27,6 @@ class Settings:
|
||||
['d', 'Touche principale pour aller vers la droite']
|
||||
self.KEY_RIGHT_SECONDARY = \
|
||||
['KEY_RIGHT', 'Touche secondaire pour aller vers la droite']
|
||||
self.KEY_FIGHT = ['f', 'Touche pour frapper un ennemi']
|
||||
self.KEY_ENTER = \
|
||||
['\n', 'Touche pour valider un menu']
|
||||
self.TEXTURE_PACK = ['ascii', 'Pack de textures utilisé']
|
||||
|
Loading…
Reference in New Issue
Block a user