TGC Codebase Backup



2D Parallax Stars by Richard Davey

12th Sep 2003 12:58
Summary

I was fed-up seeing so many slow and jittery 2D starfields done in DarkBasic that I did my own. This is a proper parallax, depth shaded starfield and in my tests I was seeing 500



Description

==========================================================
A Screaming Product Of The DARKFORGE (www.darkforge.co.uk)
==========================================================

Title

2D Parallax Starfield

Version

1.0

Date

April 12th 2000

Files

2d_parallax_starfield.dba 921 Bytes
2d_parallax_starfield.gif 2031 Bytes

Programmer

Richard Davey
rich@fatal-design.com

DB Version

DarkBasic v1.04 (Registered)

License

Public Domain

Comments

I was fed-up seeing so many slow and jittery 2D starfields
done in DarkBasic that I did my own. This is a proper
parallax, depth shaded starfield and in my tests I was
seeing 500 stars on-screen at a smooth 75 fps. Over 800
are possible, read the comments in the source for details.

==========================================================
(c) www.darkforge.co.uk 2000
==========================================================



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    ` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
`          2D Parallax Starfield
` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
` By Rich Davey (rich@fatal-design.com)
` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
` Music listened  to while  coding this
` Madonna (Ray of Light)
` -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
` Note:
`
` On my graphics card (GeForce 256 Pro) I can get a consistent 75 fps
` with 500 stars on-screen. You can push this up to around 800 stars
` if you change the x array into 3 seperate arrays, instead of having
` 1 array with 3 elements.

sync rate 0
sync on
hide mouse

n=500
dim x(n,3)

for i=1 to n
	x(i,1)=rnd(639)+1
	x(i,2)=rnd(479)+ 1
	x(i,3)=rnd(9)+1
next i

do
	cls 0

	for i=1 to n

		x(i,1)=x(i,1)-x(i,3)
		
		if x(i,1)<=1
			x(i,1)=640
			x(i,2)=rnd(479)+1
		endif
	
		col=x(i,3)*30
		ink rgb(col,col,col),1

		dot x(i,1),x(i,2)
	
	next i

	sync

loop