StarScrolling
BlitzMax Forums/BlitzMax Programming/StarScrolling
| ||
Here is a little StarScrolling demo Graphics 800,600,32,60 Type star1 Field x,y End Type Global star1_list:TList=New TList For Local i=1 To 200 Local st1:star1=New star1 star1_list.AddLast st1 st1.x=Rnd(0,800) st1.y=Rnd(0,600) Next Type star2 Field x,y End Type Global star2_list:TList=New TList For Local j=1 To 150 Local st2:star2=New star2 star2_list.AddLast st2 st2.x=Rnd(0,800) st2.y=Rnd(0,600) Next Type star3 Field x,y End Type Global star3_list:TList=New TList For Local k=1 To 100 Local st3:star3=New star3 star3_list.AddLast st3 st3.x=Rnd(0,800) st3.y=Rnd(0,600) Next Local winkel Local beam While Not KeyHit(KEY_ESCAPE) 'Escape Cls For st1:star1=EachIn star1_list SetColor 155,155,155 Plot st1.x,st1.y st1.x:-1 If st1.x<0 Then st1.x=800 EndIf Next For st2:star2=EachIn star2_list SetColor 175,175,175 Plot st2.x,st2.y st2.x:-2 If st2.x<0 Then st2.x=800 EndIf Next For st3:star3=EachIn star3_list SetColor 255,255,255 Plot st3.x,st3.y st3.x:-3 If st3.x<0 Then st3.x=800 EndIf Next Flip Wend |
| ||
Yay. Scrolling stars. Here's a OO version I adapted from some B3D code of mine. It also lets you change scroll direction. /me wonders if plot is as fast as writepixelfast ? Seems to be fast enough anyway. |
| ||
Ohh year this is cool? |
| ||
Nice ,thanks for sharing. |
| ||
Cool. Reminds me of the earlier days of the Amiga demo scene, scrolling starfields were all the rage and very often had 3 or so layers of parallax like in this demo. |
| ||
I have no idea if plot is as fast as writepixelfast, since I don't know about blitz3d or blitzplus ... but plot isnt' as fast as it could be. The Plot command is just a higher-level wrapper for a peice of OpenGL or DirectX code. e.g. glBegin(GL_POINTS) glVertex2i(100,100) glEnd(GL_POINTS) Would plot a single point in OpenGL. You could put more vertexes in between the begin and end and it'd be more efficient than having a set of those for every point. You also get rid of any overhead from jumping to the routine as you call the `Plot` function. |
| ||
Here is one more starfield routin.'Star Demo Graphics 800,600,0 strnr:Int = 1500 'amount of stars spinn:Int = 20 'amount of spinn. Turn off = 0 Local rad[strnr] Local angle[strnr] Local spd[strnr] For i = 0 To strnr rad[i]=Rnd(280) + 20 angle[i]=Rnd(65535) spd[i]=Rnd(5)+1 Next Repeat Cls For i=0 To strnr xp=400+(Sin((2*angle[i])*(Pi/360))*rad[i]) yp=300+(Cos((2*angle[i])*(Pi/360))*rad[i]) If xp < 0 Or xp > 800 Or yp < 0 Or yp > 600 rad[i]=Rnd(40) + 20 angle[i]=Rnd(65535) spd[i]=Rnd(5)+1 EndIf rad[i] = rad[i] + spd[i] angle[i] = angle[i] + spinn If spd[i]=1 Then SetColor(100,100,100) If spd[i]=2 Then SetColor(130,130,130) If spd[i]=3 Then SetColor(170,170,170) If spd[i]=4 Then SetColor(210,210,210) If spd[i]=5 Then SetColor(255,255,255) Plot(xp,yp) Next Flip() FlushMem() Until KeyHit(KEY_ESCAPE) End Sveinung |
| ||
Right on guys! Thanks for all the good code! Nice to have in my "code nuggets" folder of goodies. :) |
| ||
Nice. There can never be enough starfield routines imo ;-), so here's another B3D conversion... |
| ||
very nice guys, awsome stuff |
| ||
Hello. What about: Not tested but it should whup everyone else's routines I reckon. Goodbye. |
| ||
Looks like C64 Basic Style...... |
| ||
Hello. I don't know what you could possibly mean!!! That's class, man! [quote]There can never be enough starfield routines imo ;-)[\quote] Ok, perhaps there can ;oD Goodbye. |
| ||
Thanks all. Sveinung, your code doesn't run, out of bounds array error. |
| ||
@DannyD OOOPS...Sorry about that. Had no debugger on... Should be like this 'Star Demo Graphics 800,600,0 strnr:Int = 1500 'amount of stars spinn:Int = 20 'amount of spinn. Turn off = 0 Local rad[strnr] Local angle[strnr] Local spd[strnr] For i = 0 To strnr-1 rad[i]=Rnd(280) + 20 angle[i]=Rnd(65535) spd[i]=Rnd(5)+1 Next Repeat Cls For i=0 To strnr-1 xp=400+(Sin((2*angle[i])*(Pi/360))*rad[i]) yp=300+(Cos((2*angle[i])*(Pi/360))*rad[i]) If xp < 0 Or xp > 800 Or yp < 0 Or yp > 600 rad[i]=Rnd(40) + 20 angle[i]=Rnd(65535) spd[i]=Rnd(5)+1 EndIf rad[i] = rad[i] + spd[i] angle[i] = angle[i] + spinn If spd[i]=1 Then SetColor(100,100,100) If spd[i]=2 Then SetColor(130,130,130) If spd[i]=3 Then SetColor(170,170,170) If spd[i]=4 Then SetColor(210,210,210) If spd[i]=5 Then SetColor(255,255,255) Plot(xp,yp) Next Flip() FlushMem() Until KeyHit(KEY_ESCAPE) End Sveinung |
| ||
Dude they all rule! Thanks guys! |
| ||
Nice ! |