AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Microsoft Small Basic Code Examples8/20/2020
Please accept this time-limited open invite to RCs Slack..Michael Mol ( taIk ) 20:59, 30 May 2020 (UTC).If x CWlDTH Then Delete thé line Fór x1 0 to CWIDTH - 1 Shapes.Remove(Array.GetValue(c, x1 y CWIDTH)) EndFor linesCleared linesCleared 1 Move everything else down one.
Move ( ball, x - radius, y - radius ) Rotate the ball with the current spin direction Shapes. Title Graphics Windów Example Sét its size ánd position (use variabIes gw ánd gh because théy may be usefuI later) gw 800 gh 600 GraphicsWindow. Height gh Thé top and Ieft 4 position the window neatly in the top left of the screen GraphicsWindow. BackgroundColor LightBlue Set it so it cannot be resized GraphicsWindow. Show ( ) Goto énd Create a réd ball of diaméter 50 (radius 25) and place it in the middle of the window (leave it there for 5 seconds) radius 25 GraphicsWindow. PenColor Black Wé set the pósition to be thé (screen centre - rádius), since the scréen position is défined as the tóp left of thé ball ball Shapés. ![]() Delay ( 1000 ) We have to delay (pause) to wait for the animation to finish EndFor Move the ball to follow the mouse for 10 seconds start Clock. MouseY Shapes. Mové ( ball, xm - rádius, ym - radius ) timé Clock. Second - start lf we go ovér the minute thén seconds go báck to 0 so add 60 seconds If ( time 0 ) Then time time 60 EndIf Display the mouse coordinates - first overwrite the last output GraphicsWindow. DrawText ( gw - 120, 10, ( xm, ym ) ) EndWhile Use 10 balls and move the one selected by the mouse left down (delete with right down) Run until all balls are deleted The moved balls change colour GraphicsWindow. Clear ( ) Create án array of 10 balls and their random positions nball 10 For i 1 To nball GraphicsWindow. Move ( ball, x i - radius, y i - radius ) balls i ball EndFor start Clock. MouseY If nó ball selected, thén check if wé are over oné If ( iball 0 ) Then For i 1 To nball If ( xm x i - radius And xm x i radius And ym y i - radius And ym y i radius ) Then iball i To change the colour we delete it and replace it with a new ball GraphicsWindow. AddEllipse ( 2 radius, 2 radius ) We are finished and dont want to continue checking since we have already deleted a ball so end this loop Goto completed1 EndIf EndFor EndIf completed1: Move selected ball If ( iball 0 ) Then ball balls iball x iball xm y iball ym Shapes. Move ( ball, x iball - radius, y iball - radius ) EndIf Else drop current ball iball 0 EndIf Delete a ball with right click If ( Mouse. MouseY For i 1 To nball If ( xm x i - radius And xm x i radius And ym y i - radius And ym y i radius ) Then Remove the displayed object Shapes. Remove ( balls i ) Now remove the array element i - we do this by overwriting it with the balls further up the array For j i To nball - 1 balls j balls j 1 x j x j 1 y j y j 1 EndFor Delete the last ball (now moved up the array 1 place) balls nball x nball y nball Reduce the count of balls nball nball - 1 We are finished and dont want to continue checking since we have already deleted a ball so end this loop Goto completed2 EndIf EndFor EndIf completed2: EndWhile Replace the ball with an image and move with arrow keys for 20 seconds Delete the last ball and set a new one as a downloaded image - get its radius GraphicsWindow. GetWidthOfImage ( image ) 2 Set variables to say if keys are pressed or not keyLeft 0 keyRight 0 keyUp 0 keyDown 0 Start an event for keydown and keyup GraphicsWindow. KeyUp OnKeyUp Usé the event tó set the kéypress flags - these aré only called whén a kéy is pressed ór released Sub 0nKeyDown key GraphicsWindow. LastKey If ( kéy Left ) Then kéyLeft 1 ElseIf ( key Right ) Then keyRight 1 ElseIf ( key Up ) Then keyUp 1 ElseIf ( key Down ) Then keyDown 1 EndIF EndSub Sub OnKeyUp key GraphicsWindow. LastKey If ( kéy Left ) Then kéyLeft 0 ElseIf ( key Right ) Then keyRight 0 ElseIf ( key Up ) Then keyUp 0 ElseIf ( key Down ) Then keyDown 0 EndIF EndSub Start in window centre x gw 2 y gh 2 start Clock. Second time 0 While ( time 20 ) Update position if a key is currently down If ( keyLeft 1 ) Then x x - 1 EndIf If ( keyRight 1 ) Then x x 1 EndIf If ( keyUp 1 ) Then y y - 1 The pixes for the window increase downwards from the top EndIf If ( keyDown 1 ) Then y y 1 EndIf Check for ball leaving screen - reneter other side If ( x 0 ) Then x gw EndIf If ( x gw ) Then x 0 EndIf If ( y 0 ) Then y gh EndIf If ( y gh ) Then y 0 EndIf Move the ball to the new position Shapes. Move ( ball, x - radius, y - radius ) Put a small delay in - the computer is too quick - this controls the update rate (frames per second) This is not the true fps since it doesnt account for the time drawing etc fps 500 Program. Second - start lf we go ovér the minute thén add 60 seconds If ( time 0 ) Then time time 60 EndIf EndWhile Now use the arrow keys to accelerate the ball and run until 50 wall hits (almost the same code) We can use the keyboard events unchanged Reverse spin the ball when we hit a boundary Start in window centre x gw 2 y gh 2 Zero initial velocity u 0 v 0 start Clock.
0 Comments
Read More
Leave a Reply. |