mirror of
https://forge.apps.education.fr/blender-edutech/ropy.git
synced 2024-01-27 08:23:20 +01:00
Suppression du déplacement de Ropy (glitch) avant le dépilage (patch de Julliand Gregory <Gregory.Julliand@ac-grenoble.fr>)
This commit is contained in:
parent
0144adcd77
commit
7d42c19c33
108
ropy_lib.py
108
ropy_lib.py
@ -3,19 +3,19 @@ import math
|
||||
import time
|
||||
|
||||
###############################################################################
|
||||
# ropy_lib.py
|
||||
# ropy_lib :
|
||||
# @title: Bibliothèque du Robot Ropy (rp_*)
|
||||
# @project: Blender-EduTech
|
||||
# @project: Ropy (RobotProg pour Python)
|
||||
# @lang: fr
|
||||
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||
# @copyright: Copyright (C) 2020-2022 Philippe Roy
|
||||
# @copyright: Copyright (C) 2020 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.
|
||||
# Ropy est destiné à la découverte de la programmation procédurale et du language Python en SNT (2nde en lycée).
|
||||
# A travers plusieurs challenges, donc de manière graduée, les élèves vont apprendre à manipuler les structures algoritmiques de base et à les coder en Python.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
@ -46,6 +46,10 @@ def rp_init_position():
|
||||
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
|
||||
@ -82,20 +86,32 @@ def rp_print_position():
|
||||
|
||||
###############################################################################
|
||||
# Moteur physique
|
||||
# Détection des colisions aves les murs
|
||||
# Détection des collisions aves les murs
|
||||
###############################################################################
|
||||
|
||||
# Détection d'une colision
|
||||
# Détection d'une collision
|
||||
# rpcore_ : fonction bas niveau
|
||||
def rpcore_detect_mur(debug_flag=False):
|
||||
|
||||
# Vecteur du mouvement
|
||||
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)
|
||||
#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
|
||||
@ -160,24 +176,44 @@ def rp_detect_mur():
|
||||
# Avancer
|
||||
def rp_avancer(debug_flag=False):
|
||||
obj.visible=False
|
||||
if obj['detruit']!=True:
|
||||
|
||||
#MODIF
|
||||
if obj['detruit']!=True and obj['d'] >= 0:
|
||||
|
||||
# Vecteur du mouvement
|
||||
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)
|
||||
#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"
|
||||
obj['detruit']=True
|
||||
|
||||
#MODIF
|
||||
obj['d'] = -1
|
||||
#obj['detruit']=True
|
||||
else:
|
||||
obj.applyMovement((0, -pas, 0), True)
|
||||
#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')
|
||||
|
||||
@ -193,9 +229,15 @@ def rp_avancer(debug_flag=False):
|
||||
# Tourner à droite
|
||||
def rp_droite():
|
||||
# obj.visible=False
|
||||
if obj['detruit']!=True:
|
||||
|
||||
#MODIF
|
||||
if obj['detruit']!=True and obj['d'] >= 0:
|
||||
# scene.objects['Robot'].applyRotation((0, 0, -pas_rot), True)
|
||||
obj.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)
|
||||
@ -203,9 +245,15 @@ def rp_droite():
|
||||
# Tourner à gauche
|
||||
def rp_gauche():
|
||||
# obj.visible=False
|
||||
if obj['detruit']!=True:
|
||||
|
||||
#MODIF
|
||||
if obj['detruit']!=True and obj['d'] >= 0:
|
||||
# scene.objects['Robot'].applyRotation((0, 0, pas_rot), True)
|
||||
obj.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)
|
||||
@ -214,12 +262,20 @@ def rp_gauche():
|
||||
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)
|
||||
|
||||
###############################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user