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='.',
PLAYER='@',
HEDGEHOG='*',
HEART='',
BOMB='o',
)
TexturePack.SQUIRREL_PACK = TexturePack(
@ -58,4 +60,6 @@ TexturePack.SQUIRREL_PACK = TexturePack(
FLOOR='██',
PLAYER='🐿 ',
HEDGEHOG='🦔',
HEART='💜',
BOMB='💣',
)

View File

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

View File

@ -36,7 +36,8 @@ class Player(FightingEntity):
self.max_xp = self.level * 10
self.health = self.maxhealth
# 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:
"""

View File

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

View File

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