http://www.mediafire.com/file/5omz2uzzytz/irm.rar
Code: Select all
program ai1;
{$APPTYPE CONSOLE}
uses
windows,
IRRLICHT,mmsystem, dialogs,
IRRTYPES,IRRModel,IRRClasses,IREntities,
irrmath,
IRRUtils;
type
TBOLT=record
targetLoc,direction,Loc:Ivec3;
end;
var
but0,but:IGUI;
font:IFont;
texture:ITexture;
romm,land,camera:ISceneNode;
marine_mesh,marine_wep:IAnimatedMesh;
buff:IMesh;
selector:ITriangleSelector;
onfloor:boolean;
DemoStart,ElapsedTime,FrameTime,LastTime:single;
model:TIRRWorld ;
WEp_joint,sp,sp2,Node_weapon1:ISceneNode;
Mesh_wepon,mesh:IAnimatedMesh;
sd1,sd2,hits,shot1,shot2,shot3,sexplo:ISound;
mus:imusic;
TGPOS,Intersection,Normal:IVEC3;
RayOut:IRAY;
Triangle:ITriangle;
finished:boolean=false;
EEvents:TEngineEvents;
EntitiesEngine:TIREntitiesEngine;
bolt:TBolt;
Save8087CW: Word;
textures:array[0..9] of itexture;
type
TState=(SIdle,SGetPlayer,SRunToPlayer,SNewPath,SGoToPath,SStayInPath,SShot,SGetPathFarPlayer,SRunFar,poop,SHiting,SBlow,SHitingBlow,sdeth);
TMarine=class(TIREntitie)
private
wepnode:IScenenode;
timeshoot:single;
public
strstate:string;
target:ivec3;
targdist:single;
shotsfire,attackdist, activatedist:integer;
istalk:boolean;
savestate,state:Tstate;
frame:integer;
activetetime,lookangle,dist,timetalk:single;
onground:boolean;
ACC,
Speed : ivec3;
Ran,rotate,angle : Single;
r,
RenderADD,
RenderEnd,
ModelNum,
Health,oldattack2 : integer;
attack, Deaded:boolean;
EMMode : Byte;
procedure talk(text:pwidechar;bad:boolean);
procedure ADVANCE(speed:single);
function observar:boolean;
procedure Update(time:single);override;
procedure Init;override;
end;
TBall=class(TIREntitie)
public
targetLoc,direction:Ivec3;
step:single;
procedure Update(time:single);override;
procedure Init(pos,dir:ivec3);
end;
TBaul=class(TIREntitie)
public
targetLoc,direction:Ivec3;
step:single;
procedure Update(time:single);override;
procedure Init(pos,dir:ivec3);
procedure OnCollision(const Entetie:TIREntitie; const ColX, ColY,ColZ: single); override;
end;
TRock=class(TIREntitie)
public
isexplo:boolean;
scale:single;
vel,targetLoc,direction:Ivec3;
speed,g,step:single;
procedure Update(time:single);override;
procedure Init(pos,dir:ivec3);
procedure OnCollision(const Entetie:TIREntitie; const ColX, ColY,ColZ: single); override;
end;
procedure binit(BFROM,BTO:Ivec3);
begin
bolt.Loc:=BFROM;
BOLT.targetLoc:=BTO;
BOLT.direction:=vec_sub(BOLT.targetLoc , BOLT.Loc);
BOLT.direction:=Vec_Normalize(BOLT.direction);
end;
procedure bmove(TIME:SINGLE);
var
i: integer;
normal,intersect:ivec3;
tri:integer;
tmpNode:IsceneNode;
begin
BOLT.Loc.x:=BOLT.Loc.x+BOLT.direction.x*time;
BOLT.Loc.y:=BOLT.Loc.y+BOLT.direction.y*time;
BOLT.Loc.z:=BOLT.Loc.z+BOLT.direction.z*time;
Render_Draw3DLine(bolt.Loc,bolt.targetLoc,color(255,255,255,0));
Render_DrawSphereEx(nil,1,BOLT.Loc.x,BOLT.Loc.y,BOLT.Loc.z,cwhite);
end;
function GetTargetPos(Heading,Tilt:Single):ivec3;
var
HD,TL :Single;
begin
HD := (Heading-90)*(pi/180);
TL := Tilt*(pi/180);
Result := vector(cos(hd) * cos(tl),
sin(-tl),
sin(hd) * cos(tl));
end;
procedure TRock.OnCollision(const Entetie:TIREntitie; const ColX, ColY,ColZ: single);
var
anim:IAnimator;
begin
if Entetie is TMarine then
begin
step:=21;
//if isexplo then
if
(TMarine(Entetie).state<>sdeth) or
(TMarine(Entetie).state<>poop) or
(TMarine(Entetie).state<>SHiting) or
(TMarine(Entetie).state<>SBlow) or
(TMarine(Entetie).state<>SHitingBlow)
then
TMarine(Entetie).state:=sblow ;
//if isexplo then halt;
//if isexplo then TMarine(Entetie).state:=sblow else
//TMarine(Entetie).state:=poop;
end;
end;
procedure TRock.Update(time:single);
const EXPLOSION_FRAME_TIME=100;
var
normal:ivec3;
anim,explo:IAnimator;
velDotNorm2:single;
w:pchar;
begin
step:=step+0.1*time;
if step>20 then
begin
isexplo:=true;
anim:=Scene_CreateDeleteAnimator(1);
Node_AddAnimator(node,anim);
node:=Scene_AddBillboard(180,180,vposition,color(255,255,255,255));
Node_SetMaterialFlag(node,EMF_LIGHTING,false);
Node_SetMaterialTexture( node,0,'media/explosion/01.jpg');
Node_SetMaterialType(node,EMT_TRANSPARENT_ADD_COLOR);
Sound_Set3DPosition(sexplo,vposition);
Sound_Play(sexplo,false);
explo:=Scene_CreateTextureAnimator(9,@textures,EXPLOSION_FRAME_TIME,false);
anim:=Scene_CreateDeleteAnimator(EXPLOSION_FRAME_TIME*9);
Node_AddAnimator(node,explo);
Node_AddAnimator(node,anim);
//Node_SetDebugDataVisible(node,EDS_BBOX);
kill;
end;
g:=g+0.001*time;
vPosition.x:=vPosition.x+vel.x*speed*time;
vPosition.y:=vPosition.y+vel.y*speed*time;
vPosition.z:=vPosition.z+vel.z*speed*time;
vel.x:=vel.x+direction.x*speed*time;
vel.y:=vel.y+direction.y*speed-g*time;
vel.z:=vel.z+direction.z*speed*time;
if model.CollisionNormal(vPosition,6,normal) then
begin
Sound_Set3DPosition(hits,vposition);
Sound_Play(hits,false);
speed:=speed-0.001*time;
NORMAL:=V_MULT(NORMAL,0.0001);
vel:=Misc_reflectVectorFromSurface(vel,normal);
direction:=Misc_reflectVectorFromSurface(direction,normal);
end;
Node_SetPositionEx(node,vPosition);
end;
procedure TRock.Init(pos,dir:ivec3);
var
anim2:IAnimator;
begin
step:=0;
g:=-0.02;
scale:=0;
isexplo:=false;
speed:=0.2;
vPosition:=pos;
targetLoc:=dir;
direction:=vec_sub(targetLoc , vPosition);
direction:=Vec_Normalize(direction);
DoColide:=true;
node:=Scene_AddBillboard(8,8,vposition,color(255,0,255,255));
Node_SetMaterialFlag(node,EMF_LIGHTING,false);
Node_SetMaterialTexture( node,0,'media/portal7.bmp');
Node_SetMaterialType(node,EMT_TRANSPARENT_ADD_COLOR);
end;
///****************************************************
procedure TBaul.Update(time:single);
var
anim:IAnimator;
begin
step:=step+0.1*time;
if step>50 then
begin
anim:=Scene_CreateDeleteAnimator(1);
Node_AddAnimator(node,anim);
kill;
end;
vPosition.x:=vPosition.x+direction.x*6.0*time;
vPosition.y:=vPosition.y+direction.y*6.0*time;
vPosition.z:=vPosition.z+direction.z*6.0*time;
Node_SetPositionEx(node,vPosition);
end;
procedure TBaul.OnCollision(const Entetie:TIREntitie; const ColX, ColY,ColZ: single);
var
anim:IAnimator;
begin
if Entetie is TMarine then
begin
anim:=Scene_CreateDeleteAnimator(1);
Node_AddAnimator(node,anim);
if
(TMarine(Entetie).state<>sdeth) and
(TMarine(Entetie).state<>poop) and
(TMarine(Entetie).state<>SHiting) and
(TMarine(Entetie).state<>SBlow) and
(TMarine(Entetie).state<>SHitingBlow)
then
//if TMarine(Entetie).state=poop then exit;
TMarine(Entetie).state:=poop;
kill;
end;
end;
procedure TBaul.Init(pos,dir:ivec3);
var
anim2:IAnimator;
begin
step:=0;
vPosition:=pos;
targetLoc:=dir;
direction:=vec_sub(targetLoc , vPosition);
direction:=Vec_Normalize(direction);
DoColide:=true;
node:=Scene_AddBillboard(6,6,vposition,color(255,255,255,255));
Node_SetMaterialFlag(node,EMF_LIGHTING,false);
Node_SetMaterialTexture( node,0,'media/portal2.bmp');
Node_SetMaterialType(node,EMT_TRANSPARENT_ADD_COLOR);
//Node_SetDebugDataVisible(node,EDS_BBOX);
end;
///****************************************************
procedure TBall.Update(time:single);
var
anim:IAnimator;
begin
if uSphereVsSphere(vPosition,tgpos,20,1) then
begin
anim:=Scene_CreateDeleteAnimator(1);
Node_AddAnimator(node,anim);
kill;
end;
step:=step+0.4*time;
if step>50 then
begin
anim:=Scene_CreateDeleteAnimator(1);
Node_AddAnimator(node,anim);
kill;
end;
vPosition.x:=vPosition.x+direction.x*2.0*time;
vPosition.y:=vPosition.y+direction.y*2.0*time;
vPosition.z:=vPosition.z+direction.z*2.0*time;
Node_SetPositionEx(node,vPosition);
end;
procedure TBall.Init(pos,dir:ivec3);
var
anim2:IAnimator;
begin
step:=0;
vPosition:=pos;
targetLoc:=dir;
direction:=vec_sub(targetLoc , vPosition);
direction:=Vec_Normalize(direction);
node:=Scene_AddBillboard(8,8,vposition,color(255,255,0,0));
Node_SetMaterialFlag(node,EMF_LIGHTING,false);
Node_SetMaterialTexture( node,0,'media/light.jpg');
Node_SetMaterialType(node,EMT_TRANSPARENT_ADD_COLOR);
//Node_SetDebugDataVisible(node,EDS_BBOX);
end;
procedure AddMarine(pos:ivec3);
var
node:TMarine;
begin
node:=TMarine.Create;
node.Init;
node.Position:=pos;
EntitiesEngine.AddEntities(node);
end;
procedure MarineShoot(pos,dir:ivec3);
var
node:TBall;
begin
node:=TBall.Create;
node.Init(pos,dir);
Sound_Play(shot3,false);
Sound_Set3DPosition(shot3,pos);
EntitiesEngine.AddEntities(node);
end;
procedure playerShoot(pos,dir:ivec3);
var
node:TBaul;
begin
node:=TBaul.Create;
node.Init(pos,dir);
Sound_Play(shot1,false);
EntitiesEngine.AddEntities(node);
end;
procedure playerShoot2(pos,dir:ivec3);
var
node:TRock;
begin
node:=TRock.Create;
node.Init(pos,dir);
Sound_Play(shot2,false);
EntitiesEngine.AddEntities(node);
end;
function TMarine.observar:boolean;
begin
dist:=v_Dist(vPosition,TGPos);
if AI_NodeInFieldOfVision(node,camera,-90,880,activatedist,false) then
begin
if (dist<attackdist) then
begin
state:=SShot;
Anim_SetMD2AnimationEx(node,'attak');
Anim_SetMD2AnimationEx(wepnode,'attak');
result:=true;
exit;
end;
if (dist<activatedist) then
begin
state:=SGetPlayer;
result:=true;
exit;
end;
end;
result:=false;
end;
procedure TMarine.talk(text:pwidechar;bad:boolean);
begin
end;
procedure TMarine.ADVANCE(speed:single);
begin
vPosition.x:=vPosition.x-sin(angle*deg2rad)*speed;
vPosition.z:=vPosition.z+cos(angle*deg2rad)*speed;
Node_SetRotation(node,0,-angle-90,0);
Node_SetRotation(wepnode,0, -angle-90,0);
end;
procedure TMarine.Update(time:single);
const
quots:array[0..5] of pwidechar=
(
'its a bad day',
'i want 2 go home!',
'now one 2 kill',
'i am bored',
'my soccer club win',
'i want same sex ');
var
rayb,raye : ivec3;
ray:IRay;
seeplayer:boolean;
rannear:single;
newdest,x_dest,z_dest:single;
anim:IAnimator;
begin
activatedist:=1200;
attackdist:=480;
seeplayer:=AI_NodeInFieldOfVision(node,camera,-90,800,activatedist,false);
frame:=Anim_GetFrameNr(node);
rayb:= Mesh_GetVertex(wepnode,0,100,0);
ray:=Node_GetRay2(wepnode,0,90,1.1,1000);
case state of
SIdle://**********************************
begin
strstate:='idle';
if (observar()) then
begin
end;
if randomi(0,200)=0 then
begin
talk(quots[randomi(0,5)],false);
end;
if (timegettime - activetetime)>5000 then
begin
activetetime:=timegettime;
state:=SNewPath;
end;
end;
SGetPlayer://********************************
begin
strstate:='get player';
ran:=GetAngle(vPosition,TGPos)-90;
angle:=Math_curveangle(ran,angle,100);
advance(0.2);
Anim_SetMD2AnimationEx(node,'run');
Anim_SetMD2AnimationEx(wepnode,'run');
state:=SRunToPlayer;
end;
SRunToPlayer: //*******************************
begin
strstate:='run to player';
dist:=v_Dist(vPosition,TGPos);
if (dist<activatedist) and (dist>attackdist) then
begin
ran:=GetAngle(vPosition,TGPos)-90;
angle:=Math_curveangle(ran,angle,100);
end else
if (dist<attackdist) then
begin
state:=SShot;
Anim_SetMD2AnimationEx(node,'attak');
Anim_SetMD2AnimationEx(wepnode,'attak');
end else
begin
Anim_SetMD2Animation(node,EMAT_STAND);
Anim_SetMD2Animation(wepnode,EMAT_STAND);
state:=sidle;
end;
advance(0.8);
end;
SNewPath:
begin
strstate:='get new path 2 walk trow';
repeat
target:=vect(RandomS(-500,500),vPosition.y,randoms(-500,500));
until model.Collision(target,30)=false;
ran:=GetAngle(vPosition,target)-90;
angle:=Math_curveangle(ran,angle,100);
advance(0.2);
Anim_SetMD2AnimationEx(node,'run');
Anim_SetMD2AnimationEx(wepnode,'run');
state:=SGoToPath;
end;
SGoToPath:
begin
strstate:='go 2 new path';
if (observar()) then
begin
end;
if (dist<attackdist) then
begin
state:=SShot;
Anim_SetMD2AnimationEx(node,'attak');
Anim_SetMD2AnimationEx(wepnode,'attak');
end;
ran:=GetAngle(vPosition,target)-90;
angle:=Math_curveangle(ran,angle,100);
advance(0.6);
targdist:=v_Dist(target,vPosition);
if targdist<=20 then
begin
Anim_SetMD2Animation(node,EMAT_STAND);
Anim_SetMD2Animation(wepnode,EMAT_STAND);
state:=SStayInPath;
end;
end;
SStayInPath:
begin
strstate:='pause in path';
if (observar()) then
begin
end;
if randomi(0,200)=0 then
begin
talk(quots[randomi(0,5)],false);
end;
if (timegettime - activetetime)>5000 then
begin
activetetime:=timegettime;
state:=SNewPath;
end;
end;
SShot: ///************************************
begin
strstate:='shoting';
if shotsfire>5 then
begin
shotsfire:=0;
state:=SGetPathFarPlayer;
end;
dist:=v_Dist(vPosition,TGPos);
if (dist>attackdist) and (dist<activatedist) and (seeplayer) then
begin
Anim_SetMD2Animation(node,EMAT_STAND);
Anim_SetMD2Animation(wepnode,EMAT_STAND);
state:=SGetPlayer;
end;
if (dist>activatedist) or (not seeplayer) then
begin
Anim_SetMD2Animation(node,EMAT_STAND);
Anim_SetMD2Animation(wepnode,EMAT_STAND);
state:=sidle;
end;
ran:=GetAngle(vPosition,TGPos)-90;
angle:=Math_curveangle(ran,angle,100);
lookangle:=arctan(ran-angle);
Node_SetRotation(node,0,-angle-91,0);
Node_SetRotation(wepnode,0, -angle-91,0);
if (timegettime - timeshoot)>500 then
begin
timeshoot:=timegettime;
MarineShoot(rayb,ray.REnd);
inc(shotsfire);
end;
end;
SGetPathFarPlayer:
begin
repeat
x_dest:=randoms(-500,500);
z_dest:=randoms(-500,560);
newdest := sqrt(sqr(x_dest - TGPos.X) + sqr(z_dest - TGPos.z) );
until (newdest>activatedist/2) and model.Collision(target,30)=false;
target:=vect(x_dest,vPosition.y,z_dest);
ran:=GetAngle(vPosition,target)-90;
angle:=Math_curveangle(ran,angle,100);
advance(0.2);
Anim_SetMD2AnimationEx(node,'run');
Anim_SetMD2AnimationEx(wepnode,'run');
state:=SRunFar;
end;
SRunFar:
begin
ran:=GetAngle(vPosition,target)-90;
angle:=Math_curveangle(ran,angle,100);
advance(0.6);
targdist:=v_Dist(target,vPosition);
if targdist<=80 then
begin
Anim_SetMD2Animation(node,EMAT_STAND);
Anim_SetMD2Animation(wepnode,EMAT_STAND);
state:=SStayInPath;
end;
end;
poop:
begin
Anim_SetMD2Animation(node,EMAT_DEATH_FALLBACK);
Node_SetVisible(wepnode,false);
// Anim_SetAnimationSpeed(node,1.0);
Sound_Set3DPosition(sd2,vposition);
Sound_Play(sd2,false);
//756
//733
state:=SHiting;
end;
SHiting:
begin
if Anim_GetFrameNr(node)>=733 then
begin
Anim_SetMD2Animation(node,EMAT_BOOM);
state:=sdeth;
end;
end;
SBlow:
begin
Anim_SetMD2Animation(node,EMAT_DEATH_FALLFORWARD);
Node_SetVisible(wepnode,false);
speed.y:=speed.y+20;
vPosition.y:=vPosition.y+speed.y*2;
Sound_Set3DPosition(sd1,vposition);
Sound_Play(sd1,false);
state:=SHitingBlow;
end;
SHitingBlow:
begin
if Anim_GetFrameNr(node)>=756 then
begin
Anim_SetMD2Animation(node,EMAT_BOOM);
Anim_SetCurrentFrame(node,756);
state:=sdeth;
end;
end;
sdeth:
begin
case randomi(0,5) of
0:AddMarine(vect(129,120,-1155));
1:AddMarine(vect(129,120,-920));
2:AddMarine(vect(185,120,-1936));
3:AddMarine(vect(-978,120,-1936));
4:AddMarine(vect(-2252,120,-740));
5:AddMarine(vect(-1533,120,-570));
end;
anim:=Scene_CreateDeleteAnimator(5000);
Node_AddAnimator(node,anim);
kill;
end;
end;
if not onground then acc.y := acc.Y - 0.08;//*TimeElapsed;
Speed := V_Mult (Acc,0.8);//FrameTime/100);
vPosition := V_add (vPosition,speed);
onground := model.OnGroundCollision(vPosition,40);
model.Collision(vPosition,30);
// angle:=GetAngle(vPosition,TGPos)-90;
//Render_DrawSphereEx(nil,5,target.x,target.y,target.z,cwhite);
Node_SetPositionEx(node,vPosition);
Node_SetPositionEx(wepnode,vPosition);
end;
procedure MarineAnimationEnd(ID,EndFrame:integer);stdcall;
begin
end;
procedure TMarine.Init;
begin
randomize;
Deaded:=false;
attack:=false;
onground:=true;
istalk:=false;
health:=100;
angle:=90;
DoColide:=true;
position:=vect(-10,25,-600);
timetalk:=timegettime;
activetetime:=timegettime;
state:=sidle;
node:=Scene_AddNodFromMesh(marine_mesh,Position,zerovect,addvect,id);
Node_SetMaterialTexture(node,0,'media\marine\marine_reese.jpg');
Node_SetMaterialFlag(node,EMF_LIGHTING,false);
wepnode:=Scene_AddNodFromMesh(marine_wep,Position,zerovect,addvect,id);
Node_SetMaterialTexture(wepnode,0,'media\marine\marine_weapon.jpg');
Node_SetMaterialFlag(wepnode,EMF_LIGHTING,false);
Anim_SetMD2Animation(node,EMAT_STAND);
Anim_SetMD2Animation(wepnode,EMAT_STAND);
;
//Node_SetDebugDataVisible(node,EDS_BBOX);
end;
var
marine:TMarine;
rayb,raye : ivec3;
ray:IRay;
begin
Save8087CW := Get8087CW;
Set8087CW($133F);
Device_Init(EDT_DIRECT3D9,800,600,32,false,false,false);
Render_SetResizeAble(true);
Device_SetWindowCaption('IRRLICHT 4 Delphi');
Render_SetDebug(true,true);
Device_SetCursorVisible(false);
Input_Init(false);
font:=Font_Load('media/fonthaettenschweiler.bmp');
camera:=Scene_AddFPSCamera(100,200);
Node_SetPosition(camera,0,50,-50);
Camera_SetTarget(camera,0,0,0);
Camera_SetFarValue(camera,12000.0);
{
mesh:=Scene_AddHillPlaneMesh('media\Grass1.jpg',132,132,15,15,20.5,5,5,1,1);
land:=Scene_AddOctTreeSceneNode(mesh);
Node_SetMaterialTexture(land,0,'media\Grass1.jpg');
Node_SetMaterialFlag(land,EMF_LIGHTING,false);
}
marine_mesh:=Scene_AddMesh('media\marine\marine_warrior.md2');
marine_wep:=Scene_AddMesh('media\marine\marine_weapon.md2');
model:=TIRRWorld.Create;
model.TextureDir:='media\level\textures\';
//model.LoadFromFile('media\level\desert.mdl');
model.LoadFromFile('media\level\desert.irm');
//model.SaveToFile('media\level\desert.irm');
//model.SaveToFile('media\level\tw.irm');
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),-1,camera);
Node_SetMaterialFlag(Node_weapon1,EMF_LIGHTING,false);
{
Scene_AddSkyBox(
'media/irrlicht2_up.jpg',
'media/irrlicht2_dn.jpg',
'media/irrlicht2_lf.jpg',
'media/irrlicht2_rt.jpg',
'media/irrlicht2_ft.jpg',
'media/irrlicht2_bk.jpg');
}
textures[0]:=Texture_Load('media/explosion/01.jpg');
textures[1]:=Texture_Load('media/explosion/02.jpg');
textures[2]:=Texture_Load('media/explosion/03.jpg');
textures[3]:=Texture_Load('media/explosion/04.jpg');
textures[4]:=Texture_Load('media/explosion/05.jpg');
textures[5]:=Texture_Load('media/explosion/06.jpg');
textures[6]:=Texture_Load('media/explosion/07.jpg');
textures[7]:=Texture_Load('media/explosion/08.jpg');
textures[8]:=Texture_Load('media/explosion/09.jpg');
textures[9]:=Texture_Load('media/explosion/10.jpg');
EntitiesEngine:=TIREntitiesEngine.Create;
marine:=TMarine.Create;
marine.Init;
EntitiesEngine.AddEntities(marine);
AddMarine(vect(129,120,-1155));
AddMarine(vect(129,120,-920));
AddMarine(vect(185,120,-1936));
AddMarine(vect(-978,120,-1936));
AddMarine(vect(-2252,120,-740));
AddMarine(vect(-1533,120,-570));
Sound_Init(0.001);
shot1:=Sound_Load('media\sound\mp5-1.wav',false);
shot2:=Sound_Load('media\sound\g36.wav',false);
shot3:=Sound_Load('media\sound\light_shot.wav',true);
sexplo:=Sound_Load('media\sound\explode.wav',true);
hits:=Sound_Load('media\sound\0groundI.wav',true);
sd1:=Sound_Load('media\sound\death1.wav',true);
sd2:=Sound_Load('media\sound\death2.wav',true);
mus:=Music_Load('media\sound\music_loop.wav');
Music_Play(mus);
DemoStart := GetTickCount;
while (Device_Run) and (not finished) do
begin
Sound_UpdateListener(Camera_GetRotation(camera),Camera_GetPosition(camera),vect(1,1,1),Camera_GetUp(camera));
Input_Update;
UpdateFPS;
LastTime := GetTickCount;
FrameTime := GetTickCount - LastTime;
if Input_KeyReleased(key_f12) then
Render_TakeScreenShot('shots\');
TGPOS := Camera_GetPosition(camera);
TGPOS.Y := TGPOS.Y -0.2;
onfloor:=model.OnGroundCollision(tgpos,50-1.6);
model.Collision(tgpos,50);
Node_setpositionex(camera,TGPOS);
Device_GetEvents(EEvents);
Render_BeginScene(true,true,0,0,45);
model.Render;
Scene_DrawAll;
EntitiesEngine.Update(TimeElapsed/10);
EntitiesEngine.UpdateCollision;
rayb:= Mesh_GetVertex(Node_weapon1,0,1,0);
ray:=Node_GetRay2(camera,0,0,1.1,1000);
// if (EEvents.loopMouseInput.Event=EMIE_LMOUSE_PRESSED_DOWN) then
if Input_MouseReleased(0) then
begin
Node_SetRotation(Node_weapon1,sin(timegettime/40)*0.8,0,0);//shoot machine gun
playerShoot(rayb,ray.REnd);
// binit(rayb,ray.REnd);
end;
if Input_MouseReleased(1) then
begin
Node_SetRotation(Node_weapon1,sin(timegettime/20)*2.8,0,0);//shoot machine gun
playerShoot2(rayb,ray.REnd);
// binit(rayb,ray.REnd);
end;
bmove(4.2);
//Render_Draw3DLine(rayb,ray.REnd,color(255,0,255,255));
Render_Draw2DLine(800 div 2-10,600 div 2,800 div 2+10,600 div 2,color(255,0,255,0));
Render_Draw2DLine(800 div 2,600 div 2-10,800 div 2,600 div 2+10,color(255,0,255,0));
Font_Write(font,pchar('x:'+ftos(TGPOS.x)),20,100,cwhite);
Font_Write(font,pchar('y:'+ftos(TGPOS.y)),20,120,cwhite);
Font_Write(font,pchar('z:'+ftos(TGPOS.z)),20,140,cwhite);
//Font_Write(font,pchar('state:'+marine.strstate),20,120,cwhite);
Render_EndScene;
if EEvents.loopKeyInput.Key=27 then finished:=true;
end;
EntitiesEngine.Destroy;
Sound_Free(shot1);
Sound_Free(shot3);
Sound_Free(sexplo);
Sound_Free(shot2);
Sound_Close;
Device_Stop;
Set8087CW(Save8087CW);
end.