unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, MPlayerCtrl,
BGRABitmap, BGRACanvas2D, BGRABitmapTypes, BGRATextFX,mmsystem;
const
StarCount = 300;
MaxSpeed = 6;
type
TStar = record //
X, Y, Z: Double;
Speed: Double;
end;
{ TForm1 }
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
const dat : Array [0..110] of Int16 = (-400,-60,0,-340,-60,0,-340,0,0,-400,0,0,-400,60,0,
-320,60,0,-292,-60,0,-260,60,0,-240,-60,0,-180,-60,0,-180,0,0,-240,0,0,-240,60,0,-180,60,
0,-160,60,0,-132,-60,0,-100,60,0,-80,-60,0,-80, 60,0,-20,-60,0,-20,60,0,0,-60,0,0,60,0,60,
60,0,60,-60,0,80,-60,0,80,60,0,100,-60,0,100,60,0,140,0,0,180,-60,0,180,60,0,200,-60,0,200,
60,0,220,60,0,252,-60,0,280,60,0);
private
Stars : array of TStar;
ScreenCenter : TPoint;
FocalLength : Double;
FFieldDepth : integer;
procedure CreateColours;
procedure InitializeStarfield;
procedure UpdateStarfield;
public
MyFile: AnsiString;
WavStream : TMemoryStream;
procedure Update_Demo;
procedure Init();
end;
var
Form1: TForm1;
ctx: TBGRACanvas2D;
count : integer;
bmp : TBGRABitmap;
cx : integer = 400;
cy : integer = 256;
cz : integer = 140;
cs : integer = 0;
xr : double = 0;
yr : double = 0;
zr : integer = 0;
StarColours : array[1..maxSpeed] of TBGRAPixel;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
MyFile := Application.Location + 'paranoimia.wav';
WavStream := TMemoryStream.Create;
WavStream.LoadFromFile(MyFile);
PlaySound(WavStream.Memory, 0, SND_NODEFAULT or SND_ASYNC or SND_MEMORY);
Init();
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
WavStream.Free;
end;
procedure TForm1.Init();
begin
Randomize;
ScreenCenter := Point(ClientWidth div 2, ClientHeight div 2);
FocalLength := 100.0;
FFieldDepth := 1000;
CreateColours;
InitializeStarfield;
end;
procedure TForm1.CreateColours;
var
index : integer;
begin
for index := Low(StarColours) to High(StarColours) do
case index of
1: StarColours[index]:= BGRA(50,50,50);
2: StarColours[index]:= BGRA(75,75,75);
3: StarColours[index]:= BGRA(100,100,100);
4: StarColours[index]:= BGRA(125,125,125);
5: StarColours[index]:= BGRA(150,150,150);
6: StarColours[index]:= BGRA(175,175,175);
7: StarColours[index]:= BGRA(200,200,200);
8: StarColours[index]:= BGRA(254,254,254);
end;
end;
procedure TForm1.InitializeStarfield;
var
i: Integer;
begin
SetLength(Stars, StarCount); // Nombre d'étoiles
for i := 0 to High(Stars) do
begin
Stars[i].X := Random(ClientWidth);
Stars[i].Y := Random(ClientHeight);
Stars[i].Z := 0.1+Random(FFieldDepth); // div / 0 !! if not !
Stars[i].Speed := Random * 7 + 1; // Vitesse aléatoire
end;
end;
procedure TForm1.UpdateStarfield;
var
i : integer;
begin
for i := 0 to High(Stars) do
begin
// 3D
Stars[i].Z := Stars[i].Z - Stars[i].Speed ; // Déplacement selon la vitesse
if Stars[i].Z < 0 then // Réinitialiser la position si l'étoile sort de l'écran
begin
Stars[i].X := Random(ClientWidth);
Stars[i].Y := Random(ClientHeight);
Stars[i].Z := 0.1+Random(FFieldDepth);
Stars[i].Speed := Random * 7 + 1;
end;
end;
end;
procedure TForm1.Update_Demo();
var
i, j : integer ;
x, y, z, xa, ya : double;
xc, xs, yc, ys, zc, zs : double ;
px,py : array [0..110] of integer;
couleur: TBGRAPixel;
// st
st : integer;
sttype : integer = 7;
col: TBGRAPixel;
StarPosition: TPoint;
begin
bmp := TBGRABitmap.Create(ClientWidth, ClientHeight, clBtnFace);
ctx := bmp.Canvas2D;
i:=0;
j:=0;
x:=0;
y:=0;
z:=0;
xc :=0;
xs :=0;
yc :=0;
ys :=0;
zc :=0;
zs :=0;
xc := cos(xr);
xs := sin(xr);
yc := cos(yr);
ys := sin(yr);
zc := cos(zr);
zs := sin(zr);
ctx.fillRect(0,0,ClientWidth, ClientHeight);
ctx.fillStyle (BGRA(0, 0, 220, 255));
ctx.fillRect(0,25,ClientWidth,30);
ctx.fillRect(0,460,ClientWidth,30);
bmp.FontName:='paranoimia';
bmp.TextOut(820-count,466,'PARANOIMIA PRESENTS !!! SHINOBI WHAT A PRIMITIVE PROTECTION !!!!!! NOTE DO NOT CHANGE ANYTHING ON TRACK 0 ',BGRA(255,255,255));
bmp.TextOut(820-count,30, 'PARANOIMIA PRESENTS !!! SHINOBI WHAT A PRIMITIVE PROTECTION !!!!!! NOTE DO NOT CHANGE ANYTHING ON TRACK 0 ',BGRA(255,255,255));
// starfield
for st := 0 to High(Stars) do
begin
StarPosition.X := Round((Stars[st].X - ScreenCenter.X) * (FocalLength / Stars[st].Z) + ScreenCenter.X);
StarPosition.Y := Round((Stars[st].Y - ScreenCenter.Y) * (FocalLength / Stars[st].Z) + ScreenCenter.Y);
sttype := Round(Stars[st].Speed);
col := StarColours[sttype];
ctx.fillStyle (col);
ctx.fillRect(StarPosition.X, StarPosition.Y,2,2);
// end stars !!
end;
for i := 0 to High(dat) do
begin
x := dat[j];
y := dat[j+1];
z := dat[j+2];
j := j +3;
ya := (y * xc) + (z * xs);
z := (z * xc) - (y * xs);
y := ya;
xa := (x * yc) + (z * ys);
z := (z * yc) - (x * ys);
x := xa;
xa := (x * zc) - (y * zs);
y := (y * zc) + (x * zs);
x := xa;
z := 256 / (869 + z);
x := round(x * z) shl(8);
y := round(y * z) shl(8);
z := z + cz;
px[i] := round((x / z) + cx) ;//&0xffff;
py[i] := round((y / z) + cy) ; //&0xffff;
end;
xr := xr - 0.04;
yr := yr + 0.03;
couleur := BGRA(255, 255, 255, 255);
// P logo vertex draw !
bmp.DrawLineAntialias(px[0],py[0],px[1],py[1], couleur,2);
bmp.DrawLineAntialias(px[1],py[1],px[2],py[2], couleur,2);
bmp.DrawLineAntialias(px[2],py[2],px[3],py[3], couleur,2);
bmp.DrawLineAntialias(px[3],py[3],px[4],py[4], couleur,2);
bmp.DrawLineAntialias(px[4],py[4],px[0],py[0], couleur,2);
//A
bmp.DrawLineAntialias(px[5],py[5],px[6],py[6],couleur,2);
bmp.DrawLineAntialias(px[6],py[6],px[7],py[7],couleur,2);
//R
bmp.DrawLineAntialias(px[8],py[8],px[9],py[9],couleur,2);
bmp.DrawLineAntialias(px[9],py[9],px[10],py[10],couleur,2);
bmp.DrawLineAntialias(px[10],py[10],px[11],py[11],couleur,2);
bmp.DrawLineAntialias(px[11],py[11],px[12],py[12],couleur,2);
bmp.DrawLineAntialias(px[12],py[12],px[8],py[8],couleur,2);
bmp.DrawLineAntialias(px[11],py[11],px[13],py[13],couleur,2);
//A
bmp.DrawLineAntialias(px[14],py[14],px[15],py[15],couleur,2);
bmp.DrawLineAntialias(px[15],py[15],px[16],py[16],couleur,2);
//N
bmp.DrawLineAntialias(px[17],py[17],px[18],py[18],couleur,2);
bmp.DrawLineAntialias(px[17],py[17],px[20],py[20],couleur,2);
bmp.DrawLineAntialias(px[19],py[19],px[20],py[20],couleur,2);
//O
bmp.DrawLineAntialias(px[21],py[21],px[22],py[22],couleur,2);
bmp.DrawLineAntialias(px[22],py[22],px[23],py[23],couleur,2);
bmp.DrawLineAntialias(px[23],py[23],px[24],py[24],couleur,2);
bmp.DrawLineAntialias(px[24],py[24],px[21],py[21],couleur,2);
//I
bmp.DrawLineAntialias(px[25],py[25],px[26],py[26],couleur,2);
//M
bmp.DrawLineAntialias(px[28],py[28],px[27],py[27],couleur,2);
bmp.DrawLineAntialias(px[27],py[27],px[29],py[29],couleur,2);
bmp.DrawLineAntialias(px[29],py[29],px[30],py[30],couleur,2);
bmp.DrawLineAntialias(px[30],py[30],px[31],py[31],couleur,2);
//I
bmp.DrawLineAntialias(px[32],py[32],px[33],py[33],couleur,2);
//A
bmp.DrawLineAntialias(px[34],py[34],px[35],py[35],couleur,2);
bmp.DrawLineAntialias(px[35],py[35],px[36],py[36],couleur,2);
//
bmp.Draw(Canvas,0,0);
bmp.Free;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
count := count + 4;
if (count>3000) then count :=0;
Update_Demo;
UpdateStarfield;
end;
end.