Results 1 to 2 of 2

Thread: Irrlicht FPS Demo

  1. #1

    Irrlicht FPS Demo

    my first demo with Irrlicht 4 delphi

    http://depositfiles.com/files/4022034












    Code:
    program fps_demo;
    
    {$APPTYPE CONSOLE}
    
    uses
      SysUtils,dialogs,mmsystem,
      IRRLICHT in 'IRRLICHT.pas';
    
    
    Type
    TPlayerState=(SShot,SIdle,SRun,SDrop,SPut);
    TgameState=(Sload,SLoop);
    
    function GetNormal(v1,v2,v3:IVEC3):IVEC3;
    var
      v4,v5, nor: IVEC3;
      lenght:single;
    begin
      v4.x:=V1.x-V2.x;
      v4.y:=V1.y-V2.y;
      v4.z:=V1.z-V2.z;
      v5.x:=V2.x-V3.x;
      v5.y:=V2.y-V3.y;
      v5.z:=V2.z-V3.z;
      nor.x:=v4.y*v5.z-v4.z*v5.y;
      nor.y:=v4.z*v5.x-v4.x*v5.z;
      nor.z:=v4.x*v5.y-v4.y*v5.x;
      lenght:=sqrt(nor.x*nor.x+nor.y*nor.y+nor.z*nor.z);
      nor.x:=nor.x/lenght;
      nor.y:=nor.y/lenght;
      nor.z:=nor.z/lenght;
      Result:=nor;
    end;
    
    var
    but0,but:IGUI;
    font:IFont;
    moozle_Tex,decal_Tex:ITexture;
    room,camera:ISceneNode;
    mesh:IAnimatedMesh;
    
    selector:ITriangleSelector;
    
    Intersection,N2,Normal:IVEC3;
    RayOut:IRAY;
    Triangle:ITriangle;
    
    finished:boolean=false;
    EEvents:TEngineEvents;
    
    
    Save8087CW: Word;
    
    
    ps,flare,WEp_joint,sp,sp2,Node_weapon1,Node_weapon2:ISceneNode;
    Mesh_wepon:IAnimatedMesh;
    
    
    shottime,lasttick:integer;
    
    PlayerState:TPlayerState=SIdle;
    gameState:TgameState=Sload;
    step:integer=0;
    
    wep_sniper:boolean=false;
    
    procedure ploop;
    begin
    
    if (EEvents.loopMouseInput.Event=EMIE_LMOUSE_PRESSED_DOWN) then
    if PlayerState<>SShot then PlayerState&#58;=sshot;
    if &#40;EEvents.loopMouseInput.Event=EMIE_RMOUSE_PRESSED_DOWN&#41; then
    if PlayerState<SShot> shottime+200&#41; then
    begin
       shottime &#58;= timegettime;
    if Scene_Pick&#40;selector,camera,1000.0,Intersection,Normal,RayOut,Triangle&#41; then
    begin
    normal&#58;=GetNormal&#40;Triangle.T1,Triangle.T2,Triangle.T3&#41;;
    n2.x&#58;=normal.x;
    n2.y&#58;=normal.y;
    n2.z&#58;=normal.z;
    Intersection.x&#58;=Intersection.x+n2.x*0.01;
    Intersection.y&#58;=Intersection.y+n2.y*0.01;
    Intersection.z&#58;=Intersection.z+n2.z*0.01;
    Scene_AddDecal&#40;Intersection,n2,2,90000,decal_Tex,EMT_TRANSPARENT_ALPHA_CHANNEL&#41;;
    end;
    end;
    
    if &#40;timegettime > lasttick + 100&#41; then
    begin
        lasttick &#58;= timegettime;
        PlayerState&#58;=SIdle;
    end;
    end else
    begin
    if &#40;timegettime > shottime+80&#41; then
    begin
       shottime &#58;= timegettime;
    if Scene_Pick&#40;selector,camera,1000.0,Intersection,Normal,RayOut,Triangle&#41; then
    begin
    normal&#58;=GetNormal&#40;Triangle.T1,Triangle.T2,Triangle.T3&#41;;
    n2.x&#58;=normal.x;
    n2.y&#58;=normal.y;
    n2.z&#58;=normal.z;
    Intersection.x&#58;=Intersection.x+n2.x*0.01;
    Intersection.y&#58;=Intersection.y+n2.y*0.01;
    Intersection.z&#58;=Intersection.z+n2.z*0.01;
    Scene_AddDecal&#40;Intersection,n2,2,60000,decal_Tex,EMT_TRANSPARENT_ALPHA_CHANNEL&#41;;
    end;
    end;
    
    if &#40;timegettime > lasttick + 1000&#41; then
    begin
        lasttick &#58;= timegettime;
        PlayerState&#58;=SIdle;
    end;
    
    end;
    
    
    end;
    SIdle&#58;
    begin
    Node_SetRotation&#40;Node_weapon1,sin&#40;timegettime/1000&#41;*0.4,sin&#40;timegettime/1000&#41;*0.8,0&#41;;
    Node_SetRotation&#40;Node_weapon2,sin&#40;timegettime/1000&#41;*0.4,sin&#40;timegettime/1000&#41;*0.8,0&#41;;
    Scene_SetBillboardSize&#40;sp,0,0&#41;;
    Scene_SetBillboardSize&#40;sp2,0,0&#41;;
    end;
    SRun&#58;
    begin
    end;
    SDrop&#58;
    begin
    
      Node_SetRotation&#40;Node_weapon1,step,-step,0&#41;;//shoot machine gun
      Node_SetRotation&#40;Node_weapon2,step,-step,0&#41;;//shoot machine gun
    
    if &#40;timegettime > lasttick + 20&#41; then
    begin
        lasttick &#58;= timegettime;
         inc&#40;step&#41;;
    end;
    if step>=40 then
    begin
    wep_sniper&#58;=not wep_sniper;
    if wep_sniper then
    begin
    Node_SetVisible&#40;Node_weapon1,false&#41;;
    Node_SetVisible&#40;Node_weapon2,true&#41;;
    end else
    begin
    Node_SetVisible&#40;Node_weapon1,true&#41;;
    Node_SetVisible&#40;Node_weapon2,false&#41;;
    end;
    
    PlayerState&#58;=SPut;
    end;
    end;
    SPut&#58;
    begin
      Node_SetRotation&#40;Node_weapon1,step,-step,0&#41;;//shoot machine gun
      Node_SetRotation&#40;Node_weapon2,step,-step,0&#41;;//shoot machine gun
    
    if &#40;timegettime > lasttick + 20&#41; then
    begin
        lasttick &#58;= timegettime;
        dec&#40;step&#41;;
    end;
    if step<0 then
     begin
    
    if  wep_sniper then
    begin
    Node_SetVisible&#40;Node_weapon2,true&#41;;
    Node_SetVisible&#40;Node_weapon1,false&#41;;
    end else
    begin
    Node_SetVisible&#40;Node_weapon1,true&#41;;
    Node_SetVisible&#40;Node_weapon2,false&#41;;
    end;
    //wep_sniper&#58;=not wep_sniper;
     PlayerState&#58;=SIdle;
     end;
    
    end;
    end;
    
    Scene_DrawAll;
    
    Render_Draw2DLine&#40;800 div 2-20,600 div 2,800 div 2+20,600 div 2,color&#40;255,0,255,0&#41;&#41;;
    Render_Draw2DLine&#40;800 div 2,600 div 2-20,800 div 2,600 div 2+20,color&#40;255,0,255,0&#41;&#41;;
    
    end;
    
    procedure state&#40;int&#58;integer;msg&#58;string&#41;;
    begin
    
    Render_BeginScene&#40;true,true,0,0,0&#41;;
    Render_Draw2DRectangle&#40;10,600-40,800-10,600-5,color&#40;244,255,0,0&#41;&#41;;
    Render_Draw2DRectangle&#40;10,600-40,10+int ,600-5,color&#40;244,0,255,0&#41;&#41;;
    Font_Write&#40;font,pchar&#40;msg&#41;,15,640-70,color&#40;255,255,255,10&#41;&#41;;
    Render_EndScene;
    sleep&#40;100&#41;;
    end;
    
    procedure Pload;
    begin
    
    camera&#58;=Scene_AddFPSCamera;
    Node_SetPosition&#40;camera,500,100,300&#41;;
    
    state&#40;50,'Load SkyBox'&#41;;
    camera&#58;=Scene_AddFPSCamera;
    Node_SetPosition&#40;camera,80,80,-600&#41;;
    Scene_AddSkyBox&#40;
    'media/Nebular_up.jpg',
    'media/Nebular_dn.jpg',
    'media/Nebular_lf.jpg',
    'media/Nebular_rt.jpg',
    'media/Nebular_ft.jpg',
    'media/Nebular_bk.jpg'&#41;;
    
    state&#40;100,'Load Map'&#41;;
    mesh&#58;=Scene_AddMesh&#40;'media/scenes/mapa.dmf'&#41;;
    //mesh&#58;=Scene_AddMesh&#40;'media/scenes/mapa.3ds'&#41;;
    //Mesh_MakePlanarTextureMapping&#40;mesh,0.004&#41;;
    state&#40;200,'Build Scene Octree'&#41;;
    room&#58;=Scene_AddOctTreeSceneNode&#40;mesh&#41;;
    //room&#58;=Scene_AddNodFromMesh&#40;mesh,ZEROVECT,ZEROVECT,ADDVECT&#41;;
    Node_SetMaterialFlag&#40;room,EMF_LIGHTING,false&#41;;
    
    
    
    state&#40;300,'Create Octree colider'&#41;;
    selector&#58;=Scene_createOctTreeTriangleSelector&#40;   mesh,room&#41;;
    
    state&#40;400,'load flares'&#41;;
    flare&#58;=Scene_AddLensFlare&#40;'media/flares.jpg',nil,vect&#40;-10,1200,10&#41;,true,Scene_GetRooSceneNode&#41;;
    Node_SetTriangleSelector&#40;flare,selector&#41;;
    
    state&#40;450,'colide and response'&#41;;
    Node_SetTriangleSelector&#40;room,selector&#41;;
    Scene_CreateCollisionResponseAnimator&#40;selector,camera,
    VECT&#40;30,50,30&#41;,VECT&#40;0,-8,0&#41;,VECT&#40;0,50,0&#41;&#41;;
    
    
    state&#40;480,'load declas'&#41;;
    decal_Tex&#58;=Texture_Load&#40;'media/BULLET.BMP'&#41;;
    Texture_SetColorKey&#40;decal_Tex,0,0&#41;;
    
    
    state&#40;500,'load billboard'&#41;;
    sp&#58;=Scene_AddBillboard&#40;8,8,zerovect,Cwhite&#41;;
    moozle_Tex&#58;=Texture_Load&#40;'media/particlewhite.bmp'&#41;;
    //decal_Tex&#58;=Texture_Load&#40;'media/gun2/Flash1_1.png'&#41;;
    Texture_SetColorKey&#40;moozle_Tex,0,0&#41;;
    Node_SetMaterialTextureEx&#40;sp,0,moozle_Tex&#41;;
    Node_SetMaterialFlag&#40;sp,EMF_LIGHTING,false&#41;;
    Node_SetMaterialType&#40;sp,EMT_TRANSPARENT_ADD_COLOR&#41;;
    sp2&#58;=Node_Clone&#40;sp&#41;;
    
    
    state&#40;500,'load particles'&#41;;
    
    //ps&#58;=Scene_AddParticleSystem&#40;vect&#40;-70,60,40&#41;,ZEROVECT,vect&#40;2,2,2&#41;,false,model&#41;;
    
    //ps&#58;=Scene_AddParticleSystem&#40;vect&#40;1784,20,184&#41;,ZEROVECT,vect&#40;1,1,1&#41;,false&#41;;
    
    ps&#58;=Scene_AddParticleSystem&#40;vect&#40;1684,35,1900&#41;,ZEROVECT,vect&#40;1,1,1&#41;,false&#41;;
    
    Par_SetParticleSize&#40;ps,20,20&#41;;
    
    Node_SetMaterialTexture&#40;ps,0,'media/fire.bmp'&#41;;
    
    Node_SetMaterialFlag&#40;ps,EMF_LIGHTING,false&#41;;
    Node_SetMaterialFlag&#40;ps,EMF_ZWRITE_ENABLE,false&#41;;
    Node_SetMaterialType&#40;ps,EMT_TRANSPARENT_VERTEX_ALPHA&#41;;
    Par_AddBoxEmitter&#40;ps,-10,0,-10,10,1,10,vect&#40;0,0.06,0&#41;,color&#40;0,255,255,255&#41;,color&#40;0,255,255,255&#41;,80,100,800,2000&#41;;
    
    Par_AddFadeOutParticleAffector&#40;ps&#41;;
    
    
    //ps&#58;=Scene_AddParticleSystem&#40;vect&#40;1684,45,1900&#41;,ZEROVECT,vect&#40;1,1,1&#41;,false&#41;;
    
    ps&#58;=Scene_AddParticleSystem&#40;vect&#40;1784,20,184&#41;,ZEROVECT,vect&#40;1,1,1&#41;,false&#41;;
    
    Par_SetParticleSize&#40;ps,40,40&#41;;
    
    Node_SetMaterialTexture&#40;ps,0,'media/smoke.bmp'&#41;;
    
    Node_SetMaterialFlag&#40;ps,EMF_LIGHTING,false&#41;;
    Node_SetMaterialFlag&#40;ps,EMF_ZWRITE_ENABLE,false&#41;;
    Node_SetMaterialType&#40;ps,EMT_TRANSPARENT_VERTEX_ALPHA&#41;;
    Par_AddBoxEmitter&#40;ps,-25,4,-25,25,18,25,vect&#40;0,0.04,0&#41;,color&#40;0,55,55,55&#41;,color&#40;0,0,0,0&#41;,10,20,18000,20000,0&#41;;
    
    //Par_AddGravityAffector&#40;ps,vect&#40;0,0.001,0&#41;&#41;;
    
    Par_AddFadeOutParticleAffector&#40;ps&#41;;
    
    
    //Par_AddCylinderEmitter&#40;ps,ZEROVECT,20,vect&#40;0,0,0&#41;,2,vect&#40;0,0.03,0&#41;,color&#40;0,255,255,255&#41;,color&#40;0,255,255,255&#41;&#41;;
    
    //Par_AddPointEmitter&#40;ps,vect&#40;0,0.03,0&#41;,color&#40;0,255,255,255&#41;,color&#40;0,255,255,255&#41;&#41;;
    
    //Par_AddRingEmitter&#40;ps,vect&#40;0,0,0&#41;,2,2,vect&#40;0,0.03,0&#41;,color&#40;0,255,255,255&#41;,color&#40;0,255,255,255&#41;&#41;;
    
    //Par_AddSphereEmitter&#40;ps,vect&#40;0,0,0&#41;,6,vect&#40;0,0.03,0&#41;,color&#40;0,255,255,255&#41;,color&#40;0,255,255,255&#41;&#41;;
    
    
    
    //Par_AddAttractionParticleAffector&#40;ps,vect&#40;100,10,0&#41;,100,true,false,true,false&#41;;
    
    //Par_AddGravityAffector&#40;ps,vect&#40;0,0.03,0&#41;&#41;;
    
    //Par_AddRotationAffector&#40;ps,vect&#40;5.0,5.0,5.0&#41;,vect&#40;0,0,0&#41;&#41;;
    
    
    
    
    
    
    state&#40;600,'load machine weapon'&#41;;
    mesh&#58;=Scene_AddMesh&#40;'media/gun2/machine.b3d'&#41;;
    Node_weapon1&#58;=Scene_AddNodFromMesh&#40;mesh,vect&#40;0,-5,0&#41;,vect&#40;0,0,0&#41;,vect&#40;0.2,0.2,0.2&#41;,camera&#41;;
    Node_SetMaterialFlag&#40;Node_weapon1,EMF_LIGHTING,false&#41;;
    state&#40;700,'load sniper weapon'&#41;;
    mesh&#58;=Scene_AddMesh&#40;'media/gun2/sniper.b3d'&#41;;
    Node_weapon2&#58;=Scene_AddNodFromMesh&#40;mesh,vect&#40;0,-5,0&#41;,vect&#40;0,0,0&#41;,vect&#40;0.2,0.2,0.2&#41;,camera&#41;;
    Node_SetMaterialFlag&#40;Node_weapon2,EMF_LIGHTING,false&#41;;
    
    WEp_joint&#58;=Bone_GetJointNode&#40;Node_weapon1,'rp_sight'&#41;;
    Node_AddChilld&#40;WEp_joint,sp&#41;;
    
    WEp_joint&#58;=Bone_GetJointNode&#40;Node_weapon2,'rp_sight'&#41;;
    Node_AddChilld&#40;WEp_joint,sp2&#41;;
    
    state&#40;800-10,'AllOK'&#41;;
    Node_SetVisible&#40;Node_weapon1,true&#41;;
    Node_SetVisible&#40;Node_weapon2,false&#41;;
    end;
    
    
    
    begin
    
    Save8087CW &#58;= Get8087CW;
    Set8087CW&#40;$133F&#41;;
    
    Device_Init&#40;EDT_opengl,800,600,32,false,false,false&#41;;
    Render_SetResizeAble&#40;true&#41;;
    Device_SetWindowCaption&#40;'IRRLICHT 4 Delphi'&#41;;
    Render_SetDebug&#40;true,true&#41;;
    Device_SetCursorVisible&#40;false&#41;;
    
    
    font&#58;=Font_Load&#40;'media/fonthaettenschweiler.bmp'&#41;;
    
    
    
    
    
    
    lasttick&#58;=timegettime;
    shottime&#58;=timegettime;
    
    
    while &#40;Device_Run&#41; and &#40;not finished&#41; do
    begin
    Device_GetEvents&#40;EEvents&#41;;
    
    
    Render_BeginScene&#40;true,true,0,0,45&#41;;
    
    
    case gameState of
    Sload&#58;
    begin
    Pload;
    gameState&#58;=sloop;
    end;
    SLoop&#58;
    begin
    ploop;
    end;
    end;
    
    
    
    
    
    
    
    
    Render_EndScene;
    
    
    if EEvents.loopKeyInput.Key=27 then finished&#58;=true;
    end;
    
    Device_Stop;
    Set8087CW&#40;Save8087CW&#41;;
    
    end.
    Never underestimate the power of Delphi.
    <br />There's those who play games,...and then there's who make games...

  2. #2

    Irrlicht FPS Demo

    This is really nice for a first demo! There aren't any enemies yet, but you've got the basics covered.
    Can you tell what you've used to create the 3d models?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •