Starfield , GREAT. 
Author Message
 Starfield , GREAT.

Hello!

                Everyone remember my starfield questions from before?
Well thanks to everyone here (esp. Steven Sensarn for his great code) I
actually did it :)... I have also accomplished the ability to change the
speed of the scrolling starfield by pressing the "+", and "-" arrows...
O.k.. But here's the thing (isn't there always? :)). As you can see
(below) I used the variable 's(i)' for parallax scrolling.... So it
generates a random INT form 1-3... which determines the speed of the
stars by pixels (1-3 :))... Now... When it's moving just fine... it's
great.. but if the "-" key is pressed before anyrthing.. the background
stars will just stop, while the rest are moving! If it's pressed again,
the bacground stars go left, while forground goes right :)... It's
nuts!... I know the concept would be to work with s(i), but I am
stuck.... can anyone help here (please)... I will attach the code
below... (don't worry, it's not long)... See for yourself!.. And thank
you for all the help i've been getting recently....


  PROG.BAS
2K Download


Sat, 23 Jan 1999 03:00:00 GMT  
 Starfield , GREAT.

Quote:

> Hello!

>                 Everyone remember my starfield questions from before?
> Well thanks to everyone here (esp. Steven Sensarn for his great code)
> I actually did it :)... I have also accomplished the ability to change
> the speed of the scrolling starfield by pressing the "+", and "-"
> arrows...
> O.k.. But here's the thing (isn't there always? :)). As you can see
> (below) I used the variable 's(i)' for parallax scrolling.... So it
> generates a random INT form 1-3... which determines the speed of the
> stars by pixels (1-3 :))... Now... When it's moving just fine... it's
> great.. but if the "-" key is pressed before anyrthing.. the
> background stars will just stop, while the rest are moving! If it's
> pressed again, the bacground stars go left, while forground goes right
> :)... It's nuts!... I know the concept would be to work with s(i), but
> I am stuck.... can anyone help here (please)... I will attach the code
> below... (don't worry, it's not long)... See for yourself!.. And thank
> you for all the help i've been getting recently....

I couldn't see the code properly, but I think I see what your problem
is.  I'm assuming you have three starfields (I hope you have a color for
each field, too).

When the program starts out, the background is going at speed 1, the
midground at speed 2, and the foreground at speed 3.  When you hit [-],
each of these speeds is decremented.  Thus, the background is going at
speed 0 (stopped), the midground at speed 1, and the foreground at speed
2.  If you hit [-] again, the background is going at speed -1
(backwards), the midground at speed 0 (stopped), and the foreground at
speed 1.  That's just how the code works.

Here are your choices:
A) Start each field at a larger number (say, 3, 5, and 7).
B) Use error-checking to make sure a user can only, say, change the
   background to a speed from 1 to 5 (s/he will have to increment
   initially, the decrement).

Good luck,

Brent P. Newhall
------------------------------------------------------------------
"Our greatest weakness lies in giving up.  The most certain way to
succeed is always to try just one more time." -- Thomas A. Edison



Sun, 24 Jan 1999 03:00:00 GMT  
 Starfield , GREAT.

Quote:

> Hello!

>                 Everyone remember my starfield questions from before?
> Well thanks to everyone here (esp. Steven Sensarn for his great code) I
> actually did it :)... I have also accomplished the ability to change the
> speed of the scrolling starfield by pressing the "+", and "-" arrows...
> O.k.. But here's the thing (isn't there always? :)). As you can see
> (below) I used the variable 's(i)' for parallax scrolling.... So it
> generates a random INT form 1-3... which determines the speed of the
> stars by pixels (1-3 :))... Now... When it's moving just fine... it's
> great.. but if the "-" key is pressed before anyrthing.. the background
> stars will just stop, while the rest are moving! If it's pressed again,
> the bacground stars go left, while forground goes right :)... It's
> nuts!... I know the concept would be to work with s(i), but I am
> stuck.... can anyone help here (please)... I will attach the code
> below... (don't worry, it's not long)... See for yourself!.. And thank
> you for all the help i've been getting recently....


>     ---------------------------------------------------------------

It is often useful to declare arrays with descriptive names.  Look at this program:

'STARS.BAS BY STEVEN SENSARN

CONST NUM.STARS = 50
CONST NUM.PLANES = 3

TYPE TSTAR
    X AS SINGLE
    Y AS SINGLE
    XV AS SINGLE
    YV AS SINGLE
    CLR AS INTEGER
END TYPE

DECLARE SUB INIT.DB ()
DECLARE SUB INIT.PLANE.CLRS ()
DECLARE SUB WAIT.RETRACE ()
DECLARE SUB INIT.PALETTE ()
DECLARE SUB INIT.STARS ()

