mirror of
https://forge.apps.education.fr/blender-edutech/ropy.git
synced 2024-01-27 08:23:20 +01:00
253 lines
10 KiB
Python
253 lines
10 KiB
Python
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
|||
|
import aud # Sounds
|
|||
|
|
|||
|
###############################################################################
|
|||
|
# rp_doc.py
|
|||
|
# @title: Documentation du Robot 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
|
|||
|
#
|
|||
|
# 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.
|
|||
|
#
|
|||
|
#
|
|||
|
###############################################################################
|
|||
|
|
|||
|
scene = bge.logic.getCurrentScene()
|
|||
|
|
|||
|
# Colors
|
|||
|
# color_doc_chap = (0.153, 0.116, 0.105, 1) # WoodDark
|
|||
|
# color_doc_fct = (0.326, 0.101, 0.0592, 1) # BrownDark
|
|||
|
# color_doc_fct = (0.577, 0.233, 0.115, 1) # Brown
|
|||
|
# color_doc_hl = (0.799, 0.617, 0.021, 1) # Yellow
|
|||
|
# color_doc_hl = (0.13, 0.254, 0.407, 1) # BlueDark
|
|||
|
|
|||
|
color_doc_chap = (0, 1, 0.857,1) # Turquoise
|
|||
|
color_doc_fct = (0, 1, 0.857,1) # Turquoise
|
|||
|
color_doc_hl = (0.799, 0.617, 0.021, 1) # Jaune
|
|||
|
color_doc_activate = (0.936, 0.033, 1, 1) # Rose
|
|||
|
|
|||
|
# Sounds
|
|||
|
# audiodev = aud.Device()
|
|||
|
# snd_book_open = aud.Sound('asset/sounds/book_open.ogg')
|
|||
|
# sndbuff_book_open = aud.Sound.cache(snd_book_open)
|
|||
|
# snd_book_close = aud.Sound('asset/sounds/book_close.ogg')
|
|||
|
# sndbuff_book_close = aud.Sound.cache(snd_book_close)
|
|||
|
# snd_book_flip = aud.Sound('asset/sounds/book_flip.ogg')
|
|||
|
# sndbuff_book_flip = aud.Sound.cache(snd_book_flip)
|
|||
|
|
|||
|
# UPBGE constants
|
|||
|
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
|||
|
JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
|
|||
|
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
|||
|
# JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED
|
|||
|
|
|||
|
# Functions description
|
|||
|
fct_description ={}
|
|||
|
|
|||
|
###############################################################################
|
|||
|
# Tower
|
|||
|
###############################################################################
|
|||
|
|
|||
|
tower_card=["Build-card", "Remove-card"]
|
|||
|
|
|||
|
# ct_build (x, y, category, name, color, style)
|
|||
|
ct_build_title="Build a tower"
|
|||
|
ct_build_text="ct_build (x,y, category, name, color, style)\n \v- x position (integer)\n \v- y position (integer)\n"
|
|||
|
ct_build_text = ct_build_text +" \v- category (string) : \n \v \v- \"Archer tower\" (default value)\n \v \v- \"Mage tower\"\n"
|
|||
|
ct_build_text = ct_build_text +" \v- name (string)\n \v- color (RGB tuple, default=purple)\n"
|
|||
|
ct_build_text = ct_build_text +" \v- style (string) : \n \v \v- \"square\" (default value) or \"round\"\n \v \v- version : A (default value), B or C\n \v \v- exemple : 'round-B' \n"
|
|||
|
ct_build_text = ct_build_text +" \v- Return boolean flag (builded -> True)\n\n"
|
|||
|
ct_build_text = ct_build_text +"Predefined colors : blue, green, magenta,\n orange, purple, red, turquoise, yellow.\n\n"
|
|||
|
ct_build_text = ct_build_text +"Exemple : ct_build (1, 1, \"Archer tower\", \n \"Tower #1\", yellow, \"round-A\")\n"
|
|||
|
fct_description.update({"Build-card" : [ct_build_title, ct_build_text]})
|
|||
|
|
|||
|
# ct_remove (x, y)
|
|||
|
ct_remove_title="Remove a tower"
|
|||
|
ct_remove_text=" ct_remove (x, y) \n \v - x position (integer)\n \v - y position (integer)\n"
|
|||
|
fct_description.update({"Remove-card" : [ct_remove_title, ct_remove_text]})
|
|||
|
|
|||
|
###############################################################################
|
|||
|
# Tech
|
|||
|
###############################################################################
|
|||
|
|
|||
|
tech_card=[]
|
|||
|
|
|||
|
###############################################################################
|
|||
|
# Spell
|
|||
|
###############################################################################
|
|||
|
|
|||
|
spell_card=[]
|
|||
|
|
|||
|
###############################################################################
|
|||
|
# Interface
|
|||
|
###############################################################################
|
|||
|
|
|||
|
##
|
|||
|
# Initialisation de la tablette
|
|||
|
##
|
|||
|
|
|||
|
def init():
|
|||
|
|
|||
|
# Mettre les pages avec la couleurs par defaut
|
|||
|
# scene.objects['Doc'].worldPosition = [0, -21, 15.75]
|
|||
|
scene.objects['Doc'].worldPosition = [0, -21, 15.8]
|
|||
|
scene.objects['Doc_close'].color = color_doc_chap
|
|||
|
for page in ("general", "missions", "rover", "python"):
|
|||
|
scene.objects["Doc_icon_"+page].color = color_doc_chap
|
|||
|
scene.objects["Doc_icon_"+page+"-text"].color = color_doc_chap
|
|||
|
scene.objects['Doc'].setVisible(True,True)
|
|||
|
scene.objects['Doc_title'].setVisible(False,True)
|
|||
|
scene.objects['Doc_text'].setVisible(False,True)
|
|||
|
# sound_play (sndbuff_book_open)
|
|||
|
|
|||
|
# Activer la page screen (page par defaut)
|
|||
|
scene.objects['Doc_chap-general'].worldPosition = scene.objects['Doc'].worldPosition
|
|||
|
scene.objects['Doc_chap-general'].setVisible(True,True)
|
|||
|
scene.objects['Doc']['page_chap'] = "general"
|
|||
|
|
|||
|
# scene.objects['Book']['page_fct'] = ""
|
|||
|
# scene.objects['Book_chap-screen'].color = color_doc_activate
|
|||
|
# scene.objects['Book_page_screen'].worldPosition = scene.objects['Book'].worldPosition
|
|||
|
# scene.objects['Book_page_screen'].setVisible(True,True)
|
|||
|
|
|||
|
# Mettre les cartes avec la couleurs par defaut
|
|||
|
# for i in range(len(map_card)):
|
|||
|
# scene.objects[map_card[i]].color = color_doc_fct
|
|||
|
# for i in range(len(tower_card)):
|
|||
|
# scene.objects[tower_card[i]].color = color_doc_fct
|
|||
|
# for i in range(len(tech_card)):
|
|||
|
# scene.objects[tech_card[i]].color = color_doc_fct
|
|||
|
# for i in range(len(spell_card)):
|
|||
|
# scene.objects[spell_card[i]].color = color_doc_fct
|
|||
|
|
|||
|
##
|
|||
|
# Fermeture du livre
|
|||
|
##
|
|||
|
|
|||
|
def close():
|
|||
|
# sound_play (sndbuff_book_close)
|
|||
|
|
|||
|
# Effacer les fonctions cartes
|
|||
|
scene.objects['Doc'].setVisible(False,True)
|
|||
|
scene.objects['Doc'].worldPosition = [35, -2, 2]
|
|||
|
scene.objects['Doc_chap-general'].setVisible(False,True)
|
|||
|
scene.objects['Doc_chap-general'].worldPosition = [35, -5, 0]
|
|||
|
scene.objects['Doc_chap-missions'].setVisible(False,True)
|
|||
|
scene.objects['Doc_chap-missions'].worldPosition = [35, -7, -2]
|
|||
|
scene.objects['Doc_chap-rover'].setVisible(False,True)
|
|||
|
scene.objects['Doc_chap-rover'].worldPosition = [35, -9, -4]
|
|||
|
scene.objects['Doc_chap-python'].setVisible(False,True)
|
|||
|
scene.objects['Doc_chap-python'].worldPosition = [35, -11, -6]
|
|||
|
scene.objects['Doc'].setVisible(False,True)
|
|||
|
scene.objects['Doc'].worldPosition = [35, -2, 2]
|
|||
|
|
|||
|
##
|
|||
|
# Highlight du livre
|
|||
|
##
|
|||
|
|
|||
|
def hl (cont):
|
|||
|
if cont.sensors['MO'].status == JUST_ACTIVATED :
|
|||
|
obj = cont.owner
|
|||
|
name=obj.name[:-7]
|
|||
|
name_text=obj.name[:-7]+"-text"
|
|||
|
if name == scene.objects['Doc']['page_chap'] or name == scene.objects['Doc']['page_fct'] :
|
|||
|
scene.objects[name].color = color_doc_activate
|
|||
|
if name != "Doc_close" :
|
|||
|
scene.objects[name_text].color = color_doc_activate
|
|||
|
else:
|
|||
|
scene.objects[name].color = color_doc_hl
|
|||
|
if name != "Doc_close" :
|
|||
|
scene.objects[name_text].color = color_doc_hl
|
|||
|
|
|||
|
if cont.sensors['MO'].status == JUST_RELEASED :
|
|||
|
obj = cont.owner
|
|||
|
name=obj.name[:-7]
|
|||
|
name_text=obj.name[:-7]+"-text"
|
|||
|
if name == scene.objects['Doc']['page_chap'] or name == scene.objects['Doc']['page_fct'] :
|
|||
|
scene.objects[name].color = color_doc_activate
|
|||
|
if name != "Doc_close" :
|
|||
|
scene.objects[name_text].color = color_doc_activate
|
|||
|
else:
|
|||
|
scene.objects[name].color = color_doc_fct
|
|||
|
if name != "Doc_close" :
|
|||
|
scene.objects[name_text].color = color_doc_fct
|
|||
|
|
|||
|
# if name == scene.objects['Book']['page_chap'] or name == scene.objects['Book']['page_fct'] :
|
|||
|
# scene.objects[name].color = color_doc_activate
|
|||
|
# else:
|
|||
|
# if name[5]=="c":
|
|||
|
# scene.objects[name].color = color_doc_chap
|
|||
|
# else:
|
|||
|
# scene.objects[name].color = color_doc_fct
|
|||
|
|
|||
|
##
|
|||
|
# Afficher le chapitre
|
|||
|
##
|
|||
|
|
|||
|
def chapter(cont):
|
|||
|
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and cont.sensors['Click'].positive:
|
|||
|
# sound_play (sndbuff_book_flip)
|
|||
|
obj = cont.owner
|
|||
|
last_name_chap= scene.objects['Doc']['page_chap']
|
|||
|
name_chap= obj.name[9:-7]
|
|||
|
scene.objects['Doc_icon_'+last_name_chap].color = color_doc_chap
|
|||
|
scene.objects['Doc_icon_'+last_name_chap+'-text'].color = color_doc_chap
|
|||
|
scene.objects['Doc_icon_'+name_chap].color = color_doc_activate
|
|||
|
scene.objects['Doc_icon_'+name_chap+'-text'].color = color_doc_activate
|
|||
|
scene.objects['Doc']['page_chap'] = name_chap
|
|||
|
|
|||
|
# last_name_fct= scene.objects['Doc']['page_fct']
|
|||
|
# if last_name_fct != "":
|
|||
|
# scene.objects[last_name_fct].color = color_doc_fct
|
|||
|
# scene.objects['Book']['page_fct'] = ""
|
|||
|
|
|||
|
# Effacer les fonctions cartes
|
|||
|
scene.objects['Doc_chap-general'].setVisible(False,True)
|
|||
|
scene.objects['Doc_chap-missions'].setVisible(False,True)
|
|||
|
scene.objects['Doc_chap-rover'].setVisible(False,True)
|
|||
|
scene.objects['Doc_chap-python'].setVisible(False,True)
|
|||
|
scene.objects['Doc_title'].setVisible(False,True)
|
|||
|
scene.objects['Doc_text'].setVisible(False,True)
|
|||
|
|
|||
|
# Afficher la page
|
|||
|
scene.objects['Doc_chap-'+name_chap].worldPosition = scene.objects['Doc'].worldPosition
|
|||
|
scene.objects['Doc_chap-'+name_chap].setVisible(True,True)
|
|||
|
|
|||
|
##
|
|||
|
# Afficher les details de la fonction à partir d'une carte
|
|||
|
##
|
|||
|
|
|||
|
def card (cont):
|
|||
|
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
|||
|
sound_play (sndbuff_book_flip)
|
|||
|
obj = cont.owner
|
|||
|
|
|||
|
# Highlight des cartes
|
|||
|
last_name_fct= scene.objects['Book']['page_fct']
|
|||
|
name_fct= obj.name[:-7]
|
|||
|
if last_name_fct != "":
|
|||
|
scene.objects[last_name_fct].color = color_doc_fct
|
|||
|
scene.objects['Book']['page_fct'] = name_fct
|
|||
|
scene.objects[name_fct].color = color_doc_activate
|
|||
|
|
|||
|
# Afficher le texte de la fonction
|
|||
|
print ("name_fct : ", name_fct)
|
|||
|
print ("fct_description : ", fct_description)
|
|||
|
scene.objects['Book_text_title']['Text'] = fct_description[name_fct][0]
|
|||
|
scene.objects['Book_text']['Text'] = fct_description[name_fct][1]
|
|||
|
scene.objects['Book_text_title'].setVisible(True, False)
|
|||
|
scene.objects['Book_text'].setVisible(True, False)
|
|||
|
|
|||
|
##
|
|||
|
# Sounds
|
|||
|
##
|
|||
|
|
|||
|
def sound_play (sound):
|
|||
|
pass # FIXME
|
|||
|
# if scene.objects['Commands']['sound']:
|
|||
|
# audiodev.play(sound)
|