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 suite
This commit is contained in:
parent
ec9c006599
commit
41ddc9b212
BIN
fop-05.blend
BIN
fop-05.blend
Binary file not shown.
133
fop.py
133
fop.py
@ -12,16 +12,17 @@ import math
|
|||||||
# @license: GNU GPL
|
# @license: GNU GPL
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# UPBGE scene
|
# Scène UPBGE
|
||||||
scene = bge.logic.getCurrentScene()
|
scene = bge.logic.getCurrentScene()
|
||||||
eevee = bpy.context.scene.eevee
|
eevee = bpy.context.scene.eevee
|
||||||
# print("Objets de la scene : ", scene.objects) # Lister les objets de la scène
|
# print("Objets de la scène : ", scene.objects) # Lister les objets de la scène
|
||||||
|
|
||||||
# Constantes
|
|
||||||
|
|
||||||
|
# Constantes UPBGE
|
||||||
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
||||||
JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
|
JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
|
||||||
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
||||||
|
PLAY = bge.logic.KX_ACTION_MODE_PLAY
|
||||||
|
LOOP = bge.logic.KX_ACTION_MODE_LOOP
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Mouvements
|
# Mouvements
|
||||||
@ -33,52 +34,129 @@ ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
|||||||
|
|
||||||
def clavier(cont):
|
def clavier(cont):
|
||||||
obj = cont.owner
|
obj = cont.owner
|
||||||
|
obj_rig = scene.objects['Frankie-rig']
|
||||||
obj_cam = scene.objects['Camera']
|
obj_cam = scene.objects['Camera']
|
||||||
keyboard = bge.logic.keyboard
|
keyboard = bge.logic.keyboard
|
||||||
pas_lineaire = 0.1
|
pas_lineaire = 0.1
|
||||||
pas_courrir = 0.2
|
pas_courrir = 0.2
|
||||||
pas_angulaire = 0.05
|
pas_angulaire = 0.05
|
||||||
pas_angulaire_fps = 0.025
|
pas_angulaire_fps = 0.025
|
||||||
force_saut = 300
|
force_saut = 200
|
||||||
recul_camera = 40
|
recul_camera = 40
|
||||||
|
idle=True
|
||||||
|
|
||||||
# Avancer : 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:
|
||||||
if obj['courrir']<20:
|
idle=False
|
||||||
|
obj['chute']=0
|
||||||
|
if obj['courrir']<40: # 40 : nombre de pas pour courrir
|
||||||
obj.applyMovement((0,-pas_lineaire,0), True)
|
obj.applyMovement((0,-pas_lineaire,0), True)
|
||||||
|
start, end, speed, = 1, 18, 2
|
||||||
|
obj_rig.playAction('Frankie-avancer', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
obj['courrir']+=1
|
obj['courrir']+=1
|
||||||
else:
|
else:
|
||||||
obj.applyMovement((0,-pas_courrir,0), True)
|
obj.applyMovement((0,-pas_courrir,0), True)
|
||||||
|
start, end, speed, = 1, 18, 2
|
||||||
|
obj_rig.playAction('Frankie-courrir', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
if keyboard.inputs[bge.events.UPARROWKEY].status[0] != ACTIVATE and obj['courrir']>0:
|
if keyboard.inputs[bge.events.UPARROWKEY].status[0] != ACTIVATE and obj['courrir']>0:
|
||||||
obj['courrir']=0
|
obj['courrir']=0
|
||||||
|
|
||||||
# Reculer : 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:
|
||||||
|
idle=False
|
||||||
|
obj['chute']=0
|
||||||
obj.applyMovement((0,pas_lineaire,0), True)
|
obj.applyMovement((0,pas_lineaire,0), True)
|
||||||
|
start, end, speed, = 1, 20, 2
|
||||||
|
obj_rig.playAction('Frankie-reculer', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
|
|
||||||
# Tourner gauche : 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:
|
||||||
|
idle=False
|
||||||
|
obj['chute']=0
|
||||||
if obj_cam['fps']:
|
if obj_cam['fps']:
|
||||||
obj.applyRotation((0, 0,pas_angulaire_fps), True)
|
obj.applyRotation((0, 0,pas_angulaire_fps), True)
|
||||||
else:
|
else:
|
||||||
obj.applyRotation((0, 0,pas_angulaire), True)
|
obj.applyRotation((0, 0,pas_angulaire), True)
|
||||||
|
start, end, speed, = 1, 12, 2
|
||||||
|
obj_rig.playAction('Frankie-gauche', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
|
|
||||||
|
# start = 1
|
||||||
|
# end = 100
|
||||||
|
# layer = 0
|
||||||
|
# priority = 1
|
||||||
|
# blendin = 1.0
|
||||||
|
# mode = bge.logic.KX_ACTION_MODE_PLAY
|
||||||
|
# layerWeight = 0.0
|
||||||
|
# ipoFlags = 0
|
||||||
|
# speed = scene.objects['Commands']['speed']*8
|
||||||
|
|
||||||
# Tourner droite : 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:
|
||||||
|
idle=False
|
||||||
|
obj['chute']=0
|
||||||
if obj_cam['fps']:
|
if obj_cam['fps']:
|
||||||
obj.applyRotation((0, 0,-pas_angulaire_fps), True)
|
obj.applyRotation((0, 0,-pas_angulaire_fps), True)
|
||||||
else:
|
else:
|
||||||
obj.applyRotation((0, 0,-pas_angulaire), True)
|
obj.applyRotation((0, 0,-pas_angulaire), True)
|
||||||
|
start, end, speed, = 1, 12, 2
|
||||||
|
obj_rig.playAction('Frankie-droite', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
|
|
||||||
# Saut
|
# Saut
|
||||||
|
# obj['dist_terrain']= obj.getDistanceTo(scene.objects['Terrain'])
|
||||||
|
# obj['dist_terrain']= obj.getVectTo(scene.objects['Terrain'])[0]
|
||||||
|
# obj['dist_terrain']= obj.getVectTo((0,0,-1))[0]
|
||||||
|
# print (obj.rayCast((0,0,1), None, -10))
|
||||||
if keyboard.inputs[bge.events.SPACEKEY].status[0] == ACTIVATE:
|
if keyboard.inputs[bge.events.SPACEKEY].status[0] == ACTIVATE:
|
||||||
|
idle=False
|
||||||
|
obj['chute']=0
|
||||||
|
# print (obj.rayCast((0,0,1), None, 100))
|
||||||
|
# # print (obj.getDistanceTo(scene.objects['Terrain']))
|
||||||
|
# if obj.rayCast((0,0,1), None, 100)[0] is not None :
|
||||||
|
# obj.applyForce((0, 0,force_saut), True)
|
||||||
|
# start, end, speed, = 1, 34, 2
|
||||||
|
# obj_rig.playAction('Frankie-sauter', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
objs_sol=('Terrain', 'Platforme', 'Pont 1', 'Pont 2')
|
objs_sol=('Terrain', 'Platforme', 'Pont 1', 'Pont 2')
|
||||||
for obj_sol in objs_sol:
|
for obj_sol in objs_sol:
|
||||||
|
# print (obj.collide(scene.objects[obj_sol]))
|
||||||
if obj.collide(scene.objects[obj_sol])[0]:
|
if obj.collide(scene.objects[obj_sol])[0]:
|
||||||
if len(obj.collide(scene.objects[obj_sol])[1])>0:
|
if len(obj.collide(scene.objects[obj_sol])[1])>0:
|
||||||
obj.applyForce((0, 0,force_saut), True)
|
obj.applyForce((0, 0,force_saut), True)
|
||||||
|
start, end, speed, = 1, 34, 2
|
||||||
|
obj_rig.playAction('Frankie-sauter', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# Chute
|
||||||
|
if obj.worldPosition.z == obj['chute_z']:
|
||||||
|
obj['chute']=0
|
||||||
|
if obj.worldPosition.z < obj['chute_z'] :
|
||||||
|
obj['chute']+=1
|
||||||
|
objs_sol=('Terrain', 'Platforme', 'Pont 1', 'Pont 2')
|
||||||
|
for obj_sol in objs_sol:
|
||||||
|
print (obj.collide(scene.objects[obj_sol]))
|
||||||
|
if obj.collide(scene.objects[obj_sol])[0]:
|
||||||
|
if len(obj.collide(scene.objects[obj_sol])[1])>0:
|
||||||
|
obj['chute']=0
|
||||||
|
break
|
||||||
|
|
||||||
|
# objs_sol=('Terrain', 'Platforme', 'Pont 1', 'Pont 2')
|
||||||
|
# chute_flag=True
|
||||||
|
# for obj_sol in objs_sol:
|
||||||
|
# if obj.collide(scene.objects[obj_sol])[0]:
|
||||||
|
# chute_flag=False
|
||||||
|
# break
|
||||||
|
# if chute_flag:
|
||||||
|
# obj['chute']+=1
|
||||||
|
obj['chute_z'] = obj.worldPosition.z
|
||||||
|
if obj['chute']>50:
|
||||||
|
idle=False
|
||||||
|
start, end, speed, = 1, 33, 2
|
||||||
|
obj_rig.playAction('Frankie-tomber', start, end, 0, 1, 1.0, LOOP, 0.0, 0, speed)
|
||||||
|
|
||||||
|
# Attente
|
||||||
|
if idle:
|
||||||
|
start, end, speed, = 1, 268, 2
|
||||||
|
obj_rig.playAction('Frankie-attente', start, end, 0, 1, 1.0, LOOP, 0.0, 0, speed)
|
||||||
|
|
||||||
# Caméra FPS
|
# 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:
|
if obj_cam['fps']==False:
|
||||||
@ -96,19 +174,21 @@ def clavier(cont):
|
|||||||
obj_cam.applyMovement((0,0,-recul_camera), True)
|
obj_cam.applyMovement((0,0,-recul_camera), True)
|
||||||
obj_cam['macro'] = False
|
obj_cam['macro'] = False
|
||||||
|
|
||||||
# Saut sur les téléporte (mode debug) : avancer
|
# Saut sur les téléportes (mode debug) : avancer
|
||||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.ZKEY].queue and obj['spawn']<8:
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.ZKEY].queue and obj['spawn']<8 and obj['debugg']:
|
||||||
obj['spawn'] +=1
|
obj['spawn'] +=1
|
||||||
|
obj['chute'] = 0
|
||||||
|
obj['courrir'] = 0
|
||||||
obj_spawn = scene.objects['Spawn '+str(obj['spawn'])]
|
obj_spawn = scene.objects['Spawn '+str(obj['spawn'])]
|
||||||
print (obj_spawn['sens'])
|
|
||||||
obj.worldPosition = obj_spawn.worldPosition
|
obj.worldPosition = obj_spawn.worldPosition
|
||||||
obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+obj_spawn['sens']), False)
|
obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+obj_spawn['sens']), False)
|
||||||
|
|
||||||
# Saut sur les téléportes(mode debug) : reculer
|
# Saut sur les téléportes (mode debug) : reculer
|
||||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.AKEY].queue and obj['spawn']>0:
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.AKEY].queue and obj['spawn']>0 and obj['debugg']:
|
||||||
obj['spawn'] -=1
|
obj['spawn'] -=1
|
||||||
|
obj['chute'] = 0
|
||||||
|
obj['courrir'] = 0
|
||||||
obj_spawn = scene.objects['Spawn '+str(obj['spawn'])]
|
obj_spawn = scene.objects['Spawn '+str(obj['spawn'])]
|
||||||
print (obj_spawn['sens'])
|
|
||||||
obj.worldPosition = obj_spawn.worldPosition
|
obj.worldPosition = obj_spawn.worldPosition
|
||||||
obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+obj_spawn['sens']), False)
|
obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+obj_spawn['sens']), False)
|
||||||
|
|
||||||
@ -140,17 +220,21 @@ def init(cont):
|
|||||||
eevee.shadow_cascade_size='1024'
|
eevee.shadow_cascade_size='1024'
|
||||||
eevee.shadow_cube_size='512'
|
eevee.shadow_cube_size='512'
|
||||||
|
|
||||||
# Pancartes
|
# Mode debug
|
||||||
|
scene.objects['Frankie']['debugg']=True
|
||||||
|
|
||||||
|
# Init de Frankie
|
||||||
|
scene.objects['Frankie']['chute']=0
|
||||||
|
scene.objects['Frankie']['chute_z'] = scene.objects['Frankie'].worldPosition.z
|
||||||
scene.objects['Frankie']['spawn']=0
|
scene.objects['Frankie']['spawn']=0
|
||||||
|
|
||||||
|
# Cacher les pancartes
|
||||||
for i in range (1, 7):
|
for i in range (1, 7):
|
||||||
scene.objects['Pancarte '+str(i)].setVisible(False,True)
|
scene.objects['Pancarte '+str(i)].setVisible(False,True)
|
||||||
|
|
||||||
# Animation plateforme
|
# Mise en route de la plateforme
|
||||||
start = 1
|
start, end, speed, = 1, 200, 0.5
|
||||||
end = 200
|
scene.objects['Platforme'].playAction('Platforme-action', start, end, 0, 1, 1.0, LOOP, 0.0, 0, speed)
|
||||||
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)
|
|
||||||
|
|
||||||
# Chute
|
# Chute
|
||||||
def chute(cont):
|
def chute(cont):
|
||||||
@ -158,7 +242,9 @@ def chute(cont):
|
|||||||
if obj.worldPosition.z<=-9 :
|
if obj.worldPosition.z<=-9 :
|
||||||
obj_spawn = scene.objects['Spawn '+str(obj['spawn'])]
|
obj_spawn = scene.objects['Spawn '+str(obj['spawn'])]
|
||||||
obj.worldPosition = obj_spawn.worldPosition
|
obj.worldPosition = obj_spawn.worldPosition
|
||||||
obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+math.pi), False)
|
obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+obj_spawn['sens']), False)
|
||||||
|
obj['chute'] = 0
|
||||||
|
obj['courrir'] = 0
|
||||||
|
|
||||||
# Checkpoint
|
# Checkpoint
|
||||||
def checkpoint(cont):
|
def checkpoint(cont):
|
||||||
@ -177,11 +263,8 @@ def ressort(cont):
|
|||||||
obj_ressort=scene.objects[obj.name[:-7]]
|
obj_ressort=scene.objects[obj.name[:-7]]
|
||||||
obj_frankie = scene.objects['Frankie']
|
obj_frankie = scene.objects['Frankie']
|
||||||
if sensor.positive:
|
if sensor.positive:
|
||||||
start = 1,
|
start, end, speed, = 1, 16, 0.5
|
||||||
end = 16,
|
obj_ressort.playAction(obj_ressort.name+'-action', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
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)
|
obj_frankie.applyForce((0, 0,force_saut), True)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user