2022-08-14 08:03:07 +02:00
import bge # Bibliothèque Blender Game Engine (UPBGE)
import bpy # Blender
2022-08-22 04:41:22 +02:00
from rp_lib import * # Bibliothèque Ropy
2022-08-14 08:03:07 +02:00
import os
###############################################################################
# rp_map1.py
# @title: Carte 1 pour Ropy
# @project: Ropy (Blender-EduTech)
# @lang: fr
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
# @copyright: Copyright (C) 2020-2022 Philippe Roy
# @license: GNU GPL
#
###############################################################################
scene = bge . logic . getCurrentScene ( )
2022-08-24 14:12:23 +02:00
###############################################################################
# Missions
###############################################################################
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
2022-09-14 21:58:33 +02:00
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"]
2022-08-24 14:12:23 +02:00
# Mission 1
mission_1_title = " Mission 1 \n Premiers pas "
2022-09-14 21:58:33 +02:00
mission_1_text = " \n \n Il faut aider Ropy à atteindre la \n case de l ' objectif (à l ' est de la \n station). \n \n Afin de visualiser le trajet, il \n audra marquer les cases. "
2022-08-24 14:12:23 +02:00
mission_1_init = [ - 11.0 , 3.0 , " e " ] # Rover init position (x,y), orientation ("n|s|e|w")
mission_1_aim = [ - 7.0 , 2.0 ] # Aim position (x,y)
2022-09-14 21:58:33 +02:00
missions_card_description . update ( { " mission_1-card " : [ mission_1_title , mission_1_text ] } )
2022-08-24 14:12:23 +02:00
missions_conf . update ( { " 1 " : [ mission_1_init , mission_1_aim ] } )
# Mission 2
2022-09-14 21:58:33 +02:00
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)
2022-08-24 14:12:23 +02:00
missions_card_description . update ( { " mission_2-card " : [ mission_2_title , mission_2_text ] } )
2022-09-14 21:58:33 +02:00
missions_conf . update ( { " 2 " : [ mission_2_init , mission_2_aim ] } )
2022-08-24 14:12:23 +02:00
# Mission 3
2022-09-14 21:58:33 +02:00
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 \n utilisant 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)
2022-08-24 14:12:23 +02:00
missions_card_description . update ( { " mission_3-card " : [ mission_3_title , mission_3_text ] } )
2022-09-14 21:58:33 +02:00
missions_conf . update ( { " 3 " : [ mission_3_init , mission_3_aim ] } )
2022-08-24 14:12:23 +02:00
# Mission 4
2022-09-14 21:58:33 +02:00
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 \" "
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)
2022-08-24 14:12:23 +02:00
missions_card_description . update ( { " mission_4-card " : [ mission_4_title , mission_4_text ] } )
2022-09-14 21:58:33 +02:00
missions_conf . update ( { " 4 " : [ mission_4_init , mission_4_aim ] } )
2022-08-24 14:12:23 +02:00
# Mission 5
2022-09-14 21:58:33 +02:00
mission_5_title = " Mission 5 \n Faire face à l ' inconnu "
mission_5_text = " \n \n La case à atteindre est toujours \n la même, mais le lieu de départ \n change à chaque fois. \n \n "
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)
2022-08-24 14:12:23 +02:00
missions_card_description . update ( { " mission_5-card " : [ mission_5_title , mission_5_text ] } )
2022-09-14 21:58:33 +02:00
missions_conf . update ( { " 5 " : [ mission_5_init , mission_5_aim ] } )
2022-08-24 14:12:23 +02:00
# Mission 6
2022-09-14 21:58:33 +02:00
mission_6_title = " Mission 6 \n Se rendre utile "
mission_6_text = " \n \n Le terrain sur une zone précise \n présente des pierres à analyser. \n \n Pour les ramasser, Ropy doit passer \n sur toutes 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)
2022-08-24 14:12:23 +02:00
missions_card_description . update ( { " mission_6-card " : [ mission_6_title , mission_6_text ] } )
2022-09-14 21:58:33 +02:00
missions_conf . update ( { " 6 " : [ mission_6_init , mission_6_aim ] } )
2022-08-24 14:12:23 +02:00
# Mission 7
2022-09-14 21:58:33 +02:00
# 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]})
# missions_conf.update({"7" : [mission_7_init, mission_7_aim]})
2022-08-24 14:12:23 +02:00
# Mission 8
2022-09-14 21:58:33 +02:00
# 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]})
# missions_conf.update({"8" : [mission_8_init, mission_8_aim]})
2022-08-24 14:12:23 +02:00
# Description des cartes missions
def get_missions_card ( ) :
return missions_card
def get_card_description ( ) :
return missions_card_description
2022-08-14 08:03:07 +02:00
###############################################################################
# Map
###############################################################################
# Initialization
def map_init ( ) :
2022-08-26 01:58:49 +02:00
scene . objects [ ' Terrain ' ] [ ' map_tile_montain ' ] = [ [ - 6 , 11 ] , [ - 6 , 10 ] , [ - 7 , 10 ] , [ - 8 , 10 ] , [ - 9 , 10 ] , [ - 10 , 10 ] , [ - 11 , 10 ] , [ - 12 , 10 ] ]
scene . objects [ ' Terrain ' ] [ ' map_tile_colony ' ] = [ ]
2022-08-14 08:03:07 +02:00
# Landscape
# file_path = 'asset/map/map1-landscape.blend'
# inner_path = 'Object'
# object_name = 'Landscape'
# bpy.ops.wm.append(
# filepath=os.path.join(file_path, inner_path, object_name),
# directory=os.path.join(file_path, inner_path),
# filename=object_name)
2022-08-24 14:12:23 +02:00
# Reset de la map
2022-08-14 08:03:07 +02:00
def map_reset ( ) :
scene . objects [ ' Points ' ] [ ' step ' ] = 0
scene . objects [ ' Points ' ] [ ' nbligne ' ] = 0
2022-09-14 21:58:33 +02:00
scene . objects [ ' Points ' ] [ ' level ' ] = 1
2022-08-26 01:58:49 +02:00
2022-08-24 14:12:23 +02:00
# Mission
if scene . objects [ ' Terrain ' ] [ ' mission_current ' ] == 1 :
mission_init = mission_1_init
mission_aim = mission_1_aim
2022-08-22 04:41:22 +02:00
2022-08-26 01:58:49 +02:00
# Cacher les balises
for i in range ( 100 ) :
beacon = scene . objects [ " Beacon- " + str ( i ) ]
beacon . worldPosition = [ 29 , 1 + i , 0.2 ]
beacon . setVisible ( False , True )
beacon [ ' activated ' ] = False
scene . objects [ ' Terrain ' ] [ ' map_tile_beacon ' ] = [ ]
2022-08-24 14:12:23 +02:00
# Initialisation du rover
obj = scene . objects [ ' Rover ' ]
obj . worldPosition . x = mission_init [ 0 ]
obj . worldPosition . y = mission_init [ 1 ]
2022-08-30 03:25:36 +02:00
obj . worldPosition . z = 0.25
2022-08-24 14:12:23 +02:00
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 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
###############################################################################
# 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)