Minor fixes

This commit is contained in:
Shadow15510 2022-01-28 23:12:59 +01:00
parent b5dc823078
commit faa5ffa23e
4 changed files with 23 additions and 45 deletions

28
asci.py
View File

@ -38,16 +38,16 @@ class Asci:
def _cell_test(self, direction):
if direction == 1:
if self.data[2] - 1 < 0: return -1
else: cell = self.screen.get_cell(self.data[2] - 10, self.data[3] - 3, self.data[2] - 1, self.data[3])
else: cell = self.screen.get_cell(self.data[2: 4], self.data[2] - 1, self.data[3])
if direction == 3:
if self.data[2] + 1 >= self.map_width: return -1
else: cell = self.screen.get_cell(self.data[2] - 10, self.data[3] - 3, self.data[2] + 1, self.data[3])
else: cell = self.screen.get_cell(self.data[2: 4], self.data[2] + 1, self.data[3])
if direction == 5:
if self.data[3] - 1 < 0: return -1
else: cell = self.screen.get_cell(self.data[2] - 10, self.data[3] - 3, self.data[2], self.data[3] - 1)
else: cell = self.screen.get_cell(self.data[2: 4], self.data[2], self.data[3] - 1)
if direction == 2:
if self.data[3] + 1 >= self.map_height: return -1
else: cell = self.screen.get_cell(self.data[2] - 10, self.data[3] - 3, self.data[2], self.data[3] + 1)
else: cell = self.screen.get_cell(self.data[2: 4], self.data[2], self.data[3] + 1)
print(f"'{cell}'")
cell_patterns = self._legend
@ -113,7 +113,7 @@ class Asci:
data_copy = [self.data[0], self.data[1], x, y, self.data[4]]
# Get the event
event = self._game_events_mapping[cell_content](data_copy, self.stat, self.visible_entities, self._get_entity_id(x, y))
event = self._game_events_mapping[cell_content](data_copy, self.stat, self.current_map.entities, self._get_entity_id(x, y))
if type(event) == tuple:
quest, event = event
else:
@ -259,9 +259,11 @@ class Screen:
def set_cell(self, x_offset, y_offset, x, y, value):
self._on_screen[y - y_offset][x - x_offset] = value
def get_cell(self, x_offset, y_offset, x, y):
if 0 <= x - x_offset < self.screen_width and 0 <= y - y_offset <= self.screen_height:
return self._on_screen[y - y_offset][x - x_offset]
def get_cell(self, offsets, x, y):
x = x - (offsets[0] - 10)
y = y - (offsets[1] - 3)
if 0 <= x < self.screen_width and 0 <= y <= self.screen_height:
return self._on_screen[y][x]
else: return " "
class Event:
@ -365,15 +367,15 @@ def stand_by(entity, data, stat, screen, walkable):
pass
def follow(entity, data, stat, screen, walkable):
if data[4] == 1 and screen.get_cell(data[2] - 10, data[3] - 3, data[2] + 1, data[3]) in walkable: entity.pos_x, entity.pos_y = data[2] + 1, data[3]
elif data[4] == 2 and screen.get_cell(data[2] - 10, data[3] - 3, data[2], data[3] - 1) in walkable: entity.pos_x, entity.pos_y = data[2], data[3] - 1
elif data[4] == 3 and screen.get_cell(data[2] - 10, data[3] - 3, data[2] - 1, data[3]) in walkable: entity.pos_x, entity.pos_y = data[2] - 1, data[3]
elif data[4] == 5 and screen.get_cell(data[2] - 10, data[3] - 3, data[2], data[3] + 1) in walkable: entity.pos_x, entity.pos_y = data[2], data[3] + 1
if data[4] == 1 and screen.get_cell(data[2: 4], data[2] + 1, data[3]) in walkable: entity.pos_x, entity.pos_y = data[2] + 1, data[3]
elif data[4] == 2 and screen.get_cell(data[2: 4], data[2], data[3] - 1) in walkable: entity.pos_x, entity.pos_y = data[2], data[3] - 1
elif data[4] == 3 and screen.get_cell(data[2: 4], data[2] - 1, data[3]) in walkable: entity.pos_x, entity.pos_y = data[2] - 1, data[3]
elif data[4] == 5 and screen.get_cell(data[2: 4], data[2], data[3] + 1) in walkable: entity.pos_x, entity.pos_y = data[2], data[3] + 1
def walk(entity, data, stat, screen, walkable):
frame = (entity.args[0] + 1) % len(entity.args[1])
new_x, new_y = entity.args[1][frame]
print(new_x, new_y)
if screen.get_cell(data[2] - 10, data[3] - 3, new_x, new_y) in walkable:
if screen.get_cell(data[2: 4], new_x, new_y) in walkable:
entity.pos_x, entity.pos_y = new_x, new_y
entity.args[0] = frame

View File

@ -1,10 +1,10 @@
from asci_v2 import *
from asci import *
monde = (r"""
maison = (r"""
_ ###
/o\__ #####
|_ <>\ ###
|^|__| /_\
| <>\ ###
|____| /_\
@ -13,24 +13,10 @@ monde = (r"""
# Entités
[
("sdf", "*", 2, 5, "stand by")
],
# Portes
(1, 3, 1, 5, 7))
])
maison = (r"""
+--+--+--------+--+--+
| | | | | |
| + + + + |
| |
| + + + + |
+--/ \--------/ \--+
| |
+---|^|--------------+""",
[],
(5, 7, 0, 1, 3))
carte_monde = (monde, maison)
carte_monde = (maison,)
@ -71,4 +57,4 @@ touche = {6: affichage_stat}
def mon_jeu():
rpg_python = Asci(carte_monde, evenements, touche)
rpg_python.mainloop(7, stat=[100, 5], data=[{"main": 0}, 0, 10, 3])
rpg_python.mainloop(7, stat=[100, 5], data=[{"main": 0}, 0, 10, 3])

View File

@ -84,4 +84,4 @@ touche = {8: affichage_statistique}
def mon_jeu():
rpg_python = Asci(cartes, evenements, touche)
rpg_python.mainloop(13, [100])
rpg_python.mainloop(11, [100], [{"main": 0}, 0, 10, 3])

View File

@ -67,16 +67,6 @@ def pnj(data, stat, entites, identifiant):
4: [1, "Merci, tu as rendu un grand service a mon ami !"]
}
elif identifiant == "bandit":
# Si le bandit vient d'être tué
if xp == 3: return [1, "Vous avez reussi la quete !"]
# Si le bandit est encore vivant
elif xp < 3: return [0, "Qu'est-ce que tu regardes toi ? Casses-toi !"]
# Si le bandit est déjà mort
else: return [0, "Vous regardez le cadavre froid du bandit."]
return [0, "Hmm ?"]