News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Retro stars V1

Started by RaverDave, October 06, 2006, 04:04:52 PM

Previous topic - Next topic

RaverDave

I hope this looks like some retro type scrolling stars that i started!! Do with the code whateva you want..I might use it myself even! ;)
; PROJECT : Project3
; AUTHOR  : Raverdave
; CREATED : 06/10/2006
; ---------------------------------------------------------------------
OpenScreen 640,480,32,2
SetFPS 60
global count
global r
type tstars
image
xpos
ypos
state
inv
endtype

dim stars(151) as tstars
createfx()




do
cls 0
drawstars()

sync
loop

function drawstars()
for n=1 to 150
if stars(n).state=0
drawimage stars(n).image,stars(n).xpos,stars(n).ypos,1
stars(n).ypos=stars(n).ypos+1
if stars(n).ypos>480
stars(n).ypos=0
endif
endif
if stars(n).state=1
stars(n).inv=stars(n).inv+1
if stars(n).inv>5
stars(n).inv=0
stars(n).state=0
count=0
endif
stars(n).ypos=stars(n).ypos+1
if stars(n).ypos>480
stars(n).ypos=0
endif
endif
next
r=rnd(150)+1
if stars(r).state=0
stars(r).state=1
endif
endfunction



function createfx()
for n=1 to 150
createimage n,1,1
rendertoimage n
r=rnd(255)+1
g=rnd(255)+1
b=rnd(255)+1
dotc 0,0,rgb(r,g,b)
next
rendertoscreen
for n=1 to 150
stars(n).image=rnd(149)+1
stars(n).xpos=rnd(540)+50
stars(n).ypos=rnd(480)
next
endfunction


RaverDave

Slightly improved so it doesnt matter about screensize, also some vars have replaced simple numbers for more modularness, I shouldnt be lazy at the end of the day.

; PROJECT : retrostars
; AUTHOR  : Raverdave
; CREATED : 06/10/2006
; EDITED  : 07/10/2006
; ---------------------------------------------------------------------
OpenScreen 640,480,32,2
SetFPS 60
Global r
Global maxnum=151
Global width=GetScreenWidth()
Global height=GetScreenHeight()
Global sspeed=1
Type tstars
image
xpos
ypos
state
inv
EndType

Dim stars(maxnum) As tstars
createfx()

Do
Cls 0
drawstars()

Sync
Loop

Function drawstars()
For n=1 To maxnum-1
If stars(n).state=0
DrawImage stars(n).image,stars(n).xpos,stars(n).ypos,1
stars(n).ypos=stars(n).ypos+sspeed
If stars(n).ypos>height
;Rem the line below positions star
; differently after
;it reaches the bottom, Rem it out if
;you dont wish to but Rem it out also
;lower down when stars(n).state=1
stars(n).xpos=Rnd(width-100)+50
stars(n).ypos=0
EndIf
EndIf
If stars(n).state=1
stars(n).inv=stars(n).inv+1
If stars(n).inv>5
stars(n).inv=0
stars(n).state=0
EndIf
stars(n).ypos=stars(n).ypos+1
If stars(n).ypos>height
stars(n).ypos=0
;Rem the line below positions star
; differently after
;it reaches the bottom, Rem it out if
;you dont wish to
stars(n).xpos=Rnd(width-100)+50
EndIf
EndIf
Next
r=Rnd(maxnum)
If stars(r).state=0
stars(r).state=1
EndIf
EndFunction



Function createfx()
For n=1 To maxnum-1
CreateImage n,1,1
RenderToImage n
r=Rnd(250)+1
g=Rnd(250)+1
b=Rnd(250)+1

DotC 0,0,RGB(r,g,b)
Next
RenderToScreen
For n=1 To maxnum-1
stars(n).image=Rnd(maxnum-2)+1
stars(n).xpos=Rnd(width-100)+50
stars(n).ypos=Rnd(height)
Next
EndFunction


Calypson

I'd suggest instead of having them twinkle by switching to black at random... try instead to have it twinkle to pure white.

RaverDave

Errr, Iwould do,but thats not how it was i am afraid back in da old dayzzzz... I think you had better try playing galaga or something.. like so----->>>>  http://www.breumelhof.nl/emulationroms/component/option,com_wrapper/Itemid,62/

stef

#4
It's looking more like this (but isn't still the same :))


OpenScreen 640,480,32,2
SetFPS 60
Global r
Global maxnum=201
Global width=GetScreenWidth()
Global height=GetScreenHeight()
Global sspeed=1
Type tstars
image
xpos
ypos
state
inv
EndType

Dim stars(maxnum) As tstars
createfx()

Do
Cls 0
drawstars()
;Print FPS()
Sync
Loop

Function drawstars()
For n=1 To maxnum-1
If stars(n).state=0
DrawImage stars(n).image,stars(n).xpos,stars(n).ypos,1
stars(n).ypos=stars(n).ypos+sspeed

EndIf
If stars(n).state=1
stars(n).inv=stars(n).inv+1
If stars(n).inv>5
stars(n).inv=0
stars(n).state=0
EndIf
stars(n).ypos=stars(n).ypos+1
EndIf

If stars(n).ypos>height
stars(n).ypos=0
stars(n).xpos=Rnd(width-100)+50
EndIf
Next
For x = 0 To 20
r=Rnd(maxnum)
If stars(r).state=0
stars(r).state=1
EndIf
Next
EndFunction



Function createfx()
For n=1 To maxnum-1
CreateImage n,1,2
RenderToImage n

r=Rnd(250)+1
g=Rnd(250)+1
b=Rnd(250)+1

;DotC 0,0,RGB(r,g,b)
Cls RGB(r,g,b)
Next
RenderToScreen
For n=1 To maxnum-1
stars(n).image=Rnd(maxnum-2)+1
stars(n).xpos=Rnd(width-100)+50
stars(n).ypos=Rnd(height)
Next
EndFunction