diff --git a/ropy-16.blend b/ropy-16.blend index b935dda..cfa4d73 100644 Binary files a/ropy-16.blend and b/ropy-16.blend differ diff --git a/rp.py b/rp.py index 02403bb..474c6e1 100644 --- a/rp.py +++ b/rp.py @@ -159,6 +159,8 @@ def terrain_init (): beacon['activated']=False # Init de la carte + # Read config (mission actuelle : data/mission/current -> [1][0].text) + scene.objects['Points']['mission']=int(rp_config_tree[1][0].text) rp_map.map_init() rp_map.map_reset() @@ -269,6 +271,7 @@ def terrain_grid (): if scene.objects['Grid-u'].visible: scene.objects['Grid-u'].setVisible(False,True) scene.objects['Grid-v'].setVisible(False,True) + rp_map.aim_hide() scene.objects['Map_aim'].setVisible(False,True) else: scene.objects['Grid-u']['timer'] = 0 @@ -286,7 +289,7 @@ def terrain_grid_anim (): # bpy.data.materials["Grid"].node_tree.nodes["Emission"].inputs[1].default_value =scene.objects['Grid-u']['timer'] scene.objects['Grid-u']['timer']+=0.01 if scene.objects['Grid-u']['timer']>= 0.05 and scene.objects['Grid-u'].visible : - scene.objects['Map_aim'].setVisible(True,True) + rp_map.aim_show() if scene.objects['Grid-u']['timer']>= 1: scene.objects['Grid-u']['anim'] = False @@ -397,19 +400,23 @@ def cmd_init(): scene.objects['Commands']['speed']=float(rp_config_tree[0][0].text) i=speed_mode.index(scene.objects['Commands']['speed']) scene.objects['Text_speed']['Text']=speed_mode_txt[i] + + # Missions + # Read config (mission actuelle : data/mission/current -> [1][0].text) + # Read config (niveau atteint : data/mission/level -> [1][1].text) + scene.objects['Points']['mission']=int(rp_config_tree[1][0].text) + scene.objects['Points']['mission_init']= scene.objects['Points']['mission'] + scene.objects['Points']['level']=int(rp_config_tree[1][1].text) + scene.objects['Points-Map-text']['Text']="Mission "+str(scene.objects['Points']['mission']) + scene.objects['Book_mission']['Text'] = "Mission en cours : "+str(scene.objects['Points']['mission']) + scene.objects['Book_level']['Text'] = "Niveau actuel : "+str(scene.objects['Points']['level']) # Windows windows=("Doc", "Doc_chap-general", "Doc_chap-missions", "Doc_chap-rover", "Doc_chap-python", "About") for window in windows: scene.objects[window].setVisible(False,True) rp_doc.init() - - # Missions - # Read config (mission actuelle : data/config/mission_current -> [1][0].text) - # Read config (niveau atteint : data/config/mission_success -> [1][1].text) - scene.objects['Terrain']['mission_current']=int(rp_config_tree[1][0].text) - scene.objects['Terrain']['mission_success']=int(rp_config_tree[1][1].text) - scene.objects['Points-Map-text']['Text']="Mission "+str(scene.objects['Terrain']['mission_current']) + ## # Highlight des commandes @@ -891,6 +898,12 @@ def tablet_close (): rp_doc.close() scene.objects['Terrain']['manip_mode']=0 # Enlever la fenêtre modale + # Maj du fichier de config (mission actuelle : data/mission/current -> [1][0].text) + rp_config_tree[1][0].text=str(scene.objects['Points']['mission']) + buffer_xml = ET.tostring(rp_config_tree) + with open("rp_config.xml", "wb") as f: + f.write(buffer_xml) + # Overlay scene.objects['Points'].setVisible(True,True) scene.objects['Commands'].setVisible(True,True) @@ -925,6 +938,13 @@ def tablet_close (): scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['current_ly'] scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['current_lz'] + # Reset si changement de mission + if scene.objects['Points']['mission_init']!= scene.objects['Points']['mission']: + terrain_stop () + if scene.objects['Grid-u'].visible: + rp_map.aim_show() + scene.objects['Points']['mission_init'] = scene.objects['Points']['mission'] + ## # Clic pour fermer la tablette ## diff --git a/rp_cmd.py b/rp_cmd.py index 5e06ffd..a82290a 100644 --- a/rp_cmd.py +++ b/rp_cmd.py @@ -41,7 +41,7 @@ def commandes(): mrp_avancer() mrp_avancer() mrp_avancer() - # mrp_avancer() + mrp_avancer() # mrp_avancer() rp_droite() diff --git a/rp_config.xml b/rp_config.xml index 216e61b..372b744 100644 --- a/rp_config.xml +++ b/rp_config.xml @@ -1,15 +1,15 @@ - 1.0 + 4.0 False - -6.930208683013916 - -18.326568603515625 - 19.9746036529541 + -5.5672173500061035 + -15.25645923614502 + 13.960037231445312 - 1 - 0 + 3 + 6 \ No newline at end of file diff --git a/rp_doc.py b/rp_doc.py index 73d437b..8fa7a41 100644 --- a/rp_doc.py +++ b/rp_doc.py @@ -1,6 +1,6 @@ import bge # Bibliothèque Blender Game Engine (UPBGE) import aud # Sounds -import rp_map1 # Map definition +import rp_map1 # Map definition ############################################################################### # rp_doc.py @@ -144,7 +144,7 @@ card_description.update({"poo-card" : [rp_poo_title, rp_poo_text]}) def init(): - # Mettre les couleurs par défaut sur les icones (chapitres et cartes) + # Mettre les couleurs sur les icones (chapitres et cartes) chap=("general", "missions", "rover", "python") for page in chap: scene.objects["Doc-"+page].color = color_doc_chap @@ -161,6 +161,11 @@ def init(): 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 + scene.objects['Book_level_button'].color = color_doc_chap + scene.objects['Book_level_button'].setVisible(False,True) + scene.objects["mission_"+str(scene.objects['Points']['mission'])+"-card"].color = color_doc_mission + scene.objects["mission_"+str(scene.objects['Points']['mission'])+"-card-icon"].color = color_doc_mission + scene.objects["mission_"+str(scene.objects['Points']['mission'])+"-card-text"].color = color_doc_mission # Mémorisation de la position des pages chap=("general", "missions", "rover", "python") @@ -193,11 +198,16 @@ def open(): 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 + # Affichage ou pas du bouton de selection de la mission 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 + name_fct = scene.objects['Doc_chap-missions']['page_fct'] + if name_fct !="": + if scene.objects[name_fct]['mission'] <= scene.objects['Points']['level'] and scene.objects[name_fct]['mission'] != scene.objects['Points']['mission']: + scene.objects['Book_level_button'].setVisible(True,True) + else: + scene.objects['Book_level_button'].setVisible(False,True) + else: + scene.objects['Book_level_button'].setVisible(False,True) # Afficher le texte de la carte active if name_chap != "general": @@ -211,8 +221,12 @@ def open(): 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) + if name_chap != "missions": + 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 @@ -243,7 +257,7 @@ def hl (cont): name_icon=name+"-icon" # Close - if name == "Doc_close" : + if name == "Doc_close" or name == "Book_level_button": scene.objects[name].color = color_doc_hl else: if "Doc-" in name : # Chapitre @@ -272,7 +286,7 @@ def hl (cont): name_icon=obj.name[:-7]+"-icon" # Close - if name == "Doc_close" : + if name == "Doc_close" or name == "Book_level_button": scene.objects[name].color = color_doc_fct else: if "Doc-" in name : # Chapitre @@ -289,7 +303,7 @@ def hl (cont): 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": + if name == "mission_"+str(scene.objects['Points']['mission'])+"-card": scene.objects[name].color = color_doc_mission scene.objects[name_text].color = color_doc_mission scene.objects[name_icon].color = color_doc_mission @@ -322,11 +336,16 @@ def chapter(cont): 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 + # Bouton de selection de la mission 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 + name_fct = scene.objects['Doc_chap-missions']['page_fct'] + if name_fct !="": + if scene.objects[name_fct]['mission'] <= scene.objects['Points']['level'] and scene.objects[name_fct]['mission'] != scene.objects['Points']['mission']: + scene.objects['Book_level_button'].setVisible(True,True) + else: + scene.objects['Book_level_button'].setVisible(False,True) + else: + scene.objects['Book_level_button'].setVisible(False,True) # Afficher le texte de la carte active if name_chap != "general": @@ -361,7 +380,7 @@ def card (cont): 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": + if scene.objects['Doc_chap-'+name_chap]['page_fct'] == "mission_"+str(scene.objects['Points']['mission'])+"-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 @@ -380,6 +399,34 @@ def card (cont): scene.objects['Doc_title'].setVisible(True, False) scene.objects['Doc_text'].setVisible(True, False) + # Sélection de la mission + if "mission_" in name_fct : + if scene.objects[name_fct]['mission'] <= scene.objects['Points']['level'] and scene.objects[name_fct]['mission'] != scene.objects['Points']['mission']: + scene.objects['Book_level_button'].setVisible(True,True) + else: + scene.objects['Book_level_button'].setVisible(False,True) + +## +# Sélectionner le niveau +## + +def level_button (cont): + if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : + # sound_play (sndbuff_book_flip) + obj = cont.owner + name_fct = scene.objects['Doc_chap-missions']['page_fct'] + if name_fct !="": + mission_select=scene.objects[name_fct]['mission'] + if mission_select <= scene.objects['Points']['level'] and mission_select != scene.objects['Points']['mission']: + scene.objects["mission_"+str(scene.objects['Points']['mission'])+"-card"].color = color_doc_fct + scene.objects["mission_"+str(scene.objects['Points']['mission'])+"-card-icon"].color = color_doc_fct + scene.objects["mission_"+str(scene.objects['Points']['mission'])+"-card-text"].color = color_doc_fct + print ("Sélectionner le niveau :", str(mission_select)) + scene.objects['Points']['mission'] = mission_select + scene.objects['Points-Map-text']['Text']="Mission "+str(scene.objects['Points']['mission']) + scene.objects['Book_mission']['Text'] = "Mission en cours : "+str(scene.objects['Points']['mission']) + scene.objects['Book_level_button'].setVisible(False,True) + ## # Sounds ## diff --git a/rp_lib.py b/rp_lib.py index 7ba26f7..bdd44fd 100644 --- a/rp_lib.py +++ b/rp_lib.py @@ -9,6 +9,8 @@ import math import mathutils import random +import rp_map1 as rp_map # Map definition + ############################################################################### # rp_lib.py # @title: Bibliothèque du Rover Ropy (rp_*) @@ -234,7 +236,7 @@ def rp_avancer (): rp_tempo (0.1) # Contrôle objectif - if [x1,y1] in scene.objects['Terrain']['map_aim']: + if rp_map.objectif_control(x1,y1): print ("Goal !!") rover_goal () obj['stop'] = True @@ -292,11 +294,11 @@ def rp_avancer (): rp_tempo (0.1) # Contrôle objectif - if [x1,y1] in scene.objects['Terrain']['map_aim']: + if rp_map.objectif_control(x1,y1): print ("Goal !!") rover_goal () obj['stop'] = True - + return True ## diff --git a/rp_map1.py b/rp_map1.py index 705a2fa..d6af0cc 100644 --- a/rp_map1.py +++ b/rp_map1.py @@ -23,18 +23,15 @@ scene = bge.logic.getCurrentScene() missions_card_description ={} missions_conf ={} - ############################################################################### - # Initialisation du niveau : - # Niveau 0 : Vide - # Niveau 1 : Les premiers pas de Ropy - # Niveau 2 : Sécuriser Ropy - # Niveau 3 : Partir au bout du monde - # Niveau 4 : Faire face à l'inconnu - # Niveau 5 : Se rendre utile - ############################################################################### - - # rp_niveau (1) # Saisir le niveau (de 0 à 5) - # ropy_init.main() # Initialisation de la scène 3D +############################################################################### +# Initialisation du niveau : +# Niveau 1 : Les premiers pas de Ropy +# Niveau 2 : Ma première fonction +# Niveau 3 : Sécuriser Ropy +# Niveau 4 : Partir au bout du monde +# Niveau 5 : Faire face à l'inconnu +# Niveau 6 : Se rendre utile +############################################################################### missions_card=["mission_1-card", "mission_2-card", "mission_3-card", "mission_4-card", "mission_5-card", "mission_6-card"] # missions_card=["mission_1-card", "mission_2-card", "mission_3-card", "mission_4-card", "mission_5-card", "mission_6-card", "mission_7-card", "mission_8-card"] @@ -64,7 +61,7 @@ mission_3_title="Mission 3\n Apprendre le danger" mission_3_text="\n \n Tout d'abords, il faut provoquer une \n collision avec un obstacle (pente \n ou station) et observer ce qui se \n passe.\n \n" mission_3_text= mission_3_text + " Il faut donc sécuriser Ropy en utilisant \n une structure alternative. \n -> Voir onglet Python, page \"Si alors\" \n -> Voir onglet Rover, page \"Détecter\" \n \n" mission_3_init=[-11.0,3.0, "e"] # Rover init position (x,y), orientation ("n|s|e|w") -mission_3_aim=[] # Aim position (x,y) +mission_3_aim=[100.0,100.0] # Aim caché missions_card_description.update({"mission_3-card" : [mission_3_title, mission_3_text]}) missions_conf.update({"3" : [mission_3_init, mission_3_aim]}) @@ -72,8 +69,8 @@ missions_conf.update({"3" : [mission_3_init, mission_3_aim]}) mission_4_title="Mission 4\n Partir au bout du monde" mission_4_text="\n \n Ropy est maintenant prêt pour \n l'aventure soit atteindre la case \n du nouvel objectif (loin, très loin ...). \n \n Pour un tel voyage, l'utilisation \n d'une boucle s'impose. \n" mission_4_text= mission_4_text +" -> Voir onglet Python, page \"Boucle\" \n \n \n \n \n" -mission_4_init=[-11.0,3.0, "e"] # Rover init position (x,y), orientation ("n|s|e|w") -mission_4_aim=[9.0,11.0] # Aim position (x,y) +mission_4_init=[-7.0,4.0, "s"] # Rover init position (x,y), orientation ("n|s|e|w") +mission_4_aim=[12.0,9.0] # Aim position (x,y) missions_card_description.update({"mission_4-card" : [mission_4_title, mission_4_text]}) missions_conf.update({"4" : [mission_4_init, mission_4_aim]}) @@ -83,8 +80,8 @@ mission_5_text="\n \n La case à atteindre est toujours la \n même, mais le lie mission_5_text= mission_5_text +" Pour pallier à l\'aléatoire, vous \n utiliserez les pentes (obstacle) du \n terrain." mission_5_text= mission_5_text +" Il faudra alors créer une \n fonction avec une boucle \"tant que\" \n qui permet d'avancer jusqu'à un \n obstacle :" mission_5_text= mission_5_text +" \"mrp_avancer_mur()\". \n \n \n" -mission_5_init=[-11.0,3.0, "e"] # Rover init position (x,y), orientation ("n|s|e|w") -mission_5_aim=[9.0,11.0] # Aim position (x,y) +mission_5_init=[-7.0,4.0, "s"] # Rover init position (x,y), orientation ("n|s|e|w") +mission_5_aim=[12.0,9.0] # Aim position (x,y) missions_card_description.update({"mission_5-card" : [mission_5_title, mission_5_text]}) missions_conf.update({"5" : [mission_5_init, mission_5_aim]}) @@ -92,7 +89,7 @@ missions_conf.update({"5" : [mission_5_init, mission_5_aim]}) mission_6_title="Mission 6\n Se rendre utile" mission_6_text="\n \n Une zone précise du terrain présente \n des pierres à analyser. \n \n Elles apparaissent de manière \n aléatoire (encore ...), pour les \n ramasser, Ropy doit passer sur toutes \n les cases de la zone. \n \n \n \n \n \n \n" mission_6_init=[-11.0,3.0, "e"] # Rover init position (x,y), orientation ("n|s|e|w") -mission_6_aim=[9.0,11.0] # Aim position (x,y) +mission_6_aim=[9.0,11.0] # Aim position (x,y) # FIXME plusieurs objectifs avec des positions aléatoires missions_card_description.update({"mission_6-card" : [mission_6_title, mission_6_text]}) missions_conf.update({"6" : [mission_6_init, mission_6_aim]}) @@ -149,12 +146,8 @@ def map_init(): def map_reset(): scene.objects['Points']['step']=0 scene.objects['Points']['nbligne']=0 - scene.objects['Points']['level'] = 1 - - # Mission - if scene.objects['Terrain']['mission_current']==1: - mission_init= mission_1_init - mission_aim= mission_1_aim + mission_init = missions_conf[str(scene.objects['Points']['mission'])][0] + mission_aim = missions_conf[str(scene.objects['Points']['mission'])][1] # Cacher les balises for i in range (100): @@ -184,6 +177,31 @@ def map_reset(): obj_aim.worldPosition.y = mission_aim[1] obj_aim.worldPosition.z = 0.5 + +############################################################################### +# Objectif +############################################################################### + +def aim_show(): + if scene.objects['Points']['mission']==3 : + scene.objects['Map_aim'].setVisible(False,True) + else: + scene.objects['Map_aim'].setVisible(True,True) + +def aim_hide(): + scene.objects['Map_aim'].setVisible(False,True) + +def objectif_control(x,y): + if scene.objects['Points']['mission']==3: + return False + else: + if [x,y] in scene.objects['Terrain']['map_aim']: + return True + else: + return False + return False + + ############################################################################### # Fonction bas niveau ###############################################################################