10-16-2022, 08:07 PM
(This post was last modified: 10-16-2022, 08:43 PM by James D Jarvis.)
how's this working out? Not perfect but getting closer:
EDIT: added a really awkward paddle. WASD
EDIT: added a really awkward paddle. WASD
Code: (Select All)
'caveball 2.2
ms& = _NewImage(800, 600, 32)
border& = _NewImage(800, 600, 32)
Randomize Timer
Dim c1 As Long
Dim klr As _Unsigned Long
Dim empty As _Unsigned Long
Screen border&
c1 = _RGB(255, 255, 255)
x1 = 50
y1 = 50
flag = 0
While flag = 0
x2 = (Rnd * 80) + 80 + x1
If x2 > 750 Then
x2 = 750
flag = 1
End If
y2 = Rnd * 60 + 20
fatline x1, y1, x2, y2, 2, c1
x1 = x2
y1 = y2
Wend
flag = 0
While flag = 0
y2 = (Rnd * 80) + 80 + y1
If y2 > 550 Then
y2 = 550
flag = 1
End If
x2 = 750 - (Rnd * 60 + 20)
fatline x1, y1, x2, y2, 2, c1
x1 = x2
y1 = y2
Wend
flag = 0
While flag = 0
x2 = x1 - ((Rnd * 80) + 80)
If x2 < 50 Then
x2 = 50
flag = 1
End If
y2 = 550 - (Rnd * 60 + 20)
fatline x1, y1, x2, y2, 2, c1
x1 = x2
y1 = y2
Wend
flag = 0
While flag = 0
y2 = y1 - ((Rnd * 80) + 80)
If y2 < 50 Then
y2 = 50
flag = 1
End If
x2 = Rnd * 60 + 20
If flag = 1 Then x2 = 50
fatline x1, y1, x2, y2, 2, c1
x1 = x2
y1 = y2
Wend
paddlex = 100
paddley = 100
pang = 0
px2 = paddlex + 10 * Cos(0.01745329 * pang)
py2 = paddley + 10 * Cos(0.01745329 * pang)
bx = 400
by = 400
speed = 2
bang = Int(Rnd * 360)
Screen ms&
Do
_Limit 60
Cls
_PutImage , border&, ms&
px1 = paddlex - 30 * Cos(0.01745329 * pang)
py1 = paddley - 30 * Sin(0.01745329 * pang)
px2 = paddlex + 30 * Cos(0.01745329 * pang)
py2 = paddley + 30 * Sin(0.01745329 * pang)
fatline px1, py1, px2, py2, 4, c1
Select Case kk$
Case "w"
paddlex = paddlex + 6 * Cos(0.01745329 * (pang))
paddley = paddley + 6 * Sin(0.01745329 * (pang))
Case "s"
paddlex = paddlex - 6 * Cos(0.01745329 * (pang))
paddley = paddley - 6 * Sin(0.01745329 * (pang))
Case "a"
pang = pang - 5
Case "d"
pang = pang + 5
End Select
xchange = speed * Cos(0.01745329 * bang)
ychange = speed * Sin(0.01745329 * bang)
bm = 0
For bv = bang - 90 To bang + 90 Step 3
checkx = bx + (12) * Cos(0.01745329 * bv)
checky = by + (12) * Sin(0.01745329 * bv)
klr = Point(checkx, checky)
If klr = c1 And bm = 0 Then
xchange = (xchange * -1) * Cos(0.01745329 * (180 - bv))
ychange = (ychange * -1) * Sin(0.01745329 * (180 - bv))
bx = bx + xchange
by = by + ychange
bang = 180 + bv
bm = bv
klr = 0
End If
Next
bx = bx + xchange
by = by + ychange
Circle (bx, by), 10, c1
_Display
kk$ = InKey$
Loop Until kk$ = Chr$(27)
Sub circleBF (cx As Long, cy As Long, r As Long, klr As _Unsigned Long)
rsqrd = r * r
y = -r
While y <= r
x = Sqr(rsqrd - y * y)
Line (cx - x, cy + y)-(cx + x, cy + y), klr, BF
y = y + 1
Wend
End Sub
Sub fatline (x0, y0, x1, y1, r, klr As _Unsigned Long)
If Abs(y1 - y0) < Abs(x1 - x0) Then
If x0 > x1 Then
lineLow x1, y1, x0, y0, r, klr
Else
lineLow x0, y0, x1, y1, r, klr
End If
Else
If y0 > y1 Then
lineHigh x1, y1, x0, y0, r, klr
Else
lineHigh x0, y0, x1, y1, r, klr
End If
End If
End Sub
Sub lineLow (x0, y0, x1, y1, r, klr As _Unsigned Long)
dx = x1 - x0
dy = y1 - y0
yi = 1
If dy < 0 Then
yi = -1
dy = -dy
End If
'D = (2 * dy) - dx
d = (dy + dy) - dx
y = y0
For x = x0 To x1
circleBF x, y, r, klr
If d > 0 Then
y = y + yi
' D = D + (2 * (dy - dx))
d = d + ((dy - dx) + (dy - dx))
Else
' D = D + 2 * dy
d = d + dy + dy
End If
Next x
End Sub
Sub lineHigh (x0, y0, x1, y1, r, klr As _Unsigned Long)
dx = x1 - x0
dy = y1 - y0
xi = 1
If dx < 0 Then
xi = -1
dx = -dx
End If
' D = (2 * dx) - dy
D = (dx + dx) - dy
x = x0
For y = y0 To y1
circleBF x, y, r, klr
If D > 0 Then
x = x + xi
' D = D + (2 * (dx - dy))
D = D + ((dx - dy) + (dx - dy))
Else
' D = D + 2 * dx
D = D + dx + dx
End If
Next y
End Sub