Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Vertical Scrolling Stars

Author
Message
Hells Messenger
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: War Torn Froozen Waste Land
Posted: 2nd Jul 2004 13:17 Edited at: 2nd Jul 2004 13:18
Hey, I've just finished going through the DBP "Tutorial 8 - 2D Star Fields" and the stars move from the right side of the screen to the left, but i was wondering how can i get the stars to move from the top of the screen to the bottom instead of from right to left?

Help please. Chris

Goverment... is just another way to say Better, Than, You!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Jul 2004 21:19
Haven't seen the code, but I guess it's just a matter of changing the x offset to a y offset.

BatVink
http://biglaugh.co.uk/catalog AMD 3000+ Barton, 512Mb Ram, 120 Gig Drive space, GeForce 5200 FX 128 Mb, Asus A7N8X Mobo.
Terms & Conditions apply
Hells Messenger
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: War Torn Froozen Waste Land
Posted: 2nd Jul 2004 21:50
The code is:

Rem Project: QuickStart Tutorial 8 - 2D Starfields
Rem Created: 05/02/2003 23:50:39

Rem ***** Main Source File *****

sync rate 0
sync on
hide mouse

load image "media/logo.png",1,1

starquantity = 400
starlayers = 5
speedfactor# = 0.75

` Here we'll setup our starfield type
type starfield

X AS FLOAT
Y AS FLOAT
Z AS INTEGER
speed AS FLOAT
color AS DWORD

endtype

` Now let's create some stars
dim stars(starquantity) as starfield

` We need to give each star a location, colour and depth
for s=0 to starquantity

stars(s).x = rnd(800)
stars(s).y = rnd(600)
stars(s).z = int(s/(starquantity/starlayers))+1
stars(s).speed = stars(s).z * speedfactor#
temp_col = (255/starlayers) * stars(s).z
stars(s).color = rgb(temp_col, temp_col, temp_col)

next s

set sprite 1,0,1

` Now our main loop!
repeat

cls 0

for s=0 to starquantity

sx# = stars(s).x
dot sx#, stars(s).y, stars(s).color
sx# = sx# - stars(s).speed
if sx# < 0 then sx# = 800
stars(s).x = sx#

next s

sprite 1,200,182,1
sync

until spacekey()=1

end

But i just can't seem to get it to go from the top of the screen to the bottom. Help? Chris

Goverment... is just another way to say Better, Than, You!
EvilJason
21
Years of Service
User Offline
Joined: 3rd Jun 2003
Location:
Posted: 2nd Jul 2004 22:31
Near the bottom with stars(s).x and stars(s).y just change them around to

sx# = stars(s).y
dot sx#, stars(s).x, stars(s).color
sx# = sx# - stars(s).speed
if sx# < 0 then sx# = 800
stars(s).y = sx#

See if that works

-EvilJayson
Hells Messenger
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: War Torn Froozen Waste Land
Posted: 2nd Jul 2004 23:18
Nope it doesnt change anything except i think it changes the colour of the stars. But its still going from right to left. Chris


Goverment... is just another way to say Better, Than, You!
EvilJason
21
Years of Service
User Offline
Joined: 3rd Jun 2003
Location:
Posted: 2nd Jul 2004 23:36
I get it ok do this code

for s=0 to starquantity

sy# = stars(s).y
dot stars(s).x, sy#, stars(s).color
sy# = sy# - stars(s).speed
if sy# < 0 then sx# = 600
stars(s).y = sx#

next s

the 800 now 600 is for the screen res you know 800*600

Try that

-EvilJayson
Hells Messenger
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: War Torn Froozen Waste Land
Posted: 2nd Jul 2004 23:47
No still not working that just give me a straight line of stars accross the top of the screen, and there not moving just frooze, hmmmmmm. Chirs

Goverment... is just another way to say Better, Than, You!
EvilJason
21
Years of Service
User Offline
Joined: 3rd Jun 2003
Location:
Posted: 2nd Jul 2004 23:58
Strange you see the line

dot sx#, stars(s).y, stars(s).color

this line is the line that places the dot

the command is dot x,y,color

so if you want to move them down the screen you need to take away from the y posion which is what this line does

sx# = sx# - stars(s).speed

maybie chnage the - to a + ? and the line to dot stars(s).x,sx#,stars(s).color

the line

sx# < 0 then sx# = 800

wrapes the stars posision to the other end of the screen but because the screen is 800 long but 600 high you need to change to 600

the next line is to save the current stars new posision because sx# is reused next loop

stars(s).x = sx#

This is all i can do now, see if you wrote down something different k

Jope it helps

-EvilJayson
Hells Messenger
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: War Torn Froozen Waste Land
Posted: 3rd Jul 2004 00:16
no still not wel its gettin there the stars shoot dwn from the top left to bottom right once then no more in a straight line, bummer really the tutorial says its a simple change yet i can't seem to do it...lol thanks anyway EvilJason. Chris

Goverment... is just another way to say Better, Than, You!
Hells Messenger
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: War Torn Froozen Waste Land
Posted: 3rd Jul 2004 00:24
lol...i've just realised thats mae the stars go the oposit way so instead of going right to left, they now go left to right. Chris

Goverment... is just another way to say Better, Than, You!
Hells Messenger
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: War Torn Froozen Waste Land
Posted: 3rd Jul 2004 03:00
anyone else know how i could achive this? by makeing the stars move from top to the bottom rarther than left to right/right to left? Chris

Goverment... is just another way to say Better, Than, You!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Jul 2004 05:06
Sure. Just switch all the x's for y's and vice versa in the main loop, add the speed instead of subtract it (to move the stars down the screen rather than up), and when they reach the bottom, move them back to the top.



I'm just using a dot here instead of an image, coz I couldn't be bothered to locate any media

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Hells Messenger
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: War Torn Froozen Waste Land
Posted: 3rd Jul 2004 11:36
Hey IanM, thanks that worked thanks for the help people i was stuck but not anymore..hahaha cheers. Chris

Goverment... is just another way to say Better, Than, You!

Login to post a reply

Server time is: 2024-11-26 23:26:07
Your offset time is: 2024-11-26 23:26:07