mirror of
https://forge.apps.education.fr/phroy/frankie-on-platform.git
synced 2024-01-27 11:32:04 +01:00
Mouvement par module Python
This commit is contained in:
parent
34e90e496e
commit
8ee3c0592a
BIN
fop-04.blend
BIN
fop-04.blend
Binary file not shown.
129
fop.py
129
fop.py
@ -1,4 +1,5 @@
|
|||||||
import bge # Bibliothèque Blender Game Engine (BGE)
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
||||||
|
import bpy # Blender
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# fop.py
|
# fop.py
|
||||||
@ -10,8 +11,9 @@ import bge # Bibliothèque Blender Game Engine (BGE)
|
|||||||
# @license: GNU GPL
|
# @license: GNU GPL
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# Récupérer la scène 3D
|
# UPBGE scene
|
||||||
scene = bge.logic.getCurrentScene()
|
scene = bge.logic.getCurrentScene()
|
||||||
|
eevee = bpy.context.scene.eevee
|
||||||
# print("Objets de la scene : ", scene.objects) # Lister les objets de la scène
|
# print("Objets de la scene : ", scene.objects) # Lister les objets de la scène
|
||||||
|
|
||||||
# Constantes
|
# Constantes
|
||||||
@ -21,43 +23,136 @@ JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
|
|||||||
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Gestion du clavier
|
# Mouvements
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
###
|
||||||
# Flèches pour avancer, reculer et tourner
|
# Flèches pour avancer, reculer et tourner
|
||||||
|
###
|
||||||
|
|
||||||
def clavier(cont):
|
def clavier(cont):
|
||||||
obj = cont.owner
|
obj = cont.owner
|
||||||
|
obj_cam = scene.objects['Camera']
|
||||||
keyboard = bge.logic.keyboard
|
keyboard = bge.logic.keyboard
|
||||||
resolution = 0.01
|
pas_lineaire = 0.1
|
||||||
|
pas_courrir = 0.2
|
||||||
|
pas_angulaire = 0.05
|
||||||
|
pas_angulaire_fps = 0.025
|
||||||
|
force_saut = 300
|
||||||
|
recul_camera = 40
|
||||||
|
|
||||||
# Flèche haut - Up arrow
|
# Avancer : Flèche haut - Up arrow
|
||||||
if keyboard.inputs[bge.events.UPARROWKEY].status[0] == ACTIVATE:
|
if keyboard.inputs[bge.events.UPARROWKEY].status[0] == ACTIVATE:
|
||||||
print ("Avancer")
|
if obj['courrir']<20:
|
||||||
# obj.applyRotation((-resolution,0,-obj.worldOrientation.to_euler().z), False)
|
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
|
||||||
|
|
||||||
# Flèche bas - Down arrow
|
# Reculer : Flèche bas - Down arrow
|
||||||
if keyboard.inputs[bge.events.DOWNARROWKEY].status[0] == ACTIVATE:
|
if keyboard.inputs[bge.events.DOWNARROWKEY].status[0] == ACTIVATE:
|
||||||
print ("Reculer")
|
obj.applyMovement((0,pas_lineaire,0), True)
|
||||||
# obj.applyRotation((resolution,0,-obj.worldOrientation.to_euler().z), False)
|
|
||||||
|
|
||||||
# Flèche gauche - Left arrow
|
# Tourner gauche : Flèche gauche - Left arrow
|
||||||
if keyboard.inputs[bge.events.LEFTARROWKEY].status[0] == ACTIVATE:
|
if keyboard.inputs[bge.events.LEFTARROWKEY].status[0] == ACTIVATE:
|
||||||
print ("Gauche")
|
if obj_cam['fps']:
|
||||||
# obj.applyRotation((0, -resolution,-obj.worldOrientation.to_euler().z), False)
|
obj.applyRotation((0, 0,pas_angulaire_pfs), True)
|
||||||
|
else:
|
||||||
|
obj.applyRotation((0, 0,pas_angulaire), True)
|
||||||
|
|
||||||
# Flèche droit - Right arrow
|
# Tourner droite : Flèche droit - Right arrow
|
||||||
if keyboard.inputs[bge.events.RIGHTARROWKEY].status[0] == ACTIVATE:
|
if keyboard.inputs[bge.events.RIGHTARROWKEY].status[0] == ACTIVATE:
|
||||||
print ("Droite")
|
if obj_cam['fps']:
|
||||||
# obj.applyRotation((0, resolution, -obj.worldOrientation.to_euler().z), False)
|
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
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Caméra FPS
|
||||||
|
if keyboard.inputs[bge.events.FKEY].status[0] == ACTIVATE and obj_cam['fps']==False and obj_cam['relache']==True:
|
||||||
|
scene.active_camera = scene.objects["Camera_fps"]
|
||||||
|
obj_cam['fps'] = True
|
||||||
|
obj_cam['relache'] = False
|
||||||
|
if keyboard.inputs[bge.events.FKEY].status[0] == ACTIVATE and obj_cam['fps']==True and obj_cam['relache']==True:
|
||||||
|
scene.active_camera = scene.objects["Camera"]
|
||||||
|
obj_cam['fps'] = False
|
||||||
|
obj_cam['relache'] = False
|
||||||
|
if keyboard.inputs[bge.events.FKEY].status[0] != ACTIVATE and obj_cam['relache']==False:
|
||||||
|
obj_cam['relache'] = True
|
||||||
|
|
||||||
|
###
|
||||||
|
# Suivi par la caméra
|
||||||
|
###
|
||||||
|
|
||||||
|
def camera_track (cont):
|
||||||
|
obj = cont.owner
|
||||||
|
obj_frankie = scene.objects['Frankie']
|
||||||
|
obj.worldPosition.x=obj_frankie.worldPosition.x
|
||||||
|
obj.worldPosition.y=obj_frankie.worldPosition.y
|
||||||
|
obj.worldPosition.z=obj_frankie.worldPosition.z
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Gameplay
|
# Cycle
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# Initialisation de la scène
|
# Initialisation de la scène
|
||||||
def init(cont):
|
def init(cont):
|
||||||
obj = cont.owner
|
obj = cont.owner
|
||||||
|
|
||||||
|
# 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
|
||||||
|
scene.objects['Frankie']['spawn']="0"
|
||||||
|
for i in range (1, 7):
|
||||||
|
scene.objects['Pancarte '+str(i)].setVisible(False,True)
|
||||||
|
|
||||||
|
# Chute
|
||||||
|
def chute(cont):
|
||||||
|
obj = cont.owner
|
||||||
|
if obj.worldPosition.z<=-9 :
|
||||||
|
obj_spawn = scene.objects['Spawn '+str(obj['spawn'])]
|
||||||
|
obj_frankie.worldPosition.x = obj_spawn.worldPosition.x
|
||||||
|
obj_frankie.worldPosition.y = obj_spawn.worldPosition.y
|
||||||
|
obj_frankie.worldPosition.z = obj_spawn.worldPosition.z
|
||||||
|
|
||||||
|
# Checkpoint
|
||||||
|
def checkpoint(cont):
|
||||||
|
obj = cont.owner
|
||||||
|
print (obj.name)
|
||||||
|
obj_i=int(obj[len(obj.name)-1:])
|
||||||
|
obj_frankie = scene.objects['Frankie']
|
||||||
|
scene.objects['Pancarte '+str(obj_i)].setVisible(True,True)
|
||||||
|
obj_frankie['spawn']=obj_i
|
||||||
|
|
||||||
# # Mémorisation de la position de départ de la bille
|
# # Mémorisation de la position de départ de la bille
|
||||||
# obj['init_x']=obj.worldPosition.x
|
# obj['init_x']=obj.worldPosition.x
|
||||||
# obj['init_y']=obj.worldPosition.y
|
# obj['init_y']=obj.worldPosition.y
|
||||||
|
Loading…
Reference in New Issue
Block a user