View Full Version : any source for starfield in delphiX?
sinister
03-01-2003, 09:39 PM
any1 have any starfield source for delphiX please ? :)
TheLion
03-01-2003, 10:38 PM
Sure :) What sort of starfield are you looking for a so called 2D starfield or a 3D starfield?
I can only provide you with the source of a 2D starfield, but it's really easy (once you know it) ;)
TheLion
03-01-2003, 10:49 PM
Okay I looked on my hdd for the source of the 2D starfield and here are the usefull pieces :)
var StarField : Array[0..STARS] of TStar;
StarGraphics: Array[0..3] Of TDirectDrawSurface;
Procedure TForm1.InitStarField();
var D : Integer;
Begin
Randomize;
For D := 1 To STARS do
Begin
StarField[D].X := Random(VideoModeX);
StarField[D].Y := Random(VideoModeY);
StarField[D].Speed := 1 + Random(9);
StarField[D].Size := Random(3);
End;
StarGraphics[0] := TDirectDrawSurface.Create(DXDraw1.DDraw);
StarGraphics[0].LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Ster1.bmp');
StarGraphics[1] := TDirectDrawSurface.Create(DXDraw1.DDraw);
StarGraphics[1].LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Ster2.bmp');
StarGraphics[2] := TDirectDrawSurface.Create(DXDraw1.DDraw);
StarGraphics[2].LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Ster3.bmp');
End;
Procedure TForm1.DrawStarField();
var D : Integer;
Begin
For D := 1 To STARS do
Begin
DXDraw1.Surface.Draw(StarField[D].X, StarField[D].Y, StarGraphics[StarField[D].Size]);
StarField[D].Y := StarField[D].Y + StarField[D].Speed;
If StarField[D].Y >= VideoModeY Then
Begin
StarField[D].Y := 0;
StarField[D].X := Random(VideoModeX);
DXDraw1.Surface.Draw(StarField[D].X, StarField[D].Y, StarGraphics[StarField[D].Size]);
End;
End;
End;
Oh a usefull remark might be that you can replace the VideoModeX, VideoModeY with Screen.Width, Screen.Height! ;)
call the InitStarField(); before any drawing thing and call DrawStarField(); in your main gameloop! ;)
Hope this helps...
sinister
04-01-2003, 12:25 AM
thanx dude,it worx perfectly :))
patroclus02
27-02-2003, 08:57 PM
this code is suposed to work without any change?
I say this cause I get errors...
patroclus02
27-02-2003, 09:35 PM
Well, of course I made it work, but using bitmaps loaded intro a DXImageList and drawing from there...
I don't really know how tou use TDirectSurfaces (seems unbeliveble , but I always use the other method..). when It tries to load the images there's an error, and also Delphi says that the DXDraw.Draw sentence is incorrect...
:/
TheLion
28-02-2003, 10:43 AM
If you want to load TDirectDrawSurface images, you'll have to initialize the DXDraw component first:
DXDraw1.Initialize; // call this in the Form1.Create !
patroclus02
28-02-2003, 12:01 PM
Yes, now I it works (anyway I don't know what was the problem, cause I did initialize DXDraw).
Anyway the Draw call doesn't work. It needs a TRect instead of a TDirectDrawSurface. I changed the line to this :
DXDraw1.Surface.Draw(StarField[D].X, StarField[D].Y, StarField[D].r, StarGraphics[StarField[D].Size],false);
where r is a TRect.
was this necesary?
TheLion
28-02-2003, 09:58 PM
DelphiX has two draw procedures, one uses rect, the other doesn't. In some Delphi versions the rect-versions overrules the other draw procedure and therefor you need to add the rect-version! :)
patroclus02
01-03-2003, 10:40 AM
Thank you :)
>> var StarField : Array[0..STARS] of TStar;
Tstar is the problem. Where can I found code for Tstar class?
Thanks!!
Alimonster
06-04-2003, 01:19 PM
It could just be a record:
type
TStar = record
X: Integer;
Y: Integer;
Size: Integer;
Speed: Integer;
end;
Or something to that effect. You might want to have a look at Denthor's old tutorials. They're really old now (talking about DOS Mode13h, heh) but there's one on starfields: http://www.hornet.org/cgi-bin/scene-search.cgi?search=Denthor -- find the 13th one and have a look in the file tutpro13.pas -- just ignore any asm that you see, if required.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.