Irrlicht(delphi) FPS Demo

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
djoker
Posts: 39
Joined: Thu Dec 22, 2005 10:25 pm
Location: Portugal

Irrlicht(delphi) FPS Demo

Post by djoker »

my first demo with Irrlicht 4 delphi

http://depositfiles.com/files/4022034


Image
Image
Image
Image
Image
Image
Image
Image
Image

Code: Select all

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:=sshot;
if (EEvents.loopMouseInput.Event=EMIE_RMOUSE_PRESSED_DOWN) then
if PlayerState<>SShot then PlayerState:=sdrop;


case PlayerState of
SShot:
begin
    Node_SetRotation(Node_weapon1,sin(timegettime/40)*0.8,0,0);//shoot machine gun
    Node_SetRotation(Node_weapon2,sin(timegettime/90)*0.8,0,0);//shoot sniper
    Scene_SetBillboardSize(sp,sin(timegettime/20)*10.8,sin(timegettime/20)*10.8);
    Scene_SetBillboardSize(sp2,sin(timegettime/40)*10.8,sin(timegettime/40)*10.8);



if wep_sniper then
begin
if (timegettime > shottime+200) then
begin
   shottime := timegettime;
if Scene_Pick(selector,camera,1000.0,Intersection,Normal,RayOut,Triangle) then
begin
normal:=GetNormal(Triangle.T1,Triangle.T2,Triangle.T3);
n2.x:=normal.x;
n2.y:=normal.y;
n2.z:=normal.z;
Intersection.x:=Intersection.x+n2.x*0.01;
Intersection.y:=Intersection.y+n2.y*0.01;
Intersection.z:=Intersection.z+n2.z*0.01;
Scene_AddDecal(Intersection,n2,2,90000,decal_Tex,EMT_TRANSPARENT_ALPHA_CHANNEL);
end;
end;

if (timegettime > lasttick + 100) then
begin
    lasttick := timegettime;
    PlayerState:=SIdle;
end;
end else
begin
if (timegettime > shottime+80) then
begin
   shottime := timegettime;
if Scene_Pick(selector,camera,1000.0,Intersection,Normal,RayOut,Triangle) then
begin
normal:=GetNormal(Triangle.T1,Triangle.T2,Triangle.T3);
n2.x:=normal.x;
n2.y:=normal.y;
n2.z:=normal.z;
Intersection.x:=Intersection.x+n2.x*0.01;
Intersection.y:=Intersection.y+n2.y*0.01;
Intersection.z:=Intersection.z+n2.z*0.01;
Scene_AddDecal(Intersection,n2,2,60000,decal_Tex,EMT_TRANSPARENT_ALPHA_CHANNEL);
end;
end;

if (timegettime > lasttick + 1000) then
begin
    lasttick := timegettime;
    PlayerState:=SIdle;
end;

end;


end;
SIdle:
begin
Node_SetRotation(Node_weapon1,sin(timegettime/1000)*0.4,sin(timegettime/1000)*0.8,0);
Node_SetRotation(Node_weapon2,sin(timegettime/1000)*0.4,sin(timegettime/1000)*0.8,0);
Scene_SetBillboardSize(sp,0,0);
Scene_SetBillboardSize(sp2,0,0);
end;
SRun:
begin
end;
SDrop:
begin

  Node_SetRotation(Node_weapon1,step,-step,0);//shoot machine gun
  Node_SetRotation(Node_weapon2,step,-step,0);//shoot machine gun

if (timegettime > lasttick + 20) then
begin
    lasttick := timegettime;
     inc(step);
end;
if step>=40 then
begin
wep_sniper:=not wep_sniper;
if wep_sniper then
begin
Node_SetVisible(Node_weapon1,false);
Node_SetVisible(Node_weapon2,true);
end else
begin
Node_SetVisible(Node_weapon1,true);
Node_SetVisible(Node_weapon2,false);
end;

PlayerState:=SPut;
end;
end;
SPut:
begin
  Node_SetRotation(Node_weapon1,step,-step,0);//shoot machine gun
  Node_SetRotation(Node_weapon2,step,-step,0);//shoot machine gun

if (timegettime > lasttick + 20) then
begin
    lasttick := timegettime;
    dec(step);
end;
if step<0 then
 begin

