Hi Jarrod im testing your framework i think is ok but the name of the apis its very big and not very comfortable ops:
"Pyro_RandomNum_RangeInt"
why pyro ? Jarrod make the api more simple is juts my opinion
if i have more time i will make more samples
Jarrod i have a hold 2d game engine in opengl and i make
all sprites with horto camera this way scrolling is very simple think about the idea
best regards :Luis Santos AKA Djoker
[pascal]
program particles;
{APPTYPE CONSOLE}
uses
SysUtils,math,classes, dialogs, mmsystem,
Windows,
PyroGine3;
var
VirtualTimerSpeed:single = 1.0;
LastVirtualTime :integer= 0;
StartRealTime :integer= 0;
function getTime:integer;
begin
result:= LastVirtualTime + round((timegettime - StartRealTime) * VirtualTimerSpeed);
end;
Type
TParticle=class
x,y:integer;
acx,acy,dx,dy:integer;
startTime,endTime:integer;
end;
TEmiter=object
private
vMinParticlesPerSecond, vMaxParticlesPerSecond:integer;
vMinLifeTime,vMaxLifeTime:integer;
LastEmitTime,Time, Emitted:integer;
particles:tlist;
procedure emitt( now, timeSinceLastCall:integer);
public
procedure init(minParticlesPerSecond,maxParticlesPerSecond,l ifeTimeMin,lifeTimeMax:integer);
procedure update;
procedure render;
end;
procedure TEmiter.init(minParticlesPerSecond,maxParticlesPer Second,lifeTimeMin,lifeTimeMax:integer);
begin
vMinParticlesPerSecond:=MinParticlesPerSecond;
vmaxParticlesPerSecond:=maxParticlesPerSecond;
vMinLifeTime:=lifeTimeMin;
vMaxLifeTime:=lifeTimeMax;
time:=0;
emitted:=0;
particles:=tlist.Create;
LastEmitTime :=getTime;
end;
procedure TEmiter.emitt( now, timeSinceLastCall:integer);
var
pps:integer;
perSecond,everyWhatMillisecond:single;
particle:TParticle;
begin
Time :=time+ timeSinceLastCall;
pps := (vMaxParticlesPerSecond - vMinParticlesPerSecond);
if pps<0> everyWhatMillisecond) then
begin
Time := 0;
particle:=TParticle.Create;
Particle.startTime := now;
Particle.x:=400;
Particle.y:=500;
Particle.acx:=0;
Particle.acy:=1;
Particle.dx:=Pyro_RandomNum_RangeInt(-2,2);
Particle.dy:=Pyro_RandomNum_RangeInt(-20,-2;
if (vMaxLifeTime - vMinLifeTime =0) then
Particle.endTime := now + vMinLifeTime
else
Particle.endTime := now + Pyro_RandomNum_RangeInt(vMinLifeTime,vMaxLifeTime) ;
particles.Add(Particle);
end;
end;
procedure TEmiter.update;
var
now,timediff:integer;
particle:TParticle;
max,i:integer;
begin
now :=getTime;
timediff := getTime - LastEmitTime;
LastEmitTime := getTime;
emitt(now, timediff);
if Particles.Count>0 then
begin
i:=0;
max:=Particles.Count;
repeat
particle:=TParticle(Particles.Items[i]);
if (now > Particle.endTime) then
begin
Particles.Items[i]:=nil;
Particles.Delete(i);
dec(Max);
end else inc(i);
until i>=max;
end;
end;
procedure TEmiter.render;
var
particle:TParticle;
i:integer;
begin
for i:=0 to Particles.Count-1 do
begin
particle:=TParticle(Particles.Items[i]);
particle.dx:=particle.dx+particle.acx;
particle.dy:=particle.dy+particle.acy;
particle.x:=particle.x+particle.dx;
particle.y:=particle.y+particle.dy;
Pyro_RenderDevice_DrawCircle(particle.x,particle.y ,10,Pyro_White,rsImage,true)
end;
end;
var
particle:TEmiter;
procedure Frame;
var
i:integer;
begin
particle.update;
particle.render;
end;
var
s: string;
begin
Pyro_DisplayDevice_Open('Particles By Luis Santos AKA Djoker', dm800x600, True, True);
Pyro_RenderDevice_SetMode(seDiscard);
Pyro_Input_Open;
StartRealTime:=timegettime;
particle.init(50,90,700,1200);
repeat
Pyro_Input_Update;
Pyro_ProcessMessages;
Pyro_Timer_Update(Pyro_Timer);
Pyro_RenderDevice_ClearFrame(cfDefault, Pyro_Black);
Pyro_RenderDevice_StartFrame ;
Frame;
Pyro_RenderDevice_EndFrame;
Pyro_RenderDevice_ShowFrame;
until Pyro_Object_GetTerminated(Pyro_Self);
Pyro_RenderDevice_RestoreMode;
Pyro_Input_Close;
Pyro_DisplayDevice_Close;
end.
[/pascal]
Bookmarks