Skip to content

Commit

Permalink
Labels et ébauche de mission
Browse files Browse the repository at this point in the history
+ Introduction des labels et des goto issus du BASIC, PNJ de test vers l'escalier de la CdH
+ Petites avancées sur #5
+ Renommage de movingscript en move pour rendre les scripts plus compacts et lisibles
+ Possibilité de supprimer tous les objets d'un type donné (utile pour les objets rares)
+ Exemple de mission : câble HDMI pour le PC de la H009 (le câble est caché sous la table du prof de la I108)

- Suppression du fichier objects.yaml inutilisé
  • Loading branch information
fmkr-project committed Feb 9, 2022
1 parent 5a8647d commit 5257344
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 31 deletions.
Binary file modified res/game_data.db
Binary file not shown.
2 changes: 1 addition & 1 deletion res/maps/h009.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -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,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src/bag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"""
Expand Down
1 change: 0 additions & 1 deletion src/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions src/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand All @@ -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)

Expand Down
12 changes: 7 additions & 5 deletions src/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -47,8 +50,7 @@
"DEBUG" : "F3",
"RESET_CONFIG" : "F5",
"RESET_SAVE" : "F6"
},
"objects" : {1 : True} # Temporaire
}
}


Expand Down
31 changes: 20 additions & 11 deletions src/scriptmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
52 changes: 44 additions & 8 deletions src/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand All @@ -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é''')")""",
Expand Down Expand Up @@ -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)""",
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 5257344

Please sign in to comment.