ropy/ropy_mod.py
2022-04-21 14:06:16 +02:00

142 lines
6.4 KiB
Python

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 <philippe.roy@ac-grenoble.fr>
# @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