RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
 
Post new topic Reply to topic  
View previous topic - View next topic  
Author Message
DeveloperX
202192397


Joined: 04 May 2003
Posts: 1626
Location: Decatur, IL, USA

PostPosted: Thu Oct 30, 2003 5:59 am    Post subject: Easy Starfields [quote]

I've discovered what I find to be an easy way to create starfield simulations.

heres the code:
Code:

DEFINT A-Z

CONST QUITSTATE = 255
CONST RUNSTATE = 1

TYPE StarTyp
 x AS INTEGER
 y AS INTEGER
 xv AS INTEGER
 clr AS INTEGER
END TYPE

CONST MAXSTARS = 650

DIM SHARED Stars(MAXSTARS) AS StarTyp
DIM SHARED State

CLS
SCREEN 7, 0, 1, 0

FOR index = 0 To 255
 OUT &H3c8, index
 OUT &H3c9, i + 64
 OUT &H3c9, i + 64
 OUT &H3c9, i + 64
NEXT

 FOR index = 0 To MAXSTARS-1
  Stars(index).x = INT(RND*319)
  Stars(index).y = INT(RND*199)
  Stars(index).xv = -2 * INT(RND * 3) + -1
  Stars(index).clr = INT(RND * 15) + 1
 NEXT
DO
 CLS
 K$ = INKEY$
 IF K$ = CHR$(27) THEN State = QUITSTATE

  FOR index = 0 To MAXSTARS-1
   ' move stars
   Stars(index).x = Stars(index).x + Stars(index).xv
   IF Stars(index).x < 0 THEN Stars(index).x = 319
   ' draw stars
   PSET(Stars(index).x,Stars(index).y), Stars(index).clr
  NEXT

 PCOPY 1,0
LOOP UNTIL State = QUITSTATE
SCREEN 0
WIDTH 80
SYSTEM


enjoy.
questions, comments welcome.
_________________
Principal Software Architect
Rambling Indie Games, LLC

See my professional portfolio


Last edited by DeveloperX on Thu Nov 18, 2004 11:27 pm; edited 1 time in total
Back to top  
Hajo
Demon Hunter


Joined: 30 Sep 2003
Posts: 779
Location: Between chair and keyboard.

PostPosted: Fri Nov 12, 2004 9:47 am    Post subject: [quote]

Hi,

after your announcement to write a book and your hint that you already wrote some articles, I started to look at your articles.

I've got a few comments to this proposed starfield algorithm.

1) Stars only move in X-direction but not in Y-direcion. I think you forgot the Y component of the movement vector

2) Even if the Y move problem is fixed, it doesn't generate a good impression of depth. "Stars" closer to the screen borders ought to move faster than those close to the center of the screen. Your demo is missing this effect.
Back to top  
DeveloperX
202192397


Joined: 04 May 2003
Posts: 1626
Location: Decatur, IL, USA

PostPosted: Mon Nov 15, 2004 7:10 pm    Post subject: [quote]

Hajo wrote:
Hi,

after your announcement to write a book and your hint that you already wrote some articles, I started to look at your articles.

I've got a few comments to this proposed starfield algorithm.

1) Stars only move in X-direction but not in Y-direcion. I think you forgot the Y component of the movement vector

2) Even if the Y move problem is fixed, it doesn't generate a good impression of depth. "Stars" closer to the screen borders ought to move faster than those close to the center of the screen. Your demo is missing this effect.


I didn't miss anything in my demo.
You missed the point of it. :)
I created a starfield that moves to the left. It isn't meant to move along the Y axis, nor is it supposed to have any 'depth'
for it. It is a _simple_ 2D starfield for you to learn the technique .
Anyway, what you described would be a simulated 3d starfield demo, where you're 'flying' through it, like, say the windows screensaver. I never intended my demo to be like that, and I've recieved emails regarding this very post, thanking me for writing it, cause it cleared up the technique, and made it easy to understand.
_________________
Principal Software Architect
Rambling Indie Games, LLC

