2022-08-14 08:03:07 +02:00
import bge # Blender Game Engine (UPBGE)
import bpy # Blender
import aud # Sounds
import math
import mathutils
2022-10-09 15:34:06 +02:00
import numpy as np
2022-08-14 08:03:07 +02:00
import time
import sys
import os
2022-11-04 16:30:35 +01:00
import webbrowser # Lien internet
2022-08-14 08:03:07 +02:00
import threading # Multithreading
import xml . etree . ElementTree as ET # Creating/parsing XML file
2022-11-04 16:30:35 +01:00
import runpy # Execution de script Python légère (sans import)
2022-12-06 03:48:40 +01:00
import ast # Parser de code Python
from pylint import epylint as lint # Controle de code Python
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
# import ct_cmd # user script (commands)
###############################################################################
# rp.py
# @title: 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.
#
# 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_*
###############################################################################
# Debug flag
scene = bge . logic . getCurrentScene ( )
scene . objects [ ' Commands ' ] [ ' debug_fps ' ] = False
# Memory
sys . setrecursionlimit ( 10 * * 5 ) # Limite sur la récursivité (valeur par défaut : 1000) -> segfault de Blender
# Dynamic import user file
# importlib.invalidate_caches()
# ct_map = importlib.import_module('ct_map1') # Waves script
# ct_cmd = importlib.import_module('ct_cmd') # User script (commands) -> segfault de Blender
# UPBGE scene
eevee = bpy . context . scene . eevee
fps_time = 0.0
# 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
if scene . objects [ ' Points ' ] [ ' level ' ] > int ( rp_config_tree [ 1 ] [ 1 ] . text ) :
rp_config_tree [ 1 ] [ 1 ] . text = str ( scene . objects [ ' Points ' ] [ ' level ' ] )
buffer_xml = ET . tostring ( rp_config_tree )
with open ( " rp_config.xml " , " wb " ) as f :
f . write ( buffer_xml )
# 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 ) )
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 ) :
if cont . sensors [ ' Init ' ] . positive == False :
return False
2022-10-09 15:34:06 +02:00
2022-08-14 08:03:07 +02:00
# Ajout du Hud
scene . active_camera = scene . objects [ " Camera " ]
scene . objects [ ' Sun ' ] . setVisible ( True , True )
scene . addOverlayCollection ( scene . cameras [ ' Camera-Hud ' ] , bpy . data . collections [ ' Hud ' ] )
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
# Configuration du moteur de rendu
eevee . use_eevee_smaa = True
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
##
# Mise en route et pause du cycle
##
2022-12-06 03:48:40 +01:00
def python_validation ( ) :
lint . py_run ( ' rp_cmd.py --disable=C --disable=W --disable=R ' )
with open ( ' rp_cmd.py ' ) as f :
contents = f . read ( )
try :
ast . parse ( contents )
# or compile(contents, fname, 'exec', ast.PyCF_ONLY_AST)
return True
except SyntaxError :
return False
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 )
2022-09-30 06:59:52 +02:00
# scene.objects['Pause']. restorePhysics() # FIXME pause pas implémenté
# scene.objects['Pause'].setVisible(True,False) # FIXME pause pas implémenté
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
# Nombre de ligne du script Python
# print (os.getcwd())
file = open ( ' rp_cmd.py ' , ' r ' )
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
2022-12-06 03:48:40 +01:00
if python_validation ( ) :
runpy . run_module ( ' rp_cmd ' , 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
2022-12-06 03:48:40 +01:00
if python_validation ( ) :
runpy . run_module ( ' rp_cmd ' , 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 ]
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 ]
2022-08-14 08:03:07 +02:00
scene . objects [ ' Text_speed ' ] [ ' Text ' ] = speed_mode_txt [ i - 1 ]
2022-08-22 23:58:42 +02:00
# Maj du fichier de config (vitesse du jeu : data/config/speed -> [0][0].text)
2022-08-22 21:56:46 +02:00
rp_config_tree [ 0 ] [ 0 ] . text = str ( scene . objects [ ' Commands ' ] [ ' speed ' ] )
2022-08-14 08:03:07 +02:00
buffer_xml = ET . tostring ( rp_config_tree )
with open ( " rp_config.xml " , " wb " ) as f :
f . write ( buffer_xml )
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
# Maj du fichier de config (sound : data/config/sound -> [0][1].text)
rp_config_tree [ 0 ] [ 1 ] . text = str ( scene . objects [ ' Commands ' ] [ ' sound ' ] )
buffer_xml = ET . tostring ( rp_config_tree )
with open ( " rp_config.xml " , " wb " ) as f :
f . write ( buffer_xml )
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
# Maj du fichier de config (sound : data/config/sound -> [0][1].text)
rp_config_tree [ 0 ] [ 1 ] . text = str ( scene . objects [ ' Commands ' ] [ ' sound ' ] )
buffer_xml = ET . tostring ( rp_config_tree )
with open ( " rp_config.xml " , " wb " ) as f :
f . write ( buffer_xml )
###############################################################################
# Commandes
###############################################################################
color_cmd = ( 0.8 , 0.8 , 0.8 , 1 ) # Blanc
color_cmd_hl = ( 0.8 , 0.619 , 0.021 , 1 ) # Jaune
##
# Init
##
2022-11-25 18:07:23 +01:00
def cmd_init ( cont ) :
if cont . sensors [ ' Init ' ] . positive == False :
return False
2022-08-14 08:03:07 +02:00
2022-10-09 15:34:06 +02:00
# Taille de la fenêtre
# Read config (screen size : data/config/screen/width-> [0][3][0].text)
bge . render . setWindowSize ( int ( rp_config_tree [ 0 ] [ 3 ] [ 0 ] . text ) , int ( rp_config_tree [ 0 ] [ 3 ] [ 1 ] . text ) )
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 )
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 )
# 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 " ]
2022-09-30 06:59:52 +02:00
if scene . objects [ ' Points ' ] [ ' upgrade_speed ' ] :
scene . objects [ ' Commands ' ] [ ' speed ' ] = float ( rp_config_tree [ 0 ] [ 0 ] . text )
else :
scene . objects [ ' Commands ' ] [ ' speed ' ] = 1.00
2022-08-22 21:56:46 +02:00
i = speed_mode . index ( scene . objects [ ' Commands ' ] [ ' speed ' ] )
2022-08-14 08:03:07 +02:00
scene . objects [ ' Text_speed ' ] [ ' Text ' ] = speed_mode_txt [ i ]
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
upgrade_maj ( )
2022-08-21 02:22:56 +02:00
# Windows
2022-10-02 01:36:40 +02:00
windows = ( " Doc " , " Doc_chap-general " , " Doc_chap-missions " , " Doc_chap-rover " , " Doc_chap-python " , " About " , " Task " )
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 ( )
2022-10-02 01:36:40 +02:00
scene . objects [ ' Task ' ] . 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 )
2022-08-14 08:03:07 +02:00
# Text
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) " ,
" 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)",
# "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 ) :
2022-08-23 01:53:08 +02:00
scene . objects [ ' Cmd-text ' ] [ ' Text ' ] = " "
scene . objects [ ' Cmd-text ' ] . setVisible ( False , False )
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 ( )
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
if scene . objects [ ' Store ' ] . visible :
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
# 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 ' ] )
2022-08-22 23:58:42 +02:00
# print ("Fin :", scene.objects['Camera'].worldPosition.x, scene.objects['Camera'].worldPosition.y, scene.objects['Camera'].worldPosition.z)
buffer_xml = ET . tostring ( rp_config_tree )
with open ( " rp_config.xml " , " wb " ) as f :
f . write ( buffer_xml )
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
2022-08-21 03:52:33 +02:00
scene . removeOverlayCollection ( bpy . data . collections [ ' Hud ' ] )
scene . objects [ ' Points ' ] . setVisible ( False , True )
scene . objects [ ' Commands ' ] . setVisible ( False , True )
scene . active_camera = scene . objects [ " Camera-Hud " ]
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 ' ] )
buffer_xml = ET . tostring ( rp_config_tree )
with open ( " rp_config.xml " , " wb " ) as f :
f . write ( buffer_xml )
2022-08-19 15:43:20 +02:00
# Overlay
2022-08-21 03:52:33 +02:00
scene . objects [ ' Points ' ] . 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 . objects [ ' Commands ' ] . setVisible ( True , True )
scene . objects [ ' Camera ' ] . setVisible ( True , True )
scene . active_camera = scene . objects [ " Camera " ]
scene . addOverlayCollection ( scene . cameras [ ' Camera-Hud ' ] , bpy . data . collections [ ' Hud ' ] )
2022-08-19 15:43:20 +02: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 )
scene . objects [ ' Task ' ] . setVisible ( True , True )
scene . objects [ ' Task ' ] [ ' timer ' ] = 0
scene . objects [ ' Task ' ] [ ' anim_open ' ] = True
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
xi = x0 + ( ( x1 - x0 ) / resol ) * scene . objects [ ' Task ' ] [ ' timer ' ]
yi = y0 + ( ( y1 - y0 ) / resol ) * scene . objects [ ' Task ' ] [ ' timer ' ]
zi = z0 + ( ( z1 - z0 ) / resol ) * scene . objects [ ' Task ' ] [ ' timer ' ]
scene . objects [ ' Task ' ] . worldPosition = [ xi , yi , zi ]
scene . objects [ ' Task ' ] [ ' timer ' ] + = 1
if scene . objects [ ' Task ' ] [ ' timer ' ] == resol :
scene . objects [ ' Task ' ] [ ' anim_open ' ] = False
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 )
scene . objects [ ' Task ' ] [ ' timer ' ] = 0
scene . objects [ ' Task ' ] [ ' anim_close ' ] = True
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
xi = x0 + ( ( x1 - x0 ) / resol ) * scene . objects [ ' Task ' ] [ ' timer ' ]
yi = y0 + ( ( y1 - y0 ) / resol ) * scene . objects [ ' Task ' ] [ ' timer ' ]
zi = z0 + ( ( z1 - z0 ) / resol ) * scene . objects [ ' Task ' ] [ ' timer ' ]
scene . objects [ ' Task ' ] . worldPosition = [ xi , yi , zi ]
scene . objects [ ' Task ' ] [ ' timer ' ] + = 1
if scene . objects [ ' Task ' ] [ ' timer ' ] == resol :
scene . objects [ ' Task ' ] [ ' anim_close ' ] = False
scene . objects [ ' Task ' ] . setVisible ( False , True )
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 ( ) :
# Read config (upgrades choisis : data/upgrade/ -> [2][i].text)
upgrade_card = ( " battery " , " beacon " , " paint " , " speed " )
scene . objects [ ' Points ' ] [ ' upgrade_nb ' ] = 0
for i in range ( len ( upgrade_card ) ) :
if rp_config_tree [ 2 ] [ i ] . text == " True " :
scene . objects [ ' Points ' ] [ ' upgrade_ ' + upgrade_card [ i ] ] = True
scene . objects [ ' Points ' ] [ ' upgrade_nb ' ] + = 1
scene . objects [ " Store- " + upgrade_card [ i ] + " -card " ] [ ' upgraded ' ] = True
scene . objects [ ' Points ' ] [ ' upgrade_credit ' ] = scene . objects [ ' Points ' ] [ ' level ' ] - 1 - scene . objects [ ' Points ' ] [ ' upgrade_nb ' ]
# 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 :
scene . objects [ ' Store ' ] [ ' Grid_visible ' ] = True
terrain_grid ( )
else :
scene . objects [ ' Store ' ] [ ' Grid_visible ' ] = False
rp_store . open ( )
##
# Fermer le store
##
def store_close ( ) :
rp_store . close ( )
scene . objects [ ' Terrain ' ] [ ' manip_mode ' ] = 0 # Enlever la fenêtre modale
# 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 ) ) :
if scene . objects [ " Store- " + upgrade_card [ i ] + " -card " ] [ ' upgraded ' ] == True :
rp_config_tree [ 2 ] [ i ] . text = " True "
else :
rp_config_tree [ 2 ] [ i ] . text = " False "
buffer_xml = ET . tostring ( rp_config_tree )
with open ( " rp_config.xml " , " wb " ) as f :
f . write ( buffer_xml )
# Overlay
scene . objects [ ' Points ' ] . 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 . objects [ ' Commands ' ] . setVisible ( True , True )
scene . objects [ ' Camera ' ] . setVisible ( True , True )
scene . active_camera = scene . objects [ " Camera " ]
scene . addOverlayCollection ( scene . cameras [ ' Camera-Hud ' ] , bpy . data . collections [ ' Hud ' ] )
# 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
if scene . objects [ ' Store ' ] [ ' Grid_visible ' ] :
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 ( )
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 ' ]
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 ( )
##
2022-10-09 15:34:06 +02:00
# Configuration de l'écran
2022-08-14 08:03:07 +02:00
##
2022-10-22 01:04:48 +02:00
def get_near_pos ( array , value ) :
2022-10-09 15:34:06 +02:00
array = np . asarray ( array )
idx = ( np . abs ( array - value ) ) . argmin ( )
return idx
2022-08-14 08:03:07 +02:00
2022-10-22 01:04:48 +02:00
def about_screen_up ( cont ) :
2022-10-09 15:34:06 +02:00
if cont . sensors [ ' Click ' ] . status == JUST_ACTIVATED and cont . sensors [ ' MO ' ] . positive :
screen_width_mode = [ 640 , 960 , 1280 , 1920 ]
screen_height_mode = [ 360 , 540 , 720 , 1080 ]
screen_mode_txt = [ " 640x360 " , " 960x540 " , " 1280x720 " , " 1920x1080 " ]
2022-10-22 01:04:48 +02:00
i = get_near_pos ( screen_width_mode , bge . render . getWindowWidth ( ) )
2022-10-09 15:34:06 +02:00
if i > = 0 and i < 3 :
screen_width = screen_width_mode [ i + 1 ]
screen_height = screen_height_mode [ i + 1 ]
2022-10-22 01:04:48 +02:00
scene . objects [ ' About_screen ' ] [ ' Text ' ] = " SCREEN SIZE : " + str ( screen_width ) + " x " + str ( screen_height )
bge . render . setWindowSize ( screen_width , screen_height )
2022-11-26 01:29:27 +01:00
# Boutons < et >
if screen_width < = 640 :
scene . objects [ ' About_screen-down ' ] . setVisible ( False , True )
scene . objects [ ' About_screen-down-colbox ' ] . suspendPhysics ( True )
else :
scene . objects [ ' About_screen-down ' ] . setVisible ( True , True )
scene . objects [ ' About_screen-down-colbox ' ] . restorePhysics ( )
if screen_width > = 1920 :
scene . objects [ ' About_screen-up ' ] . setVisible ( False , True )
scene . objects [ ' About_screen-up-colbox ' ] . suspendPhysics ( True )
else :
scene . objects [ ' About_screen-up ' ] . setVisible ( True , True )
scene . objects [ ' About_screen-up-colbox ' ] . restorePhysics ( )
2022-10-22 01:04:48 +02:00
# Maj du fichier de config (screen size : data/config/screen/width-> [0][3][0].text)
rp_config_tree [ 0 ] [ 3 ] [ 0 ] . text = str ( screen_width )
rp_config_tree [ 0 ] [ 3 ] [ 1 ] . text = str ( screen_height )
buffer_xml = ET . tostring ( rp_config_tree )
with open ( " rp_config.xml " , " wb " ) as f :
f . write ( buffer_xml )
def about_screen_down ( cont ) :
if cont . sensors [ ' Click ' ] . status == JUST_ACTIVATED and cont . sensors [ ' MO ' ] . positive :
screen_width_mode = [ 640 , 960 , 1280 , 1920 ]
screen_height_mode = [ 360 , 540 , 720 , 1080 ]
screen_mode_txt = [ " 640x360 " , " 960x540 " , " 1280x720 " , " 1920x1080 " ]
i = get_near_pos ( screen_width_mode , bge . render . getWindowWidth ( ) )
if i > 0 and i < = 3 :
screen_width = screen_width_mode [ i - 1 ]
screen_height = screen_height_mode [ i - 1 ]
scene . objects [ ' About_screen ' ] [ ' Text ' ] = " SCREEN SIZE : " + str ( screen_width ) + " x " + str ( screen_height )
bge . render . setWindowSize ( screen_width , screen_height )
2022-11-26 01:29:27 +01:00
# Boutons < et >
if screen_width < = 640 :
scene . objects [ ' About_screen-down ' ] . setVisible ( False , True )
scene . objects [ ' About_screen-down-colbox ' ] . suspendPhysics ( True )
else :
scene . objects [ ' About_screen-down ' ] . setVisible ( True , True )
scene . objects [ ' About_screen-down-colbox ' ] . restorePhysics ( )
if screen_width > = 1920 :
scene . objects [ ' About_screen-up ' ] . setVisible ( False , True )
scene . objects [ ' About_screen-up-colbox ' ] . suspendPhysics ( True )
else :
scene . objects [ ' About_screen-up ' ] . setVisible ( True , True )
scene . objects [ ' About_screen-up-colbox ' ] . restorePhysics ( )
2022-10-22 01:04:48 +02:00
# Maj du fichier de config (screen size : data/config/screen/width-> [0][3][0].text)
rp_config_tree [ 0 ] [ 3 ] [ 0 ] . text = str ( screen_width )
rp_config_tree [ 0 ] [ 3 ] [ 1 ] . text = str ( screen_height )
buffer_xml = ET . tostring ( rp_config_tree )
with open ( " rp_config.xml " , " wb " ) as f :
f . write ( buffer_xml )