diff --git a/res/game_data.db b/res/game_data.db index e6b0b7e..9d6d103 100644 Binary files a/res/game_data.db and b/res/game_data.db differ diff --git a/res/maps/h009.tmx b/res/maps/h009.tmx index 8732beb..b1e90c4 100644 --- a/res/maps/h009.tmx +++ b/res/maps/h009.tmx @@ -62,7 +62,7 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2147483749,107,107,107,107,107,107,107,107,107,107,107,107,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2147483749,107,107,107,107,107,107,107,107,107,107,107,107,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2147483749,107,107,107,107,107,107,107,107,107,107,107,107,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2147483749,107,107,107,107,107,107,107,107,107,107,107,107,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2147483749,7,7,107,107,107,107,107,107,107,107,107,107,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/src/bag.py b/src/bag.py index 964936b..6e21863 100644 --- a/src/bag.py +++ b/src/bag.py @@ -31,9 +31,9 @@ def increment_item(self, object_id, qty): def save(self): """Sauvegarde le contenu du sac dans la base de données""" - cursor = self.save_db.cursor() for item, count in self.contents.items(): - cursor.execute("INSERT OR REPLACE INTO bag VALUES (?, ?)", (int(item), int(count))) + self.save_db.cursor().execute("INSERT OR REPLACE INTO bag VALUES (?, ?)", (int(item), int(count))) + self.save_db.commit() def separate(self, interval): """Séparation du contenu du Sac en groupes (listes)""" diff --git a/src/game.py b/src/game.py index c3286f2..22d6850 100644 --- a/src/game.py +++ b/src/game.py @@ -83,7 +83,6 @@ def __init__(self): self.menu_manager = menu.MenuManager(self.screen, self) self.dialogue = None # Contient le dialogue s'il existe - self.player.objects_state = save.load_config("objects") def change_window_size(self, **args): diff --git a/src/maps.py b/src/maps.py index fb0fc48..69d8429 100644 --- a/src/maps.py +++ b/src/maps.py @@ -19,7 +19,7 @@ class MapManager: """Gestionnaire des maps et de leurs éléments""" - ZOOM = 1.9 + ZOOM = 2.2 def __init__ (self,screen,game): self.game = game @@ -61,7 +61,7 @@ def load_map(self, map_id, old_bgm = None): self.portals = [] self.portals_id = [] - for portal in portals : + for portal in portals: point = self.tmx_data.get_object_by_name(portal[1]) self.portals.append(pg.Rect(point.x, point.y, point.width, point.height)) self.portals_id.append(portal[0]) @@ -88,7 +88,7 @@ def teleport_player(self, name): self.game.player.position[1] = point.y def player_layer(self, layer): - """Change le calque d'affichage du joueur. + """Change le calque d'affichage du joueur.\n Arguments possibles : "bg" pour l'arrière-plan, "fg" pour le premier plan""" self.object_group.change_layer(self.game.player, layer) diff --git a/src/save.py b/src/save.py index 1cb15f9..a9fc021 100644 --- a/src/save.py +++ b/src/save.py @@ -11,13 +11,16 @@ CONFIGURATION_FILES = { "player" : "sav/player.yaml", "window" : "stg/window.yaml", - "objects" : "sav/objects.yaml", "controls" : "stg/controls.yaml" } DEFAULT_CONFIG = { - "player" : {"map_id" : 1, "position" : [1600,1200], "speed" : 1.5}, - "window" : {"size" : (1000, 600), "fullscreen" : False}, + "player" : {"map_id" : 1, + "position" : [1600,1200], + "speed" : 1.5, + "cash" : 10.}, + "window" : {"size" : (1000, 600), + "fullscreen" : False}, "controls" : { # Contrôle du mouvement "PLAYER_MOVE_UP" : "UP", @@ -47,8 +50,7 @@ "DEBUG" : "F3", "RESET_CONFIG" : "F5", "RESET_SAVE" : "F6" - }, - "objects" : {1 : True} # Temporaire + } } diff --git a/src/scriptmanager.py b/src/scriptmanager.py index 3850178..96583b6 100644 --- a/src/scriptmanager.py +++ b/src/scriptmanager.py @@ -76,14 +76,6 @@ def write_npcflags(self, npc_id, flag_id, value): self.game.save.execute("replace into npc values (?,?);", (npc_id, f"{new_flags}")) self.game.save.commit() - def movingscript(self, direction, pix, sprint = False): - """Exécution d'un script de déplacement""" - self.game.executing_moving_script = True - self.initial_coords = copy(self.game.player.position) - self.moving_direction = direction - self.movement_boundary = pix - self.sprint_during_script = sprint - def exit_movingscript(self): """Terminaison d'un script de déplacement""" self.game.executing_moving_script = False @@ -138,6 +130,15 @@ def runscript(self, script): def interrupt(self): """Interruption de l'exécution du script courant""" self.abort = True + + def label(self): + """Commande indiquant un label accessible via la fonction goto. Ne fait rien en elle-même""" + pass + + def goto(self, label_tag): + """Saut vers un label""" + if label_tag in self.game.running_script.labels: + self.game.script_tree[-1][1] = self.game.running_script.labels[label_tag] # Fonctions graphiques def changelayer(self, layer): @@ -147,6 +148,13 @@ def changelayer(self, layer): if layer == "fg": self.game.map_manager.player_layer(1) + def move(self, direction, pix, sprint = False): + """Exécution d'un script de déplacement""" + self.game.executing_moving_script = True + self.initial_coords = copy(self.game.player.position) + self.moving_direction = direction + self.movement_boundary = pix + self.sprint_during_script = sprint # Fonctions de texte def loadtext(self, text): @@ -232,9 +240,10 @@ def get_object(self, object_id, qty): self.game.bag.increment_item(object_id, qty) def toss_object(self, object_id, qty): - """Destruction d'un objet en une quantité donnée, ne fait rien s'il n'y en a pas assez""" - if self.game.bag.contents[object_id] >= qty: - self.game.bag.increment_item(object_id, -qty) + """Destruction d'un objet en une quantité donnée, les supprime tous s'il n'y en a pas assez""" + corrected_qty = self.game.bag.contents[object_id] if qty == "all" else qty # Valeur arbitrairement grande + if self.game.bag.contents[object_id] >= corrected_qty: + self.game.bag.increment_item(object_id, -corrected_qty) # Fonctions des drapeaux des salles diff --git a/src/scripts.py b/src/scripts.py index d73e7b4..11de30a 100644 --- a/src/scripts.py +++ b/src/scripts.py @@ -14,6 +14,7 @@ def __init__(self, id, name, is_rerunnable, contents): self.is_running = False self.name = name self.contents = contents + self.labels = self.search_labels() # Dictionnaire dont les clés sont les noms des labels et les valeurs sont leurs lignes d'apparition try: self.function = eval(name) @@ -22,6 +23,15 @@ def __init__(self, id, name, is_rerunnable, contents): print("Utilisation du script ordinaryNpc à la place...") self.function = ordinaryNpc self.is_rerunnable = bool(is_rerunnable) + + def search_labels(self): + """Construction du dictionnaire des labels""" + res = {} + for command in range(len(self.contents)): + if self.contents[command][0:5] == "label": + label_tag = self.contents[command][7:-2] # Extraction du nom du label + res[label_tag] = command + return(res) def get_script_contents(name): @@ -40,14 +50,25 @@ def ordinaryNpc(): return(["""dialogue(self.current_npc, 1)"""]) def debug(): - return(["""loadtext(1)""", + return(["""loadtext('début')""", + """infobox()""", + """goto('lbl2')""", + + """label('lbl1')""", + """loadtext('label 1')""", + """infobox()""", + """goto('end')""", + + """label('lbl2')""", + """loadtext('label 2')""", + """infobox()""", + """goto('lbl1')""", + + """label('end')""", + """loadtext('fin')""", """infobox()"""]) def dummyScript(): - #return(["self.get_object(1, 500)"]) - #return(["""self.movingscript("down", 40)""", - # """self.movingscript("right", 20)""", - # """self.movingscript("down", 10)"""]) return(["""testflag(12101, 0)""", """iftrue("loadtext('''Le flag 0 de la L101 a été levé''')")""", """iffalse("loadtext('''Le flag 0 de la L101 est encore baissé''')")""", @@ -93,15 +114,15 @@ def mightybutton(): def brrr(): """Script exemple pour Skler""" - return(["""movingscript('right', 50)""", - """movingscript('up', 200)""", + return(["""move('right', 50)""", + """move('up', 200)""", """dialogue(self.current_npc, 2)""", """loadtext(4)""", """loadtext(5)""", """infobox()""", """dialogue(self.current_npc, 3)""", """runscript('denis_brogniart')""", - """movingscript('right', 8000, True)"""]) + """move('right', 8000, True)"""]) def denis_brogniart(): return(["""loadtext(6)""", @@ -137,6 +158,21 @@ def flaginator(): """iffalse("loadtext('''Le flag 0 de la L101 va être levé''')")""", """infobox()"""]) +def hdmi(): + """Petite mission pour le PC de la H009""" + return(["""testflag(-1, 0)""", + """iftrue("loadtext('''Le câble HDMI est branché à l'ordinateur.''')")""", + """iftrue("infobox()")""", + """iftrue("interrupt()")""", + """loadtext('''Il y a de la place pour un câble HDMI derrière la tour.''')""", + """infobox()""", + """compare_obj_qty(10, 'sup', 1)""", # Est-ce que le joueur a un câble HDMI ? + """iffalse("interrupt()")""", + """loadtext('''Vous branchez le câble HDMI à l'ordinateur.''')""", + """loadtext('''La souris marche maintenant depuis l'autre côté de la salle !''')""", + """infobox()""", + """toss_object(10, 'all')""", + """raiseflag(-1, 0)"""]) # Scripts des panneaux def sign1():