77 lines
2.4 KiB
QBasic
77 lines
2.4 KiB
QBasic
|
'From the FreeBASIC.Net tutorial site.
|
||
|
#include "fbgfx.bi"
|
||
|
Using FB
|
||
|
|
||
|
'Put all the vars into a custom type
|
||
|
Type ObjectType
|
||
|
x As Single
|
||
|
y As Single
|
||
|
r As Single
|
||
|
l As Single
|
||
|
u As Single
|
||
|
d As Single
|
||
|
speed As Single
|
||
|
End Type
|
||
|
|
||
|
Dim Shared CircleM As ObjectType
|
||
|
|
||
|
Screen 13,8,2,0 'A 320x200 graphical window
|
||
|
SetMouse 0,0,0 'Hide the mouse cursor
|
||
|
|
||
|
CircleM.x = 150 'Put the circle in the middle
|
||
|
CircleM.y = 90 'Of the window.
|
||
|
CircleM.l = 0
|
||
|
CircleM.r = 0
|
||
|
CircleM.u = 0
|
||
|
CircleM.d = 0
|
||
|
CircleM.speed = 1
|
||
|
|
||
|
Do
|
||
|
Cls 'Refreshes the window, so the circle doesn't "paint"
|
||
|
Circle (CircleM.x,CircleM.y), 10, 15 'Sets new location and shape
|
||
|
If CircleM.speed = 0 Then CircleM.speed = 1
|
||
|
|
||
|
If MultiKey(SC_LEFT) Then CircleM.l = 1:CircleM.r = 0:CircleM.u = 0:CircleM.d = 0
|
||
|
If MultiKey(SC_RIGHT) Then CircleM.r = 1:CircleM.l = 0:CircleM.u = 0:CircleM.d = 0
|
||
|
If MultiKey(SC_UP) Then CircleM.u = 1:CircleM.d = 0:CircleM.l = 0:CircleM.r = 0
|
||
|
If MultiKey(SC_DOWN) Then CircleM.d = 1:CircleM.u = 0:CircleM.l = 0:CircleM.r = 0
|
||
|
|
||
|
If MultiKey(SC_UP) And MultiKey(SC_LEFT) Then CircleM.u = 1:CircleM.l = 1:CircleM.d = 0:CircleM.r = 0
|
||
|
If MultiKey(SC_UP) And MultiKey(SC_RIGHT) Then CircleM.u = 1:CircleM.r = 1:CircleM.d = 0:CircleM.l = 0
|
||
|
If MultiKey(SC_DOWN) And MultiKey(SC_LEFT) Then CircleM.d = 1:CircleM.l = 1:CircleM.u = 0:CircleM.r = 0
|
||
|
If MultiKey(SC_DOWN) And MultiKey(SC_RIGHT) Then CircleM.d = 1:CircleM.r = 1:CircleM.u = 0:CircleM.l = 0
|
||
|
|
||
|
'Listens for activity on named keys, and updates the circle
|
||
|
'Position accordingly.
|
||
|
If CircleM.l = 1 Then
|
||
|
CircleM.x = CircleM.x - CircleM.speed
|
||
|
If CircleM.x < 0 Then CircleM.x = 320
|
||
|
End If
|
||
|
|
||
|
If CircleM.r = 1 Then
|
||
|
CircleM.x = CircleM.x + CircleM.speed
|
||
|
If CircleM.x > 320 Then CircleM.x = 0
|
||
|
End If
|
||
|
|
||
|
If CircleM.u = 1 Then
|
||
|
CircleM.y = CircleM.y - CircleM.speed
|
||
|
If CircleM.y < 0 Then CircleM.y = 200
|
||
|
End If
|
||
|
|
||
|
If CircleM.d = 1 Then
|
||
|
CircleM.y = CircleM.y + CircleM.speed
|
||
|
If CircleM.y > 200 Then CircleM.y = 0
|
||
|
End If
|
||
|
|
||
|
If MultiKey(SC_TAB) Then CircleM.speed = CircleM.speed + 1
|
||
|
If MultiKey(SC_SPACE) Then
|
||
|
CircleM.speed = 0
|
||
|
CircleM.l = 0
|
||
|
CircleM.r = 0
|
||
|
CircleM.u = 0
|
||
|
CircleM.d = 0
|
||
|
End If
|
||
|
|
||
|
Sleep 10, 1 'No delay makes the movement invisible
|
||
|
Loop Until MultiKey(SC_Q) Or MultiKey(SC_ESCAPE) 'Escape or Q to exit
|