diff --git a/ropy-07.blend b/ropy-07.blend
index c75c328..f1d624f 100644
Binary files a/ropy-07.blend and b/ropy-07.blend differ
diff --git a/rp.py b/rp.py
index 82a50df..2f4c84f 100644
--- a/rp.py
+++ b/rp.py
@@ -11,8 +11,8 @@ import threading # Multithreading
import xml.etree.ElementTree as ET # Creating/parsing XML file
import runpy
-import rp_map1 as rp_map # waves script
-import rp_doc # documentation
+import rp_map1 as rp_map # Map definition
+import rp_doc # Documentation
# import ct_cmd # user script (commands)
###############################################################################
@@ -144,6 +144,7 @@ def terrain_init ():
eevee.use_eevee_smaa = True
# Init de la carte
+ scene.objects['Map_aim'].setVisible(False,True)
rp_map.map_init()
rp_map.map_reset()
@@ -181,7 +182,7 @@ def terrain_run ():
# Démarrage de la map
if scene.objects['Terrain']['thread_cmd']==False:
scene.objects['Terrain']['thread_cmd']=True
- rp_map.map_reset() # Mise à zéro des compteurs
+ rp_map.map_reset()
runpy.run_module('rp_cmd', run_name='start') # Execution du script utilisateur
# Arrêt de la pause
@@ -195,6 +196,7 @@ def terrain_run ():
def terrain_stop ():
scene.objects['Terrain']['thread_cmd']=False
+ rp_map.map_reset()
##
# Fin naturelle du cycle
@@ -240,22 +242,22 @@ def terrain_speed (obj):
##
def terrain_grid ():
- # pass
if scene.objects['Grid-u'].visible:
scene.objects['Grid-u'].setVisible(False,True)
scene.objects['Grid-v'].setVisible(False,True)
+ scene.objects['Map_aim'].setVisible(False,True)
else:
- scene.objects['Grid-u']['timer'] = 0.3
+ scene.objects['Grid-u']['timer'] = 0.2
bpy.data.materials["Grid"].node_tree.nodes["Emission"].inputs[1].default_value =scene.objects['Grid-u']['timer']
- # bpy.data.materials["Grid"].node_tree.nodes["Emission"].inputs[1].default_value =0.3
scene.objects['Grid-u'].setVisible(True,True)
scene.objects['Grid-v'].setVisible(True,True)
+ scene.objects['Map_aim'].setVisible(True,True)
scene.objects['Grid-u']['anim'] = True
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']== 2:
+ if scene.objects['Grid-u']['timer']>= 1:
scene.objects['Grid-u']['anim'] = False
###############################################################################
@@ -320,7 +322,7 @@ def cmd_init():
scene.objects['Pause'].suspendPhysics()
scene.objects['Pause-Hl'].setVisible(False,False)
scene.objects['Stop-Hl'].setVisible(False,False)
- scene.objects['Objective-Hl'].setVisible(False,False)
+ scene.objects['Aim-Hl'].setVisible(False,False)
scene.objects['Doc-cmd-Hl'].setVisible(False,False)
scene.objects['ResetView-Hl'].setVisible(False,False)
scene.objects['About-cmd-Hl'].setVisible(False,False)
@@ -410,7 +412,7 @@ def cmd_hl(cont):
text_hl ={"Run":"Exécuter (F5)",
"Stop":"Stop et initialisation (F6)",
"Pause":"Pause (F5)",
- "Objective":"Afficher/cacher l'objectif",
+ "Aim":"Afficher/cacher l'objectif",
"Doc-cmd":"Documentation",
"ResetView": "Reset de la vue (Touche Début)",
"About-cmd": "A propos",
@@ -421,7 +423,7 @@ def cmd_hl(cont):
# text_hl ={"Run":"Run (F5)",
# "Stop":"Stop (F6)",
# "Pause":"Pause (F5)",
- # "Distance":"Show objective",
+ # "Aim":"Show aim",
# "Doc-cmd":"Documentation",
# "ResetView": "Reset view (Home key)",
# "About-cmd": "About",
@@ -478,7 +480,7 @@ def cmd_click (cont):
sound_play (snd_click)
terrain_stop ()
- if obj.name=="Objective":
+ if obj.name=="Aim":
sound_play (snd_grid)
terrain_grid ()
@@ -860,7 +862,7 @@ def tablet_close ():
# scene.objects['Stop'].setVisible(False,False)
# scene.objects['Stop'].suspendPhysics()
scene.objects['Stop-Hl'].setVisible(False,False)
- scene.objects['Objective-Hl'].setVisible(False,False)
+ scene.objects['Aim-Hl'].setVisible(False,False)
scene.objects['Doc-cmd-Hl'].setVisible(False,False)
scene.objects['ResetView-Hl'].setVisible(False,False)
scene.objects['About-cmd-Hl'].setVisible(False,False)
diff --git a/rp_cmd.py b/rp_cmd.py
index cc18a5b..affb7cf 100644
--- a/rp_cmd.py
+++ b/rp_cmd.py
@@ -19,12 +19,18 @@ from rp_lib import * # Bibliothèque Ropy
def commands():
print("Go !!")
- rp_sleep (0.5)
rp_gauche()
- rp_sleep (0.5)
+ rp_avancer()
+ rp_droite()
+ rp_avancer()
+ rp_avancer()
+ rp_avancer()
+ rp_avancer()
+ rp_droite()
+ rp_avancer()
rp_avancer()
- rp_sleep (2)
+
rp_fin()
###############################################################################
diff --git a/rp_config.xml b/rp_config.xml
index 595e299..d413f15 100644
--- a/rp_config.xml
+++ b/rp_config.xml
@@ -3,13 +3,13 @@
0.25
True
- 0.0057830810546875
- -26.440298080444336
- 20.22315788269043
+ -8.529211044311523
+ -2.480304479598999
+ 4.401391983032227
- 3
- 1
+ 1
+ 0
\ No newline at end of file
diff --git a/rp_doc.py b/rp_doc.py
index 59f6b01..cc3c30a 100644
--- a/rp_doc.py
+++ b/rp_doc.py
@@ -1,5 +1,6 @@
import bge # Bibliothèque Blender Game Engine (UPBGE)
import aud # Sounds
+import rp_map1 # Map definition
###############################################################################
# rp_doc.py
@@ -43,71 +44,9 @@ ACTIVATE = bge.logic.KX_INPUT_ACTIVE
# Cards description
card_description ={}
-###############################################################################
# Missions
-###############################################################################
-
- # ###############################################################################
- # # 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
-
-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"]
-
-# Mission 1
-rp_mission_1_title="Mission 1\n Premiers pas"
-rp_mission_1_text="\n \n aa"
-card_description.update({"mission_1-card" : [rp_mission_1_title, rp_mission_1_text]})
-
-# ct_build_text = ct_build_text +" \v- category (string) : \n \v \v- \"Archer tower\" (default value)\n \v \v- \"Mage tower\"\n"
-# ct_build_text = ct_build_text +" \v- name (string)\n \v- color (RGB tuple, default=purple)\n"
-# ct_build_text = ct_build_text +" \v- style (string) : \n \v \v- \"square\" (default value) or \"round\"\n \v \v- version : A (default value), B or C\n \v \v- exemple : 'round-B' \n"
-# ct_build_text = ct_build_text +" \v- Return boolean flag (builded -> True)\n\n"
-# ct_build_text = ct_build_text +"Predefined colors : blue, green, magenta,\n orange, purple, red, turquoise, yellow.\n\n"
-# ct_build_text = ct_build_text +"Exemple : ct_build (1, 1, \"Archer tower\", \n \"Tower #1\", yellow, \"round-A\")\n"
-
-# Mission 2
-rp_mission_2_title="Mission 2\n FIXME"
-rp_mission_2_text="\n \n FIXME"
-card_description.update({"mission_2-card" : [rp_mission_2_title, rp_mission_2_text]})
-
-# Mission 3
-rp_mission_3_title="Mission 3\n FIXME"
-rp_mission_3_text="\n \n FIXME"
-card_description.update({"mission_3-card" : [rp_mission_3_title, rp_mission_3_text]})
-
-# Mission 4
-rp_mission_4_title="Mission 4\n FIXME"
-rp_mission_4_text="\n \n FIXME"
-card_description.update({"mission_4-card" : [rp_mission_4_title, rp_mission_4_text]})
-
-# Mission 5
-rp_mission_5_title="Mission 5\n FIXME"
-rp_mission_5_text="\n \n FIXME"
-card_description.update({"mission_5-card" : [rp_mission_5_title, rp_mission_5_text]})
-
-# Mission 6
-rp_mission_6_title="Mission 6\n FIXME"
-rp_mission_6_text="\n \n FIXME"
-card_description.update({"mission_6-card" : [rp_mission_6_title, rp_mission_6_text]})
-
-# Mission 7
-rp_mission_7_title="Mission 7\n FIXME"
-rp_mission_7_text="\n \n FIXME"
-card_description.update({"mission_7-card" : [rp_mission_7_title, rp_mission_7_text]})
-
-# Mission 8
-rp_mission_8_title="Mission 8\n FIXME"
-rp_mission_8_text="\n \n FIXME"
-card_description.update({"mission_8-card" : [rp_mission_8_title, rp_mission_8_text]})
+card_description.update(rp_map1.get_card_description())
+missions_card=rp_map1.get_missions_card()
###############################################################################
# Rover
diff --git a/rp_lib.py b/rp_lib.py
index bce0aa2..79a193e 100644
--- a/rp_lib.py
+++ b/rp_lib.py
@@ -1,4 +1,4 @@
-+import bge # Blender Game Engine (UPBGE)
+import bge # Blender Game Engine (UPBGE)
import aud # Sounds
import threading # Multithreading
import trace
@@ -18,7 +18,7 @@ import random
# @license: GNU GPL
#
# Bibliothèque des actions du robot
-# Bibliothèque pour la construction des murs
+# Bibliothèque pour la construction des murs
#
# 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.
@@ -61,6 +61,7 @@ color_kaykit_black = (0.019, 0.032, 0.037, 1)
# sndbuff_life = aud.Sound.cache(snd_life)
threads_cmd=[]
+debug_thread = scene.objects['Terrain']['debug_thread']
# UPBGE constants
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
@@ -109,30 +110,37 @@ class thread_with_trace(threading.Thread):
def thread_start(threads, type_txt, fct):
threads.append(thread_with_trace(target = fct))
threads[len(threads)-1].start()
- print ("Thread",type_txt, "#", len(threads)-1, "open.")
+ if (debug_thread):
+ print ("Thread",type_txt, "#", len(threads)-1, "open.")
def thread_stop(threads, type_txt):
i=0
zombie_flag=False
for t in threads:
if not t.is_alive():
- print ("Thread",type_txt, "#",i,"closed.")
+ if (debug_thread):
+ print ("Thread",type_txt, "#",i,"closed.")
else:
- print ("Thread",type_txt, "#",i,"still open ...")
+ if (debug_thread):
+ print ("Thread",type_txt, "#",i,"still open ...")
t.kill()
t.join()
if not t.is_alive():
- print ("Thread",type_txt, "#",i,"killed.")
+ if (debug_thread):
+ print ("Thread",type_txt, "#",i,"killed.")
else:
- print ("Thread",type_txt, "#",i,"zombie...")
+ if (debug_thread):
+ print ("Thread",type_txt, "#",i,"zombie...")
zombie_flag=True
i +=1
if zombie_flag==False:
- print ("All threads",type_txt, "are closed.")
+ if (debug_thread):
+ print ("All threads",type_txt, "are closed.")
scene.objects['Terrain']['thread_cmd']=False
return True
else:
- print ("There are zombies threads",type_txt, ".")
+ if (debug_thread):
+ print ("There are zombies threads",type_txt, ".")
return False
def thread_cmd_start(fct):
@@ -142,8 +150,8 @@ def thread_cmd_stop():
thread_stop(threads_cmd, "commands")
def rp_end():
- rp_sleep (0.5)
- print ("Thread commands is arrived.")
+ if (debug_thread):
+ print ("Thread commands is arrived.")
scene.objects['Terrain']['thread_cmd']=False
def rp_fin():
@@ -185,6 +193,7 @@ def rp_avancer ():
obj.worldPosition=[x0+step, 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.worldPosition=[x0-step, y0, z0]
+ rp_sleep (0.25)
##
# Tourner à gauche
@@ -195,6 +204,7 @@ def rp_gauche ():
step=math.pi/2 # Pas angulaire
obj=scene.objects['Rover']
obj.applyRotation((0, 0, step), True)
+ rp_sleep (0.25)
##
# Tourner à droite
@@ -205,6 +215,7 @@ def rp_droite ():
step=math.pi/2 # Pas angulaire
obj=scene.objects['Rover']
obj.applyRotation((0, 0, -step), True)
+ rp_sleep (0.25)
##
# Marquer
@@ -250,6 +261,20 @@ def rover_radar ():
def rover_colision ():
pass
+###############################################################################
+# Temporisation
+###############################################################################
+
+def rp_sleep (duration):
+ # time.sleep(duration*(1/scene.objects['Terrain']['speed']))
+ time.sleep(duration)
+
+# def ct_tempo (duration):
+# scene.objects['Terrain']['delay_cmd']=0
+# while scene.objects['Terrain']['delay_cmd'] True)\n\n"
+# ct_build_text = ct_build_text +"Predefined colors : blue, green, magenta,\n orange, purple, red, turquoise, yellow.\n\n"
+# ct_build_text = ct_build_text +"Exemple : ct_build (1, 1, \"Archer tower\", \n \"Tower #1\", yellow, \"round-A\")\n"
+
+# Mission 2
+mission_2_title="Mission 2\n FIXME"
+mission_2_text="\n \n FIXME"
+missions_card_description.update({"mission_2-card" : [mission_2_title, mission_2_text]})
+
+# Mission 3
+mission_3_title="Mission 3\n FIXME"
+mission_3_text="\n \n FIXME"
+missions_card_description.update({"mission_3-card" : [mission_3_title, mission_3_text]})
+
+# Mission 4
+mission_4_title="Mission 4\n FIXME"
+mission_4_text="\n \n FIXME"
+missions_card_description.update({"mission_4-card" : [mission_4_title, mission_4_text]})
+
+# Mission 5
+mission_5_title="Mission 5\n FIXME"
+mission_5_text="\n \n FIXME"
+missions_card_description.update({"mission_5-card" : [mission_5_title, mission_5_text]})
+
+# Mission 6
+mission_6_title="Mission 6\n FIXME"
+mission_6_text="\n \n FIXME"
+missions_card_description.update({"mission_6-card" : [mission_6_title, mission_6_text]})
+
+# Mission 7
+mission_7_title="Mission 7\n FIXME"
+mission_7_text="\n \n FIXME"
+missions_card_description.update({"mission_7-card" : [mission_7_title, mission_7_text]})
+
+# Mission 8
+mission_8_title="Mission 8\n FIXME"
+mission_8_text="\n \n FIXME"
+missions_card_description.update({"mission_8-card" : [mission_8_title, mission_8_text]})
+
+# Description des cartes missions
+
+def get_missions_card():
+ return missions_card
+
+def get_card_description():
+ return missions_card_description
+
###############################################################################
# Map
###############################################################################
@@ -35,34 +115,73 @@ def map_init():
# directory=os.path.join(file_path, inner_path),
# filename=object_name)
- # Rover
- # obj=scene.objects['Rover']
- # applyRotationTo(obj, None, None, 0.0, True)
-
-# Reset counters
+# Reset de la map
def map_reset():
scene.objects['Points']['step']=0
scene.objects['Points']['nbligne']=0
- # scene.objects['Points']['lifes']=10
- # scene.objects['Points']['lifes_max']=10
- # scene.objects['Points']['coins']=0
- # scene.objects['Points']['level']=0
- # scene.objects['Points']['level_max']=1
- # scene.objects['Points']['minions']=0
- # scene.objects['Points']['minions_run']=0
- # scene.objects['Points']['wave']=1
+ # Mission
+ if scene.objects['Terrain']['mission_current']==1:
+ mission_init= mission_1_init
+ mission_aim= mission_1_aim
+ # Initialisation du rover
+ obj = scene.objects['Rover']
+ obj.worldPosition.x = mission_init[0]
+ obj.worldPosition.y = mission_init[1]
+ obj.worldPosition.z = 0.2
+ applyRotationTo(obj, 0, 0, 0, True)
+ if mission_init[2] == "n":
+ obj.applyRotation((0, 0, math.pi), True)
+ if mission_init[2] == "e":
+ obj.applyRotation((0, 0, math.pi/2), True)
+ if mission_init[2] == "w":
+ obj.applyRotation((0, 0, -math.pi/2), True)
- # ###############################################################################
- # # 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
- # ###############################################################################
+ # Initialisation des objectifs
+ obj_aim = scene.objects['Map_aim']
+ obj_aim.worldPosition.x = mission_aim[0]
+ obj_aim.worldPosition.y = mission_aim[1]
+ obj_aim.worldPosition.z = 0.5
- # rp_niveau (1) # Saisir le niveau (de 0 à 5)
- # ropy_init.main() # Initialisation de la scène 3D
+# Initialization
+def map_aim_near(cont):
+ print ("Goall !!")
+
+###############################################################################
+# Fonction bas niveau
+###############################################################################
+
+##
+# Atteindre une orientation
+##
+
+def applyRotationTo(obj, rx=None, ry=None, rz=None, Local=True):
+ rres=0.001 # resolution rotation
+
+ # x
+ if rx is not None:
+ while (abs(rx-obj.worldOrientation.to_euler().x) > rres) :
+ if obj.worldOrientation.to_euler().x-rx > rres:
+ obj.applyRotation((-rres, 0, 0), Local)
+ if rx-obj.worldOrientation.to_euler().x > rres:
+ obj.applyRotation((rres, 0, 0), Local)
+ # print ("delta x ",rx-obj.worldOrientation.to_euler().x)
+
+ # y
+ if ry is not None:
+ while (abs(ry-obj.worldOrientation.to_euler().y) > rres) :
+ if obj.worldOrientation.to_euler().y-ry > rres:
+ obj.applyRotation((0, -rres, 0), Local)
+ if ry-obj.worldOrientation.to_euler().y > rres:
+ obj.applyRotation((0, rres, 0), Local)
+ # print ("delta y ",ry-obj.worldOrientation.to_euler().y)
+
+ # z
+ if rz is not None:
+ while (abs(rz-obj.worldOrientation.to_euler().z) > rres) :
+ if obj.worldOrientation.to_euler().z-rz > rres:
+ obj.applyRotation((0, 0, -rres), Local)
+ if rz-obj.worldOrientation.to_euler().z > rres:
+ obj.applyRotation((0, 0, rres), Local)
+ # print ("delta z ",rz-obj.worldOrientation.to_euler().z)