PDA

View Full Version : simple fontain particles



djoker
15-02-2009, 11:44 AM
Hi Jarrod im testing your framework i think is ok but the name of the apis its very big and not very comfortable :oops:

"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




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,-28);

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.

Pyrogine
15-02-2009, 03:16 PM
djoker

1. The API and the OO framework are designed to be 1:1 so that using either feels the same. In fact the API layer is a flatten version of the OO layer. Granted in the API layer, the names can get a little long. The fact that you can use both layers interchangeably makes having similar names important, imo. For example, you can use the api for all the low-level calls and just use the oop layer for actor, and ai in the same app.

2. Coolness. Thanks for sample. I will add it to the distro if it's ok with you.

3. Pyro_Entity_Render allows you to specify virtual x and y pos. With this a camera system should be able to be implemented easily.

4. Thanks for the feedback. I do take them all into consideration.

chronozphere
15-02-2009, 03:21 PM
You are probably referring to the long routine names, right?

I second that!

Pyro_RandomNum_RangeInt() is way too long. Allthough is very descriptive, it can be replaced by Pyro_Random or Pyro_RandomInt. That would be an improvement. :)

djoker
15-02-2009, 03:31 PM
You are probably referring to the long routine names, right?

I second that!

Pyro_RandomNum_RangeInt() is way too long. Allthough is very descriptive, it can be replaced by Pyro_Random or Pyro_RandomInt. That would be an improvement. :)

RandomInt is more simple

if the engine is pyro the functions don't need the name pyro is juts my idea

djoker
15-02-2009, 03:32 PM
djoker

1. The API and the OO framework are designed to be 1:1 so that using either feels the same. In fact the API layer is a flatten version of the OO layer. Granted in the API layer, the names can get a little long. The fact that you can use both layers interchangeably makes having similar names important, imo. For example, you can use the api for all the low-level calls and just use the oop layer for actor, and ai in the same app.

2. Coolness. Thanks for sample. I will add it to the distro if it's ok with you.

3. Pyro_Entity_Render allows you to specify virtual x and y pos. With this a camera system should be able to be implemented easily.

4. Thanks for the feedback. I do take them all into consideration.

yes Jarrod you can use my code ;)

Pyrogine
15-02-2009, 04:40 PM
chronozphere, djoker
Thanks for the feedback, and thanks to djoker for the sample code.