[RESOLU] Tirs coup par coup
Publié : ven. 17/juil./2009 18:42
Salut j'ai un petit probleme. tous ce que j'ai voulu faire a fonctionner sauf une petite chose les tirs de sphere. Qaund je laisse l'ennemi tirer l'ennemi tir 1sphere tous les 10dixieme de seconde et moi je veut ralentir la cadence, c'est a dire , qu'a chaque balle tirer il y aura un moment d'attente par exemple 5 seconde.
ex: l'ennemi tir une premiere balle, il faut attendre 5 seconde avant qu'il en tir une seconde.
Je donne aussi le code entier , l'exemple qui a servi est AnimX
Help Please.
ex: l'ennemi tir une premiere balle, il faut attendre 5 seconde avant qu'il en tir une seconde.
Je donne aussi le code entier , l'exemple qui a servi est AnimX
Code : Tout sélectionner
; ------------------------------------------------------------
; DreaMotion3D(le meilleur moteur qui va me servir pour mon jeu)
;
; Exemple : AnimX(pris d'un ancien exemple de la team)
; Historique :
; 18/09/06 00:00 DreaMotion3D Team(la team va me manquer )
; 10/02/07 19:16 TMyke (mais hereusement qu'il est encore la)
;
; ------------------------------------------------------------
; Include files
IncludePath "Include\" : IncludeFile "dreamotion3d.pbi"
;EnableExplicit
Declare FrameFind( *pframe.D3DXFRAME , *frame.D3DXFRAME)
; Globales
Global anglex.f, angley.f, flagXDown.w
Global mox.f, omx.f, moy.l, omy.l
Global *camera.CEntity
Global *land.CEntity
Global Dim *tiny.CAnimX(30)
Global *cube.CMesh
Global *sphere.CMesh
Global *font.CFont
Global val.l,Quit.b
Global i.l, flag.l
Global tab.l=0, *tFrame.D3DXFRAME
Structure BULLET
*mesh.CMesh
pos.D3DXVECTOR3
EndStructure
Global Dim ball.BULLET(128)
Global num_ball.l=0
Structure BULLET2
*mesh2.CMesh
pos.D3DXVECTOR3
EndStructure
Global Dim ball2.BULLET2(128)
Global num_ball2.l=0
; Init PB modules
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
End
EndIf
; set graphic window 3D
*app = DM_Graphics3D(800,600, 32, 0, 1)
;load font
*font = DM_LoadFont( "Tahoma",9 , 0)
DM_TextColor (*font, 198,198,198,255)
; change directory for media
SetCurrentDirectory("media/")
; Set lights
DM_AmbientLight(150, 150, 150)
DM_CreateLight(3)
; ---------------------------------------
; meshs
; ---------------------------------------
; Charge le sol
*land = DM_LoadMesh("land.x")
*tiny = DM_LoadAnimMesh("bones_all.x")
DM_ScaleEntity(*tiny, 13,13,13)
DM_AnimateSpeed(*tiny, 0.01)
*sphere = DM_LoadAnimMesh("tiger.x")
DM_TranslateEntity(*sphere, 0,20,90)
*cube = DM_CreateCube()
*frame.l = DM_AnimateFindChild(*tiny, "R_hand")
DM_FrameChild(*tiny, *frame, *cube )
;Debug DM_AnimFrameName(*tiny(0)\ g_pFrameRoot)
;Debug "-------"
;FrameFind( *tiny(0)\ g_pFrameRoot, #Null)
; ---------------------------------------
; create camera
; ---------------------------------------
*camera = DM_CreateCamera()
DM_MoveEntity(*camera, 0,20,-120)
DM_TurnEntity(*camera, 0,20,0)
DM_CameraClsColor(*camera, 125, 125, 125)
; if full screen...
;change_curseur( #IDC_ARROW )
; ---------------------------------------
; main loop
; ---------------------------------------
Repeat
ExamineKeyboard()
ExamineMouse()
ShowCursor_(1)
; if Escape Key, exit
If KeyboardReleased(#PB_Key_Escape) Or WindowEvent()=#PB_Event_CloseWindow
Quit=1
EndIf
DM_PointEntity(*sphere,*tiny)
; les personnage se suit de vue.
DM_EntityDistance.f(*tiny, *sphere)
;on calcul la distance avec le code qui suit:
If DM_EntityZ(*tiny)=> DM_EntityZ(*sphere)-50
;Si la distance point de vu Z de tiny est inférieur a celle de la sphere(la sphere c'est tiger le tigre),
DM_MoveEntity(*sphere,0,0,0)
;alors la sphere ne bouge pas (coucher dit tiny au tiger lol)
ElseIf DM_EntityZ(*tiny)=> DM_EntityZ(*sphere)-150
;alors que si la distance du point de vu est a moins de 150 entre tiny et la sphere(100 metre de distanceentre 50 150 metre) alors lasphere le suit.
DM_MoveEntity(*sphere,0,0,2)
EndIf
;fin de ce code
If DM_EntityZ(*tiny)=> DM_EntityZ(*sphere)+150
; meme chose mais sauf qu'on calcule quand il sont de l'autre coter
DM_MoveEntity(*sphere,0,0,0)
;toujour zero
ElseIf DM_EntityZ(*tiny)=> DM_EntityZ(*sphere)+50
; on recommence mais pour le faire marcher a l'envère (ce qui est bien avec sa on fait d'une piere deux coups, il avoir une vue de 360°)
DM_MoveEntity(*sphere,0,0,2)
;Et la on lui dit de marcher
EndIf
;fin de celui-ci aussi
If DM_EntityX(*tiny)=> DM_EntityX(*sphere)-50
;maintenant sur les coter
DM_MoveEntity(*sphere,0,0,0)
;on l'arrete d'un coter
ElseIf DM_EntityX(*tiny)=> DM_EntityX(*sphere)-150
;mais si il est assez loin
DM_MoveEntity(*sphere,0,0,2)
;il bouge de ce coter(il c'est la sphere alias tiger)
EndIf
;fin aussi
If DM_EntityX(*tiny)=> DM_EntityX(*sphere)+150
;On recommence encore un derniere fois le code de l'autre coter
DM_MoveEntity(*sphere,0,0,0)
;il bouge pas quand il est tres proche de tiny
ElseIf DM_EntityX(*tiny)=> DM_EntityX(*sphere)+50
; mais la il est pret
DM_MoveEntity(*sphere,0,0,2)
;a le bondir dessus
EndIf
;et voila la dernière fin (je veux pas qu'il le suit en sautant betement comme le personnage, il a un cerveau l'ia alors pas de DM_EntityY).
If DM_EntityZ(*tiny)=>50
ball(num_ball)\mesh = DM_CreateSphere(8)
num_ball+1
DM_PositionEntity( ball(i)\mesh, DM_EntityX(*sphere), DM_EntityY(*sphere), DM_EntityZ(*sphere))
alpha.f = DM_EntityYaw(*sphere)
DM_RotateEntity(ball(i)\mesh, 180, alpha, 0)
EndIf
If(num_ball)
For i=0 To num_ball-1
DM_MoveEntity( ball(i)\mesh, 0,0,-5)
Next
EndIf
If DM_EntityZ(*tiny)=>-50
ball(num_ball)\mesh = DM_CreateSphere(8)
num_ball+1
DM_PositionEntity( ball(i)\mesh, DM_EntityX(*sphere), DM_EntityY(*sphere), DM_EntityZ(*sphere))
alpha.f = DM_EntityYaw(*sphere)
DM_RotateEntity(ball(i)\mesh, 180, alpha, 0)
EndIf
If(num_ball)
For i=0 To num_ball-1
DM_MoveEntity( ball(i)\mesh, 0,0,-5)
Next
EndIf
If DM_EntityX(*tiny)=>50
ball(num_ball)\mesh = DM_CreateSphere(8)
num_ball+1
DM_PositionEntity( ball(i)\mesh, DM_EntityX(*sphere), DM_EntityY(*sphere), DM_EntityZ(*sphere))
alpha.f = DM_EntityYaw(*sphere)
DM_RotateEntity(ball(i)\mesh, 180, alpha, 0)
EndIf
If(num_ball)
For i=0 To num_ball-1
DM_MoveEntity( ball(i)\mesh, 0,0,-5)
Next
EndIf
If DM_EntityX(*tiny)=>-50
ball(num_ball)\mesh = DM_CreateSphere(8)
num_ball+1
DM_PositionEntity( ball(i)\mesh, DM_EntityX(*sphere), DM_EntityY(*sphere), DM_EntityZ(*sphere))
alpha.f = DM_EntityYaw(*sphere)
DM_RotateEntity(ball(i)\mesh, 180, alpha, 0)
EndIf
If(num_ball)
For i=0 To num_ball-1
DM_MoveEntity( ball(i)\mesh, 0,0,-5)
Next
EndIf
If KeyboardPushed(#PB_Key_P)
ball(num_ball)\mesh = DM_CreateSphere(8)
num_ball+1
DM_PositionEntity( ball(i)\mesh, DM_EntityX(*tiny), DM_EntityY(*tiny), DM_EntityZ(*tiny))
EndIf
If(num_ball)
For i=0 To num_ball-1
DM_MoveEntity( ball(i)\mesh, 0,0,-5)
Next
EndIf
If KeyboardPushed(#PB_Key_Right)
DM_TurnEntity(*tiny, 0,1,0)
EndIf
If KeyboardPushed(#PB_Key_Left)
DM_TurnEntity(*tiny, 0,-1,0)
EndIf
If KeyboardPushed(#PB_Key_D)
DM_TranslateEntity(*tiny, -4,0,0)
EndIf
If KeyboardPushed(#PB_Key_F)
DM_TranslateEntity(*tiny, 4,0,0)
EndIf
If KeyboardPushed(#PB_Key_C)
DM_TranslateEntity(*tiny, 0,0,4)
EndIf
If KeyboardPushed(#PB_Key_R)
DM_TranslateEntity(*tiny, 0,0,-4)
EndIf
; change animation on Tiny 1
If KeyboardReleased(#PB_Key_F10)
DM_AnimateIndex(*tiny(0), 0)
EndIf
If KeyboardReleased(#PB_Key_F2)
DM_AnimateIndex(*tiny(0), 1)
EndIf
If KeyboardReleased(#PB_Key_F3)
DM_AnimateIndex(*tiny(0), 2)
EndIf
If KeyboardReleased(#PB_Key_F4)
DM_AnimateIndex(*tiny(0), 3)
EndIf
; change animation on Tiny 5
If KeyboardReleased(#PB_Key_B) : flag=11 : EndIf
If KeyboardReleased(#PB_Key_N) : flag=0 : EndIf
; move camera with dir key and mouse (left click)
If KeyboardPushed(#PB_Key_Up)
DM_MoveEntity(*camera, 0,0,4)
ElseIf KeyboardPushed(#PB_Key_Down)
DM_MoveEntity(*camera, 0,0,-4)
EndIf
If MouseButton(#PB_MouseButton_Left)
If flagXDown=0
omx = MouseX()
omy = MouseY()
flagXDown=11
Else
moy = MouseY()-omy
angley=(moy/5.0)
omy= MouseY()
mox = MouseX()-omx
anglex=(mox/5.0)
omx= MouseX()
DM_TurnEntity(*camera, angley,anglex,0)
EndIf
Else
flagXDown=0
EndIf
; ---------------
; Render
; ---------------
If flag=0 : DM_UpdateWorld() : EndIf
DM_BeginScene()
DM_RenderWorld(*camera)
; draw texte
DM_DrawText(*font, 10, 15, "FPS : "+Str(DM_FPS()))
DM_DrawText(*font, 10, 30, "F1/F2/F3/F4 : index of animate's tiny1")
DM_DrawText(*font, 10, 45, "F5/F6/F7/F8 : index of animate's tiny5")
DM_EndScene()
Until Quit=1
DM_ClearGraphics()
End
Procedure FrameFind( *pframe.D3DXFRAME , *frame.D3DXFRAME)
Protected a$
a$=Space(tab)
Repeat
*frame = DM_AnimateGetChild(*tiny, *pframe, *frame)
If *frame
Debug a$+DM_AnimFrameName(*frame)
tab+3
FrameFind(*frame, #Null)
EndIf
Until *frame=#Null
tab-3
EndProcedure
; IDE Options = PureBasic v4.00 (Windows - x86)
; CursorPosition = 69
; FirstLine = 53