Code:
unit Main;
{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}
interface
uses
Classes, SysUtils,
phxBase,
phxImages,
phxParticles,
phxInput,
phxTimer,
phxMath,
phxClasses,
phxLogger,
phxScreen;
const
Gravity: TVector2f = (x: 0; y: -9.81); // Gravitic Constant of Earth in M/Sec^2 (Velocity)
procedure MainLoop;
implementation
//------------------------------------------------------------------------------
procedure MainLoop;
var Screen: TPHXScreen;
Particles: TPHXParticleManager;
Mouse: TPHXMouse;
Keyboard: TPHXKeyboard;
Timer: TPHXTimer;
i,l: Word;
begin
// Get the window
Screen := TPHXScreen.getInstance;
Particles := TPHXParticleManager.Create;
Mouse := TPHXMouse.Create;
Timer := TPHXTimer.Create;
Keyboard := TPHXKeyboard.Create;
Screen.VSync := True;
Screen.DepthBits := 32;
// Open the window
if not Screen.Open('Gravity Bombs', -1, -1, 800, 600) then begin
TPHXLogger.getInstance.Log(logSevere, 'Main', 'Unable to initialize form.');
Exit;
end;
// with Particles.Effects.Add do begin
// TPHXLogger.getInstance.Log(logInfo, 'Main', 'Loading comet particle...');
// LoadFromFile('comet.phxpar');
// Name := 'Comet';
// GrowthMin := -16;
// GrowthMax := -16;
// Texture := 'particle.png';
// end;
if not Assigned(Particles.Images) then begin
Particles.Images := TPHXImageList.Create;
TPHXLogger.getInstance.Log(logWarning, 'Main', 'Imagelist is nil; initializing.');
end;
Particles.Images.LoadImage('particle.png').UpdatePatterns;
l := 0;
with Particles.Effects.Add do begin
Name := 'Comet';
Quota := 500;
EmissionRate:= 100;
Texture := 'particle.png';
Blending := bmAdd;
DurationMin := 0.50;
DurationMax := 0.75;
Direction := -90;
SpreadMin := 360;
SpreadMax := 360;
VelocityMin := 72;
VelocityMax := 84;
TimeToLiveMin := 0.5;
TimeToLiveMax := 0.5;
SizeMin := 32;
SizeMax := 32;
GrowthMin := -12;
GrowthMax := -16;
NumColors := 3;
Colors[0] := Color4f(0.7,0.8,1.0,0.6);
Colors[1] := Color4f(0.6,0.7,0.9,0.6);
Colors[2] := Color4f(0.1,0.2,0.5,0.6);
end;
Randomize;
repeat
Timer.Update;
Mouse.Update;
Keyboard.Update;
if Random(200) <100> 0 then
for I := 0 to Particles.Count - 1 do
with Particles.Systems[i] do begin
Position := VectorSub(Position,VectorMul(Gravity,Timer.FrameTime));
if Position.Y > 650 then
Particles.RemoveSystem(Particles.Systems[i]);
end;
Particles.Move(Timer.FrameTime);
if l <> Particles.Count then begin
l := particles.Count;
Screen.Title := Format('Gravity Bombs [%d active particle systems]',[l]);
end;
// Clear the window
Screen.Clear;
Particles.Render;
// Flip the buffers
Screen.Flip;
until (Screen.Visible = False);
Particles.Images.Free;
Particles.Free;
Keyboard.Free;
Mouse.Free;
Timer.Free;
Screen.Free;
end;
end.
Bookmarks