Spawn also items

This commit is contained in:
Yohann D'ANELLO 2020-11-11 16:23:27 +01:00
parent d75f4290ff
commit 2b5d82db57
5 changed files with 21 additions and 7 deletions

View File

@ -44,6 +44,8 @@ TexturePack.ASCII_PACK = TexturePack(
FLOOR='.', FLOOR='.',
PLAYER='@', PLAYER='@',
HEDGEHOG='*', HEDGEHOG='*',
HEART='',
BOMB='o',
) )
TexturePack.SQUIRREL_PACK = TexturePack( TexturePack.SQUIRREL_PACK = TexturePack(
@ -58,4 +60,6 @@ TexturePack.SQUIRREL_PACK = TexturePack(
FLOOR='██', FLOOR='██',
PLAYER='🐿 ', PLAYER='🐿 ',
HEDGEHOG='🦔', HEDGEHOG='🦔',
HEART='💜',
BOMB='💣',
) )

View File

@ -16,6 +16,10 @@ class Item(Entity):
self.held = True self.held = True
class Heart(Item):
name = "heart"
class Bomb(Item): class Bomb(Item):
name = "bomb" name = "bomb"
damage: int = 5 damage: int = 5

View File

@ -36,7 +36,8 @@ class Player(FightingEntity):
self.max_xp = self.level * 10 self.max_xp = self.level * 10
self.health = self.maxhealth self.health = self.maxhealth
# TODO Remove it, that's only fun # TODO Remove it, that's only fun
self.map.spawn_random_entities(randint(self.level, self.level * 5)) self.map.spawn_random_entities(randint(3 * self.level,
10 * self.level))
def add_xp(self, xp: int) -> None: def add_xp(self, xp: int) -> None:
""" """

View File

@ -52,7 +52,7 @@ class Game:
self.player = Player() self.player = Player()
self.map.add_entity(self.player) self.map.add_entity(self.player)
self.player.move(1, 14) self.player.move(1, 14)
self.map.spawn_random_entities(randint(1, 5)) self.map.spawn_random_entities(randint(3, 10))
@staticmethod @staticmethod
def load_game(filename: str) -> None: def load_game(filename: str) -> None:

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
from enum import Enum, auto from enum import Enum, auto
from math import sqrt from math import sqrt
from random import randint from random import choice, randint
from typing import List from typing import List
from dungeonbattle.display.texturepack import TexturePack from dungeonbattle.display.texturepack import TexturePack
@ -97,10 +97,9 @@ class Map:
tile = self.tiles[y][x] tile = self.tiles[y][x]
if tile.can_walk(): if tile.can_walk():
break break
from dungeonbattle.entities.monsters import Hedgehog entity = choice(Entity.get_all_entity_classes())()
hedgehog = Hedgehog() entity.move(y, x)
hedgehog.move(y, x) self.add_entity(entity)
self.add_entity(hedgehog)
def tick(self) -> None: def tick(self) -> None:
""" """
@ -193,6 +192,12 @@ class Entity:
""" """
return sqrt(self.distance_squared(other)) return sqrt(self.distance_squared(other))
@staticmethod
def get_all_entity_classes():
from dungeonbattle.entities.items import Heart, Bomb
from dungeonbattle.entities.monsters import Hedgehog
return [Hedgehog, Heart, Bomb]
class FightingEntity(Entity): class FightingEntity(Entity):
maxhealth: int maxhealth: int