diff --git a/fop-05.blend b/fop-05.blend index 8c32a45..91d5134 100644 Binary files a/fop-05.blend and b/fop-05.blend differ diff --git a/fop.py b/fop.py index b6cc9e0..483cb68 100644 --- a/fop.py +++ b/fop.py @@ -1,6 +1,6 @@ import bge # Bibliothèque Blender Game Engine (UPBGE) import bpy # Blender -import math +import math, time ############################################################################### # fop.py @@ -32,11 +32,22 @@ LOOP = bge.logic.KX_ACTION_MODE_LOOP # Flèches pour avancer, reculer et tourner ### -def clavier(cont): +def deplacement(cont): obj = cont.owner obj_rig = scene.objects['Frankie-rig'] obj_cam = scene.objects['Camera'] + keyboard = bge.logic.keyboard + + joy_index = 0 #int from 0 to 6 + joy = bge.logic.joysticks[joy_index] + joy_events = joy.activeButtons + joy_axis = joy.axisValues[0:4] + joy_leftstick_x = joy_axis[0] + joy_leftstick_y = joy_axis[1] + joy_rightstick_x = joy_axis[2] + joy_rightstick_y = joy_axis[3] + pas_lineaire = 0.1 pas_courrir = 0.2 pas_angulaire = 0.05 @@ -46,7 +57,14 @@ def clavier(cont): idle=True # Avancer : Flèche haut - Up arrow - if keyboard.inputs[bge.events.UPARROWKEY].status[0] == ACTIVATE and obj['chute']==False: + # joy_leftstick_y < -0.5 -> avancer + # print ("leftstick : ", joy_leftstick_x , joy_leftstick_y) + # print ("rightstick : ", joy_rightstick_x , joy_rightstick_y) + if joy_events: + print(joy_events) + + # Avancer : Flèche haut - Up arrow + if (keyboard.inputs[bge.events.UPARROWKEY].status[0] == ACTIVATE or joy_leftstick_y<-0.5) and obj['chute']==False: idle=False # Planer @@ -74,19 +92,19 @@ def clavier(cont): obj_rig.playAction('Frankie-courrir', start, end, layer, 1, 1.0, PLAY, 0.0, 0, speed) # Arrêt de la course - if keyboard.inputs[bge.events.UPARROWKEY].status[0] != ACTIVATE and obj['courrir_tics']>0: # Arrêt de la course + if (keyboard.inputs[bge.events.UPARROWKEY].status[0] != ACTIVATE and joy_leftstick_y>-0.5) and obj['courrir_tics']>0: # Arrêt de la course obj['courrir_tics']=0 obj['courrir']=False - + # Reculer : Flèche bas - Down arrow - if keyboard.inputs[bge.events.DOWNARROWKEY].status[0] == ACTIVATE and obj['saut']==False and obj['chute']==False: + if (keyboard.inputs[bge.events.DOWNARROWKEY].status[0] == ACTIVATE or joy_leftstick_y>0.5) and obj['saut']==False and obj['chute']==False: idle=False obj.applyMovement((0,pas_lineaire,0), True) start, end, speed, layer = 1, 20, 2, 0 obj_rig.playAction('Frankie-reculer', start, end, layer, 1, 1.0, PLAY, 0.0, 0, speed) # Tourner gauche : Flèche gauche - Left arrow - if keyboard.inputs[bge.events.LEFTARROWKEY].status[0] == ACTIVATE and obj['chute']==False: + if (keyboard.inputs[bge.events.LEFTARROWKEY].status[0] == ACTIVATE or joy_leftstick_x<-0.5) and obj['chute']==False: idle=False if obj_cam['fps']: obj.applyRotation((0, 0,pas_angulaire_fps), True) @@ -96,7 +114,7 @@ def clavier(cont): obj_rig.playAction('Frankie-gauche', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed) # Tourner droite : Flèche droit - Right arrow - if keyboard.inputs[bge.events.RIGHTARROWKEY].status[0] == ACTIVATE and obj['chute']==False: + if (keyboard.inputs[bge.events.RIGHTARROWKEY].status[0] == ACTIVATE or joy_leftstick_x>0.5) and obj['chute']==False: idle=False if obj_cam['fps']: obj.applyRotation((0, 0,-pas_angulaire_fps), True) @@ -106,7 +124,7 @@ def clavier(cont): obj_rig.playAction('Frankie-droite', start, end, layer, 1, 1.0, PLAY, 0.0, 0, speed) # Saut - if keyboard.inputs[bge.events.SPACEKEY].status[0] == ACTIVATE and obj['chute']==False: + if (keyboard.inputs[bge.events.SPACEKEY].status[0] == ACTIVATE or 3 in joy_events) and obj['chute']==False: idle=False objs_sol=('Terrain', 'Platforme', 'Pont 1', 'Pont 2') for obj_sol in objs_sol: # Ne peut que sauter si Frankie touche le sol @@ -138,7 +156,7 @@ def clavier(cont): if obj.worldPosition.z < obj['chute_z'] and obj['saut']==False: obj['chute_tics']+=1 obj['chute_z'] = obj.worldPosition.z - if obj['chute_tics']>50: # 50 : nombre de tics pour déclarer la chute + if obj['chute_tics']>30: # 30 : nombre de tics pour déclarer la chute idle=False obj['chute']=True start, end, speed, layer = 1, 33, 2, 0 @@ -150,22 +168,42 @@ def clavier(cont): obj_rig.playAction('Frankie-attente', start, end, layer, 1, 1.0, LOOP, 0.0, 0, speed) # Caméra FPS - if JUST_ACTIVATED in keyboard.inputs[bge.events.FKEY].queue: + if JUST_ACTIVATED in keyboard.inputs[bge.events.FKEY].queue : if obj_cam['fps']==False: scene.active_camera = scene.objects["Camera_fps"] obj_cam['fps'] = True else: scene.active_camera = scene.objects["Camera"] obj_cam['fps'] = False + if 0 in joy_events: + if obj_cam['fps']==False: + scene.active_camera = scene.objects["Camera_fps"] + obj_cam['fps'] = True + time.sleep(0.15) # Change trop rapidement + else: + scene.active_camera = scene.objects["Camera"] + obj_cam['fps'] = False + time.sleep(0.15) # Change trop rapidement # Recul caméra - if keyboard.inputs[bge.events.EKEY].status[0] == ACTIVATE and obj_cam['macro']==False: + if (keyboard.inputs[bge.events.EKEY].status[0] == ACTIVATE or 10 in joy_events) and obj_cam['macro']==False: obj_cam.applyMovement((0,0,recul_camera), True) obj_cam['macro'] = True - if keyboard.inputs[bge.events.EKEY].status[0] != ACTIVATE and obj_cam['macro']==True: + if (keyboard.inputs[bge.events.EKEY].status[0] != ACTIVATE and 10 not in joy_events) and obj_cam['macro']==True: obj_cam.applyMovement((0,0,-recul_camera), True) obj_cam['macro'] = False + # Retour au dernier checkpoint + if keyboard.inputs[bge.events.RKEY].status[0] == ACTIVATE or 9 in joy_events : + obj_spawn = scene.objects['Spawn '+str(obj['spawn'])] + obj.worldPosition = obj_spawn.worldPosition + obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+obj_spawn['sens']), False) + obj['saut'] = False + obj['chute_tics'] = 0 + obj['chute'] = False + obj['courrir_tics'] = 0 + obj['courrir'] = False + # Saut sur les téléportes (mode debug) : avancer if JUST_ACTIVATED in keyboard.inputs[bge.events.ZKEY].queue and obj['spawn']<8 and obj['debugg']: obj['spawn'] +=1 @@ -202,7 +240,7 @@ def camera_track (cont): ############################################################################### # Initialisation de la scène -def init(cont): +def init(cont): obj = cont.owner # Init EEVEE @@ -234,9 +272,9 @@ def init(cont): scene.objects['Platforme'].playAction('Platforme-action', start, end, layer, 1, 1.0, LOOP, 0.0, 0, speed) # Chute -def chute(cont): +def chute(cont): obj = cont.owner - if obj.worldPosition.z<=-9 : + if obj.worldPosition.z<=-10 : obj_spawn = scene.objects['Spawn '+str(obj['spawn'])] obj.worldPosition = obj_spawn.worldPosition obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+obj_spawn['sens']), False) @@ -247,7 +285,7 @@ def chute(cont): obj['courrir'] = False # Checkpoint -def checkpoint(cont): +def checkpoint(cont): obj = cont.owner obj_i=int(obj.name[6:-7]) obj_frankie = scene.objects['Frankie'] @@ -256,7 +294,7 @@ def checkpoint(cont): scene.objects['Pancarte '+str(obj_i)].setVisible(True,True) # Ressort -def ressort(cont): +def ressort(cont): obj = cont.owner sensor = obj.sensors['Collision'] force_saut = 1000