2022-08-14 08:03:07 +02:00
import bge # Blender Game Engine (UPBGE)
import bpy # Blender
import aud # Sounds
import math
import mathutils
import time
import sys
import os
import threading # Multithreading
2023-02-05 18:17:16 +01:00
import subprocess # Multiprocessus
2022-08-14 08:03:07 +02:00
import xml . etree . ElementTree as ET # Creating/parsing XML file
2022-12-07 17:40:14 +01:00
import runpy # Exécution de script Python légère (sans import)
2023-12-28 17:00:24 +01:00
import astroid # Inspection de script Python (Pylint)
2022-08-14 08:03:07 +02:00
2022-11-06 14:49:34 +01:00
import rp_map1 as rp_map # Map definition
2022-08-24 14:12:23 +02:00
import rp_doc # Documentation
2022-09-30 06:59:52 +02:00
import rp_store # Store
2022-10-09 15:34:06 +02:00
import rp_about # About
2022-08-14 08:03:07 +02:00
###############################################################################
# rp.py
# @title: Ropy
# @project: Ropy (Blender-EduTech)
# @lang: fr
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
2023-12-27 14:36:42 +01:00
# @copyright: Copyright (C) 2020-2024 Philippe Roy
2022-08-14 08:03:07 +02:00
# @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.
#
# Commands trigged by button : cmd_*
# Commands trigged by 3D scene objects : scn_*
# Commands trigged by user (student or map designer) : rp_*
# 3D scene manipulation : manip_*
###############################################################################
2023-02-06 14:40:00 +01:00
# UPBGE scene
2022-08-14 08:03:07 +02:00
scene = bge . logic . getCurrentScene ( )
2023-12-27 14:36:42 +01:00
debug = scene . objects [ ' Terrain ' ] [ ' debug ' ]
2023-02-06 14:40:00 +01:00
eevee = bpy . context . scene . eevee
2023-02-05 18:17:16 +01:00
scene . objects [ ' Commands ' ] [ ' script ' ] = os . path . join ( os . getcwd ( ) , " rp_cmd.py " ) # Script par défaut
2022-08-14 08:03:07 +02:00
# Memory
sys . setrecursionlimit ( 10 * * 5 ) # Limite sur la récursivité (valeur par défaut : 1000) -> segfault de Blender
2023-02-06 14:40:00 +01:00
# FPS
2022-08-14 08:03:07 +02:00
fps_time = 0.0
2023-02-06 14:40:00 +01:00
scene . objects [ ' Commands ' ] [ ' debug_fps ' ] = False
2022-08-14 08:03:07 +02:00
# Config file
rp_config = ET . parse ( ' rp_config.xml ' )
rp_config_tree = rp_config . getroot ( )
# Sounds
2022-08-22 21:56:46 +02:00
audiodev = aud . Device ( )
snd_click = aud . Sound ( ' asset/sounds/rp_click.ogg ' )
2022-08-19 15:43:20 +02:00
# sndbuff_click = aud.Sound.cache(snd_click)
2022-08-22 21:56:46 +02:00
snd_open = aud . Sound ( ' asset/sounds/rp_open.ogg ' )
# sndbuff_open = aud.Sound.cache(snd_open)
snd_close = aud . Sound ( ' asset/sounds/rp_close.ogg ' )
# sndbuff_close = aud.Sound.cache(snd_close)
snd_grid = aud . Sound ( ' asset/sounds/rp_grid.ogg ' )
# sndbuff_grid = aud.Sound.cache(snd_grid)
2022-08-14 08:03:07 +02:00
# 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
###############################################################################
# User interface : texte info et compteurs
###############################################################################
2022-10-02 01:36:40 +02:00
color_text = ( 0 , 0 , 0 , 1 ) # Noir
color_text_red = ( 0.799 , 0.031 , 0.038 , 1 )
color_text_orange = ( 0.799 , 0.176 , 0.054 , 1 )
color_text_yellow = ( 0.799 , 0.617 , 0.021 , 1 )
2022-08-14 08:03:07 +02:00
##
# Mise à jour de l'affichage des compteurs
##
def points_maj ( cont ) :
2022-09-21 07:00:44 +02:00
# Step
if scene . objects [ ' Points-Step-text ' ] [ ' Text ' ] != str ( scene . objects [ ' Points ' ] [ ' step ' ] ) :
scene . objects [ ' Points-Step-text ' ] [ ' Text ' ] = str ( scene . objects [ ' Points ' ] [ ' step ' ] )
2022-10-02 01:36:40 +02:00
if scene . objects [ ' Points ' ] [ ' upgrade_battery ' ] :
scene . objects [ ' Points ' ] [ ' battery ' ] = round ( 100 * ( 1 - ( scene . objects [ ' Points ' ] [ ' step ' ] / 200 ) ) )
else :
scene . objects [ ' Points ' ] [ ' battery ' ] = round ( 100 * ( 1 - ( scene . objects [ ' Points ' ] [ ' step ' ] / 20 ) ) )
if scene . objects [ ' Points ' ] [ ' battery ' ] < = 10 :
scene . objects [ ' Points-Battery ' ] . color = color_text_red
scene . objects [ ' Points-Battery-text ' ] . color = color_text_red
if scene . objects [ ' Points ' ] [ ' battery ' ] < = 0 :
scene . objects [ ' Points-Battery-text ' ] [ ' Text ' ] = " 0 % "
print ( " Plus de batterie ! " )
scene . objects [ ' Rover ' ] [ ' stop ' ] = True
else :
scene . objects [ ' Points-Battery-text ' ] [ ' Text ' ] = str ( scene . objects [ ' Points ' ] [ ' battery ' ] ) + " % "
2022-09-21 07:00:44 +02:00
# Level
if scene . objects [ ' Points-Level-text ' ] [ ' Text ' ] != str ( scene . objects [ ' Points ' ] [ ' level ' ] ) :
scene . objects [ ' Points-Level-text ' ] [ ' Text ' ] = str ( scene . objects [ ' Points ' ] [ ' level ' ] )
2022-10-28 01:24:58 +02:00
scene . objects [ ' Book_level ' ] [ ' Text ' ] = " Niveau actuel : " + str ( scene . objects [ ' Points ' ] [ ' level ' ] )
2022-09-21 07:00:44 +02:00
# Maj du fichier de config (sound : data/mission/level -> [1][1].text) lors d'une augmentation de niveau
2023-02-06 14:40:00 +01:00
if scene . objects [ ' Points ' ] [ ' level ' ] > int ( rp_config_tree [ 1 ] [ 1 ] . text ) and scene . objects [ ' Points ' ] [ ' level_new_flag ' ] :
2022-09-21 07:00:44 +02:00
rp_config_tree [ 1 ] [ 1 ] . text = str ( scene . objects [ ' Points ' ] [ ' level ' ] )
2023-02-06 14:40:00 +01:00
config_save ( )
scene . objects [ ' Points ' ] [ ' level_new_flag ' ] = False
2022-09-21 07:00:44 +02:00
# Nbligne
if scene . objects [ ' Points-Nbligne-text ' ] [ ' Text ' ] != str ( scene . objects [ ' Points ' ] [ ' nbligne ' ] ) :
scene . objects [ ' Points-Nbligne-text ' ] [ ' Text ' ] = str ( scene . objects [ ' Points ' ] [ ' nbligne ' ] )
2022-08-30 03:25:36 +02:00
2022-09-30 06:59:52 +02:00
# Position du Rover
2022-08-30 03:25:36 +02:00
obj = scene . objects [ ' Rover ' ]
2022-10-08 11:35:45 +02:00
obj [ ' w_position ' ] = str ( round ( obj . worldPosition . x , 3 ) ) + " , " + str ( round ( obj . worldPosition . y , 3 ) ) + " , " + str ( round ( obj . worldPosition . z , 3 ) )
2023-02-06 14:40:00 +01:00
2022-08-14 08:03:07 +02:00
###############################################################################
# Terrain
###############################################################################
##
# Initialisation lors du chargement du terrain
##
2022-11-25 18:07:23 +01:00
def terrain_init ( cont ) :
2022-12-16 01:06:14 +01:00
if cont . sensors [ ' Init ' ] . positive == False : # 1 seule fois
2022-11-25 18:07:23 +01:00
return False
2022-12-21 05:54:42 +01:00
2022-08-14 08:03:07 +02:00
# Ajout du Hud
scene . active_camera = scene . objects [ " Camera " ]
scene . objects [ ' Sun ' ] . setVisible ( True , True )
2022-08-22 23:58:42 +02:00
# Mémorisation des positions par défaut
# <worldPosition.x>0.0057830810546875</worldPosition.x>
# <worldPosition.y>-26.440298080444336</worldPosition.y>
# <worldPosition.z>20.22315788269043</worldPosition.z>
scene . objects [ ' Camera ' ] [ ' init_lx ' ] = 0.0057830810546875
scene . objects [ ' Camera ' ] [ ' init_ly ' ] = - 26.440298080444336
scene . objects [ ' Camera ' ] [ ' init_lz ' ] = 20.22315788269043
# scene.objects['Camera']['init_lx']=scene.objects['Camera'].worldPosition.x
# scene.objects['Camera']['init_ly']=scene.objects['Camera'].worldPosition.y
# scene.objects['Camera']['init_lz']=scene.objects['Camera'].worldPosition.z
scene . objects [ ' Camera ' ] [ ' past_lx ' ] = scene . objects [ ' Camera ' ] . worldPosition . x
scene . objects [ ' Camera ' ] [ ' past_ly ' ] = scene . objects [ ' Camera ' ] . worldPosition . y
scene . objects [ ' Camera ' ] [ ' past_lz ' ] = scene . objects [ ' Camera ' ] . worldPosition . z
scene . objects [ ' Terrain ' ] [ ' init_lx ' ] = scene . objects [ ' Terrain ' ] . worldPosition . x
scene . objects [ ' Terrain ' ] [ ' init_ly ' ] = scene . objects [ ' Terrain ' ] . worldPosition . y
scene . objects [ ' Terrain ' ] [ ' init_lz ' ] = scene . objects [ ' Terrain ' ] . worldPosition . z
scene . objects [ ' Terrain ' ] [ ' init_rx ' ] = scene . objects [ ' Terrain ' ] . worldOrientation . to_euler ( ) . x
scene . objects [ ' Terrain ' ] [ ' init_ry ' ] = scene . objects [ ' Terrain ' ] . worldOrientation . to_euler ( ) . y
scene . objects [ ' Terrain ' ] [ ' init_rz ' ] = scene . objects [ ' Terrain ' ] . worldOrientation . to_euler ( ) . z
2022-08-14 08:03:07 +02:00
2022-09-18 16:13:32 +02:00
# Création des balises
2022-08-26 01:58:49 +02:00
scene . objects [ ' Terrain ' ] [ ' map_tile_beacon ' ] = [ ]
2022-09-30 06:59:52 +02:00
for i in range ( 200 ) :
2022-08-26 01:58:49 +02:00
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
2022-09-18 16:13:32 +02:00
2022-10-05 18:52:03 +02:00
# Création des lieux de forage (mission 6)
scene . objects [ ' Terrain ' ] [ ' map_tile_aim-mission6 ' ] = [ ]
for i in range ( 10 ) :
drill_aim = scene . addObject ( " Drill_aim " , scene . objects [ ' Terrain ' ] )
applyRotationTo ( drill_aim , 40 * 2 * math . pi * ( 1 / 360 ) , 0 , 0 , False )
drill_aim . name = " Drill_aim- " + str ( i )
drill_aim . setVisible ( False , True )
drill_tile = scene . addObject ( " Drill_tile " , scene . objects [ ' Terrain ' ] )
drill_tile . name = " Drill_tile- " + str ( i )
drill_tile . setVisible ( False , True )
2022-09-18 16:13:32 +02:00
# Init de la carte
2022-09-20 06:40:11 +02:00
# Read config (mission actuelle : data/mission/current -> [1][0].text)
scene . objects [ ' Points ' ] [ ' mission ' ] = int ( rp_config_tree [ 1 ] [ 0 ] . text )
2022-09-18 16:13:32 +02:00
rp_map . map_init ( )
2022-09-30 06:59:52 +02:00
scene . objects [ ' Terrain ' ] [ ' thread_cmd ' ] = False
2022-08-14 08:03:07 +02:00
rp_map . map_reset ( )
2022-08-22 23:58:42 +02:00
# Récupération de la position de la caméra
2022-08-26 01:58:49 +02:00
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 ' ]
2022-08-22 23:58:42 +02:00
2022-10-09 15:34:06 +02:00
# Camera embarquée
# scene.objects['Camera-Rover'].setViewport(100,100,150,150)
# scene.objects['Camera-Rover'].useViewport = True
# width = bge.render.getWindowWidth()
# height = bge.render.getWindowHeight()
# cam1 = scene.objects["Camera"]
# cam2 = scene.objects["Camera-Rover"]
# cam1.useViewport = True
# cam2.useViewport = True
# cam1.setViewport(0, 0, int(width / 2), height)
# cam2.setViewport(int(width / 2), 0, width, height)
2022-08-14 08:03:07 +02:00
##
2023-02-05 18:17:16 +01:00
# Validation du code Python
2022-08-14 08:03:07 +02:00
##
2023-02-05 18:17:16 +01:00
def python_validation ( file ) :
2023-12-28 06:05:45 +01:00
# Terminer le processus fils précédent
if ( ' pylint_proc ' in scene . objects [ ' Commands ' ] ) :
if scene . objects [ ' Commands ' ] [ ' pylint_proc ' ] . poll ( ) == None :
scene . objects [ ' Commands ' ] [ ' pylint_proc ' ] . terminate ( )
# Lancer le processus fils
scene . objects [ ' Commands ' ] [ ' pylint_proc ' ] = subprocess . Popen ( [ sys . executable , os . path . join ( os . getcwd ( ) , " rp_pylint.py " ) , file ] , stdout = subprocess . PIPE , encoding = ' utf8 ' )
stout = scene . objects [ ' Commands ' ] [ ' pylint_proc ' ] . communicate ( )
# Présence d'erreur
if stout [ 0 ] [ : - 1 ] != ' None ' and len ( stout [ 0 ] [ : - 1 ] ) > 0 :
2023-02-05 18:17:16 +01:00
# UI : information
scene . objects [ ' Cmd-text ' ] [ ' modal ' ] = True
scene . objects [ ' Cmd-text ' ] [ ' Text ' ] = " Erreur dans le script ... "
scene . objects [ ' Cmd-text ' ] . setVisible ( True , False )
2023-12-28 06:05:45 +01:00
# Affichage console
stout_lines = stout [ 0 ] . split ( " \n " )
for stout_line in stout_lines :
print ( " Pylint : " , stout_line ) # Affichage console
2022-12-06 03:48:40 +01:00
return False
2023-12-28 06:05:45 +01:00
# Absence d'erreur
scene . objects [ ' Cmd-text ' ] [ ' modal ' ] = False
scene . objects [ ' Cmd-text ' ] [ ' Text ' ] = " "
scene . objects [ ' Cmd-text ' ] . setVisible ( False , False )
return True
2022-12-06 03:48:40 +01:00
2023-12-28 17:00:24 +01:00
##
# Inspection du code Python : détection des appels
#
# Call(func=<Name.rp_marquer l.1 at 0x7f0d137ebaf0>,
# args=[],
# keywords=[])
##
def python_inspect ( file ) :
functions = [ ]
file_buff = open ( file , ' r ' )
file_txt = file_buff . read ( )
file_lines = file_txt . split ( " \n " )
for i in range ( len ( file_lines ) ) :
try :
node = astroid . extract_node ( file_lines [ i ] )
# print (node)
if str ( node ) . find ( " Call(func=<Name. " ) > - 1 :
functions . append ( str ( node ) [ 16 : str ( node ) . find ( " l.1 " ) - 1 ] )
except :
pass
file_buff . close ( )
return functions
2023-02-06 14:40:00 +01:00
##
# Exécuter le script
##
2022-08-14 08:03:07 +02:00
def terrain_run ( ) :
# Pause
if scene . objects [ ' Terrain ' ] [ ' run ' ] == True :
scene . objects [ ' Terrain ' ] [ ' run ' ] = False
scene . objects [ ' Pause ' ] . setVisible ( False , False )
scene . objects [ ' Pause ' ] . suspendPhysics ( )
scene . objects [ ' Pause-Hl ' ] . setVisible ( False , False )
2022-10-02 01:36:40 +02:00
scene . objects [ ' Run ' ] . restorePhysics ( )
2022-08-14 08:03:07 +02:00
scene . objects [ ' Run-Hl ' ] . setVisible ( True , False )
# Run
else :
scene . objects [ ' Terrain ' ] [ ' run ' ] = True
scene . objects [ ' Run ' ] . setVisible ( False , False )
scene . objects [ ' Run ' ] . suspendPhysics ( )
scene . objects [ ' Run-Hl ' ] . setVisible ( False , False )
2023-12-27 14:36:42 +01:00
# scene.objects['Pause']. restorePhysics() # FIXME pause pas implémentée
# scene.objects['Pause'].setVisible(True,False) # FIXME pause pas implémentée
2022-08-14 08:03:07 +02:00
# Démarrage de la map
2022-08-23 03:39:37 +02:00
if scene . objects [ ' Terrain ' ] [ ' thread_cmd ' ] == False :
2022-10-09 20:26:45 +02:00
time . sleep ( 0.125 )
2022-08-23 03:39:37 +02:00
scene . objects [ ' Terrain ' ] [ ' thread_cmd ' ] = True
2022-08-24 14:12:23 +02:00
rp_map . map_reset ( )
2022-10-09 20:26:45 +02:00
time . sleep ( 0.125 )
2022-08-26 12:41:18 +02:00
2023-12-27 14:36:42 +01:00
# Sauvegarde de la config
config_save ( )
2022-08-26 12:41:18 +02:00
# Nombre de ligne du script Python
2023-02-05 18:17:16 +01:00
file = open ( scene . objects [ ' Commands ' ] [ ' script ' ] , ' r ' )
2022-08-26 12:41:18 +02:00
file_txt = file . read ( )
scene . objects [ ' Points ' ] [ ' nbligne ' ] = len ( file_txt . split ( " \n " ) ) - 28 # 28 lignes utilisées de base
file . close ( )
2022-09-18 16:13:32 +02:00
scene . objects [ ' Rover ' ] [ ' stop ' ] = False
2023-02-07 03:33:32 +01:00
scene . objects [ ' Points-Twins-text ' ] [ ' Text ' ] = " Connection fermée. "
2023-02-05 18:17:16 +01:00
if python_validation ( scene . objects [ ' Commands ' ] [ ' script ' ] ) :
2023-12-28 17:00:24 +01:00
scene . objects [ ' Commands ' ] [ ' functions ' ] = python_inspect ( scene . objects [ ' Commands ' ] [ ' script ' ] )
2023-02-05 18:17:16 +01:00
runpy . run_path ( scene . objects [ ' Commands ' ] [ ' script ' ] , run_name = ' start ' ) # Execution du script utilisateur
2022-08-14 08:03:07 +02:00
# Arrêt de la pause
else :
# FIXME : Relancer Ropy
pass
##
2022-08-23 03:39:37 +02:00
# Arrêt et réinitialisation du cycle (forçage)
2022-08-14 08:03:07 +02:00
##
def terrain_stop ( ) :
2022-08-23 03:39:37 +02:00
scene . objects [ ' Terrain ' ] [ ' thread_cmd ' ] = False
2022-08-24 14:12:23 +02:00
rp_map . map_reset ( )
2022-08-14 08:03:07 +02:00
##
2022-08-23 03:39:37 +02:00
# Fin naturelle du cycle
2022-08-14 08:03:07 +02:00
##
2022-08-23 03:39:37 +02:00
def terrain_end ( cont ) :
if cont . sensors [ ' End cycle ' ] . positive :
scene . objects [ ' Terrain ' ] [ ' run ' ] = False
2023-02-05 18:17:16 +01:00
if python_validation ( scene . objects [ ' Commands ' ] [ ' script ' ] ) :
runpy . run_path ( scene . objects [ ' Commands ' ] [ ' script ' ] , run_name = ' stop ' ) # Fin du script utilisateur
2022-08-14 08:03:07 +02:00
2022-08-23 03:39:37 +02:00
# Commandes
scene . objects [ ' Pause ' ] . setVisible ( False , False )
scene . objects [ ' Pause ' ] . suspendPhysics ( )
scene . objects [ ' Pause-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Run ' ] . setVisible ( True , False )
2022-10-02 01:36:40 +02:00
scene . objects [ ' Run ' ] . restorePhysics ( )
2022-08-14 08:03:07 +02:00
##
# Vitesse du jeu
##
def terrain_speed ( obj ) :
speed_mode = [ 0.25 , 0.5 , 1 , 2 , 4 , 10 ]
speed_mode_txt = [ " 1/4 " , " 1/2 " , " 1 " , " 2 " , " 4 " , " 10 " ]
2022-08-22 21:56:46 +02:00
i = speed_mode . index ( scene . objects [ ' Commands ' ] [ ' speed ' ] )
2022-08-14 08:03:07 +02:00
# Affichage
if obj . name == " Speed_up " and i < 5 :
2022-08-22 21:56:46 +02:00
scene . objects [ ' Commands ' ] [ ' speed ' ] = speed_mode [ i + 1 ]
2024-01-01 22:04:43 +01:00
print ( " Speed_up " )
2022-08-14 08:03:07 +02:00
scene . objects [ ' Text_speed ' ] [ ' Text ' ] = speed_mode_txt [ i + 1 ]
if obj . name == " Speed_down " and i > 0 :
2022-08-22 21:56:46 +02:00
scene . objects [ ' Commands ' ] [ ' speed ' ] = speed_mode [ i - 1 ]
2024-01-01 22:04:43 +01:00
print ( " Speed_down " )
2022-08-14 08:03:07 +02:00
scene . objects [ ' Text_speed ' ] [ ' Text ' ] = speed_mode_txt [ i - 1 ]
2022-08-22 04:41:22 +02:00
##
# Grille
##
def terrain_grid ( ) :
if scene . objects [ ' Grid-u ' ] . visible :
scene . objects [ ' Grid-u ' ] . setVisible ( False , True )
scene . objects [ ' Grid-v ' ] . setVisible ( False , True )
2022-09-20 06:40:11 +02:00
rp_map . aim_hide ( )
2022-08-22 04:41:22 +02:00
else :
2022-08-26 01:58:49 +02:00
scene . objects [ ' Grid-u ' ] [ ' timer ' ] = 0
bpy . data . materials [ " Grid " ] . node_tree . nodes [ " Shader de mélange " ] . inputs [ 0 ] . default_value = 0
2022-09-24 04:53:54 +02:00
bpy . data . materials [ " Grid-Yellow " ] . node_tree . nodes [ " Shader de mélange " ] . inputs [ 0 ] . default_value = 0
bpy . data . materials [ " Grid-Green " ] . node_tree . nodes [ " Shader de mélange " ] . inputs [ 0 ] . default_value = 0
2022-08-26 01:58:49 +02:00
bpy . data . materials [ " Grid-Holo " ] . node_tree . nodes [ " Émission " ] . inputs [ 1 ] . default_value = 0
2022-09-30 06:59:52 +02:00
bpy . data . materials [ " Grid-Holo-Yellow " ] . node_tree . nodes [ " Émission.003 " ] . inputs [ 1 ] . default_value = 0
bpy . data . materials [ " Grid-Holo-Green " ] . node_tree . nodes [ " Émission " ] . inputs [ 1 ] . default_value = 0
2022-08-22 04:41:22 +02:00
scene . objects [ ' Grid-u ' ] . setVisible ( True , True )
scene . objects [ ' Grid-v ' ] . setVisible ( True , True )
2022-10-05 23:53:47 +02:00
rp_map . aim_show ( )
2022-08-22 21:56:46 +02:00
scene . objects [ ' Grid-u ' ] [ ' anim ' ] = True
def terrain_grid_anim ( ) :
2022-08-26 01:58:49 +02:00
bpy . data . materials [ " Grid " ] . node_tree . nodes [ " Shader de mélange " ] . inputs [ 0 ] . default_value = scene . objects [ ' Grid-u ' ] [ ' timer ' ]
2022-09-24 04:53:54 +02:00
bpy . data . materials [ " Grid-Yellow " ] . node_tree . nodes [ " Shader de mélange " ] . inputs [ 0 ] . default_value = scene . objects [ ' Grid-u ' ] [ ' timer ' ]
bpy . data . materials [ " Grid-Green " ] . node_tree . nodes [ " Shader de mélange " ] . inputs [ 0 ] . default_value = scene . objects [ ' Grid-u ' ] [ ' timer ' ]
2022-08-26 01:58:49 +02:00
bpy . data . materials [ " Grid-Holo " ] . node_tree . nodes [ " Émission " ] . inputs [ 1 ] . default_value = scene . objects [ ' Grid-u ' ] [ ' timer ' ] * 5
2022-09-30 06:59:52 +02:00
bpy . data . materials [ " Grid-Holo-Yellow " ] . node_tree . nodes [ " Émission.003 " ] . inputs [ 1 ] . default_value = scene . objects [ ' Grid-u ' ] [ ' timer ' ] * 5
bpy . data . materials [ " Grid-Holo-Green " ] . node_tree . nodes [ " Émission " ] . inputs [ 1 ] . default_value = scene . objects [ ' Grid-u ' ] [ ' timer ' ] * 5
2022-10-08 11:35:45 +02:00
scene . objects [ ' Grid-u ' ] [ ' timer ' ] + = 0.05
2022-08-24 14:12:23 +02:00
if scene . objects [ ' Grid-u ' ] [ ' timer ' ] > = 1 :
2022-08-22 21:56:46 +02:00
scene . objects [ ' Grid-u ' ] [ ' anim ' ] = False
2022-08-22 04:41:22 +02:00
2022-08-14 08:03:07 +02:00
###############################################################################
# Sons
###############################################################################
def sound_play ( sound ) :
if scene . objects [ ' Commands ' ] [ ' sound ' ] :
2022-08-22 21:56:46 +02:00
# playsound('rp_click.ogg')
2022-08-14 08:03:07 +02:00
audiodev . play ( sound )
def sound_set ( ) :
scene . objects [ ' NoSound-cmd ' ] . suspendPhysics ( )
scene . objects [ ' NoSound-cmd ' ] . setVisible ( False , False )
scene . objects [ ' NoSound-cmd-Hl ' ] . setVisible ( False , False )
2022-10-02 01:36:40 +02:00
scene . objects [ ' Sound-cmd ' ] . restorePhysics ( )
2022-08-14 08:03:07 +02:00
scene . objects [ ' Sound-cmd-Hl ' ] . setVisible ( True , False )
scene . objects [ ' Commands ' ] [ ' sound ' ] = True
2022-08-22 04:41:22 +02:00
# scene.objects['Cmd-text']['Text']= "Mute"
scene . objects [ ' Cmd-text ' ] [ ' Text ' ] = " Muet "
2022-08-23 01:53:08 +02:00
# scene.objects['Cmd-text'].setVisible(True,False)
2022-08-14 08:03:07 +02:00
def sound_unset ( ) :
scene . objects [ ' Sound-cmd ' ] . suspendPhysics ( )
scene . objects [ ' Sound-cmd ' ] . setVisible ( False , False )
scene . objects [ ' Sound-cmd-Hl ' ] . setVisible ( False , False )
2022-10-02 01:36:40 +02:00
scene . objects [ ' NoSound-cmd ' ] . restorePhysics ( )
2022-08-14 08:03:07 +02:00
scene . objects [ ' NoSound-cmd-Hl ' ] . setVisible ( True , False )
scene . objects [ ' Commands ' ] [ ' sound ' ] = False
2022-08-22 04:41:22 +02:00
# scene.objects['Cmd-text']['Text']= "Unmute"
scene . objects [ ' Cmd-text ' ] [ ' Text ' ] = " Rétablir le son "
2022-08-23 01:53:08 +02:00
# scene.objects['Cmd-text'].setVisible(True,False)
2022-08-14 08:03:07 +02:00
###############################################################################
# Commandes
###############################################################################
color_cmd = ( 0.8 , 0.8 , 0.8 , 1 ) # Blanc
color_cmd_hl = ( 0.8 , 0.619 , 0.021 , 1 ) # Jaune
##
2023-07-11 22:25:15 +02:00
# Initialisation des commandes
2022-08-14 08:03:07 +02:00
##
2022-11-25 18:07:23 +01:00
def cmd_init ( cont ) :
2022-12-16 01:06:14 +01:00
if cont . sensors [ ' Init ' ] . positive == False : # 1 seule fois
2022-11-25 18:07:23 +01:00
return False
2022-08-14 08:03:07 +02:00
2023-02-05 20:56:46 +01:00
# Configuration de l'écran
2022-10-09 15:34:06 +02:00
bge . render . setWindowSize ( int ( rp_config_tree [ 0 ] [ 3 ] [ 0 ] . text ) , int ( rp_config_tree [ 0 ] [ 3 ] [ 1 ] . text ) )
2023-02-05 20:56:46 +01:00
scene . objects [ ' About ' ] [ ' quality ' ] = int ( rp_config_tree [ 0 ] [ 3 ] [ 2 ] . text )
2023-02-07 06:39:45 +01:00
rp_about . quality_apply ( scene . objects [ ' About ' ] [ ' quality ' ] , True )
2023-02-06 17:34:39 +01:00
2022-10-02 01:36:40 +02:00
# UI : Commands
2022-08-14 08:03:07 +02:00
scene . objects [ ' Run-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Pause ' ] . setVisible ( False , False )
scene . objects [ ' Pause ' ] . suspendPhysics ( )
scene . objects [ ' Pause-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Stop-Hl ' ] . setVisible ( False , False )
2022-09-24 04:53:54 +02:00
scene . objects [ ' Aim-cmd-Hl ' ] . setVisible ( False , False )
2022-08-19 15:43:20 +02:00
scene . objects [ ' Doc-cmd-Hl ' ] . setVisible ( False , False )
2022-10-02 01:36:40 +02:00
scene . objects [ ' Task-cmd-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Task_close-cmd ' ] . setVisible ( False , False )
scene . objects [ ' Task_close-cmd ' ] . suspendPhysics ( )
scene . objects [ ' Task_close-cmd-Hl ' ] . setVisible ( False , False )
2022-09-26 00:34:39 +02:00
scene . objects [ ' Store-cmd-Hl ' ] . setVisible ( False , False )
2022-08-14 08:03:07 +02:00
scene . objects [ ' ResetView-Hl ' ] . setVisible ( False , False )
scene . objects [ ' About-cmd-Hl ' ] . setVisible ( False , False )
2022-09-30 06:59:52 +02:00
scene . objects [ ' Speed_up-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Speed_down-Hl ' ] . setVisible ( False , False )
2022-08-14 08:03:07 +02:00
# UI : Sounds
# Read config (sound : data/config/sound -> [0][1].text)
if rp_config_tree [ 0 ] [ 1 ] . text == " True " :
sound_set ( )
else :
sound_unset ( )
2022-08-19 15:43:20 +02:00
# audiodev.unlock()
2022-08-14 08:03:07 +02:00
# UI : Text, ...
2022-08-23 01:53:08 +02:00
scene . objects [ ' Cmd-text ' ] [ ' Text ' ] = " "
scene . objects [ ' Cmd-text ' ] . setVisible ( True , False )
scene . objects [ ' Points-Map-text ' ] [ ' Text ' ] = " "
2022-08-22 04:41:22 +02:00
scene . objects [ ' Grid-u ' ] . setVisible ( False , True )
scene . objects [ ' Grid-v ' ] . setVisible ( False , True )
scene . objects [ ' Points-Map-text ' ] [ ' Text ' ] = " "
2022-08-23 01:53:08 +02:00
scene . objects [ ' Points-Map-text ' ] . setVisible ( True , False )
2022-11-04 16:30:35 +01:00
scene . objects [ ' Points-Twins ' ] . setVisible ( False , True )
scene . objects [ ' Points-Twins-text ' ] . setVisible ( False , False )
2023-02-05 18:17:16 +01:00
scene . objects [ ' Script-text ' ] [ ' Text ' ] = scene . objects [ ' Commands ' ] [ ' script ' ]
2022-08-14 08:03:07 +02:00
# scene.objects['Info-1-text'].setVisible(False,False)
# scene.objects['Info-2-text'].setVisible(False,False)
# UI : Mouse
# Window size : 738.5 415.5
if scene . objects [ ' Mouse_main ' ] [ ' mouse_graphic ' ] :
bge . render . setMousePosition ( int ( bge . render . getWindowWidth ( ) / 2 ) , int ( bge . render . getWindowHeight ( ) / 2 ) )
bge . render . showMouse ( scene . objects [ ' Commands ' ] [ ' debug_mouse ' ] )
scene . objects [ ' Mouse_main ' ] . worldPosition = [ 0.07 , - 8.11 , 4.71035 ] # Vielle version : [0.118161, -8.24305, 4.71035] ; [0, -3.5, 2], [0, -8, 6]
scene . objects [ ' Mouse_main ' ] . worldScale = [ 30 , 30 , 30 ]
scene . objects [ ' Mouse_main ' ] [ ' past_x ' ] = 0
scene . objects [ ' Mouse_main ' ] [ ' past_y ' ] = 0
scene . objects [ ' Mouse_main ' ] [ ' mouse_up ' ] = 0
else :
scene . objects [ ' Mouse_main ' ] . setVisible ( False , False )
bge . render . showMouse ( True )
2022-09-20 06:40:11 +02:00
# Missions
# Read config (mission actuelle : data/mission/current -> [1][0].text)
# Read config (niveau atteint : data/mission/level -> [1][1].text)
scene . objects [ ' Points ' ] [ ' mission ' ] = int ( rp_config_tree [ 1 ] [ 0 ] . text )
scene . objects [ ' Points ' ] [ ' mission_init ' ] = scene . objects [ ' Points ' ] [ ' mission ' ]
scene . objects [ ' Points ' ] [ ' level ' ] = int ( rp_config_tree [ 1 ] [ 1 ] . text )
scene . objects [ ' Points-Map-text ' ] [ ' Text ' ] = " Mission " + str ( scene . objects [ ' Points ' ] [ ' mission ' ] )
scene . objects [ ' Book_mission ' ] [ ' Text ' ] = " Mission en cours : " + str ( scene . objects [ ' Points ' ] [ ' mission ' ] )
scene . objects [ ' Book_level ' ] [ ' Text ' ] = " Niveau actuel : " + str ( scene . objects [ ' Points ' ] [ ' level ' ] )
2022-08-14 08:03:07 +02:00
2022-09-30 06:59:52 +02:00
# Upgrade
2023-02-06 14:40:00 +01:00
# Read config (upgrades choisis : data/upgrade/ -> [2][i].text)
upgrade_card = ( " battery " , " beacon " , " paint " , " speed " )
for i in range ( len ( upgrade_card ) ) :
if rp_config_tree [ 2 ] [ i ] . text == " True " :
scene . objects [ ' Points ' ] [ ' upgrade_ ' + upgrade_card [ i ] ] = True
2022-09-30 06:59:52 +02:00
upgrade_maj ( )
2023-02-06 14:40:00 +01:00
# Speed
# Read config (game speed : data/config/speed -> [0][0].text)
speed_mode = [ 0.25 , 0.5 , 1 , 2 , 4 , 10 ]
speed_mode_txt = [ " 1/4 " , " 1/2 " , " 1 " , " 2 " , " 4 " , " 10 " ]
if scene . objects [ ' Points ' ] [ ' upgrade_speed ' ] :
scene . objects [ ' Commands ' ] [ ' speed ' ] = float ( rp_config_tree [ 0 ] [ 0 ] . text )
else :
scene . objects [ ' Commands ' ] [ ' speed ' ] = 1.00
i = speed_mode . index ( scene . objects [ ' Commands ' ] [ ' speed ' ] )
scene . objects [ ' Text_speed ' ] [ ' Text ' ] = speed_mode_txt [ i ]
2022-08-21 02:22:56 +02:00
# Windows
2024-01-01 22:04:43 +01:00
windows = ( " Doc " , " Doc_chap-general " , " Doc_chap-missions " , " Doc_chap-rover " , " Doc_chap-python " , " About " , " Credits " , " Task-panel " )
2022-08-21 02:22:56 +02:00
for window in windows :
scene . objects [ window ] . setVisible ( False , True )
2022-08-21 03:03:11 +02:00
rp_doc . init ( )
2022-09-30 06:59:52 +02:00
rp_store . init ( )
2024-01-01 22:04:43 +01:00
scene . objects [ ' Task-panel ' ] . worldPosition = [ 42.6047 , - 2.09252 , 2.99685 ] # Panel task
2022-08-21 02:22:56 +02:00
2022-08-14 08:03:07 +02:00
##
# Highlight des commandes
##
def cmd_hl ( cont ) :
obj = cont . owner
# Activation
if cont . sensors [ ' MO ' ] . status == JUST_ACTIVATED and scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] == 0 :
2022-10-09 15:34:06 +02:00
if obj . name != " Run " and obj . name != " Pause " and obj . name != " Stop " and obj . name != " Doc-cmd-colbox " :
2022-08-14 08:03:07 +02:00
obj . setVisible ( False , True )
scene . objects [ obj . name + ' -Hl ' ] . setVisible ( True , True )
# Run et pause
if obj . name == " Pause " or obj . name == " Run " :
if scene . objects [ ' Terrain ' ] [ ' run ' ] == True :
2022-09-30 06:59:52 +02:00
pass
# scene.objects['Pause'].setVisible(False,False) FIXME pause pas implémenté
# scene.objects['Pause-Hl'].setVisible(True,False) FIXME pause pas implémenté
2022-08-14 08:03:07 +02:00
else :
scene . objects [ ' Run ' ] . setVisible ( False , False )
scene . objects [ ' Run-Hl ' ] . setVisible ( True , False )
# Stop
if obj . name == " Stop " :
2022-08-23 03:39:37 +02:00
scene . objects [ ' Stop ' ] . setVisible ( False , False )
scene . objects [ ' Stop-Hl ' ] . setVisible ( True , False )
2022-08-14 08:03:07 +02:00
2022-10-09 15:34:06 +02:00
# Doc
if obj . name == " Doc-cmd-colbox " :
scene . objects [ ' Doc-cmd ' ] . setVisible ( False , False )
scene . objects [ ' Doc-cmd-Hl ' ] . setVisible ( True , False )
2023-12-28 06:05:45 +01:00
# Texte
2022-08-22 04:41:22 +02:00
text_hl = { " Run " : " Exécuter (F5) " ,
2022-08-22 21:56:46 +02:00
" Stop " : " Stop et initialisation (F6) " ,
2022-08-14 08:03:07 +02:00
" Pause " : " Pause (F5) " ,
2022-09-24 04:53:54 +02:00
" Aim-cmd " : " Afficher/cacher l ' objectif " ,
2022-10-09 15:34:06 +02:00
" Doc-cmd-colbox " : " Documentation " ,
" Store-cmd " : " Boutique " ,
2022-10-02 01:36:40 +02:00
" Task-cmd " : " Liste des tâches " ,
" Task_close-cmd " : " Fermer la liste des tâches " ,
2022-08-22 04:41:22 +02:00
" ResetView " : " Reset de la vue (Touche Début) " ,
2023-02-05 18:17:16 +01:00
" File " : " Changer le fichier de commandes " ,
2022-08-22 04:41:22 +02:00
" About-cmd " : " A propos " ,
" Speed_down " : " Moins vite (-) " ,
" Speed_up " : " Plus vite (+) " ,
" Sound-cmd " : " Muet " ,
" NoSound-cmd " : " Rétablir le son " }
# text_hl ={"Run":"Run (F5)",
# "Stop":"Stop (F6)",
# "Pause":"Pause (F5)",
2022-08-24 14:12:23 +02:00
# "Aim":"Show aim",
2022-08-22 04:41:22 +02:00
# "Doc-cmd":"Documentation",
# "ResetView": "Reset view (Home key)",
2023-02-05 18:17:16 +01:00
# "File": "Change the commands file",
2022-08-22 04:41:22 +02:00
# "About-cmd": "About",
# "Speed_down": "Speed down (-)",
# "Speed_up": "Speed up (+)",
# "Sound-cmd": "Mute",
# "NoSound-cmd": "Unmute"}
2022-08-14 08:03:07 +02:00
scene . objects [ ' Cmd-text ' ] [ ' Text ' ] = text_hl [ obj . name ]
scene . objects [ ' Cmd-text ' ] . setVisible ( True , False )
# Désactivation
if cont . sensors [ ' MO ' ] . status == JUST_RELEASED and ( scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] == 0 or scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] == 9 ) :
2023-12-28 06:05:45 +01:00
# Texte
if scene . objects [ ' Cmd-text ' ] [ ' modal ' ] :
scene . objects [ ' Cmd-text ' ] [ ' Text ' ] = " Erreur dans le script ... "
scene . objects [ ' Cmd-text ' ] . setVisible ( True , False )
else :
scene . objects [ ' Cmd-text ' ] [ ' Text ' ] = " "
scene . objects [ ' Cmd-text ' ] . setVisible ( False , False )
# Icone
2022-10-09 15:34:06 +02:00
if obj . name != " Run " and obj . name != " Pause " and obj . name != " Stop " and obj . name != " Sound-cmd " and obj . name != " NoSound-cmd " and obj . name != " Task-cmd " and obj . name != " Task_close-cmd " and obj . name != " Doc-cmd-colbox " :
2022-08-14 08:03:07 +02:00
scene . objects [ obj . name + ' -Hl ' ] . setVisible ( False , True )
obj . setVisible ( True , True )
# Run et pause
if obj . name == " Pause " or obj . name == " Run " :
if scene . objects [ ' Terrain ' ] [ ' run ' ] == True :
2022-09-30 06:59:52 +02:00
pass
# scene.objects['Pause-Hl'].setVisible(False,False) FIXME pause pas implémenté
# scene.objects['Pause'].setVisible(True,False) FIXME pause pas implémenté
2022-08-14 08:03:07 +02:00
else :
scene . objects [ ' Run-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Run ' ] . setVisible ( True , False )
# Stop
if obj . name == " Stop " :
2022-08-23 03:39:37 +02:00
scene . objects [ ' Stop-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Stop ' ] . setVisible ( True , False )
2022-08-14 08:03:07 +02:00
2022-10-09 15:34:06 +02:00
# Doc
if obj . name == " Doc-cmd-colbox " :
scene . objects [ ' Doc-cmd-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Doc-cmd ' ] . setVisible ( True , False )
2022-08-14 08:03:07 +02:00
# Sound
if obj . name == " NoSound-cmd " and scene . objects [ ' Commands ' ] [ ' sound ' ] == False :
scene . objects [ ' NoSound-cmd-Hl ' ] . setVisible ( False , False )
scene . objects [ ' NoSound-cmd ' ] . setVisible ( True , False )
if obj . name == " Sound-cmd " and scene . objects [ ' Commands ' ] [ ' sound ' ] == True :
scene . objects [ ' Sound-cmd-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Sound-cmd ' ] . setVisible ( True , False )
2022-10-02 01:36:40 +02:00
# Task panel
if obj . name == " Task-cmd " :
scene . objects [ ' Task-cmd-Hl ' ] . setVisible ( False , True )
if scene . objects [ ' Commands ' ] [ ' task ' ] :
scene . objects [ ' Task-cmd ' ] . setVisible ( False , True )
else :
scene . objects [ ' Task-cmd ' ] . setVisible ( True , False )
if obj . name == " Task_close-cmd " :
scene . objects [ ' Task_close-cmd-Hl ' ] . setVisible ( False , True )
if scene . objects [ ' Commands ' ] [ ' task ' ] == False :
scene . objects [ ' Task_close-cmd ' ] . setVisible ( False , True )
else :
scene . objects [ ' Task_close-cmd ' ] . setVisible ( True , False )
2022-08-14 08:03:07 +02:00
##
# Click sur les commandes
##
def cmd_click ( cont ) :
obj = cont . owner
if cont . sensors [ ' Click ' ] . status == JUST_ACTIVATED and cont . sensors [ ' MO ' ] . positive and scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] == 0 :
2022-08-22 21:56:46 +02:00
2022-08-14 08:03:07 +02:00
if obj . name == " Pause " or obj . name == " Run " :
2022-08-22 21:56:46 +02:00
sound_play ( snd_click )
2022-08-14 08:03:07 +02:00
terrain_run ( )
2022-08-23 01:53:08 +02:00
2022-08-14 08:03:07 +02:00
if obj . name == " Stop " :
2022-08-22 21:56:46 +02:00
sound_play ( snd_click )
2022-08-14 08:03:07 +02:00
terrain_stop ( )
2022-08-23 01:53:08 +02:00
2022-09-24 04:53:54 +02:00
if obj . name == " Aim-cmd " :
2022-08-22 21:56:46 +02:00
sound_play ( snd_grid )
2022-08-22 04:41:22 +02:00
terrain_grid ( )
2022-08-23 03:39:37 +02:00
2022-08-14 08:03:07 +02:00
if obj . name == " Speed_up " or obj . name == " Speed_down " :
2022-08-22 21:56:46 +02:00
sound_play ( snd_click )
2022-08-14 08:03:07 +02:00
terrain_speed ( obj )
2022-08-23 03:39:37 +02:00
2022-08-14 08:03:07 +02:00
if obj . name == " ResetView " :
2022-08-22 21:56:46 +02:00
sound_play ( snd_click )
2022-08-14 08:03:07 +02:00
manip_reset ( )
if obj . name == " Sound-cmd " :
sound_unset ( )
if obj . name == " NoSound-cmd " :
sound_set ( )
2022-08-22 21:56:46 +02:00
sound_play ( snd_click )
2022-10-09 15:34:06 +02:00
if obj . name == " Doc-cmd-colbox " :
2022-08-22 21:56:46 +02:00
sound_play ( snd_open )
2022-08-19 15:43:20 +02:00
tablet_open ( )
2023-02-05 18:17:16 +01:00
if obj . name == " File " :
sound_play ( snd_open )
file_open ( )
2022-08-14 08:03:07 +02:00
if obj . name == " About-cmd " :
2022-08-22 21:56:46 +02:00
sound_play ( snd_open )
2022-08-14 08:03:07 +02:00
about_open ( )
2022-09-30 06:59:52 +02:00
if obj . name == " Store-cmd " :
sound_play ( snd_open )
store_open ( )
2022-10-02 01:36:40 +02:00
if obj . name == " Task-cmd " :
sound_play ( snd_open )
task_open ( )
if obj . name == " Task_close-cmd " :
task_close ( )
2022-08-14 08:03:07 +02:00
###############################################################################
# Gestion du clavier
###############################################################################
##
# Mode
#
# 0 : rien (par défaut)
# 1 : Pan avec Shift
# 2 : Zoom avec Ctrl
2022-08-21 03:52:33 +02:00
# 8 : Fenêtre Documentation
# 9 : Fenêtre About
2022-08-14 08:03:07 +02:00
##
def mode ( cont ) :
obj = cont . owner
keyboard = bge . logic . keyboard
# Touche ESC
if JUST_ACTIVATED in keyboard . inputs [ bge . events . ESCKEY ] . queue :
2022-10-02 01:36:40 +02:00
2022-08-14 08:03:07 +02:00
# Fenêtres modales
2022-10-02 01:36:40 +02:00
if scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] == 9 : # About
2022-08-14 08:03:07 +02:00
if scene . objects [ ' About ' ] . visible :
about_close ( )
2022-10-02 01:36:40 +02:00
return
elif scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] == 8 : # Doc et store
if scene . objects [ ' Doc ' ] . visible :
tablet_close ( )
return
2023-12-26 15:06:35 +01:00
if scene . objects [ ' Store-panel ' ] . visible :
2022-10-02 01:36:40 +02:00
store_close ( )
return
2022-08-22 23:58:42 +02:00
else : # Sortir du jeu
2022-08-14 08:03:07 +02:00
terrain_stop ( )
2022-08-22 23:58:42 +02:00
2023-02-06 14:40:00 +01:00
# 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)
2022-08-26 01:58:49 +02:00
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 ' ] )
2023-02-06 14:40:00 +01:00
# Ecran : data/config/screen/width, height, quality-> [0][3][0].text, [0][3][1].text, [0][3][2].text)
2023-02-05 20:56:46 +01:00
screen_width = bge . render . getWindowWidth ( )
screen_height = bge . render . getWindowHeight ( )
rp_config_tree [ 0 ] [ 3 ] [ 0 ] . text = str ( screen_width )
rp_config_tree [ 0 ] [ 3 ] [ 1 ] . text = str ( screen_height )
rp_config_tree [ 0 ] [ 3 ] [ 2 ] . text = str ( scene . objects [ ' About ' ] [ ' quality ' ] )
2023-02-06 14:40:00 +01:00
# Son : data/config/sound -> [0][1].text
rp_config_tree [ 0 ] [ 1 ] . text = str ( scene . objects [ ' Commands ' ] [ ' sound ' ] )
# Vitesse du jeu : data/config/speed -> [0][0].text)
rp_config_tree [ 0 ] [ 0 ] . text = str ( scene . objects [ ' Commands ' ] [ ' speed ' ] )
# Mission et level : data/mission/level -> [1][0].text, [1][1].text)
rp_config_tree [ 1 ] [ 0 ] . text = str ( scene . objects [ ' Points ' ] [ ' mission ' ] )
rp_config_tree [ 1 ] [ 1 ] . text = str ( scene . objects [ ' Points ' ] [ ' level ' ] )
2023-02-07 03:33:32 +01:00
# Upgrade : data/upgrade/i -> [2][i].text)
upgrade_card = ( " battery " , " beacon " , " paint " , " speed " )
for i in range ( len ( upgrade_card ) ) :
if scene . objects [ ' Points ' ] [ " upgrade_ " + upgrade_card [ i ] ] == True :
rp_config_tree [ 2 ] [ i ] . text = " True "
else :
rp_config_tree [ 2 ] [ i ] . text = " False "
2023-02-06 14:40:00 +01:00
config_save ( )
2023-02-05 20:56:46 +01:00
# Sortir
2022-08-14 08:03:07 +02:00
bge . logic . endGame ( )
# Fenêtre modale (inhibition des touches hors ESC)
if scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] == 9 :
return
# Shift -> mode 1 : Pan (clic milieu)
if JUST_ACTIVATED in keyboard . inputs [ bge . events . LEFTSHIFTKEY ] . queue :
obj [ ' manip_mode ' ] = 1
if JUST_ACTIVATED in keyboard . inputs [ bge . events . RIGHTSHIFTKEY ] . queue :
obj [ ' manip_mode ' ] = 1
# Ctrl -> mode 2 : Zoom (clic milieu)
if JUST_ACTIVATED in keyboard . inputs [ bge . events . LEFTCTRLKEY ] . queue :
obj [ ' manip_mode ' ] = 2
if JUST_ACTIVATED in keyboard . inputs [ bge . events . RIGHTCTRLKEY ] . queue :
obj [ ' manip_mode ' ] = 2
# Pas de modificateur -> mode 0 : Pas de Orbit (mode 0) ici
if JUST_RELEASED in keyboard . inputs [ bge . events . LEFTSHIFTKEY ] . queue :
obj [ ' manip_mode ' ] = 0
if JUST_RELEASED in keyboard . inputs [ bge . events . RIGHTSHIFTKEY ] . queue :
obj [ ' manip_mode ' ] = 0
if JUST_RELEASED in keyboard . inputs [ bge . events . LEFTCTRLKEY ] . queue :
obj [ ' manip_mode ' ] = 0
if JUST_RELEASED in keyboard . inputs [ bge . events . RIGHTCTRLKEY ] . queue :
obj [ ' manip_mode ' ] = 0
# Touche Home -> Reset de la vue
if JUST_ACTIVATED in keyboard . inputs [ bge . events . HOMEKEY ] . queue :
manip_reset ( )
2022-08-22 23:58:42 +02:00
# if scene.objects['Mouse_main']['mouse_graphic']:
# bge.render.setMousePosition(int(bge.render.getWindowWidth() / 2), int(bge.render.getWindowHeight() / 2))
# scene.objects['Mouse_main'].worldPosition = [0.07, -8.11, 4.71035] # Vielle version : [0.118161, -8.24305, 4.71035] ; [0, -3.5, 2], [0, -8, 6]
# scene.objects['Mouse_main'].worldScale=[30, 30, 30]
# scene.objects['Mouse_main']['past_x']=0
# scene.objects['Mouse_main']['past_y']=0
2022-08-14 08:03:07 +02:00
# Touche F5 -> Run et Pause
if JUST_ACTIVATED in keyboard . inputs [ bge . events . F5KEY ] . queue :
terrain_run ( )
# Touche F6 -> Stop / Init
if JUST_ACTIVATED in keyboard . inputs [ bge . events . F6KEY ] . queue :
2022-08-23 03:39:37 +02:00
terrain_stop ( )
# if scene.objects['Terrain']['thread_cmd']==True: # FIXME : bien utile ?
# terrain_stop ()
2022-08-14 08:03:07 +02:00
# Touche +/- du pad -> Vitesse + ou /
if JUST_ACTIVATED in keyboard . inputs [ bge . events . PADPLUSKEY ] . queue :
2022-09-30 06:59:52 +02:00
if scene . objects [ ' Points ' ] [ ' upgrade_speed ' ] :
terrain_speed ( scene . objects [ ' Speed_up ' ] )
2022-08-14 08:03:07 +02:00
if JUST_ACTIVATED in keyboard . inputs [ bge . events . PADMINUS ] . queue :
2022-09-30 06:59:52 +02:00
if scene . objects [ ' Points ' ] [ ' upgrade_speed ' ] :
terrain_speed ( scene . objects [ ' Speed_down ' ] )
2022-08-14 08:03:07 +02:00
###############################################################################
# Manipulation 3D de la scène
###############################################################################
##
# Atteindre une orientation (bas niveau)
##
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)
##
# Reset de la manipulation de la vue
##
def manip_reset ( ) :
scene . objects [ ' Camera ' ] . worldPosition . x = scene . objects [ ' Camera ' ] [ ' init_lx ' ]
scene . objects [ ' Camera ' ] . worldPosition . y = scene . objects [ ' Camera ' ] [ ' init_ly ' ]
scene . objects [ ' Camera ' ] . worldPosition . z = scene . objects [ ' Camera ' ] [ ' init_lz ' ]
2022-08-30 03:25:36 +02:00
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
2022-08-14 08:03:07 +02:00
applyRotationTo ( scene . objects [ ' Terrain ' ] , 0 , 0 , 0 )
scene . objects [ ' Cmd-text ' ] [ ' Text ' ] = " "
##
# Position de départ pour la manipulation de la vue
##
def manip_start ( cont ) :
if scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] != 9 :
obj = cont . owner
obj [ ' click_x ' ] = cont . sensors [ ' ClickM ' ] . position [ 0 ]
obj [ ' click_y ' ] = cont . sensors [ ' ClickM ' ] . position [ 1 ]
##
# Cacher le cercle de la manipulation Orbit
##
def manip_stop ( cont ) :
2022-08-26 01:58:49 +02:00
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
2022-08-14 08:03:07 +02:00
# scene.objects['Orbit'].setVisible(False,False)
2022-08-26 01:58:49 +02:00
2022-08-14 08:03:07 +02:00
##
# Manipulation du modèle ou de la caméra
##
def manip ( cont ) :
obj = cont . owner
sensibilite_orbit = 0.00005 # Base : 0.0005
sensibilite_pan = 0.001 # Base : 0.005
sensibilite_zoom = 0.005 # Base : 0.01
delta_x = cont . sensors [ ' DownM ' ] . position [ 0 ] - obj [ ' click_x ' ]
delta_y = cont . sensors [ ' DownM ' ] . position [ 1 ] - obj [ ' click_y ' ]
# Pan
if obj [ ' manip_mode ' ] == 1 : # Shift
scene . objects [ ' Camera ' ] . applyMovement ( ( delta_x * - sensibilite_pan , delta_y * sensibilite_pan , 0 ) , True )
# scene.objects['Commands-colbox'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan, 0), True)
# scene.objects['Commands-colbox'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan*math.cos(50*2*math.pi*(1/360)), delta_y*sensibilite_pan*math.sin(50*2*math.pi*(1/360))), True)
2022-08-22 23:58:42 +02:00
# if scene.objects['Mouse_main']['mouse_graphic']:
# scene.objects['Mouse_main'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan, 0), True)
2022-08-14 08:03:07 +02:00
# Zoom FIXME : marche pas au niveau de la souris
if obj [ ' manip_mode ' ] == 2 : # Ctrl
2022-08-22 23:58:42 +02:00
# if scene.objects['Mouse_main']['mouse_graphic']:
# position_scale_x = 0.0005
# position_scale_y = position_scale_x
# mouse_x=scene.objects['Mouse_main'].sensors["Mouse"].position[0]-int(bge.render.getWindowWidth() / 2)
# mouse_y=scene.objects['Mouse_main'].sensors["Mouse"].position[1]-int(bge.render.getWindowHeight() / 2)
# distance_cam_past= math.sqrt(scene.objects['Camera']['past_ly']**2+scene.objects['Camera']['past_lz']**2)
# distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
# size_scale = (distance_cam/distance_cam_past) * 0.23
if scene . objects [ ' Camera ' ] . worldPosition . z > 0.5 and scene . objects [ ' Camera ' ] . worldPosition . z < 57 :
scene . objects [ ' Camera ' ] . applyMovement ( ( 0 , 0 , ( delta_x + delta_y ) * sensibilite_zoom ) , True )
if scene . objects [ ' Camera ' ] . worldPosition . z < = 0.5 or scene . objects [ ' Camera ' ] . worldPosition . z > = 57 :
scene . objects [ ' Camera ' ] . applyMovement ( ( 0 , 0 , - ( delta_x + delta_y ) * sensibilite_zoom ) , True )
# if scene.objects['Mouse_main']['mouse_graphic']:
# scene.objects['Mouse_main'].applyMovement((mouse_x*(delta_x+delta_y)*sensibilite_zoom*position_scale_x, -mouse_y*(delta_x+delta_y)*sensibilite_zoom*position_scale_y, 0), True)
# scene.objects['Mouse_main'].worldScale *= (delta_x+delta_y)*sensibilite_zoom*size_scale
# scene.objects['Camera']['past_ly']=scene.objects['Camera'].worldPosition.y
# scene.objects['Camera']['past_lz']=scene.objects['Camera'].worldPosition.z
2022-08-14 08:03:07 +02:00
##
# Manipulation du modèle ou de la caméra
##
def manip_wheel ( cont ) :
if scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] != 9 : # Fenêtre modale
obj = cont . owner
2022-08-22 23:58:42 +02:00
# sensibilite_wheel = 5 # Base : 20
sensibilite_wheel = scene . objects [ ' Camera ' ] . worldPosition . z / 5 # Sensibilité progressive
# if scene.objects['Mouse_main']['mouse_graphic']:
# position_scale_x = 0.0005
# position_scale_y = position_scale_x
# mouse_x=scene.objects['Mouse_main'].sensors["Mouse"].position[0]-int(bge.render.getWindowWidth() / 2)
# mouse_y=scene.objects['Mouse_main'].sensors["Mouse"].position[1]-int(bge.render.getWindowHeight() / 2)
# distance_cam_past = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
# # size_scale = (distance_cam/distance_cam_past) * 0.23
# size_scale = 0.2
# # size_scale = 0.23
if cont . sensors [ ' WheelUp ' ] . positive :
2022-08-14 08:03:07 +02:00
scene . objects [ ' Camera ' ] . applyMovement ( ( 0 , 0 , - sensibilite_wheel ) , True )
2022-08-22 23:58:42 +02:00
# if scene.objects['Mouse_main']['mouse_graphic']:
# distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
# scene.objects['Mouse_main'].applyMovement((-mouse_x*sensibilite_wheel*position_scale_x, mouse_y*sensibilite_wheel*position_scale_y, 0), True)
# scene.objects['Mouse_main'].worldScale *= sensibilite_wheel* (distance_cam/distance_cam_past) *size_scale
elif cont . sensors [ ' WheelDown ' ] . positive and scene . objects [ ' Camera ' ] . worldPosition . z < 50 :
2022-08-14 08:03:07 +02:00
scene . objects [ ' Camera ' ] . applyMovement ( ( 0 , 0 , sensibilite_wheel ) , True )
2022-08-22 23:58:42 +02:00
# if scene.objects['Mouse_main']['mouse_graphic']:
# distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
# scene.objects['Mouse_main'].applyMovement((mouse_x*sensibilite_wheel*position_scale_x, -mouse_y*sensibilite_wheel*position_scale_y, 0), True)
# scene.objects['Mouse_main'].worldScale /= sensibilite_wheel* (distance_cam_past/distance_cam) *size_scale
2022-08-14 08:03:07 +02:00
else :
return
2022-08-26 01:58:49 +02:00
manip_stop ( cont )
2022-08-14 08:03:07 +02:00
##
# Icone de la souris
##
def mouse ( cont ) :
if scene . objects [ ' Mouse_main ' ] [ ' mouse_graphic ' ] == False :
return
obj = cont . owner
# Ancienne version basée sur la position de la caméra
# distance_cam_init= math.sqrt(scene.objects['Camera']['init_ly']**2+scene.objects['Camera']['init_lz']**2)
# distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
# ratio = ((distance_cam_init - distance_cam)/distance_cam_init)*1.39 # trop vite -> +, pas assez vite -> -
# scale_x=0.0118-0.0118*ratio
# scale_y=scale_x
# delta_x=cont.sensors["Mouse"].position[0]-obj['past_x']
# delta_y=cont.sensors["Mouse"].position[1]-obj['past_y']
# if delta_x<500 and delta_y<500:
# scene.objects['Mouse_main'].worldPosition.x += delta_x*scale_x
# scene.objects['Mouse_main'].worldPosition.y -= delta_y*scale_y*math.cos(50*2*math.pi*(1/360))
# scene.objects['Mouse_main'].worldPosition.z -= delta_y*scale_y*math.sin(50*2*math.pi*(1/360))
# scene.objects['Mouse_main']['past_x']=cont.sensors["Mouse"].position[0]
# scene.objects['Mouse_main']['past_y']=cont.sensors["Mouse"].position[1]
# Version basée sur obj.getDistanceTo(scene.objects['Camera'])
delta_x = cont . sensors [ " Mouse " ] . position [ 0 ] - obj [ ' past_x ' ]
delta_y = cont . sensors [ " Mouse " ] . position [ 1 ] - obj [ ' past_y ' ]
vect = mathutils . Vector ( ( 1 , 1 , 1 ) ) - obj . getVectTo ( scene . objects [ ' Camera ' ] ) [ 1 ]
dist = obj . getDistanceTo ( scene . objects [ ' Camera ' ] )
# print ("delta_x, delta_y, vect, dist : ", delta_x, delta_y, vect, dist)
if obj [ ' past_dist ' ] == 0 :
obj [ ' past_dist ' ] = obj . getDistanceTo ( scene . objects [ ' Camera ' ] )
ratio = dist / obj [ ' past_dist ' ]
# print ("delta_x, delta_y, vect, dist : ", delta_x, delta_y, vect, dist)
scale_x = ratio * 0.016
scale_y = ratio * 0.0162
# scale_xy=ratio*0.0005
scale_xy = ratio * 0
if delta_x < 500 and delta_y < 500 :
# scene.objects['Mouse_main'].applyMovement((delta_x*scale_x, -vect[1]*delta_y*scale_y, -vect[1]*delta_y*scale_y), False)
scene . objects [ ' Mouse_main ' ] . applyMovement ( ( delta_x * scale_x + delta_x * delta_y * scale_xy ,
- delta_y * scale_y * math . cos ( 50 * 2 * math . pi * ( 1 / 360 ) ) ,
- delta_y * scale_y * math . sin ( 50 * 2 * math . pi * ( 1 / 360 ) ) ) , False )
obj [ ' past_x ' ] = cont . sensors [ " Mouse " ] . position [ 0 ]
obj [ ' past_y ' ] = cont . sensors [ " Mouse " ] . position [ 1 ]
##
# Mise en avant de la souris
##
def mouse_up ( ) :
scene . objects [ ' Mouse_main ' ] [ ' mouse_up ' ] + = 1
if scene . objects [ ' Mouse_main ' ] [ ' mouse_up ' ] == 1 :
decal = 18
size_scale = 0.2
# print (scene.objects['Mouse_main'].getVectTo(scene.objects['Camera'])[1])
vect = scene . objects [ ' Mouse_main ' ] . getVectTo ( scene . objects [ ' Camera ' ] ) [ 1 ]
dist_past = scene . objects [ ' Mouse_main ' ] . getDistanceTo ( scene . objects [ ' Camera ' ] )
scene . objects [ ' Mouse_main ' ] . applyMovement ( ( vect [ 0 ] * decal , vect [ 1 ] * decal , vect [ 2 ] * decal ) , False )
dist = scene . objects [ ' Mouse_main ' ] . getDistanceTo ( scene . objects [ ' Camera ' ] )
scene . objects [ ' Mouse_main ' ] . worldScale * = ( dist / dist_past ) * size_scale
scene . objects [ ' Mouse_main ' ] . worldScale = [ 8 , 8 , 8 ]
##
# Mise en arrière de la souris
##
def mouse_down ( ) :
scene . objects [ ' Mouse_main ' ] [ ' mouse_up ' ] - = 1
if scene . objects [ ' Mouse_main ' ] [ ' mouse_up ' ] == 0 :
decal = 18
size_scale = 0.2
# print (scene.objects['Mouse_main'].getVectTo(scene.objects['Camera'])[1])
vect = scene . objects [ ' Mouse_main ' ] . getVectTo ( scene . objects [ ' Camera ' ] ) [ 1 ]
dist_past = scene . objects [ ' Mouse_main ' ] . getDistanceTo ( scene . objects [ ' Camera ' ] )
scene . objects [ ' Mouse_main ' ] . applyMovement ( ( - vect [ 0 ] * decal , - vect [ 1 ] * decal , - vect [ 2 ] * decal ) , False )
dist = scene . objects [ ' Mouse_main ' ] . getDistanceTo ( scene . objects [ ' Camera ' ] )
scene . objects [ ' Mouse_main ' ] . worldScale / = ( dist_past / dist ) * size_scale
scene . objects [ ' Mouse_main ' ] . worldScale = [ 30 , 30 , 30 ]
2022-08-19 15:43:20 +02:00
###############################################################################
# Documentation
###############################################################################
##
# Allumer la tablette
##
def tablet_open ( ) :
2022-09-30 06:59:52 +02:00
# Fenêtre
2022-08-21 03:52:33 +02:00
scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] = 8 # Fenêtre modale Aide
2022-09-18 16:13:32 +02:00
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 [ ' Camera ' ] . worldPosition . x = scene . objects [ ' Camera ' ] [ ' init_lx ' ]
scene . objects [ ' Camera ' ] . worldPosition . y = scene . objects [ ' Camera ' ] [ ' init_ly ' ]
scene . objects [ ' Camera ' ] . worldPosition . z = scene . objects [ ' Camera ' ] [ ' init_lz ' ]
applyRotationTo ( scene . objects [ ' Terrain ' ] , 0 , 0 , 0 )
scene . objects [ ' Cmd-text ' ] [ ' Text ' ] = " "
2022-08-19 15:43:20 +02:00
# Overlay
2024-01-01 22:04:43 +01:00
scene . active_camera = scene . objects [ " Camera-Simple " ]
2022-08-21 03:52:33 +02:00
scene . objects [ ' Camera ' ] . setVisible ( False , True )
2022-10-10 05:09:00 +02:00
scene . objects [ ' Doc-cmd-colbox ' ] . suspendPhysics ( True )
2022-08-21 03:52:33 +02:00
# Ouvrir la tablette
2022-08-21 03:03:11 +02:00
rp_doc . open ( )
2022-08-19 15:43:20 +02:00
##
2022-09-30 06:59:52 +02:00
# Fermeture de la tablette
2022-08-19 15:43:20 +02:00
##
def tablet_close ( ) :
rp_doc . close ( )
2022-08-21 03:52:33 +02:00
scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] = 0 # Enlever la fenêtre modale
2022-08-19 15:43:20 +02:00
2022-09-20 06:40:11 +02:00
# Maj du fichier de config (mission actuelle : data/mission/current -> [1][0].text)
rp_config_tree [ 1 ] [ 0 ] . text = str ( scene . objects [ ' Points ' ] [ ' mission ' ] )
2023-02-06 14:40:00 +01:00
config_save ( )
2022-09-20 06:40:11 +02:00
2022-08-19 15:43:20 +02:00
# Overlay
2024-01-01 22:04:43 +01:00
scene . objects [ ' Camera ' ] . setVisible ( True , True )
2022-11-06 14:49:34 +01:00
if scene . objects [ ' Commands ' ] [ ' twins ' ] :
scene . objects [ ' Points-Twins ' ] . setVisible ( True , True )
scene . objects [ ' Points-Twins-text ' ] . setVisible ( True , False )
2022-11-07 03:09:51 +01:00
else :
scene . objects [ ' Points-Twins ' ] . setVisible ( False , True )
scene . objects [ ' Points-Twins-text ' ] . setVisible ( False , False )
2022-08-21 03:52:33 +02:00
scene . active_camera = scene . objects [ " Camera " ]
2024-01-01 22:04:43 +01:00
2022-08-21 03:52:33 +02:00
# UI : Commands
scene . objects [ ' Run-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Pause ' ] . setVisible ( False , False )
scene . objects [ ' Pause ' ] . suspendPhysics ( )
scene . objects [ ' Pause-Hl ' ] . setVisible ( False , False )
2022-08-23 03:39:37 +02:00
# scene.objects['Stop'].setVisible(False,False)
# scene.objects['Stop'].suspendPhysics()
2022-08-21 03:52:33 +02:00
scene . objects [ ' Stop-Hl ' ] . setVisible ( False , False )
2022-09-24 04:53:54 +02:00
scene . objects [ ' Aim-cmd-Hl ' ] . setVisible ( False , False )
2022-08-21 03:52:33 +02:00
scene . objects [ ' Doc-cmd-Hl ' ] . setVisible ( False , False )
2022-10-10 05:09:00 +02:00
scene . objects [ ' Doc-cmd-colbox ' ] . restorePhysics ( )
2022-08-21 03:52:33 +02:00
scene . objects [ ' ResetView-Hl ' ] . setVisible ( False , False )
scene . objects [ ' About-cmd-Hl ' ] . setVisible ( False , False )
2022-09-30 06:59:52 +02:00
scene . objects [ ' Speed_up-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Speed_down-Hl ' ] . setVisible ( False , False )
2022-08-21 03:52:33 +02:00
scene . objects [ ' Cmd-text ' ] . setVisible ( False , False )
2022-08-19 15:43:20 +02:00
2022-10-02 01:36:40 +02:00
# Task panel
if scene . objects [ ' Commands ' ] [ ' task ' ] :
scene . objects [ ' Task-cmd ' ] . setVisible ( False , True )
scene . objects [ ' Task-cmd ' ] . suspendPhysics ( )
scene . objects [ ' Task-cmd-Hl ' ] . setVisible ( False , True )
scene . objects [ ' Task_close-cmd ' ] . setVisible ( True , True )
scene . objects [ ' Task_close-cmd ' ] . restorePhysics ( )
scene . objects [ ' Task_close-cmd-Hl ' ] . setVisible ( False , True )
else :
scene . objects [ ' Task_close-cmd ' ] . setVisible ( False , True )
scene . objects [ ' Task_close-cmd ' ] . suspendPhysics ( )
scene . objects [ ' Task_close-cmd-Hl ' ] . setVisible ( False , True )
scene . objects [ ' Task-cmd ' ] . setVisible ( True , True )
scene . objects [ ' Task-cmd ' ] . restorePhysics ( )
scene . objects [ ' Task-cmd-Hl ' ] . setVisible ( False , True )
2022-10-27 21:35:08 +02:00
# Vitesse
if scene . objects [ ' Points ' ] [ ' upgrade_speed ' ] == False :
scene . objects [ ' Text_speed ' ] . setVisible ( False , True )
scene . objects [ ' Text_speed_label-fr ' ] . setVisible ( False , True )
scene . objects [ ' Speed_down ' ] . setVisible ( False , True )
scene . objects [ ' Speed_up ' ] . setVisible ( False , True )
2022-08-26 01:58:49 +02:00
# 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 ' ]
2022-09-20 06:40:11 +02:00
# Reset si changement de mission
if scene . objects [ ' Points ' ] [ ' mission_init ' ] != scene . objects [ ' Points ' ] [ ' mission ' ] :
terrain_stop ( )
2022-10-02 01:36:40 +02:00
rp_map . task ( )
2022-09-20 06:40:11 +02:00
if scene . objects [ ' Grid-u ' ] . visible :
rp_map . aim_show ( )
scene . objects [ ' Points ' ] [ ' mission_init ' ] = scene . objects [ ' Points ' ] [ ' mission ' ]
2022-08-19 15:43:20 +02:00
##
2022-08-21 03:52:33 +02:00
# Clic pour fermer la tablette
2022-08-19 15:43:20 +02:00
##
def tablet_close_click ( cont ) :
if cont . sensors [ ' Click ' ] . status == JUST_ACTIVATED and cont . sensors [ ' MO ' ] . positive :
2022-08-22 21:56:46 +02:00
sound_play ( snd_close )
2022-08-19 15:43:20 +02:00
tablet_close ( )
2022-10-02 01:36:40 +02:00
###############################################################################
# Liste des tâches
###############################################################################
##
# Allumer la tablette des tâches
##
def task_open ( ) :
scene . objects [ ' Commands ' ] [ ' task ' ] = True
scene . objects [ ' Task-cmd ' ] . setVisible ( False , True )
scene . objects [ ' Task-cmd ' ] . suspendPhysics ( )
scene . objects [ ' Task-cmd-Hl ' ] . setVisible ( False , True )
2024-01-01 22:04:43 +01:00
scene . objects [ ' Task-panel ' ] . setVisible ( True , True )
scene . objects [ ' Task-panel ' ] [ ' timer ' ] = 0
scene . objects [ ' Task-panel ' ] [ ' anim_open ' ] = True
2022-10-02 01:36:40 +02:00
rp_map . task ( )
def task_open_anim ( ) :
x0_cam = 0.005783
y0_cam = - 26.4403
z0_cam = 20.2232
x_cam = scene . objects [ ' Camera ' ] . worldPosition . x
y_cam = scene . objects [ ' Camera ' ] . worldPosition . y
z_cam = scene . objects [ ' Camera ' ] . worldPosition . z
resol = 50
x0 = 0.291678 - x0_cam + x_cam
y0 = - 25.9416 - y0_cam + y_cam
z0 = 19.793 - z0_cam + z_cam
x1 = 0.201271 - x0_cam + x_cam
y1 = - 25.9416 - y0_cam + y_cam
z1 = 19.793 - z0_cam + z_cam
2024-01-01 22:04:43 +01:00
xi = x0 + ( ( x1 - x0 ) / resol ) * scene . objects [ ' Task-panel ' ] [ ' timer ' ]
yi = y0 + ( ( y1 - y0 ) / resol ) * scene . objects [ ' Task-panel ' ] [ ' timer ' ]
zi = z0 + ( ( z1 - z0 ) / resol ) * scene . objects [ ' Task-panel ' ] [ ' timer ' ]
scene . objects [ ' Task-panel ' ] . worldPosition = [ xi , yi , zi ]
scene . objects [ ' Task-panel ' ] [ ' timer ' ] + = 1
if scene . objects [ ' Task-panel ' ] [ ' timer ' ] == resol :
scene . objects [ ' Task-panel ' ] [ ' anim_open ' ] = False
2022-10-02 01:36:40 +02:00
scene . objects [ ' Task_close-cmd ' ] . setVisible ( True , True )
scene . objects [ ' Task_close-cmd-Hl ' ] . setVisible ( False , True )
scene . objects [ ' Task_close-cmd ' ] . restorePhysics ( )
##
# Allumer la tablette des tâches
##
def task_close ( ) :
scene . objects [ ' Commands ' ] [ ' task ' ] = False
scene . objects [ ' Task_close-cmd ' ] . setVisible ( False , True )
scene . objects [ ' Task_close-cmd ' ] . suspendPhysics ( )
scene . objects [ ' Task_close-cmd-Hl ' ] . setVisible ( False , True )
2024-01-01 22:04:43 +01:00
scene . objects [ ' Task-panel ' ] [ ' timer ' ] = 0
scene . objects [ ' Task-panel ' ] [ ' anim_close ' ] = True
2022-10-02 01:36:40 +02:00
def task_close_anim ( ) :
x0_cam = 0.005783
y0_cam = - 26.4403
z0_cam = 20.2232
x_cam = scene . objects [ ' Camera ' ] . worldPosition . x
y_cam = scene . objects [ ' Camera ' ] . worldPosition . y
z_cam = scene . objects [ ' Camera ' ] . worldPosition . z
resol = 50
x0 = 0.201271 - x0_cam + x_cam
y0 = - 25.9416 - y0_cam + y_cam
z0 = 19.793 - z0_cam + z_cam
x1 = 0.291678 - x0_cam + x_cam
y1 = - 25.9416 - y0_cam + y_cam
z1 = 19.793 - z0_cam + z_cam
2024-01-01 22:04:43 +01:00
xi = x0 + ( ( x1 - x0 ) / resol ) * scene . objects [ ' Task-panel ' ] [ ' timer ' ]
yi = y0 + ( ( y1 - y0 ) / resol ) * scene . objects [ ' Task-panel ' ] [ ' timer ' ]
zi = z0 + ( ( z1 - z0 ) / resol ) * scene . objects [ ' Task-panel ' ] [ ' timer ' ]
scene . objects [ ' Task-panel ' ] . worldPosition = [ xi , yi , zi ]
scene . objects [ ' Task-panel ' ] [ ' timer ' ] + = 1
if scene . objects [ ' Task-panel ' ] [ ' timer ' ] == resol :
scene . objects [ ' Task-panel ' ] [ ' anim_close ' ] = False
scene . objects [ ' Task-panel ' ] . setVisible ( False , True )
2022-10-02 01:36:40 +02:00
scene . objects [ ' Task-cmd ' ] . setVisible ( True , True )
scene . objects [ ' Task-cmd-Hl ' ] . setVisible ( False , True )
scene . objects [ ' Task-cmd ' ] . restorePhysics ( )
##
# Clic pour fermer la tablette des tâches
##
def task_close_click ( cont ) :
if cont . sensors [ ' Click ' ] . status == JUST_ACTIVATED and cont . sensors [ ' MO ' ] . positive :
sound_play ( snd_close )
task_close ( )
2022-09-30 06:59:52 +02:00
###############################################################################
# Store
###############################################################################
##
# Prendre en compte les upgrades
##
def upgrade_maj ( ) :
2023-02-06 14:40:00 +01:00
2022-09-30 06:59:52 +02:00
# Batterie
if scene . objects [ ' Points ' ] [ ' upgrade_battery ' ] :
2022-10-03 14:02:01 +02:00
scene . objects [ ' St-Panels-3 ' ] . setVisible ( True , True )
2022-09-30 06:59:52 +02:00
else :
2022-10-03 14:02:01 +02:00
scene . objects [ ' St-Panels-3 ' ] . setVisible ( False , True )
2022-09-30 06:59:52 +02:00
# Balise, voir rp_marquer ()
if scene . objects [ ' Points ' ] [ ' upgrade_beacon ' ] :
2022-10-03 14:02:01 +02:00
scene . objects [ ' St-Cubes ' ] . setVisible ( True , True )
2022-09-30 06:59:52 +02:00
else :
2022-10-03 14:02:01 +02:00
scene . objects [ ' St-Cubes ' ] . setVisible ( False , True )
2022-09-30 06:59:52 +02:00
2022-10-03 14:02:01 +02:00
# Peinture (uniquement sous forme de fonction)
2022-09-30 06:59:52 +02:00
# Vitesse
if scene . objects [ ' Points ' ] [ ' upgrade_speed ' ] :
scene . objects [ ' Text_speed ' ] . setVisible ( True , True )
scene . objects [ ' Text_speed_label-fr ' ] . setVisible ( True , True )
scene . objects [ ' Speed_down ' ] . setVisible ( True , True )
scene . objects [ ' Speed_down ' ] . restorePhysics ( )
scene . objects [ ' Speed_up ' ] . setVisible ( True , True )
scene . objects [ ' Speed_up ' ] . restorePhysics ( )
else :
scene . objects [ ' Text_speed ' ] . setVisible ( False , True )
scene . objects [ ' Text_speed_label-fr ' ] . setVisible ( False , True )
scene . objects [ ' Speed_down ' ] . setVisible ( False , True )
scene . objects [ ' Speed_down ' ] . suspendPhysics ( )
scene . objects [ ' Speed_up ' ] . setVisible ( False , True )
scene . objects [ ' Speed_up ' ] . suspendPhysics ( )
##
# Ouvrir le store
##
def store_open ( ) :
upgrade_maj ( )
if scene . objects [ ' Grid-u ' ] . visible :
2023-12-26 15:06:35 +01:00
scene . objects [ ' Store-panel ' ] [ ' Grid_visible ' ] = True
2022-09-30 06:59:52 +02:00
terrain_grid ( )
else :
2023-12-26 15:06:35 +01:00
scene . objects [ ' Store-panel ' ] [ ' Grid_visible ' ] = False
2022-09-30 06:59:52 +02:00
rp_store . open ( )
##
# Fermer le store
##
def store_close ( ) :
rp_store . close ( )
scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] = 0 # Enlever la fenêtre modale
2023-12-27 14:36:42 +01:00
2022-09-30 06:59:52 +02:00
# Maj du fichier de config (upgrade : data/upgrade/i -> [2][i].text)
upgrade_card = ( " battery " , " beacon " , " paint " , " speed " )
for i in range ( len ( upgrade_card ) ) :
2024-01-01 16:47:53 +01:00
if scene . objects [ ' Points ' ] [ " upgrade_ " + upgrade_card [ i ] ] :
2022-09-30 06:59:52 +02:00
rp_config_tree [ 2 ] [ i ] . text = " True "
else :
rp_config_tree [ 2 ] [ i ] . text = " False "
2023-02-06 14:40:00 +01:00
config_save ( )
2022-09-30 06:59:52 +02:00
# Overlay
2024-01-01 22:04:43 +01:00
scene . objects [ ' Camera ' ] . setVisible ( True , True )
2022-11-06 14:49:34 +01:00
if scene . objects [ ' Commands ' ] [ ' twins ' ] :
scene . objects [ ' Points-Twins ' ] . setVisible ( True , True )
scene . objects [ ' Points-Twins-text ' ] . setVisible ( True , False )
2022-11-07 03:09:51 +01:00
else :
scene . objects [ ' Points-Twins ' ] . setVisible ( False , True )
scene . objects [ ' Points-Twins-text ' ] . setVisible ( False , False )
2022-09-30 06:59:52 +02:00
scene . active_camera = scene . objects [ " Camera " ]
# UI : Commands
scene . objects [ ' Run-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Pause ' ] . setVisible ( False , False )
scene . objects [ ' Pause ' ] . suspendPhysics ( )
scene . objects [ ' Pause-Hl ' ] . setVisible ( False , False )
# scene.objects['Stop'].setVisible(False,False)
# scene.objects['Stop'].suspendPhysics()
scene . objects [ ' Stop-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Aim-cmd-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Doc-cmd-Hl ' ] . setVisible ( False , False )
scene . objects [ ' ResetView-Hl ' ] . setVisible ( False , False )
scene . objects [ ' About-cmd-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Speed_up-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Speed_down-Hl ' ] . setVisible ( False , False )
scene . objects [ ' Cmd-text ' ] . setVisible ( False , False )
2022-10-02 01:36:40 +02:00
# Task panel
if scene . objects [ ' Commands ' ] [ ' task ' ] :
scene . objects [ ' Task-cmd ' ] . setVisible ( False , True )
scene . objects [ ' Task-cmd ' ] . suspendPhysics ( )
scene . objects [ ' Task-cmd-Hl ' ] . setVisible ( False , True )
scene . objects [ ' Task_close-cmd ' ] . setVisible ( True , True )
scene . objects [ ' Task_close-cmd ' ] . restorePhysics ( )
scene . objects [ ' Task_close-cmd-Hl ' ] . setVisible ( False , True )
else :
scene . objects [ ' Task_close-cmd ' ] . setVisible ( False , True )
scene . objects [ ' Task_close-cmd ' ] . suspendPhysics ( )
scene . objects [ ' Task_close-cmd-Hl ' ] . setVisible ( False , True )
scene . objects [ ' Task-cmd ' ] . setVisible ( True , True )
scene . objects [ ' Task-cmd ' ] . restorePhysics ( )
scene . objects [ ' Task-cmd-Hl ' ] . setVisible ( False , True )
2022-09-30 06:59:52 +02:00
# Maj de l'interface
upgrade_maj ( )
# Affichage de la grille + mission
2023-12-26 15:06:35 +01:00
if scene . objects [ ' Store-panel ' ] [ ' Grid_visible ' ] :
2022-09-30 06:59:52 +02:00
terrain_grid ( )
##
# Clic pour fermer le store
##
def store_close_click ( cont ) :
if cont . sensors [ ' Click ' ] . status == JUST_ACTIVATED and cont . sensors [ ' MO ' ] . positive :
sound_play ( snd_close )
store_close ( )
2023-02-05 18:17:16 +01:00
###############################################################################
# Fichier
###############################################################################
2023-02-06 14:40:00 +01:00
##
# Sélectionner le fichier de commandes
##
2023-02-05 18:17:16 +01:00
def file_open ( ) :
2023-12-28 06:05:45 +01:00
# Terminer le processus fils précédent
2023-02-05 18:17:16 +01:00
if ( ' file_proc ' in scene . objects [ ' Commands ' ] ) :
if scene . objects [ ' Commands ' ] [ ' file_proc ' ] . poll ( ) == None :
scene . objects [ ' Commands ' ] [ ' file_proc ' ] . terminate ( )
2023-12-28 06:05:45 +01:00
# Démarrer le processus fils
2023-02-05 18:17:16 +01:00
if sys . platform == " linux " : # wxPython ne s'installe pas bien sur GNU/linux -> Qt5
scene . objects [ ' Commands ' ] [ ' file_proc ' ] = subprocess . Popen ( [ sys . executable , os . path . join ( os . getcwd ( ) , " rp_file_qt.py " ) ] , stdout = subprocess . PIPE , encoding = ' utf8 ' )
else : # Qt5 ne s'installe pas bien sur Windows -> wxPython
scene . objects [ ' Commands ' ] [ ' file_proc ' ] = subprocess . Popen ( [ sys . executable , os . path . join ( os . getcwd ( ) , " rp_file_wx.py " ) ] , stdout = subprocess . PIPE , encoding = ' utf8 ' )
2023-12-28 06:05:45 +01:00
# Récupérer le nom du fichier
2023-02-05 18:17:16 +01:00
stout = scene . objects [ ' Commands ' ] [ ' file_proc ' ] . communicate ( )
2023-02-07 03:33:32 +01:00
if stout [ 0 ] [ : - 1 ] != ' None ' and len ( stout [ 0 ] [ : - 1 ] ) > 0 :
2023-02-05 18:17:16 +01:00
scene . objects [ ' Commands ' ] [ ' script ' ] = stout [ 0 ] [ : - 1 ]
scene . objects [ ' Script-text ' ] [ ' Text ' ] = scene . objects [ ' Commands ' ] [ ' script ' ]
2023-02-06 14:40:00 +01:00
config_load ( )
##
# Sauvegarder la configuration
##
def config_save ( ) :
buffer_xml = ET . tostring ( rp_config_tree )
fichier_xml = os . path . join ( os . path . split ( ( scene . objects [ ' Commands ' ] [ ' script ' ] ) ) [ 0 ] , " rp_config.xml " )
with open ( fichier_xml , " wb " ) as f :
f . write ( buffer_xml )
##
# Chargement de la configuration
##
def config_load ( ) :
2023-12-27 14:36:42 +01:00
# Lecture du nouveau fichier
2023-02-06 14:40:00 +01:00
fichier_xml = os . path . join ( os . path . split ( ( scene . objects [ ' Commands ' ] [ ' script ' ] ) ) [ 0 ] , " rp_config.xml " )
2023-02-07 03:33:32 +01:00
if os . path . exists ( fichier_xml ) == False :
return
2023-02-06 14:40:00 +01:00
rp_config2 = ET . parse ( fichier_xml )
rp_config_tree2 = rp_config2 . getroot ( )
2023-12-27 14:36:42 +01:00
# Réécriture de la configuration courante (trois niveaux) avec le nouveau fichier
for i in range ( len ( rp_config_tree ) ) :
if debug :
print ( " XML config : i, tag : " , i , rp_config_tree2 [ i ] . tag )
child_flag_i = False
for child_i in rp_config_tree [ i ] :
child_flag_i = True
if child_flag_i :
for j in range ( len ( rp_config_tree [ i ] ) ) :
child_flag_j = False
for child_j in rp_config_tree [ i ] [ j ] :
child_flag_j = True
if child_flag_j :
if debug :
print ( " XML config : i, j, tag : " , i , j , rp_config_tree2 [ i ] [ j ] . tag )
for k in range ( len ( rp_config_tree [ i ] [ j ] ) ) :
rp_config_tree [ i ] [ j ] [ k ] . text = rp_config_tree2 [ i ] [ j ] [ k ] . text
if debug :
print ( " XML config : i, j, k, tag, text : " , i , j , k , rp_config_tree2 [ i ] [ j ] [ k ] . tag , rp_config_tree2 [ i ] [ j ] [ k ] . text )
else :
rp_config_tree [ i ] [ j ] . text = rp_config_tree2 [ i ] [ j ] . text
if debug :
print ( " XML config : i, j, tag, text : " , i , j , rp_config_tree2 [ i ] [ j ] . tag , rp_config_tree2 [ i ] [ j ] . text )
else :
rp_config_tree [ i ] . text = rp_config_tree2 [ i ] . text
if debug :
print ( " XML config : i, tag, text : " , i , rp_config_tree2 [ i ] . tag , rp_config_tree2 [ i ] . text )
2023-02-06 14:40:00 +01:00
# Configuration de l'écran
2023-12-27 14:36:42 +01:00
bge . render . setWindowSize ( int ( rp_config_tree [ 0 ] [ 3 ] [ 0 ] . text ) , int ( rp_config_tree [ 0 ] [ 3 ] [ 1 ] . text ) )
scene . objects [ ' About ' ] [ ' quality ' ] = int ( rp_config_tree [ 0 ] [ 3 ] [ 2 ] . text )
2023-02-06 17:34:39 +01:00
rp_about . quality_apply ( scene . objects [ ' About ' ] [ ' quality ' ] )
2023-02-06 14:40:00 +01:00
# Init de la carte
# Read config (mission actuelle : data/mission/current -> [1][0].text)
2023-12-27 14:36:42 +01:00
scene . objects [ ' Points ' ] [ ' mission ' ] = int ( rp_config_tree [ 1 ] [ 0 ] . text )
2023-02-06 14:40:00 +01:00
rp_map . map_init ( )
scene . objects [ ' Terrain ' ] [ ' thread_cmd ' ] = False
rp_map . map_reset ( )
# Récupération de la position de la caméra
2023-12-27 14:36:42 +01:00
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 )
2023-02-06 14:40:00 +01:00
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 ' ]
# UI : Sounds
# Read config (sound : data/config/sound -> [0][1].text)
2023-12-27 14:36:42 +01:00
if rp_config_tree [ 0 ] [ 1 ] . text == " True " :
2023-02-06 14:40:00 +01:00
sound_set ( )
else :
sound_unset ( )
# audiodev.unlock()
# Missions
# Read config (mission actuelle : data/mission/current -> [1][0].text)
# Read config (niveau atteint : data/mission/level -> [1][1].text)
2023-12-27 14:36:42 +01:00
scene . objects [ ' Points ' ] [ ' mission ' ] = int ( rp_config_tree [ 1 ] [ 0 ] . text )
2023-02-06 14:40:00 +01:00
scene . objects [ ' Points ' ] [ ' mission_init ' ] = scene . objects [ ' Points ' ] [ ' mission ' ]
2023-12-27 14:36:42 +01:00
scene . objects [ ' Points ' ] [ ' level ' ] = int ( rp_config_tree [ 1 ] [ 1 ] . text )
2023-02-06 14:40:00 +01:00
scene . objects [ ' Points-Map-text ' ] [ ' Text ' ] = " Mission " + str ( scene . objects [ ' Points ' ] [ ' mission ' ] )
scene . objects [ ' Book_mission ' ] [ ' Text ' ] = " Mission en cours : " + str ( scene . objects [ ' Points ' ] [ ' mission ' ] )
scene . objects [ ' Book_level ' ] [ ' Text ' ] = " Niveau actuel : " + str ( scene . objects [ ' Points ' ] [ ' level ' ] )
2023-12-27 14:36:42 +01:00
rp_map . task ( )
if scene . objects [ ' Grid-u ' ] . visible :
rp_map . aim_show ( )
2023-02-06 14:40:00 +01:00
# Upgrade
upgrade_card = ( " battery " , " beacon " , " paint " , " speed " )
for i in range ( len ( upgrade_card ) ) :
2023-12-27 14:36:42 +01:00
if rp_config_tree [ 2 ] [ i ] . text == " True " :
2023-02-06 14:40:00 +01:00
scene . objects [ ' Points ' ] [ ' upgrade_ ' + upgrade_card [ i ] ] = True
else :
scene . objects [ ' Points ' ] [ ' upgrade_ ' + upgrade_card [ i ] ] = False
upgrade_maj ( )
2023-02-05 18:17:16 +01:00
2023-02-06 14:40:00 +01:00
# Speed
# Read config (game speed : data/config/speed -> [0][0].text)
speed_mode = [ 0.25 , 0.5 , 1 , 2 , 4 , 10 ]
speed_mode_txt = [ " 1/4 " , " 1/2 " , " 1 " , " 2 " , " 4 " , " 10 " ]
if scene . objects [ ' Points ' ] [ ' upgrade_speed ' ] :
2023-12-27 14:36:42 +01:00
scene . objects [ ' Commands ' ] [ ' speed ' ] = float ( rp_config_tree [ 0 ] [ 0 ] . text )
2023-02-06 14:40:00 +01:00
else :
scene . objects [ ' Commands ' ] [ ' speed ' ] = 1.00
i = speed_mode . index ( scene . objects [ ' Commands ' ] [ ' speed ' ] )
scene . objects [ ' Text_speed ' ] [ ' Text ' ] = speed_mode_txt [ i ]
2022-08-14 08:03:07 +02:00
###############################################################################
# About
###############################################################################
##
# Ouvrir le about
##
def about_open ( ) :
2022-08-21 03:52:33 +02:00
scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] = 9 # Fenêtre modale About
2022-09-18 16:13:32 +02:00
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 [ ' Camera ' ] . worldPosition . x = scene . objects [ ' Camera ' ] [ ' init_lx ' ]
scene . objects [ ' Camera ' ] . worldPosition . y = scene . objects [ ' Camera ' ] [ ' init_ly ' ]
scene . objects [ ' Camera ' ] . worldPosition . z = scene . objects [ ' Camera ' ] [ ' init_lz ' ]
applyRotationTo ( scene . objects [ ' Terrain ' ] , 0 , 0 , 0 )
scene . objects [ ' Cmd-text ' ] [ ' Text ' ] = " "
2022-10-09 15:34:06 +02:00
rp_about . open ( )
2022-08-16 03:14:28 +02:00
2022-08-14 08:03:07 +02:00
##
# Fermer le about
##
def about_close ( ) :
scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] = 0
scene . objects [ ' About ' ] . setVisible ( False , True )
2022-08-19 15:43:20 +02:00
scene . objects [ ' About ' ] . worldPosition = [ 42 , - 2 , 3 ]
2022-08-26 01:58:49 +02:00
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 ' ]
2023-02-07 06:39:45 +01:00
# Maj du fichier de config (écran : data/config/screen/width, height, quality-> [0][3][0].text, [0][3][1].text, [0][3][2].text)
screen_width = bge . render . getWindowWidth ( )
screen_height = bge . render . getWindowHeight ( )
rp_config_tree [ 0 ] [ 3 ] [ 0 ] . text = str ( screen_width )
rp_config_tree [ 0 ] [ 3 ] [ 1 ] . text = str ( screen_height )
rp_config_tree [ 0 ] [ 3 ] [ 2 ] . text = str ( scene . objects [ ' About ' ] [ ' quality ' ] )
2023-02-06 14:40:00 +01:00
config_save ( )
2022-08-14 08:03:07 +02:00
##
# Click pour fermer le about
##
def about_close_click ( cont ) :
if cont . sensors [ ' Click ' ] . status == JUST_ACTIVATED and cont . sensors [ ' MO ' ] . positive :
2022-08-22 21:56:46 +02:00
sound_play ( snd_close )
2022-08-14 08:03:07 +02:00
about_close ( )