if  wep_sniper then
begin
Node_SetVisible(Node_weapon2,true);
Node_SetVisible(Node_weapon1,false);
end else
begin
Node_SetVisible(Node_weapon1,true);
Node_SetVisible(Node_weapon2,false);
end;
//wep_sniper:=not wep_sniper;
 PlayerState:=SIdle;
 end;

end;
end;

Scene_DrawAll;

Render_Draw2DLine(800 div 2-20,600 div 2,800 div 2+20,600 div 2,color(255,0,255,0));
Render_Draw2DLine(800 div 2,600 div 2-20,800 div 2,600 div 2+20,color(255,0,255,0));

end;

procedure state(int:integer;msg:string);
begin

Render_BeginScene(true,true,0,0,0);
Render_Draw2DRectangle(10,600-40,800-10,600-5,color(244,255,0,0));
Render_Draw2DRectangle(10,600-40,10+int ,600-5,color(244,0,255,0));
Font_Write(font,pchar(msg),15,640-70,color(255,255,255,10));
Render_EndScene;
sleep(100);
end;

procedure Pload;
begin

camera:=Scene_AddFPSCamera;
Node_SetPosition(camera,500,100,300);

state(50,'Load SkyBox');
camera:=Scene_AddFPSCamera;
Node_SetPosition(camera,80,80,-600);
Scene_AddSkyBox(
'media/Nebular_up.jpg',
'media/Nebular_dn.jpg',
'media/Nebular_lf.jpg',
'media/Nebular_rt.jpg',
'media/Nebular_ft.jpg',
'media/Nebular_bk.jpg');

state(100,'Load Map');
mesh:=Scene_AddMesh('media/scenes/mapa.dmf');
//mesh:=Scene_AddMesh('media/scenes/mapa.3ds');
//Mesh_MakePlanarTextureMapping(mesh,0.004);
state(200,'Build Scene Octree');
room:=Scene_AddOctTreeSceneNode(mesh);
//room:=Scene_AddNodFromMesh(mesh,ZEROVECT,ZEROVECT,ADDVECT);
Node_SetMaterialFlag(room,EMF_LIGHTING,false);



state(300,'Create Octree colider');
selector:=Scene_createOctTreeTriangleSelector(   mesh,room);

state(400,'load flares');
flare:=Scene_AddLensFlare('media/flares.jpg',nil,vect(-10,1200,10),true,Scene_GetRooSceneNode);
Node_SetTriangleSelector(flare,selector);

state(450,'colide and response');
Node_SetTriangleSelector(room,selector);
Scene_CreateCollisionResponseAnimator(selector,camera,
VECT(30,50,30),VECT(0,-8,0),VECT(0,50,0));


state(480,'load declas');
decal_Tex:=Texture_Load('media/BULLET.BMP');
Texture_SetColorKey(decal_Tex,0,0);


state(500,'load billboard');
sp:=Scene_AddBillboard(8,8,zerovect,Cwhite);
moozle_Tex:=Texture_Load('media/particlewhite.bmp');
//decal_Tex:=Texture_Load('media/gun2/Flash1_1.png');
Texture_SetColorKey(moozle_Tex,0,0);
Node_SetMaterialTextureEx(sp,0,moozle_Tex);
Node_SetMaterialFlag(sp,EMF_LIGHTING,false);
Node_SetMaterialType(sp,EMT_TRANSPARENT_ADD_COLOR);
sp2:=Node_Clone(sp);


state(500,'load particles');

//ps:=Scene_AddParticleSystem(vect(-70,60,40),ZEROVECT,vect(2,2,2),false,model);

//ps:=Scene_AddParticleSystem(vect(1784,20,184),ZEROVECT,vect(1,1,1),false);

ps:=Scene_AddParticleSystem(vect(1684,35,1900),ZEROVECT,vect(1,1,1),false);

Par_SetParticleSize(ps,20,20);

Node_SetMaterialTexture(ps,0,'media/fire.bmp');

Node_SetMaterialFlag(ps,EMF_LIGHTING,false);
Node_SetMaterialFlag(ps,EMF_ZWRITE_ENABLE,false);
Node_SetMaterialType(ps,EMT_TRANSPARENT_VERTEX_ALPHA);
Par_AddBoxEmitter(ps,-10,0,-10,10,1,10,vect(0,0.06,0),color(0,255,255,255),color(0,255,255,255),80,100,800,2000);

