From 088c29a6e3117179c6fd6a28d683b83b2defb223 Mon Sep 17 00:00:00 2001 From: Shadow15510 Date: Mon, 18 Apr 2022 12:07:51 +0200 Subject: [PATCH 1/2] Add customisable screen size --- asci.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/asci.py b/asci.py index a90d213..5c76e25 100644 --- a/asci.py +++ b/asci.py @@ -1,4 +1,4 @@ -# Asci (1.8.2) +# Asci (1.8.3) class Asci: def __init__(self, maps, entities, events_mapping, keys_mapping, behaviors=None, screen_width=21, screen_height=7): @@ -182,7 +182,7 @@ class Asci: data_copy = self.data[:] for entity in self.current_map.entities.values(): self._behaviors[entity.behavior](entity, data_copy, self.stat, self.screen, walkable) - if entity.map_id == self.data[1] and (0 <= entity.pos_x - self.data[2] + 10 < self.screen.screen_width) and (0 <= entity.pos_y - self.data[3] + 3 < self.screen.screen_height): + if entity.map_id == self.data[1] and (0 <= entity.pos_x - self.data[2] + self.screen.pos_player[0] < self.screen.screen_width) and (0 <= entity.pos_y - self.data[3] + self.screen.pos_player[1] < self.screen.screen_height): self.screen.set_cell(entity.pos_x, entity.pos_y, entity.symbol) self.screen.set_cell(self.data[2], self.data[3], player) @@ -221,6 +221,7 @@ class Screen: # Screen configuration self.screen_width = screen_width self.screen_height = screen_height + self.pos_player = (screen_width // 2, screen_height // 2) self._on_screen = [[" " for _ in range(screen_width)] for _ in range(screen_height)] self._asci_data = [] @@ -236,7 +237,7 @@ class Screen: self.map_height = len(self._world) def set_screen(self): - x = self._asci_data[2] - 10 ; y = self._asci_data[3] - 3 + x = self._asci_data[2] - self.pos_player[0] ; y = self._asci_data[3] - self.pos_player[1] for x_map in range(x, x + self.screen_width): for y_map in range(y, y + self.screen_height): self._on_screen[y_map - y][x_map - x] = " " @@ -268,18 +269,19 @@ class Screen: else: input() def set_cell(self, x, y, value): - x = x - (self._asci_data[2] - 10) - y = y - (self._asci_data[3] - 3) + x = x - (self._asci_data[2] - self.pos_player[0]) + y = y - (self._asci_data[3] - self.pos_player[1]) if 0 <= x < self.screen_width and 0 <= y < self.screen_height: self._on_screen[y][x] = value def get_cell(self, x, y): - x = x - (self._asci_data[2] - 10) - y = y - (self._asci_data[3] - 3) + x = x - (self._asci_data[2] - self.pos_player[0]) + y = y - (self._asci_data[3] - self.pos_player[1]) if 0 <= x < self.screen_width and 0 <= y < self.screen_height: return self._on_screen[y][x] else: return " " + class Event: def __init__(self, xp, text, answer=0, *stat): self.xp = xp From 3ad286dd5a6ee31636815077b4806fb4362025d6 Mon Sep 17 00:00:00 2001 From: Shadow15510 Date: Tue, 12 Jul 2022 11:00:46 +0200 Subject: [PATCH 2/2] Add some extra functions --- asci.py | 60 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/asci.py b/asci.py index 5c76e25..8fde004 100644 --- a/asci.py +++ b/asci.py @@ -1,4 +1,6 @@ -# Asci (1.8.3) +# Asci (1.9.0) +from math import floor, ceil + class Asci: def __init__(self, maps, entities, events_mapping, keys_mapping, behaviors=None, screen_width=21, screen_height=7): @@ -260,7 +262,7 @@ class Screen: print("\n" * self.screen_height) def display_text(self, string): - paragraphs = [i for i in text_formater(string) if i] + paragraphs = [i for i in text_formater(string, self.screen_width, self.screen_height) if i] nb_par = len(paragraphs) for index in range(nb_par): self.clear() @@ -386,29 +388,11 @@ def get_multi_move(key): return [(convert(k), 1) for k in key] - -# Extra functions -def print_text(text, min_value=0, max_value=0, default_value=0): - paragraphs = [i for i in text_formater(text) if i] - nb = len(paragraphs) - for index in range(nb): - print("\n" * 7) - print(paragraphs[index]) - - if index + 1 == nb and (min_value or max_value or default_value) and min_value <= max_value: - result = input(">") - try: result = int(result) - except: result = default_value - if not (min_value <= result <= max_value): result = default_value - - return result - - else: input() - - +# Motions functions def stand_by(entity, data, stat, screen, walkable): pass + def permanent(entity, data, stat, screen, walkable): pass @@ -466,4 +450,34 @@ def _walk_engine(entity, frame): new_y = entity.pos_y if delta_x: new_x += abs(delta_x) // delta_x if delta_y: new_y += abs(delta_y) // delta_y - return new_x, new_y \ No newline at end of file + return new_x, new_y + + +# Extra functions +def print_text(text, min_value=0, max_value=0, default_value=0, screen_width=21, screen_height=7): + paragraphs = [i for i in text_formater(text, screen_width, screen_height) if i] + nb = len(paragraphs) + for index in range(nb): + print("\n" * 7) + print(paragraphs[index]) + + if index + 1 == nb and (min_value or max_value or default_value) and min_value <= max_value: + result = input(">") + try: result = int(result) + except: result = default_value + if not (min_value <= result <= max_value): result = default_value + + return result + + else: input() + + +def center(string, total_length, symbol): + left = floor((total_length - len(string)) / 2) + right = ceil((total_length - len(string)) / 2) + + return left * symbol + string + right * symbol + + +def enumerate(data): + return [(i, data[i]) for i in range(len(data))] \ No newline at end of file