diff --git a/asset/icons/hud/icon_exit.svg b/asset/icons/hud/icon_exit.svg new file mode 100644 index 0000000..5feac47 --- /dev/null +++ b/asset/icons/hud/icon_exit.svg @@ -0,0 +1,32 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git a/asset/sounds/rp_click.ogg b/asset/sounds/rp_click.ogg new file mode 100644 index 0000000..62de5e4 Binary files /dev/null and b/asset/sounds/rp_click.ogg differ diff --git a/asset/sounds/rp_close.ogg b/asset/sounds/rp_close.ogg new file mode 100644 index 0000000..7340960 Binary files /dev/null and b/asset/sounds/rp_close.ogg differ diff --git a/asset/sounds/rp_grid.ogg b/asset/sounds/rp_grid.ogg new file mode 100644 index 0000000..6b5cd23 Binary files /dev/null and b/asset/sounds/rp_grid.ogg differ diff --git a/asset/sounds/rp_open.ogg b/asset/sounds/rp_open.ogg new file mode 100644 index 0000000..7bf1f24 Binary files /dev/null and b/asset/sounds/rp_open.ogg differ diff --git a/ropy-08.blend b/ropy-08.blend new file mode 100644 index 0000000..210a0a8 Binary files /dev/null and b/ropy-08.blend differ diff --git a/ropy_cmd.py b/ropy_cmd.py deleted file mode 100644 index 4d2c513..0000000 --- a/ropy_cmd.py +++ /dev/null @@ -1,42 +0,0 @@ -import bge # Bibliothèque Blender Game Engine (BGE) -import math # Bibliothèque Math -from ropy_lib import * # Bibliothèque Ropy -import ropy_init # Initialisation du robot Ropy - -############################################################################### -# ropy_cmd.py -# @title: Commandes du Robot Ropy -# @project: Blender-EduTech -############################################################################### - -def main(): - - ############################################################################### - # Récupérer les objets du moteur 3D (BGE) << NE PAS MODIFIER CETTE SECTION >> - ############################################################################### - - scene = bge.logic.getCurrentScene() # Récupérer la scène 3D - cont = bge.logic.getCurrentController() # Récupérer le contrôleur BGE - obj = cont.owner # Récupérer le robot de la scène 3D - obj.visible=False - - ############################################################################### - # 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 - - ############################################################################### - # Fonctions - ############################################################################### - - ############################################################################### - # Commandes - ############################################################################### diff --git a/ropy_init.py b/ropy_init.py deleted file mode 100644 index 26e8a55..0000000 --- a/ropy_init.py +++ /dev/null @@ -1,161 +0,0 @@ -import bge # Bibliothèque Blender Game Engine (BGE) -import random -from ropy_lib import * - -############################################################################### -# ropy_init.py -# @title: Initialisation du Robot Ropy -# @project: Blender-EduTech -# @lang: fr -# @authors: Philippe Roy -# @copyright: Copyright (C) 2020-2022 Philippe Roy -# @license: GNU GPL -# -# Initialisation du Robot -# -# 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. -# -############################################################################### - -def main(): - - ############################################################################### - # Récupérer les objets du moteur 3D (BGE) - ############################################################################### - - scene = bge.logic.getCurrentScene() # Récupérer la scène 3D - cont = bge.logic.getCurrentController() # Récupérer le contrô´leur BGE - obj = cont.owner # Récupérer le robot de la scène 3D - - ############################################################################### - # Initialisation - ############################################################################### - - # niveau = obj['level'] - - # print ("") - # print ("Construction du niveau ...") - - # # Position initiale du robot - # rp_init_position() # zone de 10x10 -> par défaut, au centre case (X,Y) : 5,5 - # rp_orientation("est") # il y a nord, sud, est, ouest - # obj['mvts'] = "" # Liste des mouvements - # obj['mvt_i'] = 0 # Liste des mouvements - # # obj.visible=False - - # # Enlever les murs et les marques - # def_murs=[] - # rp_enlever_marques() - - ############################################################################### - # Construction du niveau - # Zone de 10x10 - # - # Murs : - # Longueur des murs : fixe d' une case - # Position des murs : liste imbriquée : [[mur1_x1,mur1_y1,mur1_x2,mur1_y2],[mur2_x1,mur2_y1,mur2_x2,mur2_y2], ...] - ############################################################################### - - niveau = obj['level'] - - print ("") - print ("Construction du niveau ...") - - # Enlever les murs et les marques - def_murs=[] - rp_enlever_marques() - rp_orientation("est") # il y a nord, sud, est, ouest - - # niveau 0 : Vide (bac à sable élève) - if niveau==0: - def_murs=[] - obj['x_init'] = 5 - obj['y_init'] = 5 - - # niveau 10 : Bac à sable enseignant - if niveau==10: - - # Murs de test - def_murs=[[4,3, 5,3],[4,3, 4,4]] - # def_murs=[[4,3, 4,4]] - # def_murs=[[4,3, 5,3]] - rp_construire_murs(def_murs) - obj['x_init'] = 5 - obj['y_init'] = 5 - - ############################################################################### - # niveau 1 : Mission 1 : Les premiers pas de Ropy - ############################################################################### - - if niveau==1: - - # Petite maison - def_murs=[ - [4,3, 4,4],[4,4, 4,5],[4,5, 4,6], - [4,6, 5,6],[5,6, 6,6],[6,6, 7,6], - [7,5, 7,6],[7,4, 7,5],[7,3, 7,4], - [4,3, 5,3], [6,3, 7,3]] - rp_construire_murs(def_murs) - rp_marquer_objectif (7,2) - obj['x_init'] = 5 - obj['y_init'] = 5 - - ############################################################################### - # Mission 2 : Sécuriser Ropy - ############################################################################### - - if niveau==2: - - # Petite maison - def_murs=[ - [4,3, 4,4],[4,4, 4,5],[4,5, 4,6], - [4,6, 5,6],[5,6, 6,6],[6,6, 7,6], - [7,5, 7,6],[7,4, 7,5],[7,3, 7,4], - [4,3, 5,3], [6,3, 7,3]] - rp_construire_murs(def_murs) - rp_marquer_objectif (7,2) - obj['x_init'] = 5 - obj['y_init'] = 5 - - ############################################################################### - # Mission 3 : Partir au bout du monde - ############################################################################### - - if niveau==3: - def_murs=[] - rp_marquer_objectif (10,10) - obj['x_init'] = 5 - obj['y_init'] = 4 - - ############################################################################### - # Mission 4 : Faire face à l'inconnu - ############################################################################### - - if niveau==4: - def_murs=[] - rp_marquer_objectif (10,10) - obj['x_init'] = random.randint(1,10) - obj['y_init'] = random.randint(1,10) - - ############################################################################### - # Mission 5 : Se rendre utile - ############################################################################### - - if niveau==5: - for i in range (10): - rp_marquer_objectif (random.randint(1,10),random.randint(1,10)) # Position aléatoire des objectifs - def_murs=[] - obj['x_init'] = random.randint(1,10) - obj['y_init'] = random.randint(1,10) - - ############################################################################### - # Position initiale du robot - ############################################################################### - - rp_init_position() - # rp_orientation("est") # il y a nord, sud, est, ouest - obj['mvts'] = "" # Liste des mouvements - obj['mvt_i'] = 0 # Liste des mouvements - # obj.visible=False - diff --git a/ropy_lib.py b/ropy_lib.py deleted file mode 100644 index 98eeab9..0000000 --- a/ropy_lib.py +++ /dev/null @@ -1,373 +0,0 @@ -import bge # Bibliothèque Blender Game Engine (BGE) -import math -import time - -############################################################################### -# ropy_lib.py -# @title: Bibliothèque du Robot Ropy (rp_*) -# @project: Ropy du projet Blender-EduTech -# @lang: fr -# @authors: Philippe Roy -# @copyright: Copyright (C) 2020-2022 Philippe Roy -# @license: GNU GPL -# -# Bibliothèque des actions du robot -# 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. -# -############################################################################### - -# Récupérer l'objet robot - -cont = bge.logic.getCurrentController() -obj = cont.owner -scene = bge.logic.getCurrentScene() -nb_objets_fixes = len(scene.objects) -# print ("Nombre d'objets fixes de la scene : ", nb_objets_fixes) -print("Objets de la scene : ", scene.objects) - -# Configuration des mouvements - -pas=3 # Pas linéaire -pas_rot=math.pi/2 # Pas angulaire - -############################################################################### -# Initialisation de la position du robot -############################################################################### - -# Position initiale du robot -def rp_init_position(): - x = obj['x_init'] - y = obj['y_init'] - obj.worldPosition.x = -((y-4.5)*3)+3 - obj.worldPosition.y = (x-5.5)*3 - obj.worldPosition.z = 1.25 - print('\x1b[6;30;47m', "Placer le robot case (X,Y) :", x, y, '\x1b[0m') - - #MODIF - obj['x'],obj['y'] = x,y - obj['d'] = 1 #est - - # Pile des mouvements - # obj['mvts'] = "" - # obj['mvt_i'] = 0 - - # Répérer le robot détruit - if obj['detruit']: - start = 300 - end = start+75 - layer = 0 - priority = 1 - blendin = 1.0 - mode = bge.logic.KX_ACTION_MODE_PLAY - layerWeight = 0.0 - ipoFlags = 0 - speed = 3 - scene.objects['Armature'].playAction('ArmatureAction.Saut.001', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - # scene.objects['Body'].playAction('BodyAction.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - # scene.objects['Eyes_glass'].playAction('Eyes_glassAction.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - # scene.objects['Mouth'].playAction('MouthAction.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - # scene.objects['Jetpack'].playAction('JetpackAction.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['poignee1'].playAction('poignee1Action.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['poignee2'].playAction('poignee2Action.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['poignee3'].playAction('poignee3Action.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['poignee4'].playAction('poignee4Action.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - obj['detruit']=False - -############################################################################### -# Affichage -############################################################################### - -#Afficher position -def rp_print_position(): - print('\x1b[6;30;42m', "Position case (X,Y) : ", round(-obj.worldPosition.x/3+5.5), round(obj.worldPosition.y/3+5.5), '\x1b[0m') - -############################################################################### -# Moteur physique -# Détection des collisions aves les murs -############################################################################### - -# Détection d'une collision -# rpcore_ : fonction bas niveau -def rpcore_detect_mur(debug_flag=False): - - # Vecteur du mouvement - #MODIF - init_x,init_y = obj['x'],obj['y'] - final_x,final_y = init_x,init_y - direction = obj['d'] - if direction == 0: #nord - final_y+=1 - elif direction == 1: #est - final_x+=1 - elif direction == 2: #sud - final_y-=1 - elif direction == 3: #ouest - final_x-=1 - #init_x = round(obj.worldPosition.y/3+5.5) - #init_y = round(-obj.worldPosition.x/3+5.5) - #obj.applyMovement((0, -pas, 0), True) - #final_x = round(obj.worldPosition.y/3+5.5) - #final_y = round(-obj.worldPosition.x/3+5.5) - #obj.applyMovement((0, pas, 0), True) - - # Calcul du centre du mouvement - mov_xc =init_x + (final_x - init_x)/2-0.5 - mov_yc =init_y + (final_y - init_y)/2-0.5 - if debug_flag: - print('\x1b[6;30;47m', "Mouvement (X_init,Y_init,X_final,Y_final) : ", init_x,init_y, final_x,final_y, '\x1b[0m') - print('\x1b[6;30;47m', "Mouvement (xc,yc) : ", mov_xc, mov_yc, '\x1b[0m') - - # Test sur les murs exterieurs (10x10) - if ((final_x <1) or (final_y <1) or (final_x >10) or (final_y >10)): - if debug_flag: - print ("Détection de mur : mur détecté") - return True - - # Test sur les murs intéreurs - else: - i=0 - for mur in scene.objects: - i +=1 - if mur.name=="Mur": - - # Mur en X : calcul du centre du mur - if (round(mur.worldOrientation.to_euler().z,2) == round(math.pi,2)) or (round(mur.worldOrientation.to_euler().z,2) == round(-math.pi,2)): - mur_xc =mur['x1'] - mur_yc =mur['y1']+0.5 - - # Mur en Y : calcul du centre du mur - elif (round(mur.worldOrientation.to_euler().z,2) == round(math.pi/2,2)) or (round(mur.worldOrientation.to_euler().z,2) == round(-math.pi/2,2)): - mur_xc =mur['x1']+0.5 - mur_yc =mur['y1'] - - # Trace de debug - if debug_flag: - print('\x1b[6;30;47m', "Mur",mur['murId'],"X (x1,y1,x2,y2) : ", mur['x1'], mur['y1'], mur['x2'], mur['y2'], '\x1b[0m') - print('\x1b[6;30;47m', "Mur",mur['murId'],"Y (xc,yc) : ", mur_xc, mur_yc, '\x1b[0m') - - # Même centre -> mouvement pas possible - if (mov_xc == mur_xc) and(mov_yc == mur_yc): - if debug_flag: - print ("Détection de mur : mur détecté") - return True - - # Mouvement possible - if debug_flag: - print ("Détection de mur : pas de mur") - return False - - -# Fonction pour l'élève -def rp_detect_mur(): - if rpcore_detect_mur() == True: - print('\x1b[6;30;45m', "Détection de mur : mur devant ! : Position case (X,Y): ", round(-obj.worldPosition.x/3+5.5), round(obj.worldPosition.y/3+5.5), '\x1b[0m') - return True - else: - print('\x1b[6;30;45m', "Détection de mur : voie libre : Position case (X,Y):", round(-obj.worldPosition.x/3+5.5), round(obj.worldPosition.y/3+5.5), '\x1b[0m') - return False - -############################################################################### -# Mouvements -############################################################################### - -# Avancer -def rp_avancer(debug_flag=False): - obj.visible=False - - #MODIF - if obj['detruit']!=True and obj['d'] >= 0: - - # Vecteur du mouvement - #MODIF - init_x,init_y = obj['x'],obj['y'] - final_x,final_y = init_x,init_y - direction = obj['d'] - if direction == 0: #nord - final_y+=1 - elif direction == 1: #est - final_x+=1 - elif direction == 2: #sud - final_y-=1 - elif direction == 3: #ouest - final_x-=1 - #init_x = round(obj.worldPosition.y/3+5.5) - #init_y = round(-obj.worldPosition.x/3+5.5) - #obj.applyMovement((0, -pas, 0), True) - #final_x = round(obj.worldPosition.y/3+5.5) - #final_y = round(-obj.worldPosition.x/3+5.5) - #obj.applyMovement((0, pas, 0), True) - - # Test des murs - if rpcore_detect_mur(debug_flag) == True: - print('\x1b[6;30;41m', "Avancer case (X,Y) -> case (X,Y) :", init_x,",",init_y,"->",final_x,",",final_y, '\x1b[0m') - print('\x1b[6;30;41m', "Bling, blang ... L'aventure de Ropy s'arrête donc ici ...", '\x1b[0m') - obj['mvts'] = obj['mvts']+"c" - - #MODIF - obj['d'] = -1 - #obj['detruit']=True - else: - #MODIF - obj['x'],obj['y']=final_x,final_y - #obj.applyMovement((0, -pas, 0), True) - - obj['mvts'] = obj['mvts']+"a" - print('\x1b[6;30;42m', "Avancer case (X,Y) -> case (X,Y) :", init_x,",",init_y,"->",final_x,",",final_y, '\x1b[0m') - - # Test de l'objectif - i=0 - for objectif in scene.objects: - i +=1 - if objectif.name=="Objectif": - if objectif['x'] == final_x and objectif['y'] == final_y: - print('\x1b[6;30;42m', "Objectif atteint", '\x1b[0m') - obj['mvts'] = obj['mvts']+"o" - -# Tourner à droite -def rp_droite(): - # obj.visible=False - - #MODIF - if obj['detruit']!=True and obj['d'] >= 0: - # scene.objects['Robot'].applyRotation((0, 0, -pas_rot), True) - - #MODIF - #obj.applyRotation((0, 0, -pas_rot), True) - obj['d'] = (obj['d']+1)%4 - - obj['mvts'] = obj['mvts']+"d" - print('\x1b[6;30;42m', "Tourner à droite", '\x1b[0m') - # print("Orientation : ", obj.worldOrientation.to_euler().z) - -# Tourner à gauche -def rp_gauche(): - # obj.visible=False - - #MODIF - if obj['detruit']!=True and obj['d'] >= 0: - # scene.objects['Robot'].applyRotation((0, 0, pas_rot), True) - - #MODIF - obj['d'] = (obj['d']+3)%4 - #obj.applyRotation((0, 0, pas_rot), True) - - obj['mvts'] = obj['mvts']+"g" - print('\x1b[6;30;42m', "Tourner à gauche", '\x1b[0m') - # print("Orientation : ", obj.worldOrientation.to_euler().z) - -# Orienter -def rp_orientation(orientation): - if orientation=="nord": - obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z-math.pi/2), True) - #MODIF - obj['d']=0 - if orientation=="sud": - obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+math.pi/2), True) - #MODIF - obj['d']=2 - if orientation=="est": - obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+math.pi), True) - #MODIF - obj['d']=1 - if orientation=="ouest": - obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z), True) - #MODIF - obj['d']=3 - # print("Orientation : ", obj.worldOrientation.to_euler().z) - -############################################################################### -# Marquage du sol -############################################################################### - -# Marquer une case -def rp_marquer(): - if obj['detruit']!=True: - obj['mvts'] = obj['mvts']+"m" - if obj['mvts_start'] ==False : # à condition d'avoir terminé le mouvement - marque1= scene.addObject("Marque", obj) - marque1.worldPosition.x = obj.worldPosition.x - marque1.worldPosition.y = obj.worldPosition.y - marque1.worldPosition.z = 0.2 - # print('\x1b[6;30;43m', "Marquer case (X,Y) :", round(obj.worldPosition.y/3+5.5),",",round(-obj.worldPosition.x/3+5.5), '\x1b[0m') - -# Enlever l'ensemble des murs et des marques -def rp_enlever_marques(): - print ("") - print ("Table rase !") - for i in range (nb_objets_fixes, len(scene.objects)): - scene.objects[i].endObject() - -############################################################################### -# Construction du niveau -############################################################################### - -# Définition du niveau -def rp_niveau (niveau=0): - obj['level'] =niveau - -# Construire les murs -# Longueur : fixe d' une case -# Position des murs : liste imbriquée : [[mur1_x1,mur1_y1,mur1_x2,mur1_y2],[mur2_x1,mur2_y1,mur2_x2,mur2_y2], ...] -# FIXME : verifier si les murs sont dans la zone 10x10 -# FIXME : intervertir l'ordre des coordonnéees -# FIXME : verifier si le mur est d'une case -def rp_construire_murs (def_murs): - # print("Objets de la scene : ", scene.objects) - i=0 - for def_mur in def_murs: - i +=1 - # print (def_mur) - - # Mur en X - if def_mur[0] == def_mur[2]: - mur1= scene.addObject("Mur", obj) - mur1['murId'] = i - mur1['x1'] = def_mur[0] - mur1['y1'] = def_mur[1] - mur1['x2'] = def_mur[2] - mur1['y2'] = def_mur[3] - # print ("mur ", 0) - # mur1.applyRotation((0, 0, -obj.worldOrientation.to_euler().z), True) - # mur1.applyRotation((0, 0, -math.pi/2), True) - # mur1.applyRotation((0, 0, -obj.worldOrientation.to_euler().z), True) - - # mur1.worldOrientation.to_euler().z = 0 - mur1.worldPosition.x = -((def_mur[1]-4.5)*3) - mur1.worldPosition.y = ((def_mur[0]-5.5)*3)+1.5 - mur1.worldPosition.z = 1.5 - print('\x1b[6;30;47m', "Construire mur X",mur1['murId'],"coordonnées (x1,y1,x2,y2) :", def_mur[0], def_mur[1], def_mur[2], def_mur[3], '\x1b[0m') - - # Mur en Y - elif def_mur[1] == def_mur[3]: - mur2= scene.addObject("Mur", obj) - mur2['murId'] = i - mur2['x1'] = def_mur[0] - mur2['y1'] = def_mur[1] - mur2['x2'] = def_mur[2] - mur2['y2'] = def_mur[3] - # print ("mur ", -obj.worldOrientation.to_euler().z-math.pi/2) - mur2.applyRotation((0, 0, -obj.worldOrientation.to_euler().z-math.pi/2), True) - # print ("mur ", math.pi/2) - # mur2.applyRotation((0, 0, -math.pi), True) - # mur2.worldOrientation.to_euler().z = math.pi/2 - - mur2.worldPosition.x = -((def_mur[1]-5.5)*3)-1.5 - mur2.worldPosition.y = ((def_mur[0]-4.5)*3) - mur2.worldPosition.z = 1.5 - print('\x1b[6;30;47m', "Construire mur Y",mur2['murId'],"coordonnées (x1,y1,x2,y2) :", def_mur[0], def_mur[1], def_mur[2], def_mur[3], '\x1b[0m') - else: - print ('\x1b[6;30;41m', "Mur ni sur X ni sur Y !", '\x1b[0m') - -# Marquer l'objectif -def rp_marquer_objectif (x,y): - objectif1= scene.addObject("Objectif", obj) - objectif1.worldPosition.x = -((y-4.5)*3)+3 - objectif1.worldPosition.y = (x-5.5)*3 - objectif1.worldPosition.z = 0.2 - objectif1['x'] = x - objectif1['y'] = y - print('\x1b[6;30;47m', "Marquer l'objectif case (X,Y) :", x,y, '\x1b[0m') - diff --git a/ropy_mod.py b/ropy_mod.py deleted file mode 100644 index ef026f2..0000000 --- a/ropy_mod.py +++ /dev/null @@ -1,141 +0,0 @@ -import bge # Bibliothèque Blender Game Engine (BGE) -import math -import time - -from ropy_init import * # Bibliothèque Ropy -import ropy_init # Initialisation du robot Ropy -import ropy_cmd # Comnandes élèves du robot Ropy - -############################################################################### -# ropy_module.py -# @title: Module pour UPBGE -# @project: Blender-EduTech -# @lang: fr -# @authors: Philippe Roy -# @copyright: Copyright (C) 2020-2022 Philippe Roy -# @license: GNU GPL -# -# Fonctions autres que ceux de la bibliothèque du Robot Ropy (rp_*) -# -# 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. -# -############################################################################### - -# Récupérer l'objet robot - -cont = bge.logic.getCurrentController() -obj = cont.owner -scene = bge.logic.getCurrentScene() -nb_objets_fixes = len(scene.objects) -# print ("Nombre d'objets fixes de la scene : ", nb_objets_fixes) -# print("Objets de la scene : ", scene.objects) - -# Configuration des mouvements - -pas=3 # Pas linéaire -pas_rot=math.pi/2 # Pas angulaire - -############################################################################### -# Rustines pour corriger des bugs de UPBGE EEVEE (version alpha) -############################################################################### - -# Mouvement -# Problème : Les mouvements du robot ne sont pas vue -# Solution : Dépilage de la liste des mouvements du robot -def mvt(): - - if obj['mvts_start']: - # print ("Mouvements : ", obj['mvts']) - # print ("Nombre de mouvement : ", len(obj['mvts'])) - # print ("Nombre actuel : ", obj['mvt_i']) - - # Au debut - if obj['mvt_i'] == 0: - rp_init_position() - rp_orientation("est") # il y a nord, sud, est, ouest - obj.visible=True - - # Tous les mouvements sont dépilés - if obj['mvt_i'] >= len(obj['mvts']): - # print ("Plus de mouvement") - obj['mvts_start'] =False - - # Execution des mouvements - # a : avancer, d : droite, g : gauche, m : marquer - # c : crash, o : objectif atteint - - else: - # print ("Mouvement actuel : ", obj['mvt_i'], " ", obj['mvts'][obj['mvt_i']]) - - # Avancer - if obj['mvts'][obj['mvt_i']]=="a": - obj.applyMovement((0, -pas, 0), True) - - # Droite - if obj['mvts'][obj['mvt_i']]=="d": - # scene.objects['Robot'].applyRotation((0, 0, -pas_rot), True) - obj.applyRotation((0, 0, -pas_rot), True) - - # Gauche - if obj['mvts'][obj['mvt_i']]=="g": - # scene.objects['Robot'].applyRotation((0, 0, pas_rot), True) - obj.applyRotation((0, 0, pas_rot), True) - - # Marquer - if obj['mvts'][obj['mvt_i']]=="m": - marque1= scene.addObject("Marque", obj) - marque1.worldPosition.x = obj.worldPosition.x - marque1.worldPosition.y = obj.worldPosition.y - marque1.worldPosition.z = 0.2 - - # Objectif - if obj['mvts'][obj['mvt_i']]=="o": - if obj['level'] != 5: # Bug sur l'animation -> pas d'animation quand il y a plusieurs objectifs - start = 1 - end = 125 - layer = 0 - priority = 1 - blendin = 1.0 - mode = bge.logic.KX_ACTION_MODE_PLAY - layerWeight = 0.0 - ipoFlags = 0 - speed = 3.0 - scene.objects['Armature'].playAction('ArmatureAction.Saut.001', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['Body'].playAction('BodyAction.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['Eyes_glass'].playAction('Eyes_glassAction.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['Mouth'].playAction('MouthAction.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['Jetpack'].playAction('JetpackAction.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['poignee1'].playAction('poignee1Action.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['poignee2'].playAction('poignee2Action.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['poignee3'].playAction('poignee3Action.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['poignee4'].playAction('poignee4Action.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - - # Crash - if obj['mvts'][obj['mvt_i']]=="c": - start = 150 - end = start+75 - layer = 0 - priority = 1 - blendin = 1.0 - mode = bge.logic.KX_ACTION_MODE_PLAY - layerWeight = 0.0 - ipoFlags = 0 - speed = 3 - scene.objects['Armature'].playAction('ArmatureAction.Saut.001', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - # scene.objects['Body'].playAction('BodyAction.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - # scene.objects['Eyes_glass'].playAction('Eyes_glassAction.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - # scene.objects['Mouth'].playAction('MouthAction.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - # scene.objects['Jetpack'].playAction('JetpackAction.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['poignee1'].playAction('poignee1Action.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['poignee2'].playAction('poignee2Action.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['poignee3'].playAction('poignee3Action.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - scene.objects['poignee4'].playAction('poignee4Action.Saut', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) - obj['detruit']=True - obj['mvt_i'] = len(obj['mvts']) # Annulation des mouvements suivants - - else: - # Mouvement suivant - if obj['mvts'][obj['mvt_i']]!="c": - obj['mvt_i']+=1 - diff --git a/rp.py b/rp.py index 2f4c84f..8a0753f 100644 --- a/rp.py +++ b/rp.py @@ -51,7 +51,6 @@ eevee = bpy.context.scene.eevee fps_time=0.0 # Config file -# print (os.getcwd()) rp_config = ET.parse('rp_config.xml') rp_config_tree = rp_config.getroot() @@ -145,13 +144,26 @@ def terrain_init (): # Init de la carte scene.objects['Map_aim'].setVisible(False,True) - rp_map.map_init() + scene.objects['Terrain']['map_tile_beacon']= [] + # for i in range (500): + for i in range (100): + beacon= scene.addObject("Beacon", scene.objects['Terrain']) + beacon.worldPosition=[29,1+i,0.2] + beacon.setVisible(False,True) + beacon.name="Beacon-"+str(i) + beacon.suspendPhysics (True) + beacon['activated']=False + # print("Objets de la scene : ", scene.objects) + rp_map.map_reset() # Récupération de la position de la caméra - scene.objects['Camera'].worldPosition.x = float(rp_config_tree[0][2][0].text) - scene.objects['Camera'].worldPosition.y = float(rp_config_tree[0][2][1].text) - scene.objects['Camera'].worldPosition.z = float(rp_config_tree[0][2][2].text) + scene.objects['Camera']['current_lx'] = float(rp_config_tree[0][2][0].text) + scene.objects['Camera']['current_ly'] = float(rp_config_tree[0][2][1].text) + scene.objects['Camera']['current_lz'] = float(rp_config_tree[0][2][2].text) + scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['current_lx'] + scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['current_ly'] + scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['current_lz'] ## # Mise en route et pause du cycle @@ -183,6 +195,7 @@ def terrain_run (): if scene.objects['Terrain']['thread_cmd']==False: scene.objects['Terrain']['thread_cmd']=True rp_map.map_reset() + time.sleep(0.25) runpy.run_module('rp_cmd', run_name='start') # Execution du script utilisateur # Arrêt de la pause @@ -247,16 +260,22 @@ def terrain_grid (): scene.objects['Grid-v'].setVisible(False,True) scene.objects['Map_aim'].setVisible(False,True) else: - scene.objects['Grid-u']['timer'] = 0.2 - bpy.data.materials["Grid"].node_tree.nodes["Emission"].inputs[1].default_value =scene.objects['Grid-u']['timer'] + scene.objects['Grid-u']['timer'] = 0 + bpy.data.materials["Grid"].node_tree.nodes["Shader de mélange"].inputs[0].default_value = 0 + bpy.data.materials["Grid-Holo"].node_tree.nodes["Émission"].inputs[1].default_value = 0 + # bpy.data.materials["Grid"].node_tree.nodes["Emission"].inputs[1].default_value =scene.objects['Grid-u']['timer'] scene.objects['Grid-u'].setVisible(True,True) scene.objects['Grid-v'].setVisible(True,True) - scene.objects['Map_aim'].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'] + bpy.data.materials["Grid"].node_tree.nodes["Shader de mélange"].inputs[0].default_value=scene.objects['Grid-u']['timer'] + bpy.data.materials["Grid-Holo"].node_tree.nodes["Émission"].inputs[1].default_value =scene.objects['Grid-u']['timer']*5 + # 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) if scene.objects['Grid-u']['timer']>= 1: scene.objects['Grid-u']['anim'] = False @@ -533,9 +552,9 @@ def mode(cont): terrain_stop () # Maj du fichier de config (position de la camera : data/config/cam_x,y,z -> [0][2][0].text, [0][2][1].text, [0][2][2].text) - rp_config_tree[0][2][0].text=str(scene.objects['Camera'].worldPosition.x) - rp_config_tree[0][2][1].text=str(scene.objects['Camera'].worldPosition.y) - rp_config_tree[0][2][2].text=str(scene.objects['Camera'].worldPosition.z) + rp_config_tree[0][2][0].text=str(scene.objects['Camera']['current_lx']) + rp_config_tree[0][2][1].text=str(scene.objects['Camera']['current_ly']) + rp_config_tree[0][2][2].text=str(scene.objects['Camera']['current_lz']) # print ("Fin :", scene.objects['Camera'].worldPosition.x, scene.objects['Camera'].worldPosition.y, scene.objects['Camera'].worldPosition.z) buffer_xml = ET.tostring(rp_config_tree) with open("rp_config.xml", "wb") as f: @@ -658,8 +677,11 @@ def manip_start(cont): ## def manip_stop(cont): + scene.objects['Camera']['current_lx'] = scene.objects['Camera'].worldPosition.x + scene.objects['Camera']['current_ly'] = scene.objects['Camera'].worldPosition.y + scene.objects['Camera']['current_lz'] = scene.objects['Camera'].worldPosition.z # scene.objects['Orbit'].setVisible(False,False) - pass + ## # Manipulation du modèle ou de la caméra @@ -734,6 +756,7 @@ def manip_wheel(cont): # scene.objects['Mouse_main'].worldScale /= sensibilite_wheel* (distance_cam_past/distance_cam) *size_scale else: return + manip_stop(cont) ## # Icone de la souris @@ -876,6 +899,11 @@ def tablet_close (): # audiodev.unlock() scene.objects['Cmd-text'].setVisible(False,False) + # Camera + scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['current_lx'] + scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['current_ly'] + scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['current_lz'] + ## # Clic pour fermer la tablette ## @@ -899,11 +927,11 @@ color_link_hl = (0.799, 0.617, 0.021, 1) # Jaune def about_open(): scene.objects['Terrain']['manip_mode']=9 # Fenêtre modale About manip_reset() - + scene.objects['About_link-git'].color= color_link scene.objects['About_link-gpl'].color= color_link scene.objects['About_link-upbge'].color= color_link - # scene.objects['About_link-kay'].color= color_link + scene.objects['About_link-kay'].color= color_link scene.objects['About_link-kenney'].color= color_link scene.objects['About_link-polygonrunway'].color= color_link scene.objects['About_link-icons'].color= color_link @@ -954,6 +982,9 @@ def about_close(): scene.objects['About'].setVisible(False,True) scene.objects['About'].worldPosition = [42, -2, 3] scene.objects['About']['timer']= 0 + scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['current_lx'] + scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['current_ly'] + scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['current_lz'] ## # Click pour fermer le about diff --git a/rp_cmd.py b/rp_cmd.py index affb7cf..10faf21 100644 --- a/rp_cmd.py +++ b/rp_cmd.py @@ -11,6 +11,9 @@ from rp_lib import * # Bibliothèque Ropy # Fonctions ############################################################################### +def mrp_avancer(): + rp_avancer() + rp_marquer() ############################################################################### # Commandes @@ -19,16 +22,38 @@ from rp_lib import * # Bibliothèque Ropy def commands(): print("Go !!") + # rp_marquer() # A tendance au plantage + rp_gauche() rp_avancer() rp_droite() - rp_avancer() - rp_avancer() - rp_avancer() - rp_avancer() + rp_marquer() + mrp_avancer() + rp_marquer() + mrp_avancer() + rp_marquer() + mrp_avancer() + mrp_avancer() rp_droite() - rp_avancer() - rp_avancer() + mrp_avancer() + mrp_avancer() + + rp_droite() + 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() + mrp_avancer() rp_fin() diff --git a/rp_config.xml b/rp_config.xml index d413f15..32197d0 100644 --- a/rp_config.xml +++ b/rp_config.xml @@ -1,11 +1,11 @@ - 0.25 + 4.0 True - -8.529211044311523 - -2.480304479598999 - 4.401391983032227 + -7.034218788146973 + -10.528145790100098 + 12.590240478515625 diff --git a/rp_lib.py b/rp_lib.py index 79a193e..a28c0a7 100644 --- a/rp_lib.py +++ b/rp_lib.py @@ -178,7 +178,7 @@ def sound_play (sound): ## def rp_avancer (): - print ("rp_avancer") + print ("rp_avancer()") step =1 obj=scene.objects['Rover'] # print (obj.worldOrientation.to_euler().z) @@ -193,37 +193,61 @@ 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) + rp_tempo (0.1) ## # Tourner à gauche ## def rp_gauche (): - print ("rp_gauche") + print ("rp_gauche()") step=math.pi/2 # Pas angulaire obj=scene.objects['Rover'] obj.applyRotation((0, 0, step), True) - rp_sleep (0.25) + rp_tempo (0.1) ## # Tourner à droite ## def rp_droite (): - print ("rp_droite") + print ("rp_droite()") step=math.pi/2 # Pas angulaire obj=scene.objects['Rover'] obj.applyRotation((0, 0, -step), True) - rp_sleep (0.25) + rp_tempo (0.1) ## # Marquer ## def rp_marquer (): - print ("rp_marquer") - # FIXME + rp_tempo (0.1) + print ("rp_marquer()") + obj=scene.objects['Rover'] + x = obj.worldPosition.x + y = obj.worldPosition.y + z = obj.worldPosition.z + + # Vérification de l'absence de balise sur la tuile + if [x,y] in scene.objects['Terrain']['map_tile_beacon'] : + print ("Case déjà marquée !") + return False + + for i in range (100): + beacon = scene.objects["Beacon-"+str(i)] + if beacon['activated']==False: + beacon.worldPosition=[x,y,0.2] + beacon['activated']=True + beacon.setVisible(True, True) + break + if i ==99 : + 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 ## # Détecter @@ -266,688 +290,22 @@ def rover_colision (): ############################################################################### 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'] scene.objects['Points']['level_max'] : -# tour= scene.addObject("Tower_error", scene.objects['Terrain']) -# tour.worldPosition=[x,y,0.2] -# tour.worldScale=[1,1,1] -# scene.objects['Terrain']['scene_tile_tower'].append([x,y]) -# return False - -# # Blocage des autres threads pendant la construction -# scene.objects['Terrain']['thread_cmd_lock'] = True - -# # Objets 3D -# time.sleep(0.02) -# tour= scene.addObject('Tower-'+building, scene.objects['Terrain']) -# time.sleep(0.02) -# tour.color = color -# tour.worldPosition=[x,y,0.2] -# tour.worldScale=[1,1,1] -# tour.name="tower("+str(x)+','+str(y)+")" -# scene.objects['Terrain']['scene_tile_tower'].append([x,y]) -# tower_minion= scene.addObject(body, scene.objects['Terrain']) -# tower_minion['type_towerminion']=False -# del tower_minion['type_minion'] -# tower_minion.name="tm("+str(x)+','+str(y)+")" # Tower minion (tm) -# tower_minion.worldPosition=[x,y,1] -# tower_minion.worldScale=[0.25,0.25,0.25] - -# # Draw3d -# if cat=="Archer tower": -# for i in range (3): -# ct_add_tower_bullet(x,y,i, "Arrow") -# if cat=="Mage tower": -# ct_add_tower_cast(x,y) - -# # Sounds -# sound_play(sndbuff_build) - -# # Caracteristics -# tower_carac= scene.objects['Terrain']['tower_carac'] -# tour['cat']=tower_carac[cat][0] -# tour['tower_name']=tower_name -# tour['xp']=0 -# tour['lvl_current']=1 -# tour['lvl']=1 -# tour['damage']=tower_carac[cat][1] -# tour['speed']=tower_carac[cat][2] -# tour['range']=tower_carac[cat][3] -# tour['techno']=[] -# tour['cast']="slow" -# # tour['cast_duration']=2 -# tour['cast_duration']=3 -# tour['target']=[] -# tour['target_past']=[] - -# # Capteur Near -# tour.sensors['Near'].distance=tour['range']*2.5 # Range : 1 point = 2,5 -# # tour.sensors['Near'].skippedTicks =round(1/(tour['speed']*scene.objects['Terrain']['speed'])) -# tour.sensors['Near'].skippedTicks =round(tour['speed']*50*scene.objects['Terrain']['speed']) # Speed : 1 point = 50 tics - -# # Déblocage des autres threads après la construction -# scene.objects['Terrain']['thread_cmd_lock'] = False -# # print (scene.objects) -# return True - -# ## -# # Suppression d'une tour -# ## - -# def ct_remove(x,y): -# for obj_i in scene.objects: -# if "type_tower" in obj_i.getPropertyNames(): -# if x == obj_i.worldPosition.x and y == obj_i.worldPosition.y: -# scene.objects["tm("+str(round(obj_i.worldPosition.x))+','+str(round(obj_i.worldPosition.y))+")"].endObject() -# obj_i.endObject() -# scene.objects['Points']['level']= scene.objects['Points']['level'] - 1 - -# ## -# # Création d'un projectile -# ## - -# def ct_add_tower_bullet(x, y, num, cat="Ball"): -# if cat=="Ball": -# bullet= scene.addObject("Bullet", scene.objects['Terrain']) -# if cat=="Arrow": -# bullet= scene.addObject("Arrow", scene.objects['Terrain']) -# bullet.name="tower("+str(x)+','+str(y)+")-bullet"+str(num) -# bullet.worldPosition=[x,y,1.5] -# bullet.worldScale=[0.75,0.75,0.75] -# bullet.suspendPhysics (True) -# bullet.setVisible(False) -# bullet['activated']=False - -# ## -# # Création des sorts -# ## - -# def ct_add_tower_cast(x, y): -# cast= scene.addObject("Cast-slow", scene.objects['Terrain']) -# cast.name="tower("+str(x)+','+str(y)+")-cast" -# cast.worldPosition=[x,y,1.5] -# cast.worldScale=[0.75,0.75,0.75] -# cast.suspendPhysics (True) -# cast.setVisible(False) -# cast['activated']=False - - -# ## -# # Réaction d'une tour -# ## - -# def scn_tower_near(cont): -# obj = cont.owner -# sensor = obj.sensors['Near'] - -# # Tir -# if sensor.positive and len(sensor.hitObjectList)>0 and scene.objects['Terrain']['run']==True : - -# # Tir sur le plus avancé basé sur les distances parcourues -# target=sensor.hitObjectList[0] -# target_dist = target['dist'] -# for obj_i in sensor.hitObjectList: -# if obj_i['dist']> target_dist: -# target=obj_i -# target_dist = target['dist'] - -# # Tir sur le plus avancé basé sur l'ordre de passage -# # target=sensor.hitObjectList[0] -# # target_id = target['navPosition'] -# # for obj_i in sensor.hitObjectList: -# # if obj_i['navPosition']< target_id: -# # target=obj_i -# # target_id = target['navPosition'] - -# # Tir sur le plus avancé basé sur les distances par rapport à la tour -> ne marche pas -# # target=sensor.hitObjectList[0] -# # if len(sensor.hitObjectList)>1: -# # target_eloignement = False -# # target_distance_eloignement = 0 -# # target_distance_approche = 100 -# # print ("detection:",sensor.hitObjectList) -# # for obj_i in sensor.hitObjectList: -# # for obj_j in obj['target_past']: -# # if obj_j[0]==obj_i.name: -# # print ("name :", obj_j[0], "distance :", obj.getDistanceTo(obj_i), "distance old :", obj_j[1], "ecart :", obj.getDistanceTo(obj_i) - obj_j[1]) -# # # Éloignement -# # if obj.getDistanceTo(obj_i) - obj_j[1] > 0: # Ecart de distance -# # target_eloignement = True -# # if obj.getDistanceTo(obj_i) > target_distance_eloignement: -# # target=obj_i -# # target_distance_eloignement = obj.getDistanceTo(obj_i) -# # # Approche -# # else: -# # if target_eloignement == False: -# # if obj.getDistanceTo(obj_i) < target_distance_approche: -# # target=obj_i -# # target_distance_approche = obj.getDistanceTo(obj_i) -# # if target_eloignement == True: -# # print ("Eloignement : target:", target.name, "distance :", obj.getDistanceTo(target)) -# # print ("") -# # else: -# # print ("Approche : target:", target.name, "distance :", obj.getDistanceTo(target)) -# # print ("") -# # obj['target_past']=[] -# # for obj_i in sensor.hitObjectList: -# # obj['target_past'].append([obj_i.name, obj.getDistanceTo(obj_i)]) - -# # Orientation du tower minion -# towerminion="tm("+str(round(obj.worldPosition.x))+','+str(round(obj.worldPosition.y))+")" -# angle =math.atan((target.worldPosition.y-obj.worldPosition.y)/(target.worldPosition.x-obj.worldPosition.x)) -# if target.worldPosition.x>obj.worldPosition.x: -# angle2=math.pi/2+angle-scene.objects[towerminion].worldOrientation.to_euler().z -# angle3=angle -# else: -# angle2=math.pi+math.pi/2+angle-scene.objects[towerminion].worldOrientation.to_euler().z -# angle3=math.pi+angle -# scene.objects[towerminion].applyRotation((0, 0, angle2), False) - -# # Sounds -# if obj['cat']=="Archer tower": -# sound_play(sndbuff_archer) -# if obj['cat']=="Mage tower": -# sound_play(sndbuff_mage) - -# # Ligne (drawLine) (vitesse rapide) -# if scene.objects['Terrain']['speed']<4: # Pas d'animation à 10 -> plantage - -# # Archer (tir de flêche) -# if obj['cat']=="Archer tower": -# if target.name in scene.objects: -# for i in range (3): -# bullet = scene.objects[obj.name+"-bullet"+str(i)] -# if bullet['activated']==False: -# bullet.worldPosition=[obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8] -# bullet['activated']=True -# bullet.setVisible(True) -# scene.objects['Terrain']['draw3d_process']=True -# scene.objects['Terrain']['draw3d_list'].append([20, "arrow", obj.name, bullet.name, target.name, "normal", 20]) -# break -# if i ==3 : -# print ("Plus de bullet de disponible pour la tour : "+obj.name) - -# # Cast zone -# if obj['cat']=="Mage tower": # Mage (cast) -# cast = scene.objects[obj.name+"-cast"] -# cast.worldPosition=[obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8] -# cast.worldScale=[0.01,0.01,0.01] -# cast.setVisible(True) -# scene.objects['Terrain']['draw3d_process']=True -# scene.objects['Terrain']['draw3d_list'].append([60, "cast", obj.name, cast.name, "slow", 60]) - -# # Rayon -# # FIXME : ne marche plus (zoom et pan) -# # if obj['cat']=="Test": -# # if target.name in scene.objects: -# # scene.objects['Terrain']['draw2d_process']=True -# # scene.objects['Terrain']['draw2d_list'].append([5, "ray", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8], target.name, angle3, ray_yellow,5]) # Suivi du minion - -# # Dégats : pas d'animation à 10 -# if scene.objects['Terrain']['speed'] >= 4: -# target['hp'] = target['hp'] - obj['damage'] -# if target['hp']<=0: -# target['dead']=True - -# # Cast (buff and debuff) -# if obj['cat']=="Mage tower": -# for target_i in sensor.hitObjectList: -# target_i['buff'].append([obj['cast'], obj['cast_duration']]) - -# ############################################################################### -# # Carte -# ############################################################################### - -# ## -# # Texte de carte -# ## - -# def ct_map_text_wave(wave): -# scene.objects['Points-Map-text']['Text']=("Wave " + str(wave)) -# scene.objects['Points-Map-text'].setVisible(True,False) -# scene.objects['Points-Map-text'].color = color_text_yellow -# scene.objects['Points-Map-text']['timer']=0 -# scene.objects['Points-Map-text']['anim']=True - -# ## -# # Texte de carte -# ## - -# def ct_map_text(text): -# scene.objects['Points-Map-text']['Text']=text -# scene.objects['Points-Map-text'].setVisible(True,False) - -# ## -# # Fin -# ## - -# def ct_map_end(x,y): -# scene.objects['Map_end'].worldPosition=[x,y,0.2] -# scene.objects['Map_end'].worldScale=[0.25,0.25,0.25] - -# ## -# # Minion arrivé à la fin -# ## - -# def scn_map_end_near(cont): -# obj = cont.owner -# sensor = obj.sensors['Near'] -# if sensor.positive : -# for obj_i in sensor.hitObjectList : -# sound_play(sndbuff_life) -# if scene.objects['Points']['lifes']>0: -# scene.objects['Points']['lifes']= scene.objects['Points']['lifes']-obj_i['lifes_damage'] -# scene.objects['Points']['minions_run'] -=1 -# for obj_i in sensor.hitObjectList : -# obj_i.setVisible(False) -# obj_i.suspendPhysics (True) -# # obj_i.endObject() - -# ## -# # Drapeau de fin -# ## - -# def ct_map_endflag(x,y): -# endflag= scene.addObject("Map_endflag", scene.objects['Terrain']) -# endflag.worldPosition=[x,y,0.3] -# endflag.worldScale=[0.3,0.3,0.3] -# if round(x) == x : -# if round(y) == y : -# scene.objects['Terrain']['scene_tile_noncontruct'].append([x,y]) -# else: -# scene.objects['Terrain']['scene_tile_noncontruct'].append([x,math.floor(y)]) -# scene.objects['Terrain']['scene_tile_noncontruct'].append([x,math.ceil(y)]) -# else: -# if round(y) == y : -# scene.objects['Terrain']['scene_tile_noncontruct'].append([math.floor(x),y]) -# scene.objects['Terrain']['scene_tile_noncontruct'].append([math.ceil(x),y]) -# else: -# scene.objects['Terrain']['scene_tile_noncontruct'].append([math.floor(x),math.floor(y)]) -# scene.objects['Terrain']['scene_tile_noncontruct'].append([math.floor(x),math.ceil(y)]) -# scene.objects['Terrain']['scene_tile_noncontruct'].append([math.ceil(x),math.floor(y)]) -# scene.objects['Terrain']['scene_tile_noncontruct'].append([math.ceil(x),math.ceil(y)]) - -# ############################################################################### -# # Affichage -# ############################################################################### - -# ## -# # Texte du panel d'information -# ## - -# def ct_print (text): -# # text_info (texte) -# if text=="": -# scene.objects['Info-1-text'].setVisible(False,False) -# scene.objects['Info-2-text'].setVisible(False,False) -# else: -# lines_txt=text.split("\n", 6) -# for i in range (len(lines_txt),6): -# lines_txt.append("") -# scene.objects['Info-1-text'].setVisible(True,False) -# scene.objects['Info-2-text'].setVisible(True,False) -# scene.objects['Info-1-text']['Text']=lines_txt[0]+"\n"+lines_txt[1]+"\n"+lines_txt[2] -# scene.objects['Info-2-text']['Text']=lines_txt[3]+"\n"+lines_txt[4]+"\n"+lines_txt[5] - -# ############################################################################### -# # Dessin 3d -# ############################################################################### - -# def scn_draw3d(cont): -# obj = cont.owner -# if obj.sensors['Draw3d'].positive==False: -# return -# if len(scene.objects['Terrain']['draw3d_list'])==0: -# scene.objects['Terrain']['draw3d_process']=False -# return - -# # Dépilage des draws à executer -# for draw_cmd in scene.objects['Terrain']['draw3d_list']: - -# # Archer (tir de flêche) -# # scene.objects['Terrain']['draw3d_list'].append([20, "arrow", obj.name, bullet.name, target.name, "normal", 20]) -# if draw_cmd[1]=="arrow": -# if draw_cmd[4] in scene.objects: -# tower= scene.objects[draw_cmd[2]] -# bullet = scene.objects[draw_cmd[3]] -# target = scene.objects[draw_cmd[4]] -# x0 = tower.worldPosition.x -# y0 = tower.worldPosition.y -# # z0 = tower.worldPosition.z+0.8 # ajustement +0.8 -# z0 = tower.worldPosition.z+1 # ajustement +1 -# x1 = target.worldPosition.x -# y1 = target.worldPosition.y -# z1 = target.worldPosition.z+0.5 # ajustement +0.5 -# if x1>x0: -# angle_z =math.atan((y1-y0)/(x1-x0))+math.pi/2 -# else: -# angle_z =math.pi+math.atan((y1-y0)/(x1-x0))+math.pi/2 -# angle_y =math.atan((z1-z0)/(math.sqrt((x1-x0)**2+(y1-y0)**2))) -# step_x=(x1-x0)/draw_cmd[6] -# step_y=(y1-y0)/draw_cmd[6] -# step_z=(z1-z0)/draw_cmd[6] -# step = draw_cmd[6]-draw_cmd[0] -# bullet.worldPosition=[x0+step_x*step, y0+step_y*step, z0+step_z*step] -# bullet.worldOrientation=[0, angle_y, angle_z] -# draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed'] - -# # Dégats -# if draw_cmd[0]<=0: -# bullet['activated']=False -# bullet.setVisible(False) -# target['hp'] = target['hp'] - tower['damage'] -# if target['hp']<=0: # Mort -# target['dead']=True - -# # Mage (cast) -# # scene.objects['Terrain']['draw3d_list'].append([60, "cast", obj.name, cast.name, "slow", 60]) -# if draw_cmd[1]=="cast": -# cast = scene.objects[draw_cmd[3]] -# step = draw_cmd[5]-draw_cmd[0] -# cast.worldScale=[0.05*step,0.05*step,0.05*step] -# # cast.worldScale=[0.75*step,0.75*step,0.75*step] -# draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed'] - -# # Fin -# if draw_cmd[0]<=0: -# cast.setVisible(False) - -# # Suppression des draws finis -# i=0 -# for draw_cmd in scene.objects['Terrain']['draw3d_list']: -# if draw_cmd[0]<=0: -# scene.objects['Terrain']['draw3d_list'].pop(i) -# else: -# i=i+1 -# if len(scene.objects['Terrain']['draw3d_list'])==0: -# scene.objects['Terrain']['draw3d_process']=False - -# ############################################################################### -# # Dessin 2d (bge.render.drawLine) -# ############################################################################### - -# def circle (center, radius, color): -# ang = 0.0 -# # ang_step = 0.1 -# ang_step = 0.2 -# while ang< 2 * math.pi: -# x0 = center[0]+float(radius*math.cos(ang)) -# y0 = center[1]+float(radius*math.sin(ang)) -# x1 = center[0]+float(radius*math.cos(ang+ang_step)) -# y1 = center[1]+float(radius*math.sin(ang+ang_step)) -# bge.render.drawLine([x0,y0,center[2]],[x1,y1,center[2]],color) -# ang += ang_step - -# ## -# # Affiche les draws 2d en cours -# # -# # Type de draw 2d: -# # arrow : [5, "arrow", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],target.name, angle3, ray_yellow,5] -# # cast : [30, "cast", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8], ray_blue,30] -# # ray : [5, "ray", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],[target.worldPosition.x, target.worldPosition.y, target.worldPosition.z], angle3, ray_yellow,5] -# ## - -# def scn_draw2d(cont): -# obj = cont.owner -# if obj.sensors['Draw2d'].positive==False: -# return -# if len(scene.objects['Terrain']['draw2d_list'])==0: -# scene.objects['Terrain']['draw2d_process']=False -# return - -# # Dépilage des draws à executer -# for draw_cmd in scene.objects['Terrain']['draw2d_list']: - -# # Archer (tir de flêche) -# if draw_cmd[1]=="arrow": -# if draw_cmd[3] in scene.objects: -# # x0 = draw_cmd[2][0]+0.25*(math.cos(draw_cmd[4])) -# # y0 = draw_cmd[2][1]+0.25*(math.sin(draw_cmd[4])) -# x0 = draw_cmd[2][0] -# y0 = draw_cmd[2][1] -# z0 = draw_cmd[2][2] -# x1 = scene.objects[draw_cmd[3]].worldPosition.x -# y1 = scene.objects[draw_cmd[3]].worldPosition.y -# z1 = scene.objects[draw_cmd[3]].worldPosition.z-0.1 # ajustement -0.1 -# distance = math.sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2) -# distance_xy = math.sqrt((x1-x0)**2+(y1-y0)**2) -# distance_z = z1-z0 -# angle_z =math.atan((z1-z0)/(distance_xy)) -# angle_xy =math.atan((y1-y0)/(x1-x0)) -# step=distance_xy/(2+draw_cmd[6]) -# step_z=distance_z/(2+draw_cmd[6]) -# if x1>x0: -# angle2=angle_xy -# else: -# angle2=math.pi+angle_xy -# x2=x0+(((6-draw_cmd[0])*step)*(math.cos(angle2))) -# y2=y0+(((6-draw_cmd[0])*step)*(math.sin(angle2))) -# z2=z0-(((6-draw_cmd[0])*step_z)*(math.sin(angle_z))) -# x3=x0+(((6-draw_cmd[0])*step+step)*(math.cos(angle2))) -# y3=y0+(((6-draw_cmd[0])*step+step)*(math.sin(angle2))) -# z3=z0-(((6-draw_cmd[0])*step_z+step_z)*(math.sin(angle_z))) -# bge.render.drawLine([x2,y2, z2], [x3,y3,z3], draw_cmd[5]) -# draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed'] -# # if scene.objects['Terrain']['speed']<1: -# # draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed'] -# # else: -# # draw_cmd[0] = draw_cmd[0]-1 -# # bge.render.drawLine([draw_cmd[2][0]+((6-draw_cmd[0])*0.25)*(math.cos(draw_cmd[4])), draw_cmd[2][1]+((6-draw_cmd[0])*0.25)*(math.sin(draw_cmd[4])),draw_cmd[2][2]], -# # [draw_cmd[2][0]+((6-draw_cmd[0])*0.25+0.25)*(math.cos(draw_cmd[4])), draw_cmd[2][1]+((6-draw_cmd[0])*0.25+0.25)*(math.sin(draw_cmd[4])),draw_cmd[2][2]], -# # draw_cmd[5]) - -# # Mage (cast) -# # FIXME : Problème -# if draw_cmd[1]=="cast": # Mage (cast) -# circle(draw_cmd[2], 3.1-draw_cmd[0]*0.1, draw_cmd[3]) -# circle(draw_cmd[2], 3-draw_cmd[0]*0.1, draw_cmd[3]) -# circle(draw_cmd[2], 2.9-draw_cmd[0]*0.1, draw_cmd[3]) -# draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed'] -# # if scene.objects['Terrain']['speed']<=2: -# # draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed'] -# # if scene.objects['Terrain']['speed']==4: -# # draw_cmd[0] = draw_cmd[0]-draw_cmd[4]/2 -# # circle(draw_cmd[2], 3, draw_cmd[3]) # simple -# # radius=[3,3,2.5,2.5,2,2,1.5,1.5,1,1,1] # basé sur un tableau -# # circle(draw_cmd[2], radius[draw_cmd[0]], draw_cmd[3]) - -# # Rayon -# if draw_cmd[1]=="ray": -# if draw_cmd[3] in scene.objects: -# x0 = draw_cmd[2][0]+0.25*(math.cos(draw_cmd[4])) -# y0 = draw_cmd[2][1]+0.25*(math.sin(draw_cmd[4])) -# x1 = scene.objects[draw_cmd[3]].worldPosition.x -# y1 = scene.objects[draw_cmd[3]].worldPosition.y -# z1 = scene.objects[draw_cmd[3]].worldPosition.z -# bge.render.drawLine([x0,y0, draw_cmd[2][2]], [x1,y1,z1], draw_cmd[5]) # suivi minion -# # bge.render.drawLine([draw_cmd[2][0]+0.25*(math.cos(draw_cmd[4])), draw_cmd[2][1]+0.25*(math.sin(draw_cmd[4])), draw_cmd[2][2]], draw_cmd[3], draw_cmd[5]) # décalage minion -# # bge.render.drawLine(draw_cmd[2], draw_cmd[3], draw_cmd[5]) # simple -# draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed'] - -# # Suppression des draws finis -# i=0 -# for draw_cmd in scene.objects['Terrain']['draw2d_list']: -# if draw_cmd[0]<=0: -# scene.objects['Terrain']['draw2d_list'].pop(i) -# else: -# i=i+1 -# if len(scene.objects['Terrain']['draw2d_list'])==0: -# scene.objects['Terrain']['draw2d_process']=False +def rp_tempo (duration): + # time.sleep(duration*(1/scene.objects['Commands']['speed'])) + scene.objects['Commands']['time']=0 + while scene.objects['Commands']['time']