Post Reply 
Micro$oft SMALLBASIC
08-16-2020, 03:36 PM (This post was last modified: 09-06-2020 03:00 PM by compsystems.)
Post: #2
RE: Micro$oft SMALLBASIC
Hello.
A proposal
Please, who wants to join the collaborative port of some graphical codes from SB to HpPrime in order to compare the logic and the way of coding between different educational platforms?

another simple game, a ball on a platform, the idea is to keep the ball as long as possible

PHP Code:
GraphicsWindow.Title  "Rocker"

gw 450
gh 
400
tx 
225
ty 
320

score 
0
angle 
0
ballDirection 
= -1
ballSpeed 
0.3
acceleration 
1.001
power 
1.2
gameStarted 
"False"
ballX 210
ballY 
280

GraphicsWindow
.KeyDown OnKeyDown
CreateUI
()

gameOver "False"

While gameStarted "False"
  
Program.Delay(300)
EndWhile

gameStartTime Clock.ElapsedMilliseconds
Shapes
.Remove(directions)
While 
gameOver "False"
  
Shapes.Rotate(paddleangle)
  
  
power Math.Abs(angle) / 200
  Shapes
.Rotate(paddleangle)
  
  
CalculateBallMetrics()  
  
Shapes.Move(ballballXballY)
  
  
WriteTime()
  
Program.Delay(20)
  
  If 
ballX 105 Or ballX 315 Then
    gameOver 
"True"
  
EndIf
EndWhile

GraphicsWindow.ShowMessage("You survived for " timeDisplayText ".""Game Over")

Sub CreateUI
  GraphicsWindow
.CanResize "False"
  
GraphicsWindow.Width gw
  GraphicsWindow
.Height gh
  GraphicsWindow
.Top = (Desktop.Height gh) / 2
  GraphicsWindow
.Left = (Desktop.Width gw) / 2
  
  GraphicsWindow
.DrawRectangle(1010430380)
  
  
GraphicsWindow.BrushColor "Violet"
  
tri Shapes.AddTriangle(txtytx 50ty 50tx 50ty 50
  
  
GraphicsWindow.BrushColor "Purple"
  
paddle Shapes.AddRectangle(21010)  
  
Shapes.Move(paddle120310)
  
  
GraphicsWindow.BrushColor "Red"
  
ball Shapes.AddEllipse(3030)
  
Shapes.Move(ballballXballY)  
  
  
GraphicsWindow.FontSize 16
  GraphicsWindow
.FontName "Verdana"  
  
directions Shapes.AddText("Press ENTER to start the game!")
  
Shapes.Move(directions80150)
  
  
GraphicsWindow.BrushColor "Blue"
  
timeText Shapes.AddText("Time: 00:00")
  
Shapes.Move(timeText31016)
EndSub

Sub OnKeyDown
  
If gameStarted "True" Then
    
If GraphicsWindow.LastKey "Left" Then
      angle 
Math.Max(-40angle 1)
    ElseIf 
GraphicsWindow.LastKey "Right" Then
      angle 
Math.Min(40angle 1)
    EndIf
  Else
    If 
GraphicsWindow.LastKey "Return" Then
      gameStarted 
"True"
    
EndIf
  EndIf
EndSub

Sub CalculateBallMetrics
  
If ballDirection Math.Abs(angle) = angle Then
    
    ballSpeed 
Math.Min(2ballSpeed power)
  Else
    
ballSpeed Math.Max(0.1ballSpeed power)
    If 
ballSpeed 0.2 Then
      ballDirection 
= -ballDirection
      ballSpeed 
0.2
    
EndIf
  EndIf
  
ballX ballX ballDirection ballSpeed
  deltaX 
ballX 210
  deltaY 
deltaX Math.Sin(Math.GetRadians(angle))
  
ballY 280 deltaY
EndSub
Sub WriteTime
  elapsedTime 
Clock.ElapsedMilliseconds gameStartTime
  totalSeconds 
Math.Round(elapsedTime 1000)
  
seconds Math.Remainder(totalSeconds60)
  
minutes Math.Round(totalSeconds 60)
  If (
seconds 10Then
    seconds 
Text.Append("0"seconds)
  EndIf
  If (
minutes 10Then
    minutes 
Text.Append("0"minutes)
  EndIf
  
timeDisplayText minutes ":" seconds
  Shapes
.SetText(timeText"Time: " timeDisplayText)
EndSub 


SMALL BASIC PRIME IDE 1.1.7.0
https://github.com/litdev1/SB-IDE/releases
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Micro$oft SMALLBASIC - compsystems - 08-15-2020, 03:34 PM
RE: Micro$oft SMALLBASIC - compsystems - 08-16-2020 03:36 PM



User(s) browsing this thread: 1 Guest(s)