'ClickAwayBalls.bas v1.1
'new: speed increases, added timer, clicking bad choice restarts.
'by Dav, DEC/2020
'Click on balls in order, starting at 1 untill all gone,
'before the timer runs out. Clicking wrong number restarts.
balls = 15: size = 40: speed = 3
REDIM BallX
(balls
), BallY
(balls
), BallDx
(balls
), BallDy
(balls
), BallSize
(balls
), BallShow
(balls
), BallC
(balls
) AS _UNSIGNED LONG
restart:
'Generate random ball data
BallSize
(B
) = 40 + (RND * 30) BallX
(B
) = BallSize
(B
) + RND * (w
- 2 * BallSize
(B
)): BallY
(B
) = BallSize
(B
) + RND * (h
- 2 * BallSize
(B
)) BallDx
(B
) = Ballspeed
* COS(a
): BallDy
(B
) = Ballspeed
* SIN(a
)
curball = 1
timelimit = 30
'compute ball movement
BallX(t) = BallX(t) + BallDx(t) 'move ball then make sure in bounds
BallY(t) = BallY(t) + BallDy(t)
IF BallX
(t
) > w
- BallSize
(t
) THEN BallDx
(t
) = -BallDx
(t
): BallX
(t
) = w
- BallSize
(t
) IF BallX
(t
) < BallSize
(t
) THEN BallDx
(t
) = -BallDx
(t
): BallX
(t
) = BallSize
(t
) IF BallY
(t
) > h
- BallSize
(t
) THEN BallDy
(t
) = -BallDy
(t
): BallY
(t
) = h
- BallSize
(t
) IF BallY
(t
) < BallSize
(t
) THEN BallDy
(t
) = -BallDy
(t
): BallY
(t
) = BallSize
(t
) 'draw background
r
= SIN(1.1 * t
) * h2
- y
+ h2
'PSET (x, y), _RGB(r, r - y, -r)
LINE (x
, y
)-(x
, y
), _RGB(r
, r
- y
, -r
), BF
t = t + .01
PLAY "o2l16cegagfefgabgc3l4"
'draw balls
drawBall BallX(i), BallY(i), BallSize(i), BallC(i)
'If click on one ball (no overlayed oned) remove it
'erase ball
drawBall BallX(firstball), BallY(firstball), BallSize(firstball), BallC(firstball)
BallShow(firstball) = 0
curball = curball + 1
found = 0
found = found + 1
lastfound = firstball
''If click over several balls, remove top one
'IF found > 1 THEN
' 'BallShow(lastfound) = 0
' drawball BallX(lastfound), BallY(lastfound), BallSize(lastfound), 255, 200, 100
' _PRINTSTRING (BallX(lastfound) - 15, BallY(lastfound) - 15), STR$(lastfound)
' _DISPLAY: PLAY "mbl16o2fbfbl8f"
' found = 0
' _DELAY .5
' GOTO restart
'END IF
'check if all clicked
anyleft = 0
IF BallShow
(c
) = 1 THEN anyleft
= anyleft
+ 1 gameover = 1
PLAY "mbo1l4dl8ddl4dl8feeddc#l2d"
'==============
GetMouseClick:
'==============
found = 0
IF mx
> (BallX
(m
) - BallSize
(m
)) AND mx
< (BallX
(m
) + BallSize
(m
)) THEN IF my
> (BallY
(m
) - BallSize
(m
)) AND my
< (BallY
(m
) + BallSize
(m
)) THEN IF found
= 0 THEN firstball
= m
found = found + 1
lastfound = m
done = 1
f = 1 - rr / r
fcirc x
, y
, rr
, _RGB32(rred
* f
, grn
* f
, blu
* f
)
Radius
= ABS(R
): RadiusError
= -Radius: X
= Radius: Y
= 0 LINE (CX
- X
, CY
)-(CX
+ X
, CY
), C
, BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), C
, BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), C
, BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
LINE (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), C
, BF
LINE (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), C
, BF