From: Christian Heller Date: Thu, 21 Feb 2019 12:19:33 +0000 (+0100) Subject: Add "item" thing type differentiated from animate thing types. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/ledger?a=commitdiff_plain;h=d33b918833cc762029abf5ca0b6930e16f91e8da;p=plomrogue2-experiments Add "item" thing type differentiated from animate thing types. --- diff --git a/new/example_client.py b/new/example_client.py index 039d8de..8a0de50 100755 --- a/new/example_client.py +++ b/new/example_client.py @@ -172,6 +172,8 @@ class Game: symbol = '@' elif type_ == 'monster': symbol = 'm' + elif type_ == 'item': + symbol = 'i' return symbol @@ -292,7 +294,10 @@ class MapWidget(Widget): terrain_as_list = list(self.tui.game.world.map_.terrain[:]) for t in self.tui.game.world.things: pos_i = self.tui.game.world.map_.get_position_index(t.position) - terrain_as_list[pos_i] = self.tui.game.symbol_for_type(t.type_) + symbol = self.tui.game.symbol_for_type(t.type_) + if symbol in {'i'} and terrain_as_list[pos_i] in {'@', 'm'}: + continue + terrain_as_list[pos_i] = symbol return ''.join(terrain_as_list) def pad_or_cut_x(lines): @@ -315,6 +320,8 @@ class MapWidget(Widget): for c in ''.join(lines): if c in {'@', 'm'}: chars_with_attrs += [(c, curses.color_pair(1))] + elif c == 'i': + chars_with_attrs += [(c, curses.color_pair(4))] elif c == '.': chars_with_attrs += [(c, curses.color_pair(2))] elif c in {'x', 'X', '#'}: @@ -365,6 +372,7 @@ class TUI: curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_RED) curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_BLUE) + curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_YELLOW) curses.curs_set(False) # hide cursor self.to_send = [] self.edit = EditWidget(self, (0, 6), (1, 14), check_tui = ['edit']) diff --git a/new/plomrogue/game.py b/new/plomrogue/game.py index a031406..dcc6c3d 100755 --- a/new/plomrogue/game.py +++ b/new/plomrogue/game.py @@ -8,7 +8,7 @@ from plomrogue.mapping import MapHex from plomrogue.parser import Parser from plomrogue.io import GameIO from plomrogue.misc import quote, stringify_yx -from plomrogue.things import Thing, ThingMonster, ThingHuman +from plomrogue.things import Thing, ThingMonster, ThingHuman, ThingItem @@ -83,7 +83,10 @@ class World(WorldBase): npc = self.game.thing_types['monster'](self, 1) npc.position = [random.randint(0, yx[0] -1), random.randint(0, yx[1] -1)] - self.things = [player, npc] + item = self.game.thing_types['item'](self, 2) + item.position = [random.randint(0, yx[0] -1), + random.randint(0, yx[1] -1)] + self.things = [player, npc, item] return 'success' @@ -107,7 +110,9 @@ class Game: self.world_type = World self.world = self.world_type(self) self.thing_type = Thing - self.thing_types = {'human': ThingHuman, 'monster': ThingMonster} + self.thing_types = {'human': ThingHuman, + 'monster': ThingMonster, + 'item': ThingItem} def get_string_options(self, string_option_type): if string_option_type == 'direction': diff --git a/new/plomrogue/tasks.py b/new/plomrogue/tasks.py index fe41e41..2625762 100644 --- a/new/plomrogue/tasks.py +++ b/new/plomrogue/tasks.py @@ -40,7 +40,7 @@ class Task_MOVE(Task): if self.thing.world.map_[test_pos] != '.': raise GameError('%s would move into illegal terrain' % self.thing.id_) for t in self.thing.world.things: - if t.position == test_pos: + if t.blocking and t.position == test_pos: raise GameError('%s would move into other thing' % self.thing.id_) def do(self): diff --git a/new/plomrogue/things.py b/new/plomrogue/things.py index 2decc67..386dbc4 100644 --- a/new/plomrogue/things.py +++ b/new/plomrogue/things.py @@ -13,6 +13,20 @@ class ThingBase: class Thing(ThingBase): + blocking = False + + def proceed(self): + pass + + + +class ThingItem(Thing): + type_ = 'item' + + + +class ThingAnimate(Thing): + blocking = True def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -129,10 +143,10 @@ class Thing(ThingBase): -class ThingHuman(Thing): +class ThingHuman(ThingAnimate): type_ = 'human' -class ThingMonster(Thing): +class ThingMonster(ThingAnimate): type_ = 'monster'