• Welcome to Dark Bit Factory & Gravity.
 

Another starfield that differs to Clydes!

Started by DrewPee, December 16, 2006

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

DrewPee

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
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

DrewPee

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
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Clyde

Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: