diff --git a/ropy-16.blend b/ropy-16.blend index cfa4d73..fd1b99a 100644 Binary files a/ropy-16.blend and b/ropy-16.blend differ diff --git a/rp.py b/rp.py index 474c6e1..717318d 100644 --- a/rp.py +++ b/rp.py @@ -95,19 +95,29 @@ ACTIVATE = bge.logic.KX_INPUT_ACTIVE def points_maj (cont): - # Texte - scene.objects['Points-Step-text']['Text']=str(scene.objects['Points']['step']) - scene.objects['Points-Level-text']['Text']=str(scene.objects['Points']['level']) - scene.objects['Points-Nbligne-text']['Text']=str(scene.objects['Points']['nbligne']) + # Step + if scene.objects['Points-Step-text']['Text']!= str(scene.objects['Points']['step']): + scene.objects['Points-Step-text']['Text']=str(scene.objects['Points']['step']) + + # Level + if scene.objects['Points-Level-text']['Text']!=str(scene.objects['Points']['level']): + scene.objects['Points-Level-text']['Text']=str(scene.objects['Points']['level']) + + # Maj du fichier de config (sound : data/mission/level -> [1][1].text) lors d'une augmentation de niveau + if scene.objects['Points']['level']>int(rp_config_tree[1][1].text): + rp_config_tree[1][1].text=str(scene.objects['Points']['level']) + buffer_xml = ET.tostring(rp_config_tree) + with open("rp_config.xml", "wb") as f: + f.write(buffer_xml) + + # Nbligne + if scene.objects['Points-Nbligne-text']['Text']!=str(scene.objects['Points']['nbligne']): + scene.objects['Points-Nbligne-text']['Text']=str(scene.objects['Points']['nbligne']) # Position du rover obj=scene.objects['Rover'] - # print ("Rover position :", obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z) obj['position']=str(obj.worldPosition.x)+","+str(obj.worldPosition.y)+","+str(obj.worldPosition.z) - # Fin de la mission - # FIXME - ############################################################################### # Terrain ############################################################################### diff --git a/rp_cmd.py b/rp_cmd.py index a82290a..a9c4e00 100644 --- a/rp_cmd.py +++ b/rp_cmd.py @@ -30,53 +30,24 @@ def mrp_avancer(): ############################################################################### def commandes(): - # rp_niveau (1) # Saisir le niveau (de 1 à 5) print("Go !!") + rp_marquer() rp_gauche() mrp_avancer() rp_droite() - - mrp_avancer() - mrp_avancer() - mrp_avancer() - mrp_avancer() - # mrp_avancer() - - rp_droite() + mrp_avancer() + mrp_avancer() mrp_avancer() mrp_avancer() rp_droite() + + mrp_avancer() + mrp_avancer() mrp_avancer() - - # rp_droite() - - # mrp_avancer() - - # rp_droite() - # mrp_avancer() - # mrp_avancer() - # mrp_avancer() - - # rp_droite() - # mrp_avancer() - # mrp_avancer() - # mrp_avancer() - # mrp_avancer() - - # rp_droite() - # mrp_avancer() - # mrp_avancer() - # mrp_avancer() - - # mrp_avancer() - # mrp_avancer() - # mrp_avancer() - # mrp_avancer() - rp_fin() diff --git a/rp_config.xml b/rp_config.xml index 372b744..4b2f796 100644 --- a/rp_config.xml +++ b/rp_config.xml @@ -1,15 +1,15 @@ 4.0 - False + True - -5.5672173500061035 - -15.25645923614502 - 13.960037231445312 + -6.888219356536865 + -9.308107376098633 + 10.550951957702637 - 3 - 6 + 2 + 3 \ No newline at end of file diff --git a/rp_doc.py b/rp_doc.py index 8fa7a41..f448141 100644 --- a/rp_doc.py +++ b/rp_doc.py @@ -68,7 +68,7 @@ card_description.update({"tourner-card" : [rp_tourner_title, rp_tourner_text]}) # Baliser rp_baliser_title="Baliser" -rp_baliser_text=" rp_marquer() \n -> Place une balise sur la case." +rp_baliser_text=" rp_marquer() \n -> Place une balise sur la case. \n \n Ropy possède que 150 balises, \n il ne peut pas en poser plus." card_description.update({"baliser-card" : [rp_baliser_title, rp_baliser_text]}) # Prendre @@ -112,7 +112,7 @@ rp_alternative_text=rp_alternative_text + " instruction_2\n \n" rp_alternative_text=rp_alternative_text + "Le sinon (\"else\") est facultatif. \n\n" card_description.update({"alternative-card" : [rp_alternative_title, rp_alternative_text]}) -# Boucle +# Boucles rp_boucle_title="Boucles" rp_boucle_text=" Il y a deux types de boucle : \n - avec \"for\" pour définir un nombre \n de répétition (ici N), \n - avec \"while\" (tant que) pour \n prendre en compte une condition. \n \n" rp_boucle_text=rp_boucle_text + " for i in range (n) : \n instruction \n \n" diff --git a/rp_lib.py b/rp_lib.py index bdd44fd..c9a1333 100644 --- a/rp_lib.py +++ b/rp_lib.py @@ -235,13 +235,6 @@ def rp_avancer (): obj.worldPosition=[x0-1, y0, z0] rp_tempo (0.1) - # Contrôle objectif - if rp_map.objectif_control(x1,y1): - print ("Goal !!") - rover_goal () - obj['stop'] = True - return True - # FIXME : Animation sacadée # step =1/100 # print (obj.worldOrientation.to_euler().z) @@ -260,45 +253,43 @@ def rp_avancer (): # rp_tempo (0.1*step) # Animation - # obj['avancer_anim']=True - start = 1 - end = 100 - layer = 0 - priority = 1 - blendin = 1.0 - mode = bge.logic.KX_ACTION_MODE_PLAY - layerWeight = 0.0 - ipoFlags = 0 - speed = scene.objects['Commands']['speed']*4 - if round(obj.worldOrientation.to_euler().z, 2) == 0.00: # Sud - obj.playAction('Rover-Avancer-Y-', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - # obj.worldPosition=[x0, y0-step*i, z0] - if round(obj.worldOrientation.to_euler().z, 2) == round(math.pi,2) or round(obj.worldOrientation.to_euler().z, 2) == - round(math.pi,2) : # Nord - obj.playAction('Rover-Avancer-Y+', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - # obj.worldPosition=[x0, y0+step*i, z0] - if round(obj.worldOrientation.to_euler().z, 2) == round(math.pi/2,2) or round(obj.worldOrientation.to_euler().z, 2) == -round(3*(math.pi/2),2) : # Est - obj.playAction('Rover-Avancer-X+', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - # obj.worldPosition=[x0+step*i, y0, z0] - if round(obj.worldOrientation.to_euler().z, 2) == round(-math.pi/2,2) or round(obj.worldOrientation.to_euler().z, 2) == round(3*(math.pi/2),2) : # Ouest - obj.playAction('Rover-Avancer-X-', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - # obj.worldPosition=[x0-step*i, y0, z0] - scene.objects['Wheel-right-front'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['Wheel-right-mid'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['Wheel-right-rear'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['Wheel-left-front'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['Wheel-left-mid'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['Wheel-left-rear'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - while scene.objects['Wheel-right-front'].isPlayingAction(): # Forçage du redraw - # scene.objects['Camera'].applyMovement((0, 0, 0), True) - scene.objects['Sun'].applyMovement((0, 0, 0), True) - rp_tempo (0.1) + if scene.objects['Commands']['speed'] != 10: + # obj['avancer_anim']=True + start = 1 + end = 100 + layer = 0 + priority = 1 + blendin = 1.0 + mode = bge.logic.KX_ACTION_MODE_PLAY + layerWeight = 0.0 + ipoFlags = 0 + speed = scene.objects['Commands']['speed']*4 + if round(obj.worldOrientation.to_euler().z, 2) == 0.00: # Sud + obj.playAction('Rover-Avancer-Y-', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + # obj.worldPosition=[x0, y0-step*i, z0] + if round(obj.worldOrientation.to_euler().z, 2) == round(math.pi,2) or round(obj.worldOrientation.to_euler().z, 2) == - round(math.pi,2) : # Nord + obj.playAction('Rover-Avancer-Y+', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + # obj.worldPosition=[x0, y0+step*i, z0] + if round(obj.worldOrientation.to_euler().z, 2) == round(math.pi/2,2) or round(obj.worldOrientation.to_euler().z, 2) == -round(3*(math.pi/2),2) : # Est + obj.playAction('Rover-Avancer-X+', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + # obj.worldPosition=[x0+step*i, y0, z0] + if round(obj.worldOrientation.to_euler().z, 2) == round(-math.pi/2,2) or round(obj.worldOrientation.to_euler().z, 2) == round(3*(math.pi/2),2) : # Ouest + obj.playAction('Rover-Avancer-X-', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + # obj.worldPosition=[x0-step*i, y0, z0] + scene.objects['Wheel-right-front'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-right-mid'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-right-rear'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-left-front'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-left-mid'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-left-rear'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + while scene.objects['Wheel-right-front'].isPlayingAction(): # Forçage du redraw + # scene.objects['Camera'].applyMovement((0, 0, 0), True) + scene.objects['Sun'].applyMovement((0, 0, 0), True) + rp_tempo (0.1) # Contrôle objectif if rp_map.objectif_control(x1,y1): - print ("Goal !!") - rover_goal () - obj['stop'] = True - + rover_goal () return True ## @@ -403,8 +394,7 @@ def rp_marquer (): return False # Points et console - print ("rp_marquer()") - scene.objects['Points']['step'] +=1 + print ("rp_marquer(), balise #"+ str(len(scene.objects['Terrain']['map_tile_beacon']))) rp_tempo (0.1) x = obj.worldPosition.x y = obj.worldPosition.y @@ -415,18 +405,18 @@ def rp_marquer (): print ("Case déjà marquée !") return False - for i in range (100): + for i in range (150): beacon = scene.objects["Beacon-"+str(i)] if beacon['activated']==False: beacon.worldPosition=[x,y,0.2] beacon['activated']=True beacon.setVisible(True, True) + scene.objects['Terrain']['map_tile_beacon'].append([x,y]) break - if i ==99 : + if i ==149 : print ("Plus de balise disponible !") # beacon= scene.addObject("Beacon", scene.objects['Terrain']) # beacon.worldPosition=[x,y,0.2] - scene.objects['Terrain']['map_tile_beacon'].append([x,y]) rp_tempo (0.1) return True @@ -560,6 +550,8 @@ def rover_colision_station (): def rover_goal (): obj=scene.objects['Rover'] + print ("Goal !!") + obj['stop'] = True # Animation start = 1 @@ -594,7 +586,12 @@ def rover_goal (): while scene.objects['Wheel-right-front'].isPlayingAction(): # Forçage du redraw scene.objects['Sun'].applyMovement((0, 0, 0), True) rp_tempo (0.1) - return True + + # Level + print ("scene.objects['Points']['mission'] :", scene.objects['Points']['mission']) + print ("scene.objects['Points']['level'] :", scene.objects['Points']['level']) + if scene.objects['Points']['mission']==scene.objects['Points']['level']: + scene.objects['Points']['level']+=1 def map_aim_near (cont): pass diff --git a/rp_map1.py b/rp_map1.py index d6af0cc..e9d3d90 100644 --- a/rp_map1.py +++ b/rp_map1.py @@ -51,8 +51,8 @@ missions_conf.update({"1" : [mission_1_init, mission_1_aim]}) # Mission 2 mission_2_title="Mission 2\n Ma première fonction" mission_2_text= "\n \n Pour faciliter le codage, vous allez \n créer la fonction \"mrp_avancer()\" \n regroupant avancer et marquer. \n -> Voir onglet Python, page \"Fonction\"." -mission_2_init=[-11.0,3.0, "e"] # Rover init position (x,y), orientation ("n|s|e|w") -mission_2_aim=[-7.0,2.0] # Aim position (x,y) +mission_2_init=[-11.0,3.0, "e"] +mission_2_aim=[-7.0,2.0] missions_card_description.update({"mission_2-card" : [mission_2_title, mission_2_text]}) missions_conf.update({"2" : [mission_2_init, mission_2_aim]}) @@ -69,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=[-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) +mission_4_init=[-7.0,4.0, "s"] +mission_4_aim=[12.0,9.0] missions_card_description.update({"mission_4-card" : [mission_4_title, mission_4_text]}) missions_conf.update({"4" : [mission_4_init, mission_4_aim]}) @@ -80,16 +80,16 @@ 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=[-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) +mission_5_init=[-7.0,4.0, "s"] # FIXME position aléatoire +mission_5_aim=[12.0,9.0] missions_card_description.update({"mission_5-card" : [mission_5_title, mission_5_text]}) missions_conf.update({"5" : [mission_5_init, mission_5_aim]}) # Mission 6 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) # FIXME plusieurs objectifs avec des positions aléatoires +mission_6_init=[-7.0,4.0, "s"] # FIXME position aléatoire +mission_6_aim=[9.0,11.0] # 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]}) @@ -182,23 +182,60 @@ def map_reset(): # Objectif ############################################################################### +## +# Afficher l'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) +## +# Cacher l'objectif +## + def aim_hide(): scene.objects['Map_aim'].setVisible(False,True) +## +# Validation de l'objectif atteint +## + def objectif_control(x,y): + + # Mission 1 + if scene.objects['Points']['mission']==1: + if [x,y] in scene.objects['Terrain']['map_aim']: # Aim + if len(scene.objects['Terrain']['map_tile_beacon'])>=6: # 6 balises posées mini + return True + + # Mission 2 (fonction) + if scene.objects['Points']['mission']==2: + if [x,y] in scene.objects['Terrain']['map_aim']: # Aim + if len(scene.objects['Terrain']['map_tile_beacon'])>=6: # 6 balises posées mini + if scene.objects['Points']['nbligne'] <=40: # 40 lignes de code maxi + txt=["def mrp_avancer():", "def mrp_avancer() :", "def mrp_avancer ():", "def mrp_avancer () :"] + if rp_cmd_txtcount(txt): + return True + + # Mission 3 (structure alternative) if scene.objects['Points']['mission']==3: return False - else: - if [x,y] in scene.objects['Terrain']['map_aim']: - return True - else: - return False + + # Mission 4 (boucle en for) + if scene.objects['Points']['mission']==4: + return False + + # Mission 5 (boucle en while) + if scene.objects['Points']['mission']==5: + return False + + # Mission 6 (passer sur tout le terrain) + if scene.objects['Points']['mission']==6: + return False + return False @@ -206,6 +243,27 @@ def objectif_control(x,y): # Fonction bas niveau ############################################################################### +## +# Recherche de texte dans le script +## + +def rp_cmd_txtcount (text_list): + # print (os.getcwd()) + file = open('rp_cmd.py', 'r') + file_txt = file.read() + print (file_txt) + for text in text_list: + # print ("text :", text) + # print ("file_txt.count (text) :", file_txt.count (text)) + if file_txt.count (text) >0: + # print ("Recherche de ",text," dans le script 'rp_cmd.py' -> True") + file.close() + return True + # else: + # print ("Recherche de ",text," dans le script 'rp_cmd.py' -> False") + file.close() + return False + ## # Atteindre une orientation ##