Code : Tout sélectionner
; DreaMotion3D
;
; Exemple : Base_Game
; Historique :
; 18/09/06 00:00 TeamSpeed
; 10/02/07 19:16 Guerrier001
;
; ------------------------------------------------------------
;-Include Files
IncludePath "Include\" : IncludeFile "dreamotion3d.pbi"
Declare FrameFind( *pframe.D3DXFRAME , *frame.D3DXFRAME)
;-Globales
Global anglex.f, angley.f, flagXDown.w
Global mox.f, omx.f, moy.l, omy.l, PlayerSpeed.l
Global mFar.f, hh.f
Global *camera.CEntity
Global *texture.CTexture
Global *font.CFont
Global Dim *tiny.CAnimX(30)
Global 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
Procedure MON_JEU()
DM_InitPhysic()
;-Init PB modules
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
End
EndIf
;-set graphic window 3D
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 ambient color
DM_AmbientLight(250, 250, 250)
DM_CreateLight(3)
PlayerSpeed = 5
; ---------------------------------------
;-a little skybox, well here a skydome must be define in first
;
; ---------------------------------------
*sky.CSkySphere = DM_LoadSkySphere("grassenvmap1024.dds", 50)
DM_TranslateEntity(*sky, 0,-10,0)
DM_TextureMipLevel( 0 )
; ---------------------------------------
;-create terrain with terrain engine
;
; ---------------------------------------
;-create base terrain with heightmap "map.jpg"
*terrain = DM_CreateTerrain("Height113.bmp", 1.5, #False)
*brush = DM_CreateBrush("terrain")
DM_LoadTexture("sol113.jpg", DM_GetTexture(*brush))
DM_LoadTexture("detail3.bmp", DM_GetTexture(*brush,1))
DM_PaintTerrain(*terrain, *brush )
DM_FreeBrush(*brush)
mFar=800.0
*sphere = DM_LoadAnimMesh("tiger.x")
DM_TranslateEntity(*sphere, 0,20,90)
*tiny = DM_LoadAnimMesh("bones_all.x")
DM_ScaleEntity(*tiny, 13,13,13)
DM_AnimateSpeed(*tiny, 0.01)
DM_RotateEntity(*tiny, 0,225,0)
*cube = DM_CreateCube()
*frame.l = DM_AnimateFindChild(*tiny, "R_hand")
DM_FrameChild(*tiny, *frame, *cube )
; ---------------------------------------
;-create camera
; ---------------------------------------
*camera = DM_CreateCamera(800,600,*tiny)
DM_MoveEntity(*camera, 0,2,4)
DM_TurnEntity(*camera, 10,180,0)
DM_CameraClsColor(*camera, 125, 125, 125)
DM_CameraProjRatio(*camera, 800,600, mFar)
; ---------------------------------------
;-main loop
; ---------------------------------------
;-if fullscreen, must do it for keep mouse cursor
;-change_curseur( #IDC_ARROW )
Timer = ElapsedMilliseconds()
TouteLesCinqSecondes = Timer + 5000
Repeat
Timer = ElapsedMilliseconds()
ExamineMouse()
If flagXdown=0
flagXDown=11
Else
moy = MouseDeltaY()/10*PlayerSpeed/2
mox = MouseDeltaX()/10*PlayerSpeed/2
DM_TurnEntity(*tiny, 0,mox,0)
EndIf
ExamineKeyboard()
;-if Escape Key, exit
If KeyboardReleased(#PB_Key_Escape) Or WindowEvent()=#PB_Event_CloseWindow
Quit=1
EndIf
h.f = DM_GetTerrainHeight(*terrain, DM_EntityX(*sphere), DM_EntityZ(*sphere))
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
DM_PositionEntity(*sphere, DM_EntityX(*sphere), h+5, DM_EntityZ(*sphere))
;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
DM_PositionEntity(*sphere, DM_EntityX(*sphere), h+5, DM_EntityZ(*sphere))
;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
DM_PositionEntity(*sphere, DM_EntityX(*sphere), h+5, DM_EntityZ(*sphere))
; 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
DM_PositionEntity(*sphere, DM_EntityX(*sphere), h+5, DM_EntityZ(*sphere))
; 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
DM_PositionEntity(*sphere, DM_EntityX(*sphere), h+5, DM_EntityZ(*sphere))
;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_PositionEntity(*sphere, DM_EntityX(*sphere), h+5, DM_EntityZ(*sphere))
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
DM_PositionEntity(*sphere, DM_EntityX(*sphere), h+5, DM_EntityZ(*sphere))
;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
DM_PositionEntity(*sphere, DM_EntityX(*sphere), h+5, DM_EntityZ(*sphere))
; 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 And TouteLesCinqSecondes < Timer
TouteLesCinqSecondes = Timer + 5000
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,-1)
Next
EndIf
If DM_EntityZ(*tiny)=>-50 And TouteLesCinqSecondes < Timer
TouteLesCinqSecondes = Timer + 5000
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,-1)
Next
EndIf
If DM_EntityX(*tiny)=>50 And TouteLesCinqSecondes < Timer
TouteLesCinqSecondes = Timer + 5000
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,-1)
Next
EndIf
If DM_EntityX(*tiny)=>-50 And TouteLesCinqSecondes < Timer
TouteLesCinqSecondes = Timer + 5000
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,-1)
Next
EndIf
If KeyboardReleased(#PB_Key_Space)
ball(num_ball)\mesh = DM_CreateSphere(32)
num_ball+1
DM_PositionEntity( ball(i)\mesh, DM_EntityX(*cube), DM_EntityY(*cube), DM_EntityZ(*cube))
alpha.f = DM_EntityYaw(*tiny)
DM_RotateEntity(ball(i)\mesh, 0, alpha, 0)
EndIf
If(num_ball)
For i=0 To num_ball-1
DM_MoveEntity( ball(i)\mesh, 0,0,-5)
Next
EndIf
h.f = DM_GetTerrainHeight(*terrain, DM_EntityX(*tiny), DM_EntityZ(*tiny))
If KeyboardPushed(#PB_Key_Down)
DM_AnimateIndex(*tiny, 1)
DM_MoveEntity(*tiny, 0,0,4)
DM_PositionEntity(*tiny, DM_EntityX(*tiny), h+5, DM_EntityZ(*tiny))
EndIf
If KeyboardReleased(#PB_Key_Down)
DM_AnimateIndex(*tiny, 0)
DM_MoveEntity(*tiny, 0,0,0)
DM_PositionEntity(*tiny, DM_EntityX(*tiny), h+5, DM_EntityZ(*tiny))
EndIf
If KeyboardPushed(#PB_Key_Up)
DM_AnimateIndex(*tiny, 1)
DM_MoveEntity(*tiny, 0,0,-4)
DM_PositionEntity(*tiny, DM_EntityX(*tiny), h+5, DM_EntityZ(*tiny))
EndIf
If KeyboardReleased(#PB_Key_Up)
DM_AnimateIndex(*tiny, 0)
DM_MoveEntity(*tiny, 0,0,0)
DM_PositionEntity(*tiny, DM_EntityX(*tiny), h+5, DM_EntityZ(*tiny))
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_TurnEntity(*sphere, 0,1,0)
EndIf
If KeyboardPushed(#PB_Key_A)
DM_TurnEntity(*sphere, 0,-1,0)
EndIf
; ---------------
;-Render
; ---------------
If flag=0 : DM_UpdateWorld() : EndIf
DM_BeginScene()
DM_RenderWorld(*camera)
;-draw some informations
DM_DrawText(*font, 10, 15, "FPS: "+Str(DM_FPS()))
DM_EndScene()
Until quit=1
;-end
DM_ClearGraphics()
EndProcedure
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