Add customisable screen size
This commit is contained in:
parent
7a3388fa76
commit
088c29a6e3
16
asci.py
16
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
|
||||
|
|
Loading…
Reference in New Issue