2023-07-19 01:32:03 +02:00
|
|
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
|
|
|
import bpy # Blender
|
2023-07-20 16:43:41 +02:00
|
|
|
import math
|
2023-07-18 12:16:31 +02:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# fop.py
|
|
|
|
# @title: module principale du jeu Frankie on Platform
|
|
|
|
# @project: Frankie on Platform
|
|
|
|
# @lang: fr
|
|
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
|
|
|
# @copyright: Copyright (C) 2023 Philippe Roy
|
|
|
|
# @license: GNU GPL
|
|
|
|
###############################################################################
|
|
|
|
|
2023-07-19 01:32:03 +02:00
|
|
|
# UPBGE scene
|
2023-07-18 12:16:31 +02:00
|
|
|
scene = bge.logic.getCurrentScene()
|
2023-07-19 01:32:03 +02:00
|
|
|
eevee = bpy.context.scene.eevee
|
2023-07-18 12:16:31 +02:00
|
|
|
# print("Objets de la scene : ", scene.objects) # Lister les objets de la scène
|
|
|
|
|
|
|
|
# Constantes
|
|
|
|
|
|
|
|
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
|
|
|
JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
|
|
|
|
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
|
|
|
|
|
|
|
###############################################################################
|
2023-07-19 01:32:03 +02:00
|
|
|
# Mouvements
|
2023-07-18 12:16:31 +02:00
|
|
|
###############################################################################
|
|
|
|
|
2023-07-19 01:32:03 +02:00
|
|
|
###
|
2023-07-18 21:36:01 +02:00
|
|
|
# Flèches pour avancer, reculer et tourner
|
2023-07-19 01:32:03 +02:00
|
|
|
###
|
|
|
|
|
2023-07-18 12:16:31 +02:00
|
|
|
def clavier(cont):
|
|
|
|
obj = cont.owner
|
2023-07-19 01:32:03 +02:00
|
|
|
obj_cam = scene.objects['Camera']
|
2023-07-18 12:16:31 +02:00
|
|
|
keyboard = bge.logic.keyboard
|
2023-07-19 01:32:03 +02:00
|
|
|
pas_lineaire = 0.1
|
|
|
|
pas_courrir = 0.2
|
|
|
|
pas_angulaire = 0.05
|
|
|
|
pas_angulaire_fps = 0.025
|
|
|
|
force_saut = 300
|
|
|
|
recul_camera = 40
|
2023-07-18 12:16:31 +02:00
|
|
|
|
2023-07-19 01:32:03 +02:00
|
|
|
# Avancer : Flèche haut - Up arrow
|
2023-07-18 12:16:31 +02:00
|
|
|
if keyboard.inputs[bge.events.UPARROWKEY].status[0] == ACTIVATE:
|
2023-07-19 01:32:03 +02:00
|
|
|
if obj['courrir']<20:
|
|
|
|
obj.applyMovement((0,-pas_lineaire,0), True)
|
|
|
|
obj['courrir']+=1
|
|
|
|
else:
|
|
|
|
obj.applyMovement((0,-pas_courrir,0), True)
|
|
|
|
if keyboard.inputs[bge.events.UPARROWKEY].status[0] != ACTIVATE and obj['courrir']>0:
|
|
|
|
obj['courrir']=0
|
|
|
|
|
|
|
|
# Reculer : Flèche bas - Down arrow
|
2023-07-18 12:16:31 +02:00
|
|
|
if keyboard.inputs[bge.events.DOWNARROWKEY].status[0] == ACTIVATE:
|
2023-07-19 01:32:03 +02:00
|
|
|
obj.applyMovement((0,pas_lineaire,0), True)
|
2023-07-18 12:16:31 +02:00
|
|
|
|
2023-07-19 01:32:03 +02:00
|
|
|
# Tourner gauche : Flèche gauche - Left arrow
|
2023-07-18 12:16:31 +02:00
|
|
|
if keyboard.inputs[bge.events.LEFTARROWKEY].status[0] == ACTIVATE:
|
2023-07-19 01:32:03 +02:00
|
|
|
if obj_cam['fps']:
|
2023-07-20 16:43:41 +02:00
|
|
|
obj.applyRotation((0, 0,pas_angulaire_fps), True)
|
2023-07-19 01:32:03 +02:00
|
|
|
else:
|
|
|
|
obj.applyRotation((0, 0,pas_angulaire), True)
|
2023-07-18 12:16:31 +02:00
|
|
|
|
2023-07-19 01:32:03 +02:00
|
|
|
# Tourner droite : Flèche droit - Right arrow
|
2023-07-18 12:16:31 +02:00
|
|
|
if keyboard.inputs[bge.events.RIGHTARROWKEY].status[0] == ACTIVATE:
|
2023-07-19 01:32:03 +02:00
|
|
|
if obj_cam['fps']:
|
|
|
|
obj.applyRotation((0, 0,-pas_angulaire_fps), True)
|
|
|
|
else:
|
|
|
|
obj.applyRotation((0, 0,-pas_angulaire), True)
|
|
|
|
|
|
|
|
# Saut
|
|
|
|
if keyboard.inputs[bge.events.SPACEKEY].status[0] == ACTIVATE:
|
|
|
|
objs_sol=('Terrain', 'Platforme', 'Pont 1', 'Pont 2')
|
|
|
|
for obj_sol in objs_sol:
|
|
|
|
if obj.collide(scene.objects[obj_sol])[0]:
|
|
|
|
if len(obj.collide(scene.objects[obj_sol])[1])>0:
|
|
|
|
obj.applyForce((0, 0,force_saut), True)
|
|
|
|
break
|
|
|
|
|
2023-07-20 16:43:41 +02:00
|
|
|
# Caméra FPS
|
|
|
|
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
|
|
|
|
|
2023-07-19 01:32:03 +02:00
|
|
|
# Recul caméra
|
|
|
|
if keyboard.inputs[bge.events.EKEY].status[0] == ACTIVATE 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:
|
|
|
|
obj_cam.applyMovement((0,0,-recul_camera), True)
|
|
|
|
obj_cam['macro'] = False
|
|
|
|
|
2023-07-20 16:43:41 +02:00
|
|
|
# Saut sur les téléporte (mode debug) : avancer
|
|
|
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.ZKEY].queue and obj['spawn']<8:
|
|
|
|
obj['spawn'] +=1
|
|
|
|
obj_spawn = scene.objects['Spawn '+str(obj['spawn'])]
|
2023-07-20 22:44:24 +02:00
|
|
|
print (obj_spawn['sens'])
|
2023-07-20 16:43:41 +02:00
|
|
|
obj.worldPosition = obj_spawn.worldPosition
|
2023-07-20 22:44:24 +02:00
|
|
|
obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+obj_spawn['sens']), False)
|
2023-07-20 16:43:41 +02:00
|
|
|
|
2023-07-20 22:44:24 +02:00
|
|
|
# Saut sur les téléportes(mode debug) : reculer
|
2023-07-20 16:43:41 +02:00
|
|
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.AKEY].queue and obj['spawn']>0:
|
|
|
|
obj['spawn'] -=1
|
|
|
|
obj_spawn = scene.objects['Spawn '+str(obj['spawn'])]
|
2023-07-20 22:44:24 +02:00
|
|
|
print (obj_spawn['sens'])
|
2023-07-20 16:43:41 +02:00
|
|
|
obj.worldPosition = obj_spawn.worldPosition
|
2023-07-20 22:44:24 +02:00
|
|
|
obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+obj_spawn['sens']), False)
|
2023-07-19 01:32:03 +02:00
|
|
|
|
|
|
|
###
|
|
|
|
# Suivi par la caméra
|
|
|
|
###
|
|
|
|
|
|
|
|
def camera_track (cont):
|
2023-07-20 16:43:41 +02:00
|
|
|
cont.owner.worldPosition = scene.objects['Frankie'].worldPosition
|
2023-07-18 12:16:31 +02:00
|
|
|
|
|
|
|
###############################################################################
|
2023-07-19 01:32:03 +02:00
|
|
|
# Cycle
|
2023-07-18 12:16:31 +02:00
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
# Initialisation de la scène
|
|
|
|
def init(cont):
|
2023-07-18 21:36:01 +02:00
|
|
|
obj = cont.owner
|
2023-07-18 12:16:31 +02:00
|
|
|
|
2023-07-19 01:32:03 +02:00
|
|
|
# Init EEVEE
|
|
|
|
eevee.use_taa_reprojection = True
|
|
|
|
eevee.use_ssr = True # Screen space reflection
|
|
|
|
eevee.use_ssr_refraction = True # Screen space refractions
|
|
|
|
eevee.use_ssr_halfres = True
|
|
|
|
eevee.use_gtao = False
|
|
|
|
eevee.taa_render_samples = 64
|
|
|
|
eevee.taa_samples = 16
|
|
|
|
eevee.use_volumetric_lights = True
|
|
|
|
eevee.use_volumetric_shadows = False
|
|
|
|
eevee.shadow_cascade_size='1024'
|
|
|
|
eevee.shadow_cube_size='512'
|
|
|
|
|
|
|
|
# Pancartes
|
2023-07-20 16:43:41 +02:00
|
|
|
scene.objects['Frankie']['spawn']=0
|
2023-07-19 01:32:03 +02:00
|
|
|
for i in range (1, 7):
|
|
|
|
scene.objects['Pancarte '+str(i)].setVisible(False,True)
|
|
|
|
|
2023-07-20 22:44:24 +02:00
|
|
|
# Animation plateforme
|
|
|
|
start = 1
|
|
|
|
end = 200
|
|
|
|
mode = bge.logic.KX_ACTION_MODE_LOOP
|
|
|
|
speed = 0.5
|
|
|
|
scene.objects['Platforme'].playAction('Platforme-action', start, end, 0, 1, 1.0, mode, 0.0, 0, speed)
|
|
|
|
|
2023-07-19 01:32:03 +02:00
|
|
|
# Chute
|
|
|
|
def chute(cont):
|
|
|
|
obj = cont.owner
|
|
|
|
if obj.worldPosition.z<=-9 :
|
|
|
|
obj_spawn = scene.objects['Spawn '+str(obj['spawn'])]
|
2023-07-20 16:43:41 +02:00
|
|
|
obj.worldPosition = obj_spawn.worldPosition
|
|
|
|
obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+math.pi), False)
|
2023-07-19 01:32:03 +02:00
|
|
|
|
|
|
|
# Checkpoint
|
|
|
|
def checkpoint(cont):
|
|
|
|
obj = cont.owner
|
2023-07-20 16:43:41 +02:00
|
|
|
obj_i=int(obj.name[6:-7])
|
2023-07-19 01:32:03 +02:00
|
|
|
obj_frankie = scene.objects['Frankie']
|
2023-07-20 16:43:41 +02:00
|
|
|
if obj_i > obj_frankie['spawn']:
|
|
|
|
obj_frankie['spawn']=obj_i
|
|
|
|
scene.objects['Pancarte '+str(obj_i)].setVisible(True,True)
|
2023-07-18 12:16:31 +02:00
|
|
|
|
2023-07-20 22:44:24 +02:00
|
|
|
# Ressort
|
|
|
|
def ressort(cont):
|
|
|
|
obj = cont.owner
|
|
|
|
sensor = obj.sensors['Collision']
|
|
|
|
force_saut = 1000
|
|
|
|
obj_ressort=scene.objects[obj.name[:-7]]
|
|
|
|
obj_frankie = scene.objects['Frankie']
|
|
|
|
if sensor.positive:
|
|
|
|
start = 1,
|
|
|
|
end = 16,
|
|
|
|
mode = bge.logic.KX_ACTION_MODE_PLAY,
|
|
|
|
speed = 0.5
|
|
|
|
obj_ressort.playAction(obj_ressort.name+'-action', start, end, 0, 1, 1.0, mode, 0.0, 0, speed)
|
|
|
|
obj_frankie.applyForce((0, 0,force_saut), True)
|
|
|
|
|
|
|
|
|
2023-07-18 12:16:31 +02:00
|
|
|
###############################################################################
|
|
|
|
# Gestion du Joystick (Joystick USB)
|
|
|
|
###############################################################################
|
|
|
|
|
2023-07-18 21:36:01 +02:00
|
|
|
# def joystick(cont):
|
|
|
|
# obj = cont.owner
|
|
|
|
# joystickIndex = 0 #int from 0 to 6
|
|
|
|
# joy = bge.logic.joysticks[joystickIndex]
|
|
|
|
# events = joy.activeButtons
|
|
|
|
# axis = joy.axisValues[0:4]
|
|
|
|
# resolution = 0.01
|
2023-07-18 12:16:31 +02:00
|
|
|
|
2023-07-18 21:36:01 +02:00
|
|
|
# leftStick_x = axis[0]; leftStick_y = axis[1]
|
|
|
|
# rightStick_x = axis[2]; rightStick_y = axis[3]
|
|
|
|
|
|
|
|
# #if any button is pressed
|
|
|
|
# # if events:
|
|
|
|
# # print(events) #spit out integer index of pressed buttons
|
|
|
|
# # if 0 in events:
|
|
|
|
# # doSomething()
|
2023-07-18 12:16:31 +02:00
|
|
|
|
2023-07-18 21:36:01 +02:00
|
|
|
# # Up
|
|
|
|
# if leftStick_y <-0.1 :
|
|
|
|
# obj.applyRotation((-resolution,0,0), False)
|
2023-07-18 12:16:31 +02:00
|
|
|
|
2023-07-18 21:36:01 +02:00
|
|
|
# # Down
|
|
|
|
# if leftStick_y >0.1 :
|
|
|
|
# obj.applyRotation((resolution,0,0), False)
|
2023-07-18 12:16:31 +02:00
|
|
|
|
2023-07-18 21:36:01 +02:00
|
|
|
# # Left
|
|
|
|
# if leftStick_x <-0.1 :
|
|
|
|
# obj.applyRotation((0, -resolution,0), False)
|
2023-07-18 12:16:31 +02:00
|
|
|
|
2023-07-18 21:36:01 +02:00
|
|
|
# # Right
|
|
|
|
# if leftStick_x >0.1 :
|
|
|
|
# obj.applyRotation((0, resolution,0), False)
|