Par_AddFadeOutParticleAffector(ps);


//ps:=Scene_AddParticleSystem(vect(1684,45,1900),ZEROVECT,vect(1,1,1),false);

ps:=Scene_AddParticleSystem(vect(1784,20,184),ZEROVECT,vect(1,1,1),false);

Par_SetParticleSize(ps,40,40);

Node_SetMaterialTexture(ps,0,'media/smoke.bmp');

Node_SetMaterialFlag(ps,EMF_LIGHTING,false);
Node_SetMaterialFlag(ps,EMF_ZWRITE_ENABLE,false);
Node_SetMaterialType(ps,EMT_TRANSPARENT_VERTEX_ALPHA);
Par_AddBoxEmitter(ps,-25,4,-25,25,18,25,vect(0,0.04,0),color(0,55,55,55),color(0,0,0,0),10,20,18000,20000,0);

//Par_AddGravityAffector(ps,vect(0,0.001,0));

Par_AddFadeOutParticleAffector(ps);


//Par_AddCylinderEmitter(ps,ZEROVECT,20,vect(0,0,0),2,vect(0,0.03,0),color(0,255,255,255),color(0,255,255,255));

//Par_AddPointEmitter(ps,vect(0,0.03,0),color(0,255,255,255),color(0,255,255,255));

//Par_AddRingEmitter(ps,vect(0,0,0),2,2,vect(0,0.03,0),color(0,255,255,255),color(0,255,255,255));

//Par_AddSphereEmitter(ps,vect(0,0,0),6,vect(0,0.03,0),color(0,255,255,255),color(0,255,255,255));



//Par_AddAttractionParticleAffector(ps,vect(100,10,0),100,true,false,true,false);

//Par_AddGravityAffector(ps,vect(0,0.03,0));

//Par_AddRotationAffector(ps,vect(5.0,5.0,5.0),vect(0,0,0));






state(600,'load machine weapon');
mesh:=Scene_AddMesh('media/gun2/machine.b3d');
Node_weapon1:=Scene_AddNodFromMesh(mesh,vect(0,-5,0),vect(0,0,0),vect(0.2,0.2,0.2),camera);
Node_SetMaterialFlag(Node_weapon1,EMF_LIGHTING,false);
state(700,'load sniper weapon');
mesh:=Scene_AddMesh('media/gun2/sniper.b3d');
Node_weapon2:=Scene_AddNodFromMesh(mesh,vect(0,-5,0),vect(0,0,0),vect(0.2,0.2,0.2),camera);
Node_SetMaterialFlag(Node_weapon2,EMF_LIGHTING,false);

WEp_joint:=Bone_GetJointNode(Node_weapon1,'rp_sight');
Node_AddChilld(WEp_joint,sp);

WEp_joint:=Bone_GetJointNode(Node_weapon2,'rp_sight');
Node_AddChilld(WEp_joint,sp2);

state(800-10,'AllOK');
Node_SetVisible(Node_weapon1,true);
Node_SetVisible(Node_weapon2,false);
end;



begin

Save8087CW := Get8087CW;
Set8087CW($133F);

Device_Init(EDT_opengl,800,600,32,false,false,false);
Render_SetResizeAble(true);
Device_SetWindowCaption('IRRLICHT 4 Delphi');
Render_SetDebug(true,true);
Device_SetCursorVisible(false);


font:=Font_Load('media/fonthaettenschweiler.bmp');






lasttick:=timegettime;
shottime:=timegettime;


while (Device_Run) and (not finished) do
begin
Device_GetEvents(EEvents);


Render_BeginScene(true,true,0,0,45);


case gameState of
Sload:
begin
Pload;
gameState:=sloop;
end;
SLoop:
begin
ploop;
end;
end;








Render_EndScene;


if EEvents.loopKeyInput.Key=27 then finished:=true;
end;

Device_Stop;
Set8087CW(Save8087CW);

end.

Never underestimate the power of Delphi....Ignorance is bliss, but knowledge is power...
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Wow that's pretty cool, great job!
TheQuestion = 2B || !2B
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Not bad for a first project, keep it up!
Image Image Image
Post Reply