Author Topic: 2D Starfield going up?  (Read 3605 times)

0 Members and 1 Guest are viewing this topic.

Gamer2007

  • Guest
2D Starfield going up?
« on: October 14, 2008 »
hello,

I want 2D Starfield going up but I dont know how to do it  ???


Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: 2D Starfield going up?
« Reply #1 on: October 14, 2008 »
just draw dots (point primitive in your graphics framework)

keep an array of your stars. Each star should have the following properties

position x
position y
speed x
speed y
color

at each redraw pass, add speed x and y to the position of the star, the draw it. use the color of the star

now if you keep an array of "star" structures, a simple loop through all the stars to increment the x,y position by the speed x,y will give you a nice starfield.

if you initialize your stars with different speeds and colors (especially if the color is darker when the speed is smaller) then you get a nice 2d starfield. the speed x and y will definie the direction of the motion.

So in your case, the x speed should be zero. y speed can be positive or negative to move your stars up or down
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 2D Starfield going up?
« Reply #2 on: October 14, 2008 »
Hello there Newbie, :hi: aboard.

Good one Stormbringer.

How much coding knowledge do you have Newbie dude? Do you understand what variables are?

Please dont get me wrong, if you know quite a bit allready, just that going by your username, it looks as if you're just starting out. Post back, if you are in any doubts, and some of us here will put you on the right track.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Gamer2007

  • Guest
Re: 2D Starfield going up?
« Reply #3 on: October 14, 2008 »
It wont go up  ???

Code: [Select]
Global num_stars = 200

Graphics 640,480,16,2
SetBuffer BackBuffer()

; Main menu arrays.
Dim y(num_stars,3)

; Generate the stars
For i=1 To num_stars
y(i,1)=Rnd(639)+1
y(i,2)=Rnd(479)+ 1
y(i,3)=Rnd(5)+1
Next


While Not KeyDown(1)

      update_stars()

      Flip:Cls

Wend



Function update_stars()
For i = 1 To num_stars
    y(i,1) = y(i,1) + y(i,3)

    ; if Starfield go pass Y= 0 then
            ; Restart the starfield at the bottom
If y(i,1) =<0
y(i,1) = 480
y(i,2) = Rnd(479) +1
EndIf

col = y(i,3) * 30
Color col,col,col

Rect y(i,1),y(i,2),2,2
Next
End Function

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 2D Starfield going up?
« Reply #4 on: October 14, 2008 »
Just going through the code you posted dude and so far I've gathered that:

y(i,1) is the X Position.
y(i,2) is the Y Position.
y(i,3) is the speed.

And currently it's going left to right; which is the x position; y(i,1) is the X Position and your looking to do stuff to the Y position ;)

I'd highly recommend that you use more suitable names for your variables dude, that way you wont confuse yourself for one thing.
« Last Edit: October 14, 2008 by Clyde »
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Gamer2007

  • Guest
Re: 2D Starfield going up?
« Reply #5 on: October 14, 2008 »
thank you Clyde  ;D

FIXED!  8)

Code: [Select]
Global num_stars = 200

Graphics 640,480,16,2
SetBuffer BackBuffer()

; Main menu arrays.
Dim X(num_stars,2)
Dim y(num_stars,3)

; Generate the stars
For i=1 To num_stars
x(i,1)=Rnd(639)+1  ; X
y(i,2)=Rnd(479)+ 1 ; Y
y(i,3)=Rnd(5)+1    ; Speed
Next


While Not KeyDown(1)

      update_stars()

      Flip:Cls

Wend



Function update_stars()
For i = 1 To num_stars
    y(i,2)= y(i,2)-y(i,3)

    ; if Starfield go pass Y= 0 then
        ; Restart the starfield at the bottom
If y(i,2)=<0
y(i,2) = 480
;(i,2) = Rnd(479) +1
EndIf

col = y(i,3) * 30
Color col,col,col

Rect x(i,1),y(i,2),2,2
Next
End Function