mirror of
https://forge.apps.education.fr/phroy/frankie-on-platform.git
synced 2024-01-27 11:32:04 +01:00
Ajout de la chute et du saut
This commit is contained in:
parent
8eb468e390
commit
266c52a19f
BIN
fop-05.blend
BIN
fop-05.blend
Binary file not shown.
111
fop.py
111
fop.py
@ -46,33 +46,48 @@ def clavier(cont):
|
|||||||
idle=True
|
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 and obj['chute']==False:
|
||||||
idle=False
|
idle=False
|
||||||
obj['chute']=0
|
|
||||||
if obj['courrir']<40: # 40 : nombre de pas pour courrir
|
# Planer
|
||||||
|
if obj['saut']:
|
||||||
obj.applyMovement((0,-pas_lineaire,0), True)
|
obj.applyMovement((0,-pas_lineaire,0), True)
|
||||||
|
start, end, speed, layer = 1, 13, 2, 0
|
||||||
|
obj_rig.playAction('Frankie-planer', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
|
obj['courrir_tics']=0
|
||||||
|
obj['courrir']=False
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
# Avancer normalement
|
||||||
|
if obj['courrir_tics']<40: # 40 : nombre de tics pour courrir
|
||||||
|
obj.applyMovement((0,-pas_lineaire,0), True)
|
||||||
|
obj['courrir_tics']+=1
|
||||||
start, end, speed, layer = 1, 18, 2, 0
|
start, end, speed, layer = 1, 18, 2, 0
|
||||||
obj_rig.playAction('Frankie-avancer', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
obj_rig.playAction('Frankie-avancer', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
obj['courrir']+=1
|
|
||||||
|
# Courrir
|
||||||
else:
|
else:
|
||||||
obj.applyMovement((0,-pas_courrir,0), True)
|
obj.applyMovement((0,-pas_courrir,0), True)
|
||||||
|
obj['courrir']=True
|
||||||
start, end, speed, layer = 1, 18, 2, 0
|
start, end, speed, layer = 1, 18, 2, 0
|
||||||
obj_rig.playAction('Frankie-courrir', start, end, layer, 1, 1.0, PLAY, 0.0, 0, speed)
|
obj_rig.playAction('Frankie-courrir', start, end, layer, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
if keyboard.inputs[bge.events.UPARROWKEY].status[0] != ACTIVATE and obj['courrir']>0:
|
|
||||||
obj['courrir']=0
|
# Arrêt de la course
|
||||||
|
if keyboard.inputs[bge.events.UPARROWKEY].status[0] != ACTIVATE and obj['courrir_tics']>0: # Arrêt de la course
|
||||||
|
obj['courrir_tics']=0
|
||||||
|
obj['courrir']=False
|
||||||
|
|
||||||
# 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 and obj['saut']==False and obj['chute']==False:
|
||||||
idle=False
|
idle=False
|
||||||
obj['chute']=0
|
|
||||||
obj.applyMovement((0,pas_lineaire,0), True)
|
obj.applyMovement((0,pas_lineaire,0), True)
|
||||||
start, end, speed, layer = 1, 20, 2, 0
|
start, end, speed, layer = 1, 20, 2, 0
|
||||||
obj_rig.playAction('Frankie-reculer', start, end, layer, 1, 1.0, PLAY, 0.0, 0, speed)
|
obj_rig.playAction('Frankie-reculer', start, end, layer, 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 and obj['chute']==False:
|
||||||
idle=False
|
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:
|
||||||
@ -81,9 +96,8 @@ def clavier(cont):
|
|||||||
obj_rig.playAction('Frankie-gauche', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
obj_rig.playAction('Frankie-gauche', start, end, 0, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
|
|
||||||
# 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 and obj['chute']==False:
|
||||||
idle=False
|
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:
|
||||||
@ -92,54 +106,41 @@ def clavier(cont):
|
|||||||
obj_rig.playAction('Frankie-droite', start, end, layer, 1, 1.0, PLAY, 0.0, 0, speed)
|
obj_rig.playAction('Frankie-droite', start, end, layer, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
|
|
||||||
# Saut
|
# Saut
|
||||||
# obj['dist_terrain']= obj.getDistanceTo(scene.objects['Terrain'])
|
if keyboard.inputs[bge.events.SPACEKEY].status[0] == ACTIVATE and obj['chute']==False:
|
||||||
# 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:
|
|
||||||
idle=False
|
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: # Ne peut que sauter si Frankie touche le sol
|
||||||
if obj.collide(scene.objects[obj_sol])[0]:
|
if obj.collide(scene.objects[obj_sol])[0]:
|
||||||
|
if obj.collide(scene.objects[obj_sol])[1] is not None:
|
||||||
if len(obj.collide(scene.objects[obj_sol])[1])>0:
|
if len(obj.collide(scene.objects[obj_sol])[1])>0:
|
||||||
|
obj['saut']=True
|
||||||
obj.applyForce((0, 0,force_saut), True)
|
obj.applyForce((0, 0,force_saut), True)
|
||||||
start, end, speed, layer = 1, 34, 2, 1
|
start, end, speed, layer = 1, 34, 2, 1
|
||||||
obj_rig.playAction('Frankie-sauter', start, end, layer, 1, 1.0, PLAY, 0.0, 0, speed)
|
obj_rig.playAction('Frankie-sauter', start, end, layer, 1, 1.0, PLAY, 0.0, 0, speed)
|
||||||
break
|
break
|
||||||
|
|
||||||
print (obj_rig.isPlayingAction(1))
|
# Touche le sol -> plus de saut ni de chute
|
||||||
|
|
||||||
# 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')
|
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 obj.collide(scene.objects[obj_sol])[1] is not None:
|
||||||
if len(obj.collide(scene.objects[obj_sol])[1])>0:
|
if len(obj.collide(scene.objects[obj_sol])[1])>0:
|
||||||
obj['chute']=0
|
if obj['saut']:
|
||||||
|
obj['sol_tics']+=1
|
||||||
|
if obj['sol_tics']>3: # 3 : nombre de tics sur le sol pour annuler le saut
|
||||||
|
obj['saut']=False
|
||||||
|
obj['sol_tics']=0
|
||||||
|
obj['chute_tics']=0
|
||||||
|
obj['chute']=False
|
||||||
break
|
break
|
||||||
|
|
||||||
# objs_sol=('Terrain', 'Platforme', 'Pont 1', 'Pont 2')
|
# Chute
|
||||||
# chute_flag=True
|
if obj.worldPosition.z < obj['chute_z'] and obj['saut']==False:
|
||||||
# for obj_sol in objs_sol:
|
obj['chute_tics']+=1
|
||||||
# if obj.collide(scene.objects[obj_sol])[0]:
|
|
||||||
# chute_flag=False
|
|
||||||
# break
|
|
||||||
# if chute_flag:
|
|
||||||
# obj['chute']+=1
|
|
||||||
obj['chute_z'] = obj.worldPosition.z
|
obj['chute_z'] = obj.worldPosition.z
|
||||||
if obj['chute']>50:
|
if obj['chute_tics']>50: # 50 : nombre de tics pour déclarer la chute
|
||||||
idle=False
|
idle=False
|
||||||
|
obj['chute']=True
|
||||||
start, end, speed, layer = 1, 33, 2, 0
|
start, end, speed, layer = 1, 33, 2, 0
|
||||||
obj_rig.playAction('Frankie-tomber', start, end, layer, 1, 1.0, LOOP, 0.0, 0, speed)
|
obj_rig.playAction('Frankie-tomber', start, end, layer, 1, 1.0, LOOP, 0.0, 0, speed)
|
||||||
|
|
||||||
@ -168,8 +169,11 @@ def clavier(cont):
|
|||||||
# Saut sur les téléportes (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 and obj['debugg']:
|
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['saut'] = False
|
||||||
obj['courrir'] = 0
|
obj['chute_tics'] = 0
|
||||||
|
obj['chute'] = False
|
||||||
|
obj['courrir_tics'] = 0
|
||||||
|
obj['courrir'] = False
|
||||||
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+obj_spawn['sens']), False)
|
obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+obj_spawn['sens']), False)
|
||||||
@ -177,8 +181,11 @@ def clavier(cont):
|
|||||||
# 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 and obj['debugg']:
|
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['saut'] = False
|
||||||
obj['courrir'] = 0
|
obj['chute_tics'] = 0
|
||||||
|
obj['chute'] = False
|
||||||
|
obj['courrir_tics'] = 0
|
||||||
|
obj['courrir'] = False
|
||||||
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+obj_spawn['sens']), False)
|
obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+obj_spawn['sens']), False)
|
||||||
@ -212,10 +219,9 @@ def init(cont):
|
|||||||
eevee.shadow_cube_size='512'
|
eevee.shadow_cube_size='512'
|
||||||
|
|
||||||
# Mode debug
|
# Mode debug
|
||||||
scene.objects['Frankie']['debugg']=True
|
scene.objects['Frankie']['debugg']=True # 'debug' est réservé
|
||||||
|
|
||||||
# Init de Frankie
|
# Init de Frankie
|
||||||
scene.objects['Frankie']['chute']=0
|
|
||||||
scene.objects['Frankie']['chute_z'] = scene.objects['Frankie'].worldPosition.z
|
scene.objects['Frankie']['chute_z'] = scene.objects['Frankie'].worldPosition.z
|
||||||
scene.objects['Frankie']['spawn']=0
|
scene.objects['Frankie']['spawn']=0
|
||||||
|
|
||||||
@ -234,8 +240,11 @@ def chute(cont):
|
|||||||
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+obj_spawn['sens']), False)
|
obj.applyRotation((0, 0, -obj.worldOrientation.to_euler().z+obj_spawn['sens']), False)
|
||||||
obj['chute'] = 0
|
obj['saut'] = False
|
||||||
obj['courrir'] = 0
|
obj['chute_tics'] = 0
|
||||||
|
obj['chute'] = False
|
||||||
|
obj['courrir_tics'] = 0
|
||||||
|
obj['courrir'] = False
|
||||||
|
|
||||||
# Checkpoint
|
# Checkpoint
|
||||||
def checkpoint(cont):
|
def checkpoint(cont):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user