DIM SHARED STARS(NUM.STARS - 1) AS TSTAR

DIM SHARED DB.SEGMENT AS LONG
DIM SHARED DB.OFFSET AS LONG
DIM SHARED DB.BUFFER(32001) AS INTEGER

DIM SHARED PLANE.CLRS(NUM.PLANES - 1)

DIM INDEX AS INTEGER
DIM OFFSET AS LONG

DIM SHARED PLANE AS INTEGER

RANDOMIZE TIMER

SCREEN 13

INIT.PLANE.CLRS
INIT.DB
INIT.PALETTE
INIT.STARS

DEF SEG = DB.SEGMENT

DO
    FOR INDEX = 0 TO NUM.STARS - 1
        OFFSET = INT(CLNG(STARS(INDEX).Y)) * 320 + INT(STARS(INDEX).X)
        OFFSET = OFFSET + DB.OFFSET
        POKE OFFSET, 0

        STARS(INDEX).X = STARS(INDEX).X + STARS(INDEX).XV
        STARS(INDEX).Y = STARS(INDEX).Y + STARS(INDEX).YV
        IF STARS(INDEX).X > 319 THEN STARS(INDEX).X = 0
        IF STARS(INDEX).X < 0 THEN STARS(INDEX).X = 319
        IF STARS(INDEX).Y > 199 THEN STARS(INDEX).Y = 0
        IF STARS(INDEX).Y < 0 THEN STARS(INDEX).Y = 199

        OFFSET = INT(CLNG(STARS(INDEX).Y)) * 320 + INT(STARS(INDEX).X)
        OFFSET = OFFSET + DB.OFFSET
        POKE OFFSET, STARS(INDEX).CLR
    NEXT INDEX
    WAIT.RETRACE
    PUT (0, 0), DB.BUFFER, PSET
LOOP UNTIL INKEY$ = CHR$(27)

SUB INIT.DB
    DB.SEGMENT = VARSEG(DB.BUFFER(0))
    DB.OFFSET = VARPTR(DB.BUFFER(0)) + 4
    DB.BUFFER(0) = 320 * 8
    DB.BUFFER(1) = 200
END SUB

SUB INIT.PALETTE
    DIM INDEX AS INTEGER
    DIM GREY.SHADE AS INTEGER

    FOR INDEX = 1 TO 255
        GREY.SHADE = INT(RND * 64)
        OUT &H3C6, &HFF
        OUT &H3C8, INDEX
        OUT &H3C9, GREY.SHADE
        OUT &H3C9, GREY.SHADE
        OUT &H3C9, GREY.SHADE
    NEXT INDEX
END SUB

SUB INIT.PLANE.CLRS
    DIM INDEX AS INTEGER

    FOR INDEX = 0 TO NUM.PLANES - 1
        PLANE.CLRS(INDEX) = INT(RND * 255 + 1)
    NEXT INDEX
END SUB

SUB INIT.STARS
    DIM INDEX AS INTEGER

    FOR INDEX = 0 TO NUM.STARS - 1
        PLANE = INT(RND * NUM.PLANES)
        STARS(INDEX).X = INT(RND * 320)
        STARS(INDEX).Y = INT(RND * 200)
        STARS(INDEX).XV = (PLANE + 1) * 2
        STARS(INDEX).YV = 0
        STARS(INDEX).CLR = PLANE.CLRS(PLANE)
    NEXT INDEX
END SUB

SUB WAIT.RETRACE
    WAIT &H3DA, 8
    WAIT &H3DA, 8, 8
END SUB

I wrote that just for you (in the past 20 minutes).  Notice the variable and function
names--they are discriptive.  Your S(I) is just like my STARS(INDEX).XV (not too
discriptive; it stands for X AXIS VELOCITY).

