_Title "DrawWorms Test and Demo, worms should avoid Yellow and White" 'b+ 2021-10-06 ' This is intended for Crypt-O-Gram Puzzle but may use else where also.
' This needs to be done in background on the side and updated with main loop in program using it.
' Use general Object
Const xmax
= 800, ymax
= 600 Color &HFFDDDDDD, &HFF442211 init = -1
'sample main loop action
lc = lc + 1
DrawWorms init
'_ScreenMove _Middle
' end perfect
_Delay .25 ' <<<< possible racing problem with change of screen size and _width adn Height update NewWormYard
0, 0, _Width, _Height ' <<< update WornYard to new screen sizeinit = -1 'only way to see sc& ??????????????/
DrawWorms init
Sub DrawWorms
(DrawReset
) ' one frame in main loop NewWorm i
x(i, j) = 0: y(i, j) = 0
DrawReset = 0
For j
= 1 To Worms
(i
).sz
' blackout old segments If x
(i
, j
) And y
(i
, j
) Then fcirc x
(i
, j
), y
(i
, j
), 8, &HFF000000 tryAgain:
If Rnd < .3 Then Worms
(i
).dx
= Worms
(i
).dx
+ .8 * Rnd - .4 Else Worms
(i
).dy
= Worms
(i
).dy
+ .8 * Rnd - .4 If Abs(Worms
(i
).dx
) > 2 Then Worms
(i
).dx
= Worms
(i
).dx
* .5 If Abs(Worms
(i
).dy
) > 2 Then Worms
(i
).dy
= Worms
(i
).dy
* .5 x = Worms(i).x + Worms(i).dx * 2.0: y = Worms(i).y + Worms(i).dy * 2.0
good = -1
If x
>= WormYard.x
+ 6 And x
<= WormYard.x
+ WormYard.w
- 6 Then If y
>= WormYard.y
+ 6 And y
<= WormYard.y
+ WormYard.h
- 6 Then good = 0
good = 0
If good
= 0 Then 'turn the worm 'Beep: Locate 1, 1: Print x, y
'Input "enter >", w$
Worms(i).dx = -Worms(i).dx
Worms(i).dy = -Worms(i).dy
x(i, j) = x(i, j - 1): y(i, j) = y(i, j - 1)
If x
(i
, j
) And y
(i
, j
) Then drawBall x
(i
, j
), y
(i
, j
), 6, Worms
(i
).c
x(i, 1) = x: y(i, 1) = y
drawBall x(i, 1), y(i, 1), 6, Worms(i).c
Worms(i).x = x: Worms(i).y = y
Sub NewWormYard
(x
, y
, w
, h
) WormYard.x = x: WormYard.y = y: WormYard.w = w: WormYard.h = h
NewWorm i
'pick which side to enter, for dx, dy generally headed towards inner screen
Worms(i).x = WormYard.x + 6
Worms
(i
).y
= WormYard.y
+ 6 + (WormYard.h
- 12) * Rnd Worms(i).dx = 1
Worms(i).dy = 0
Worms(i).x = WormYard.x + WormYard.w - 6
Worms
(i
).y
= WormYard.y
+ 6 + (WormYard.h
- 12) * Rnd Worms(i).dx = -1
Worms(i).dy = 0
Worms(i).y = WormYard.y + 6
Worms
(i
).x
= WormYard.x
+ 6 + (WormYard.w
- 12) * Rnd Worms(i).dx = 0
Worms(i).dy = 1
Worms(i).y = WormYard.y + WormYard.h - 6
Worms
(i
).x
= WormYard.x
+ 6 + (WormYard.w
- 12) * Rnd Worms(i).dx = 0
Worms(i).dy = -1
Worms
(i
).sz
= Int(Rnd * 11) + 10 Worms
(i
).c
= _RGB32(255 - 20 * lev
+ 50, 180 - 15 * lev
, 180 - 15 * lev
) Worms
(i
).c
= _RGB32(255 - 20 * lev
, 180 - 15 * lev
+ 50, 180 - 15 * lev
) Worms
(i
).c
= _RGB32(255 - 20 * lev
, 180 - 15 * lev
, 180 - 15 * lev
+ 20) Worms
(i
).c
= _RGB32(255 - 20 * lev
, 180 - 15 * lev
, 180 - 15 * lev
)
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
f = 1.25 - rr / r
fcirc x
, y
, rr
, _RGB32(rred
* f
, grn
* f
, blu
* f
)