See my professional portfolio
Back to top  
Hajo
Demon Hunter


Joined: 30 Sep 2003
Posts: 779
Location: Between chair and keyboard.

PostPosted: Tue Nov 16, 2004 8:21 am    Post subject: [quote]

I'm sorry for misreading the code.

A few comments might be helpful to get the reader on the right track ;)

Maybe we can use the misunderstanding to do something good: In your new book, be careful that all examples are easy understandable and well commented.
Back to top  
Happy
JonA's American snack pack


Joined: 03 Aug 2002
Posts: 200

PostPosted: Tue Nov 16, 2004 1:32 pm    Post subject: Re: Easy Starfields [quote]

DeveloperX wrote:
I've discovered what I find to be an easy way to create starfield simulations.


I don't think that simulates starfields! Stars move slower the further they are from the viewer! Also, comments in the code would be more than welcome! Thanks for sharing your wonderful (but useless) discovery!
Back to top  
Bjorn
Demon Hunter


Joined: 29 May 2002
Posts: 1425
Location: Germany

PostPosted: Tue Nov 16, 2004 5:37 pm    Post subject: [quote]

I think anybody that knows how to add numbers and keep an array (like, knows how to program) automatically is able to simulate a starfield given the ability to paint dots to a screen, with simulated depth even.

As such this whole example came to me as useless the first time it was posted, unless it was meant as a creative example for people trying to get to grips with for loops, arrays and pixel drawing.

Of course I'm not talking about doing it in true 3D, which requires some additional mathematical background.
Back to top  
DeveloperX
202192397


Joined: 04 May 2003
Posts: 1626
Location: Decatur, IL, USA

PostPosted: Tue Nov 16, 2004 8:07 pm    Post subject: [quote]

Guys, I wrote this post last year!
Back when I was just learning about velocity and shit.
I only posted it cause I thought it would be helpful for a newbie programmer.

Also, in regards to the comment bout my book:
All examples are, infact overly commented, so that even a complete newbie could grasp the concepts.
There are 2 versions of the code, heavily commented (for newbies), and generally commented (for intermediate programmers).

Anyway, please, enough about how my year old post contains useless information, geez.
_________________
Principal Software Architect
Rambling Indie Games, LLC

See my professional portfolio
Back to top  
Bjorn
Demon Hunter


Joined: 29 May 2002
Posts: 1425
Location: Germany

PostPosted: Tue Nov 16, 2004 9:50 pm    Post subject: [quote]

Really, I agree.
Back to top  
Happy
JonA's American snack pack


Joined: 03 Aug 2002
Posts: 200

PostPosted: Tue Nov 16, 2004 9:53 pm    Post subject: [quote]

It's rather hard to forget about it when you make it sticky.
Back to top  
BadMrBox
Bringer of Apocalypse


Joined: 26 Jun 2002
Posts: 1022
Location: Dark Forest's of Sweden

PostPosted: Thu Dec 09, 2004 3:28 pm    Post subject: [quote]

Well, unstick it.
_________________
Back to top  
Bjorn
Demon Hunter


Joined: 29 May 2002
Posts: 1425
Location: Germany

PostPosted: Thu Dec 09, 2004 6:30 pm    Post subject: [quote]

I'm pretty sure it was unsticked ages ago now. :-)
Back to top  
DeveloperX
202192397


Joined: 04 May 2003
Posts: 1626
Location: Decatur, IL, USA

PostPosted: Fri Dec 10, 2004 9:28 pm    Post subject: [quote]

Bjørn wrote:
I'm pretty sure it was unsticked ages ago now. :-)


heh heh heh.
_________________
Principal Software Architect
Rambling Indie Games, LLC

See my professional portfolio
Back to top  
Post new topic Reply to topic Page 1 of 1 All times are GMT
 



Display posts from previous:   
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum