import bge # Bibliothèque Blender Game Engine (UPBGE) import aud # Sounds import rp_map1 # Map definition ############################################################################### # rp_doc.py # @title: Documentation du Robot Ropy # @project: Ropy (Blender-EduTech) # @lang: fr # @authors: Philippe Roy # @copyright: Copyright (C) 2020-2022 Philippe Roy # @license: GNU GPL # # Ropy est destiné à la découverte de la programmation procédurale et du language Python. # A travers plusieurs challenges, donc de manière graduée, les élèves vont apprendre à manipuler les structures algorithmiques de base et à les coder en Python. # # ############################################################################### scene = bge.logic.getCurrentScene() # Colors color_doc_chap = (0, 1, 0.857,1) # Turquoise color_doc_fct = (0, 1, 0.857,1) # Turquoise color_doc_hl = (0.799, 0.617, 0.021, 1) # Jaune color_doc_activate = (0.936, 0.033, 1, 1) # Rose color_doc_mission = (1, 0.192, 0.03, 1) # Orange # Sounds # audiodev = aud.Device() # snd_book_open = aud.Sound('asset/sounds/book_open.ogg') # sndbuff_book_open = aud.Sound.cache(snd_book_open) # snd_book_close = aud.Sound('asset/sounds/book_close.ogg') # sndbuff_book_close = aud.Sound.cache(snd_book_close) # snd_book_flip = aud.Sound('asset/sounds/book_flip.ogg') # sndbuff_book_flip = aud.Sound.cache(snd_book_flip) # UPBGE constants JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED ACTIVATE = bge.logic.KX_INPUT_ACTIVE # JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED # Cards description card_description ={} # Missions card_description.update(rp_map1.get_card_description()) missions_card=rp_map1.get_missions_card() ############################################################################### # Rover ############################################################################### rover_card=["avancer-card", "tourner-card", "baliser-card", "prendre-card", "detecter-card", "radar-card"] # Avancer rp_avancer_title="Avancer" rp_avancer_text="FIXME" card_description.update({"avancer-card" : [rp_avancer_title, rp_avancer_text]}) # Tourner rp_tourner_title="Tourner" rp_tourner_text="FIXME" card_description.update({"tourner-card" : [rp_tourner_title, rp_tourner_text]}) # Baliser rp_baliser_title="Baliser" rp_baliser_text="FIXME" card_description.update({"baliser-card" : [rp_baliser_title, rp_baliser_text]}) # Prendre rp_prendre_title="Prendre" rp_prendre_text="FIXME" card_description.update({"prendre-card" : [rp_prendre_title, rp_prendre_text]}) # Détecter rp_detecter_title="Détecter" rp_detecter_text="FIXME" card_description.update({"detecter-card" : [rp_detecter_title, rp_detecter_text]}) # Radar rp_radar_title="Radar" rp_radar_text="FIXME" card_description.update({"radar-card" : [rp_radar_title, rp_radar_text]}) ############################################################################### # Python ############################################################################### python_card=["fonction-card", "alternative-card", "boucle-card", "liste-card", "dict-card", "poo-card"] # Fonction rp_fonction_title="Fonction" rp_fonction_text="FIXME" card_description.update({"fonction-card" : [rp_fonction_title, rp_fonction_text]}) # Alternative rp_alternative_title="Alternative" rp_alternative_text="FIXME" card_description.update({"alternative-card" : [rp_alternative_title, rp_alternative_text]}) # Boucle rp_boucle_title="Boucle" rp_boucle_text="FIXME" card_description.update({"boucle-card" : [rp_boucle_title, rp_boucle_text]}) # Liste rp_liste_title="Liste" rp_liste_text="FIXME" card_description.update({"liste-card" : [rp_liste_title, rp_liste_text]}) # Dictionnaire rp_dict_title="Dictionnaire" rp_dict_text="FIXME" card_description.update({"dict-card" : [rp_dict_title, rp_dict_text]}) # Objet (POO) rp_poo_title="Programmation\norientée objet (POO)" rp_poo_text="\nFIXME" card_description.update({"poo-card" : [rp_poo_title, rp_poo_text]}) ############################################################################### # Interface ############################################################################### ## # Initialisation de la tablette ## def init(): # Mettre les couleurs par défaut sur les icones (chapitres et cartes) chap=("general", "missions", "rover", "python") for page in chap: scene.objects["Doc-"+page].color = color_doc_chap scene.objects["Doc-"+page+"-text"].color = color_doc_chap for i in range(len(missions_card)): scene.objects[missions_card[i]].color = color_doc_fct scene.objects[missions_card[i]+"-icon"].color = color_doc_fct scene.objects[missions_card[i]+"-text"].color = color_doc_fct for i in range(len(rover_card)): scene.objects[rover_card[i]].color = color_doc_fct scene.objects[rover_card[i]+"-icon"].color = color_doc_fct scene.objects[rover_card[i]+"-text"].color = color_doc_fct for i in range(len(python_card)): scene.objects[python_card[i]].color = color_doc_fct scene.objects[python_card[i]+"-icon"].color = color_doc_fct scene.objects[python_card[i]+"-text"].color = color_doc_fct # Mémorisation de la position des pages chap=("general", "missions", "rover", "python") for page in chap: scene.objects["Doc_chap-"+page]['init_lx']=scene.objects["Doc_chap-"+page].worldPosition.x scene.objects["Doc_chap-"+page]['init_ly']=scene.objects["Doc_chap-"+page].worldPosition.y scene.objects["Doc_chap-"+page]['init_lz']=scene.objects["Doc_chap-"+page].worldPosition.z # Page par défaut scene.objects['Doc']['page_chap'] = "general" ## # Ouvrir la tablette ## def open(): # Placer la tablette # scene.objects['Doc'].worldPosition = [0, -21, 15.75] scene.objects['Doc'].worldPosition = [0, -21, 15.8] scene.objects['Doc_close'].color = color_doc_chap scene.objects['Doc'].setVisible(True,True) scene.objects['Doc_title'].setVisible(False,True) scene.objects['Doc_text'].setVisible(False,True) # Placer le nouveau chapitre name_chap = scene.objects['Doc']['page_chap'] scene.objects['Doc-'+name_chap].color = color_doc_activate scene.objects['Doc-'+name_chap+'-text'].color = color_doc_activate scene.objects['Doc_chap-'+name_chap].worldPosition = scene.objects['Doc'].worldPosition scene.objects['Doc_chap-'+name_chap].setVisible(True,True) # Placer la carte de la mission active if name_chap == "missions": scene.objects["mission_"+str(scene.objects['Terrain']['mission_current'])+"-card"].color = color_doc_mission scene.objects["mission_"+str(scene.objects['Terrain']['mission_current'])+"-card-icon"].color = color_doc_mission scene.objects["mission_"+str(scene.objects['Terrain']['mission_current'])+"-card-text"].color = color_doc_mission # Afficher le texte de la carte active if name_chap != "general": if scene.objects['Doc_chap-'+name_chap]['page_fct'] !="": name_fct = scene.objects['Doc_chap-'+name_chap]['page_fct'] scene.objects['Doc_title']['Text'] = card_description[name_fct][0] scene.objects['Doc_text']['Text'] = card_description[name_fct][1] scene.objects['Doc_title'].setVisible(True, False) scene.objects['Doc_text'].setVisible(True, False) else: scene.objects['Doc_title'].setVisible(False,True) scene.objects['Doc_text'].setVisible(False,True) else: scene.objects['Doc_title'].setVisible(False,True) scene.objects['Doc_text'].setVisible(False,True) ## # Fermeture du livre ## def close(): # sound_play (sndbuff_book_close) chap=("general", "missions", "rover", "python") for page in chap: scene.objects["Doc_chap-"+page].setVisible(False,True) scene.objects["Doc_chap-"+page].worldPosition.x = scene.objects["Doc_chap-"+page]['init_lx'] scene.objects["Doc_chap-"+page].worldPosition.y = scene.objects["Doc_chap-"+page]['init_ly'] scene.objects["Doc_chap-"+page].worldPosition.z = scene.objects["Doc_chap-"+page]['init_lz'] scene.objects['Doc'].setVisible(False,True) scene.objects['Doc'].worldPosition = [35, -2, 2] ## # Highlight du livre ## def hl (cont): # Activation if cont.sensors['MO'].status == JUST_ACTIVATED : obj = cont.owner name=obj.name[:-7] name_text=name+"-text" name_icon=name+"-icon" # Close if name == "Doc_close" : scene.objects[name].color = color_doc_hl else: if "Doc-" in name : # Chapitre if name[4:] == scene.objects['Doc']['page_chap']: scene.objects[name].color = color_doc_activate scene.objects[name_text].color = color_doc_activate else: scene.objects[name].color = color_doc_hl scene.objects[name_text].color = color_doc_hl else: # Carte name_chap = scene.objects['Doc']['page_chap'] if name == scene.objects['Doc_chap-'+name_chap]['page_fct'] : scene.objects[name].color = color_doc_activate scene.objects[name_text].color = color_doc_activate scene.objects[name_icon].color = color_doc_activate else: scene.objects[name].color = color_doc_hl scene.objects[name_text].color = color_doc_hl scene.objects[name_icon].color = color_doc_hl # Désactivation if cont.sensors['MO'].status == JUST_RELEASED : obj = cont.owner name=obj.name[:-7] name_text=obj.name[:-7]+"-text" name_icon=obj.name[:-7]+"-icon" # Close if name == "Doc_close" : scene.objects[name].color = color_doc_fct else: if "Doc-" in name : # Chapitre if name[4:] == scene.objects['Doc']['page_chap']: scene.objects[name].color = color_doc_activate scene.objects[name_text].color = color_doc_activate else: scene.objects[name].color = color_doc_fct scene.objects[name_text].color = color_doc_fct else: # Carte name_chap = scene.objects['Doc']['page_chap'] if name == scene.objects['Doc_chap-'+name_chap]['page_fct'] : scene.objects[name].color = color_doc_activate scene.objects[name_text].color = color_doc_activate scene.objects[name_icon].color = color_doc_activate else: if name == "mission_"+str(scene.objects['Terrain']['mission_current'])+"-card": scene.objects[name].color = color_doc_mission scene.objects[name_text].color = color_doc_mission scene.objects[name_icon].color = color_doc_mission else: scene.objects[name].color = color_doc_fct scene.objects[name_text].color = color_doc_fct scene.objects[name_icon].color = color_doc_fct ## # Afficher le chapitre ## def chapter(cont): if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and cont.sensors['Click'].positive: # sound_play (sndbuff_book_flip) obj = cont.owner # Enlever l'ancien chapitre scene.objects['Doc-'+scene.objects['Doc']['page_chap']].color = color_doc_chap scene.objects['Doc-'+scene.objects['Doc']['page_chap']+'-text'].color = color_doc_chap scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']].worldPosition.x = scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']]['init_lx'] scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']].worldPosition.y = scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']]['init_ly'] scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']].worldPosition.z = scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']]['init_lz'] # Placer le nouveau chapitre name_chap= obj.name[4:-7] scene.objects['Doc-'+name_chap].color = color_doc_activate scene.objects['Doc-'+name_chap+'-text'].color = color_doc_activate scene.objects['Doc']['page_chap'] = name_chap scene.objects['Doc_chap-'+name_chap].worldPosition = scene.objects['Doc'].worldPosition scene.objects['Doc_chap-'+name_chap].setVisible(True,True) # Placer la carte de la mission active if name_chap == "missions": scene.objects["mission_"+str(scene.objects['Terrain']['mission_current'])+"-card"].color = color_doc_mission scene.objects["mission_"+str(scene.objects['Terrain']['mission_current'])+"-card-icon"].color = color_doc_mission scene.objects["mission_"+str(scene.objects['Terrain']['mission_current'])+"-card-text"].color = color_doc_mission # Afficher le texte de la carte active if name_chap != "general": if scene.objects['Doc_chap-'+name_chap]['page_fct'] !="": name_fct = scene.objects['Doc_chap-'+name_chap]['page_fct'] scene.objects['Doc_title']['Text'] = card_description[name_fct][0] scene.objects['Doc_text']['Text'] = card_description[name_fct][1] scene.objects['Doc_title'].setVisible(True, False) scene.objects['Doc_text'].setVisible(True, False) else: scene.objects['Doc_title'].setVisible(False,True) scene.objects['Doc_text'].setVisible(False,True) else: scene.objects['Doc_title'].setVisible(False,True) scene.objects['Doc_text'].setVisible(False,True) ## # Afficher les details de la fonction à partir d'une carte ## def card (cont): if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : # sound_play (sndbuff_book_flip) obj = cont.owner name_chap = scene.objects['Doc']['page_chap'] name_fct= obj.name[:-7] # Enlever l'ancienne carte if scene.objects['Doc_chap-'+name_chap]['page_fct'] !="": # Placer la carte de la mission active if scene.objects['Doc_chap-'+name_chap]['page_fct'] == "mission_"+str(scene.objects['Terrain']['mission_current'])+"-card": scene.objects[scene.objects['Doc_chap-'+name_chap]['page_fct']].color = color_doc_mission scene.objects[scene.objects['Doc_chap-'+name_chap]['page_fct']+'-text'].color = color_doc_mission scene.objects[scene.objects['Doc_chap-'+name_chap]['page_fct']+'-icon'].color = color_doc_mission else: scene.objects[scene.objects['Doc_chap-'+name_chap]['page_fct']].color = color_doc_fct scene.objects[scene.objects['Doc_chap-'+name_chap]['page_fct']+'-text'].color = color_doc_fct scene.objects[scene.objects['Doc_chap-'+name_chap]['page_fct']+'-icon'].color = color_doc_fct # Afficher le texte de la carte scene.objects['Doc_chap-'+name_chap]['page_fct'] = name_fct scene.objects[name_fct].color = color_doc_activate scene.objects[name_fct+'-icon'].color = color_doc_activate scene.objects[name_fct+'-text'].color = color_doc_activate scene.objects['Doc_title']['Text'] = card_description[name_fct][0] scene.objects['Doc_text']['Text'] = card_description[name_fct][1] scene.objects['Doc_title'].setVisible(True, False) scene.objects['Doc_text'].setVisible(True, False) ## # Sounds ## def sound_play (sound): pass # FIXME # if scene.objects['Commands']['sound']: # audiodev.play(sound)