mirror of
https://forge.apps.education.fr/blender-edutech/ropy.git
synced 2024-01-27 08:23:20 +01:00
Passage d'un niveau à l'autre.
This commit is contained in:
parent
8afa1e4703
commit
031bdb4101
BIN
ropy-16.blend
BIN
ropy-16.blend
Binary file not shown.
26
rp.py
26
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
|
||||
###############################################################################
|
||||
|
41
rp_cmd.py
41
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()
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
<data>
|
||||
<config>
|
||||
<speed>4.0</speed>
|
||||
<sound>False</sound>
|
||||
<sound>True</sound>
|
||||
<cam>
|
||||
<worldPosition.x>-5.5672173500061035</worldPosition.x>
|
||||
<worldPosition.y>-15.25645923614502</worldPosition.y>
|
||||
<worldPosition.z>13.960037231445312</worldPosition.z>
|
||||
<worldPosition.x>-6.888219356536865</worldPosition.x>
|
||||
<worldPosition.y>-9.308107376098633</worldPosition.y>
|
||||
<worldPosition.z>10.550951957702637</worldPosition.z>
|
||||
</cam>
|
||||
</config>
|
||||
<mission>
|
||||
<current>3</current>
|
||||
<level>6</level>
|
||||
<current>2</current>
|
||||
<level>3</level>
|
||||
</mission>
|
||||
</data>
|
@ -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"
|
||||
|
95
rp_lib.py
95
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
|
||||
|
84
rp_map1.py
84
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
|
||||
##
|
||||
|
Loading…
Reference in New Issue
Block a user