Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: DrewPee on December 16, 2006
-
Here you go - as already posted within Clydes thread . . . thought I would re-post under my own!!
Feedback welcome!
Drew
option explicit
#include once "tinyptc.bi"
const xres = 1024
const yres = 768
Dim shared as Integer NS
NS=64
Dim shared as Integer x(ns),y(ns)
Dim Shared as Integer x1(ns),y1(ns)
Dim Shared as Integer x2(ns),y2(ns)
Dim Shared as Integer x3(ns),y3(ns)
Dim shared as Integer a
Dim shared as String key
Declare Sub DrawStars1
Declare Sub MoveStars1
for a=0 to ns-1
  x(a)=int(rnd(1)*xres)
  y(a)=int(rnd(1)*yres)
  x1(a)=int(rnd(1)*xres)
  y1(a)=int(rnd(1)*yres)
  x2(a)=int(rnd(1)*xres)
  y2(a)=int(rnd(1)*yres)
  x3(a)=int(rnd(1)*xres)
  y3(a)=int(rnd(1)*yres)
next
If( ptc_open( "Starfield", XRES, YRES ) = 0 ) Then
End -1
End If
Dim Shared sb(xres*yres)
#define PP(x,y,argb) sb(y*XRES+x)=argb
while key<>chr$(27)
  key = inkey$()
  erase sb(0)
  DrawStars1
  MoveStars1
  ptc_update @sb(0)
Wend
Sub DrawStars1
  for a=0 to ns-1
    pp(x(a),y(a),rgb(255,255,255))
    pp(x1(a),y1(a),rgb(192,192,192))
    pp(x2(a),y2(a),rgb(128,128,128))
    pp(x3(a),y3(a),rgb(64,64,64))
  next a
End Sub
Sub MoveStars1
  for a=0 to ns-1
    x(a)=x(a)+8
    x1(a)=x1(a)+4
    x2(a)=x2(a)+2
    x3(a)=x3(a)+1
    if x(a)>=xres then x(a)=0
    if x1(a)>=xres then x1(a)=0
    if x2(a)>=xres then x2(a)=0
    if x3(a)>=xres then x3(a)=0
  next a
End Sub
-
btw - change the NS figure to the number of stars required - go on . . . put a higher figure in there!!! It's still relatively smooth!!!!
and if you want more layers . . . just add x4,y4 etc etc into the code . . . it works, i have had eight parallax layers scrolling!!!
Drew
-
Nice one DrewPee :)