Fight other entities while bumping them, without any weapon

This commit is contained in:
Yohann D'ANELLO 2020-11-11 01:04:30 +01:00
parent 9909b12501
commit c5e6459d37
3 changed files with 9 additions and 14 deletions

View File

@ -34,16 +34,18 @@ class Player(FightingEntity):
self.current_xp += xp self.current_xp += xp
self.level_up() 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: for entity in self.map.entities:
if entity != self and isinstance(entity, FightingEntity) and\ if entity.y == y and entity.x == x and \
self.distance_squared(entity) <= 1: isinstance(entity, FightingEntity):
self.hit(entity) self.hit(entity)
one_fight = True
if entity.dead: if entity.dead:
self.add_xp(randint(3, 7)) self.add_xp(randint(3, 7))
return one_fight return True
return super().check_move(y, x, move_if_possible)

View File

@ -24,7 +24,6 @@ class KeyValues(Enum):
RIGHT = auto() RIGHT = auto()
ENTER = auto() ENTER = auto()
SPACE = auto() SPACE = auto()
FIGHT = auto()
class Game: class Game:
@ -89,8 +88,6 @@ class Game:
elif key in (self.settings.KEY_UP_PRIMARY, elif key in (self.settings.KEY_UP_PRIMARY,
self.settings.KEY_UP_SECONDARY): self.settings.KEY_UP_SECONDARY):
return KeyValues.UP return KeyValues.UP
elif key == self.settings.KEY_FIGHT:
return KeyValues.FIGHT
elif key == self.settings.KEY_ENTER: elif key == self.settings.KEY_ENTER:
return KeyValues.ENTER return KeyValues.ENTER
elif key == ' ': elif key == ' ':
@ -125,9 +122,6 @@ class Game:
elif key == KeyValues.RIGHT: elif key == KeyValues.RIGHT:
if self.player.move_right(): if self.player.move_right():
self.map.tick() self.map.tick()
elif key == KeyValues.FIGHT:
if self.player.fight():
self.map.tick()
elif key == KeyValues.SPACE: elif key == KeyValues.SPACE:
self.state = GameMode.MAINMENU self.state = GameMode.MAINMENU

View File

@ -27,7 +27,6 @@ class Settings:
['d', 'Touche principale pour aller vers la droite'] ['d', 'Touche principale pour aller vers la droite']
self.KEY_RIGHT_SECONDARY = \ self.KEY_RIGHT_SECONDARY = \
['KEY_RIGHT', 'Touche secondaire pour aller vers la droite'] ['KEY_RIGHT', 'Touche secondaire pour aller vers la droite']
self.KEY_FIGHT = ['f', 'Touche pour frapper un ennemi']
self.KEY_ENTER = \ self.KEY_ENTER = \
['\n', 'Touche pour valider un menu'] ['\n', 'Touche pour valider un menu']
self.TEXTURE_PACK = ['ascii', 'Pack de textures utilisé'] self.TEXTURE_PACK = ['ascii', 'Pack de textures utilisé']