As you know, an x axis velocity (I'm gonna call it the abscissa velocity from here on)
is merely a number telling each star how far to move to the right/left.  The position is
calculated like this:

THIS.STARS.POSITION = THIS.STARS.POSITION + THIS.STARS.ABSCISSA.VELOCITY

As you can see, the abscissa position will move to the right as long as the abscissa
velocity is positive.  Should it be zero, the stars will not move at all (a + 0 = a).  
When the velocity is negative, the stars will move to the left (a + -b = a - b).  By
pressing the minus '-' key, I assume your program does this:

S(I)=S(I)-1

If S(I) is larger than one, the outcome will still be a positive velocity, therefore
continually moving the star to the right.  If S(I) is one, the outcome will be zero,
causing the star to stop.  When S(I) is zero, the outcome will become negative and the
star will move in the opposite direction.  Should you further press minus '-', the star
would move faster and faster in the opposite direction.  Change your statement to this:

IF S(I) > 1 THEN S(I) = S(I) - 1

Now S(I) will only be decreased if the outcome of the computation yields a positive
velocity.

--
______________________________

Steven Sensarn

______________________________



Sun, 24 Jan 1999 03:00:00 GMT  
 Starfield , GREAT.

Quote:

> I wrote that just for you (in the past 20 minutes).  Notice the variable and function
> names--they are discriptive.  Your S(I) is just like my STARS(INDEX).XV (not too
> discriptive; it stands for X AXIS VELOCITY).

> As you know, an x axis velocity (I'm gonna call it the abscissa velocity from here on)
> is merely a number telling each star how far to move to the right/left.  The position is
> calculated like this:

> THIS.STARS.POSITION = THIS.STARS.POSITION + THIS.STARS.ABSCISSA.VELOCITY

> As you can see, the abscissa position will move to the right as long as the abscissa
> velocity is positive.  Should it be zero, the stars will not move at all (a + 0 = a).
> When the velocity is negative, the stars will move to the left (a + -b = a - b).  By
> pressing the minus '-' key, I assume your program does this:

> S(I)=S(I)-1

> If S(I) is larger than one, the outcome will still be a positive velocity, therefore
> continually moving the star to the right.  If S(I) is one, the outcome will be zero,
> causing the star to stop.  When S(I) is zero, the outcome will become negative and the
> star will move in the opposite direction.  Should you further press minus '-', the star
> would move faster and faster in the opposite direction.  Change your statement to this:

> IF S(I) > 1 THEN S(I) = S(I) - 1

> Now S(I) will only be decreased if the outcome of the computation yields a positive
> velocity.

        Wow ... thanx for the help and support... that was very nice of
you! I'm going to go study the thing right now! ... thanks.




Mon, 25 Jan 1999 03:00:00 GMT  
 Starfield , GREAT.

Quote:

>         Wow ... thanx for the help and support... that was very nice of
> you! I'm going to go study the thing right now! ... thanks.

You're welcome!

Quote:



--
______________________________

Steven Sensarn

______________________________



Tue, 26 Jan 1999 03:00:00 GMT  
 Starfield , GREAT.

Quote:

>Hello!
>            Everyone remember my starfield questions from before?
>Well thanks to everyone here (esp. Steven Sensarn for his great code) I
>actually did it :)... I have also accomplished the ability to change the
>speed of the scrolling starfield by pressing the "+", and "-" arrows...

Hi, I've whipped up another varient of the 'star-field' program.  it
adds in a z-axis variable, and standardizes the x and y movement, so
each star does not need to store it's own movement...   To get around
the layer problem, and speed problem, I've added a 'z-weight'
variable, which 'weights' the movement of each star based on how far
away it is (z-coordinate).  Take a look at it, and do what ever you
want with it, there are additional notes and comments in the source.

                Bryon

'
*************************************************************************
'
' PROJ. NAME : STARS1.BAS
' PROJ. PROG : Bryon Quackenbush
' PROJ. STRT : 08/09/96
' PROJ. VERS : 0.1
' PROJ. DESC : Display a moving star field in screen mode 13, and '
allow
'              the user to control the direction and speed of the
moving
'              stars.
'
*************************************************************************
'

' *** DECLARE STATMENTS ***
DECLARE SUB define.star (star.number)

' *** DEFINE CONSTANTS ***
CONST max.stars = 50                   ' Max # of stars program will
allow.
CONST z.weight = .5                    ' weight z-axis holds on x/y
movement
CONST key.right$ = "6"
CONST key.left$ = "4"
CONST key.up$ = "8"
CONST key.down$ = "2"
CONST key.center$ = "5"

' *** Variable definitions ***
key.escape$ = CHR$(27)                 ' sets constant escape key

' !!! - You can change the max.stars variable to fit your own needs.
'       max.stars is used to DIM the x,y, and z coordinates for each
star.
'       a seperate tracking variable can be used to contain the
current
'       number of actual stars, but I have not implemented it here.

' *** DEFINE VARIABLES ***
DIM SHARED viewer.xmove AS INTEGER
DIM SHARED viewer.ymove AS INTEGER
DIM SHARED viewer.zmove AS INTEGER
DIM SHARED star.xloc(max.stars) AS INTEGER
DIM SHARED star.yloc(max.stars) AS INTEGER
DIM SHARED star.zloc(max.stars) AS INTEGER

' !!! - note that a tracking variable for z-axis movement
(viewer.zmove)
'       is defined, but I do not monipulate this variable at all
during
'       in this example, so it will remain 0 (no movment)

' !!! - the star.zloc() is used both for selecting the grey scale, as
well
'       as the weighted speed of a star.  The further away a star's z
'       coordinate is, the slower it will move, and the darker it will
be.

' *** PRE-RUN WORK ***

' ** Star with some basics
RANDOMIZE TIMER
SCREEN 13

' ** Next, we want to assign random star field locations to each star
FOR current.star = 1 TO max.stars
   define.star (current.star)
   NEXT current.star

' ** Finally, we pre-set the viewer movement variables, and change
'    to the desired screen mode
viewer.xmove = 1
viewer.ymove = 0
viewer.zmove = 0

' *** MAIN PROGRAM LOOP ***
DO
   FOR current.star = 1 TO max.stars

      ' ** clear current star's location
      PSET (star.xloc(current.star), star.yloc(current.star)), 0

      ' ** move star to new location                                
      star.xloc(current.star) = star.xloc(current.star) +
(viewer.xmove * (star.zloc(current.star)) * z.weight)
      IF star.xloc(current.star) > 319 THEN star.xloc(current.star) =
0
      IF star.xloc(current.star) < 0 THEN star.xloc(current.star) =
319

      star.yloc(current.star) = star.yloc(current.star) +
(viewer.ymove * (star.zloc(current.star)) * z.weight)
      IF star.yloc(current.star) > 199 THEN star.yloc(current.star) =
0
      IF star.yloc(current.star) < 0 THEN star.yloc(current.star) =
199

      ' ** set new star location
      PSET (INT(star.xloc(current.star)),
INT(star.yloc(current.star))), 31
      NEXT current.star

      key.input$ = INKEY$
      IF key.input$ = key.left$ THEN viewer.xmove = viewer.xmove + 1
      IF key.input$ = key.right$ THEN viewer.xmove = viewer.xmove - 1
      IF key.input$ = key.up$ THEN viewer.ymove = viewer.ymove + 1
      IF key.input$ = key.down$ THEN viewer.ymove = viewer.ymove - 1
      IF key.input$ = key.center$ THEN
         viewer.xmove = 0
         viewer.ymove = 0
         END IF
   LOOP UNTIL key.input$ = key.escape$

END

'
************************************************************************
'
' ## NOTES ##
'
' This example uses a variable z-coordinate, and a constant z-weight
' variable to determine a particular stars movement in the starfrield
' for both x and y movement.  In order to work correctly, the z-weight
' should be between 0-1 (although other values would work with
varrying
' effects).
'
' The 2, 4, 6, and 8 keys are set up to control X and Y axis
movements,
' and the 5 key will stop all axis movement. I did not add in a way to
' change the Z axis movement, since in this example z really does not
' control z-movment, but more of the speed of the star, which would be
' the same for parrallel star field viewing only.  There are some
other
' calculations to take into accout for an accurate z-axis movment,
which
' given those calculations someone should be able to fit into here
' easier.
'
' Finally, this example uses PSET instead of defining a starfield
graphic
' variable array.  However, switching to the use of a variable array
' should not be that difficult.  It's just a difference of PSET'ing
' directly to the screen, or POOK'ing to the variable array, and then
' PUT'ing to the screen all at the same time.
'
'
'
***********************************************************************
'
' ## ENHANCMENTS ##
'
' There are a number of enhancments that can be added to this using
the
' existing structure, that any who are interested can try to tackle.
If
' anyone is interested, I might add some of these next week, and
re-post
' this, or someone else with a little bit more free time on there
hands
' can.
'
' * Star color based on z-distance : Currently all stars are forced to
'   color 31, which is the bright white on the bright end of the grey
'   scale. colors 16 - 31 on screen mode 13 contains your grey-scale
'   colors, starting from dark (black) to brightest (white).  You
should
'   be able to base this also on the z-axis.
'
' * Add Z-axis movement : This requires a little bit better
understanding
'   of 3-D plotting, as if I remember correctly, there is some type of
'   rule, or formula floating around to account for the z-axis
movment.
'

SUB define.star (star.number)
' !!! - This sub will assign a given star it's initial x, y, and z
'       coordinates
star.xloc(star.number) = INT(RND * 319) + 1
star.yloc(star.number) = INT(RND * 199) + 1
star.zloc(star.number) = INT(RND * 6) + 1

END SUB



Wed, 27 Jan 1999 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Delphi = GREAT And VB5 = Not so great

2. GREAT QUESTION NEED GREAT HELP

3. Starfield Code?

4. starfield moving, XOR.

5. Starfield Moving, xor.

6. Starfield...

7. Starfield?

8. Making a Starfield

9. Starfield simulation with VB

10. How to write Starfield Simulation? (fast animation)

11. Looking for VB Starfield example

12. Find record with "greatest" date

 

 
Powered by phpBB® Forum Software