Starfield
Hi all
I am very tired it's 4.49 , i have worked about 6 hours to do
the legendary AMIGA starfield on B4A..
You can improve it with starfield colors, it's not hard,
OK Done;
Let's begin like AMIGA
Lea $30000
Good luck
Hi all
I am very tired it's 4.49 , i have worked about 6 hours to do
the legendary AMIGA starfield on B4A..
You can improve it with starfield colors, it's not hard,
OK Done;
Let's begin like AMIGA
Lea $30000
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim time As Timer
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim cnv As Canvas
Dim stpanel As Panel
Dim xitbtn As Button
Dim starx(100) As Int 'xpos
Dim stary(100) As Int 'ypos
Dim starspeed(100) As Int 'stars
Dim nbstar(100) As Int 'numstars
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("starscroll") 'nothing special just stpanel + exitbtn in layout
cnv.Initialize(stpanel)
For i=0 To nbstar.Length-1
starx(i)=Rnd(1,460) 'store xpos in table 100 xpos
stary(i)=Rnd(1,800) 'store ypos ..100 ypos
starspeed(i)=Rnd(1,8) 'store starspeed .. 100 speed
Next
time.Initialize("time",5)
time.Enabled=True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub time_Tick
drawstars
End Sub
Sub DrawStars
' nothing HARD here :) just clear stars ypos -starspeed(i) from table...
dim clr as int
For i=0 To nbstar.Length-1
cnv.DrawCircle(starx(i),stary(i)-starspeed(i),2,Colors.black,True,2dip)
cnv.DrawCircle(starx(i),stary(i),2,clr,True,2dip)
stary(i)=stary(i)+starspeed(i)
If starspeed(i)=1 Then clr=Colors.RGB(50,50,50)
If starspeed(i)=2 Then clr=Colors.RGB(80,80,80)
If starspeed(i)=3 Then clr=Colors.RGB(100,100,100)
If starspeed(i)=4 Then clr=Colors.RGB(150,150,150)
If starspeed(i)=5 Then clr=Colors.RGB(180,180,180)
If starspeed(i)=6 Then clr=Colors.RGB(200,200,200)
If starspeed(i)=7 Then clr=Colors.RGB(230,230,230)
If starspeed(i)=8 Then clr=Colors.RGB(255,255,255)
If stary(i)>860 Then stary(i)=-10
stpanel.Invalidate
Next
End Sub
Sub xitbtn_Click
time.enabled=false
activity.Finish
End Sub
Good luck
Last edited: