X Tutup
Skip to content

Commit 6747b9a

Browse files
committed
sVB 3.6 and Sahla-En 1.0.5.4
1 parent ba3f9d9 commit 6747b9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2235
-1281
lines changed

SBCompiler/SBCompiler/Statements/SubroutineStatement.vb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,10 @@ Namespace Microsoft.SmallVisualBasic.Statements
433433

434434
Sub SetParams(parentRunner As ProgramRunner, targetRunner As ProgramRunner, args As List(Of Expressions.Expression))
435435
If Params IsNot Nothing AndAlso Params.Count > 0 Then
436-
Dim subName = Name.LCaseText
437-
Dim keyPrefix = subName & "."
436+
Dim keyPrefix = Name.LCaseText & "."
438437

439438
For i = 0 To Params.Count - 1
440-
Dim argKey = $"{subName}.{Params(i).LCaseText}"
439+
Dim argKey = keyPrefix & Params(i).LCaseText
441440
targetRunner.Fields(argKey) = args(i).Evaluate(parentRunner)
442441
Next
443442
End If

Samples/Games/Starship/StarShip.sb

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Thread.InitializationDelay = 3
1111
ExitUpdateFrame = False
1212
EnemyShipLabel2 = ""
1313
EnemyShipLabel3 = ""
14-
PlayerSpeed = 3
15-
BulletSpeed = 10
14+
PlayerSpeed = 7
15+
BulletSpeed = 15
1616

1717
' -------------------------------------------------------------------
1818
' Using ListBox to add and remove items has better performance that SB array.
@@ -50,12 +50,14 @@ Timer.Tick = UpdateFrame
5050
CreateEnemies()
5151

5252

53+
' ------------------------------------------------
5354
Sub CreateEnemies()
5455
For i = 1 To 3
5556
CreateEnemy()
5657
Next
5758
EndSub
5859

60+
' ------------------------------------------------
5961
Sub CreateEnemy()
6062
lblEnemy = GetHiddenLabel(Enemies)
6163
If lblEnemy = "" Then
@@ -65,7 +67,7 @@ Sub CreateEnemy()
6567
0
6668
)
6769
lblEnemy.Tag = {
68-
Math.Rnd(-15, 15), ' Speed X
70+
Math.Rnd(-15, 15), ' Speed X
6971
Math.Rnd(2, 4), ' Speed y
7072
Math.Rnd(20, 50) ' Bullet frequency
7173
}
@@ -76,6 +78,9 @@ Sub CreateEnemy()
7678
EndIf
7779
EndSub
7880

81+
82+
' --------------------------------------------------
83+
7984
Function CreateShip(image, x, y)
8085
ship = Controls.AddLabel("", x, y)
8186
ship.Image = image
@@ -84,6 +89,7 @@ Function CreateShip(image, x, y)
8489
Return ship
8590
EndFunction
8691

92+
' --------------------------------------------------
8793
Sub UpdateFrame()
8894
MovePlayerShip()
8995
If ExitUpdateFrame Then
@@ -98,16 +104,22 @@ Sub UpdateFrame()
98104
EndIf
99105

100106
Thread.SubToRun = MoveBullets
107+
Thread.SubToRun = MoveEnemyBullets
108+
Thread.SubToRun = MoveEnemies
101109

110+
ExitUpdateFrame = False
111+
EndSub
112+
' -----------------------------------------------------------------
113+
114+
Sub MoveEnemies()
102115
For i = 1 To Enemies.Count
103116
EnemyShipLabel = Enemies[i]
104117
If EnemyShipLabel.Visible Then
105118
Thread.SubToRun = MoveEnemy
106119
EndIf
107120
Next
108-
109-
ExitUpdateFrame = False
110121
EndSub
122+
' -----------------------------------------------------------------
111123

112124
Sub MoveEnemy()
113125
lblEnemy = EnemyShipLabel
@@ -149,6 +161,7 @@ Sub MoveEnemy()
149161
EnemyShipLabel3 = lblEnemy
150162
Thread.SubToRun = CheckEnemyAndBuulets
151163
EndSub
164+
' -----------------------------------------------------------------
152165

153166
Sub FireEnemyBullet()
154167
lblEnemy = EnemyShipLabel2
@@ -166,6 +179,7 @@ Sub FireEnemyBullet()
166179
lblBullet.Visible = True
167180
EndIf
168181
EndSub
182+
' -----------------------------------------------------------------
169183

170184
Sub CheckEnemyAndBuulets()
171185
lblEnemy = EnemyShipLabel3
@@ -176,6 +190,7 @@ Sub CheckEnemyAndBuulets()
176190
EndIf
177191
EndSub
178192

193+
' -----------------------------------------------------------------
179194
Sub MoveBullets()
180195
For i = Bullets.Count To 1 Step -1
181196
lblBullet = Bullets[i]
@@ -186,7 +201,10 @@ Sub MoveBullets()
186201
EndIf
187202
EndIf
188203
Next
189-
204+
EndSub
205+
206+
' -----------------------------------------------------------------
207+
Sub MoveEnemyBullets()
190208
ForEach lblBullet In EnemyBullets
191209
If lblBullet.Visible Then
192210
lblBullet.Top = lblBullet.Top + BulletSpeed
@@ -205,7 +223,7 @@ Sub MoveBullets()
205223
EndIf
206224
Next
207225
EndSub
208-
226+
' -----------------------------------------------------------
209227
Function CollideWithPlayerBullets(lblEnemy)
210228
ForEach lblBullet In Bullets
211229
If lblBullet.Visible Then
@@ -218,6 +236,7 @@ Function CollideWithPlayerBullets(lblEnemy)
218236
Return False
219237
EndFunction
220238

239+
' -----------------------------------------------------------
221240
Function BulletHitsEnemy(lblBullet, lblEnemy)
222241
If ImageList.Collide(
223242
lblBullet.Left, lblBullet.Top, UpBulletImage,
@@ -232,6 +251,7 @@ Function BulletHitsEnemy(lblBullet, lblEnemy)
232251
Return False
233252
EndFunction
234253

254+
' --------------------------------------------------
235255
Function EnemyHitsPlayer(lblEnemy)
236256
If lblEnemy.Tag = "" Then
237257
image = DownBulletImage
@@ -253,6 +273,7 @@ Function EnemyHitsPlayer(lblEnemy)
253273
Return False
254274
EndFunction
255275

276+
' --------------------------------------------------
256277
Sub GraphicsWindow_KeyDown()
257278
k = Keyboard.LastKey
258279

@@ -275,6 +296,7 @@ Sub GraphicsWindow_KeyDown()
275296
EndIf
276297
EndSub
277298

299+
' ------------------------------------------------
278300
Sub MovePlayerShip()
279301
If Keyboard.IsKeyDown(Keys.Left) Then
280302
PlayerShip.Left = PlayerShip.Left - PlayerSpeed
@@ -302,6 +324,7 @@ Sub MovePlayerShip()
302324
EndIf
303325
EndSub
304326

327+
' ------------------------------------------------
305328
Function GetHiddenLabel(arr)
306329
ForEach _label In arr
307330
If _label.Visible = False Then
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
X = E(1)
2+
TW.WriteLine("Calculated e = " & X)
3+
Y = Math.E
4+
TW.WriteLine(" Math.E = " & Y)
5+
TW.WriteLine(" delta = " & (X - Y))
6+
TW.WriteLine("")
7+
X = E(10)
8+
TW.WriteLine("Calculated e^10 = " & X)
9+
Y = Math.Power(Math.E, 10)
10+
TW.WriteLine(" Math.E^10 = " & Y)
11+
TW.WriteLine(" delta = 0000" & (X - Y))
12+
13+
' ------------------------------------------------
14+
' Calculates 1 + x + x^2/2! + x^3/3! + ...........
15+
Function E(x)
16+
sum = 1
17+
For i = 1 To 500
18+
n = x
19+
For j = 2 To i
20+
n = n * (x / j)
21+
Next
22+
sum = sum + n
23+
Next
24+
Return sum
25+
EndFunction
26+
27+

Samples/Math Samples/Calculator.sb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
TextWindow.Write("Enter 1st number: ")
2+
N1 = TW.ReadNumber()
3+
TextWindow.Write("Enter operator(+ - * / %): ")
4+
Op = TW.Read()
5+
TextWindow.Write("Enter 2nd number: ")
6+
N2 = TW.ReadNumber()
7+
Error = False
8+
9+
If Op = "+" Then
10+
Result = N1 + N2
11+
ElseIf Op = "-" Then
12+
Result = N1 - N2
13+
ElseIf Op = "*" Then
14+
Result = N1 * N2
15+
ElseIf Op = "/" Then
16+
If N2 = 0 Then
17+
Result = "Can't divide by 0"
18+
Error = True
19+
Else
20+
Result = N1 / N2
21+
EndIf
22+
ElseIf Op = "%" Then
23+
If N2 = 0 Then
24+
Result = "Can't divide by 0"
25+
Error = True
26+
Else
27+
Result = N1 Mod N2
28+
EndIf
29+
Else
30+
Result = "Invalid operator"
31+
Error = True
32+
EndIf
33+
34+
If Error Then
35+
TextWindow.WriteLine(Result)
36+
Else
37+
TextWindow.WriteFormatted(
38+
"[1] [2] [3] = [4]",
39+
{N1, Op, N2, Result}
40+
)
41+
EndIf

0 commit comments

Comments
 (0)
X Tutup