3 hours ago
SaucerZap. A very simple mod of a QBJS example. move your saucer with WASD, point and click with mouse to shoot.
[qbjs]'Option _Explicit
'_Title "Saucer Zap" ' for QBJS by James D. Jarvis
' A mod of Plasma Laser Canon demo prep for GUI 2020-11-11
Screen _NewImage(1200, 600, 32)
Randomize Timer
Dim Shared As Long ShipLights
Dim Shared As _Unsigned Long ShipColor
Dim As Long cx, cy, mx, my, mb, sx, sy, ix, iy
Dim As Single ma, md, dx, dy, damage
Dim targetx(10), targety(10), targetvx(10), targetvy(10), targetalive(10)
Dim targetcolor(10) As _Unsigned Long
Dim ik$
cy = _Height / 2: cx = _Width / 2
ShipColor = &HFF3366AA
' _MouseHide '??? not supported and bad idea anyway
sx = cx
sy = cy
For x = 1 To 10
Do
targetx(x) = Int(Rnd * _Width)
targety(x) = Int(Rnd * _Height)
targetvx(x) = Int(Rnd * 2) - Int(Rnd * 2)
targetvy(x) = Int(Rnd * 2) - Int(Rnd * 2)
targetcolor(x) = _RGB32(Int(100 + Rnd * 150), Int(100 + Rnd * 150), Int(100 + Rnd * 150))
targetalive(x) = 10
Loop Until Int(targetx(x) / 30) <> Int(sx / 20) And Int(targety(x) / 30) <> Int(sy / 30)
Next x
_FullScreen
Do
_Limit 300
Cls
ik$ = InKey$
While _MouseInput: Wend
mx = _MouseX: my = _MouseY: mb = _MouseButton(1)
Select Case ik$
Case "W", "w"
iy = iy - 4
ix = 0
Case "A", "a"
iy = 0
ix = ix - 4
Case "S", "s"
iy = iy + 4
ix = 0
Case "D", "d"
iy = 0
ix = ix + 2
End Select
dx = mx - sx ' ship avoids collision with mouse
dy = my - sy
ma = _Atan2(dy, dx)
md = Sqr(dy * dy + dx * dx)
If md < 80 Then md = 80
'sx = cx + md * Cos(ma + 3.1415)
' sy = cy + md * Sin(ma + 3.1415)
sx = sx + ix
sy = sy + iy
ix = ix / 2
iy = iy / 2
drawShip sx, sy, ShipColor
If mb Then
If md < 301 Then PLC sx, sy, mx, my, 10 ' Fire! aaa w
ShipColor = _RGB32(Int(Rnd * 100) + 150, Int(Rnd * 100) + 150, Int(Rnd * 100) + 150)
For x = 1 To 10
If Int(targetx(x) / 20) = Int(mx / 20) And Int(targety(x) / 20) = Int(my / 20) And targetalive(x) > 0 Then
damage = 1 + Abs((10 - Int(Rnd * Sqr(md))))
targetalive(x) = targetalive(x) - damage
cdiv = (20 - targetalive(x)) / 2
targetcolor(x) = _RGB32(Int(Rnd * (100 / cdiv)) + (150 / cdiv), Int(Rnd * (100 / cdiv)) + (150 / cdiv), Int(Rnd * (100 / cdiv)) + (150 / cdiv))
Beep
If targetalive(x) <= 0 Then score = score + 1
End If
Next x
End If
For x = 1 To 10
targetx(x) = targetx(x) + targetvx(x)
targety(x) = targety(x) + targetvy(x)
If Int(targetx(x) / 30) = Int(sx / 30) And Int(targety(x) / 20) = Int(sy / 20) And targetalive(x) > 0 Then
_PrintString (sx, sy), "BOOM!!!!"
killflag = 13
End If
If Rnd * 100 < 30 Then
Select Case Int(Rnd * 20)
Case 1, 2, 3
'seek ship
If targetx(x) < sx Then targetvx(x) = 2
If targetx(x) > sx Then targetvx(x) = -2
If targety(x) < sx Then targetvy(x) = 2
If targety(x) > sx Then targetvy(x) = -2
Case 4, 5
'flee ship
If targetx(x) < sx Then targetvx(x) = -2
If targetx(x) > sx Then targetvx(x) = 2
If targety(x) < sx Then targetvy(x) = -2
If targety(x) > sx Then targetvy(x) = 2
Case 7
'rando change
targetvy(x) = targetvy(x) + Int(Rnd * 3) - Int(Rnd * 3)
targetvx(x) = targetvx(x) + Int(Rnd * 3) - Int(Rnd * 3)
End Select
End If
If targetx(x) < -20 Then targetx(x) = _Width
If targetx(x) > _Width + 20 Then targetx(x) = 0
If targety(x) < -20 Then targety(x) = _Height
If targety(x) > _Height + 20 Then targety(x) = 0
If targetalive(x) > 0 Then drawtarget targetx(x), targety(x), targetcolor(x)
Next x
_Display
_Limit 60
Loop Until _KeyDown(27) Or killflag = 13
_AutoDisplay
_Delay 1
Cls
Color _RGB32(255, 255, 255)
Print
Print "GAME OVER"
Print
Print "Score "; (score * score) * 1000
Sleep
Sub PLC (baseX, baseY, targetX, targetY, targetR) ' PLC for PlasmaLaserCannon
Dim r, g, b, hp, ta, dist, dr, x, y, c, rr
r = Rnd ^ 2 * Rnd: g = Rnd ^ 2 * Rnd: b = Rnd ^ 2 * Rnd: hp = _Pi(.5) ' red, green, blue, half pi
ta = _Atan2(targetY - baseY, targetX - baseX) ' angle of target to cannon base
dist = _Hypot(targetY - baseY, targetX - baseX) ' distance cannon to target
dr = targetR / dist
For r = 0 To dist Step .25
x = baseX + r * Cos(ta)
y = baseY + r * Sin(ta)
c = c + .3
Color _RGB32(128 + 127 * Sin(r * c), 128 + 127 * Sin(g * c), 128 + 127 * Sin(b * c))
fcirc x, y, dr * r
Next
For rr = dr * r To 0 Step -.5
c = c + 1
Color _RGB32(128 + 127 * Sin(r * c), 128 + 127 * Sin(g * c), 128 + 127 * Sin(b * c))
fcirc x, y, rr
Next
End Sub
Sub drawShip (x, y, colr As _Unsigned Long) 'shipType collisions same as circle x, y radius = 30
' shared here ShipLights
Dim light As Long, r As Long, g As Long, b As Long
r = _Red32(colr): g = _Green32(colr): b = _Blue32(colr)
Color _RGB32(r, g - 120, b - 100)
fEllipse x, y, 6, 15
Color _RGB32(r, g - 60, b - 50)
fEllipse x, y, 18, 11
Color _RGB32(r, g, b)
fEllipse x, y, 30, 7
For light = 0 To 5
Color _RGB32(ShipLights * 50, ShipLights * 50, ShipLights * 50)
fcirc x - 30 + 11 * light + ShipLights, y, 1
Next
ShipLights = ShipLights + 1
If ShipLights > 5 Then ShipLights = 0
End Sub
Sub drawtarget (x, y, colr As _Unsigned Long) 'shipType collisions same as circle x, y radius = 30
' shared here ShipLights
Dim light As Long, r As Long, g As Long, b As Long
r = _Red32(colr): g = _Green32(colr): b = _Blue32(colr)
Color _RGB32(r, g - 120, b - 100)
fEllipse x, y, 3, 15
Color _RGB32(r, g - 60, b - 50)
fEllipse x, y, 9, 11
Color _RGB32(r, g, b)
fEllipse x, y, 15, 7
For light = 1 To 3
Color _RGB32(ShipLights * 50, ShipLights * 50, ShipLights * 50)
fcirc x - 30 + 11 * light + ShipLights, y, 1
Next
ShipLights = ShipLights + 1
If ShipLights > 5 Then ShipLights = 0
End Sub
' these do work in QBJS without mod see le bombe
Sub fcirc (CX As Long, CY As Long, R As Long)
Dim subRadius As Long, RadiusError As Long
Dim X As Long, Y As Long
subRadius = Abs(R)
RadiusError = -subRadius
X = subRadius
Y = 0
If subRadius = 0 Then PSet (CX, CY): Exit Sub
' Draw the middle span here so we don't draw it twice in the main loop,
' which would be a problem with blending turned on.
Line (CX - X, CY)-(CX + X, CY), , BF
While X > Y
RadiusError = RadiusError + Y * 2 + 1
If RadiusError >= 0 Then
If X <> Y + 1 Then
Line (CX - Y, CY - X)-(CX + Y, CY - X), , BF
Line (CX - Y, CY + X)-(CX + Y, CY + X), , BF
End If
X = X - 1
RadiusError = RadiusError - X * 2
End If
Y = Y + 1
Line (CX - X, CY - Y)-(CX + X, CY - Y), , BF
Line (CX - X, CY + Y)-(CX + X, CY + Y), , BF
Wend
End Sub
Sub fEllipse (CX As Long, CY As Long, xRadius As Long, yRadius As Long)
Dim scale As Single, x As Long, y As Long
scale = yRadius / xRadius
Line (CX, CY - yRadius)-(CX, CY + yRadius), , BF
For x = 1 To xRadius
y = scale * Sqr(xRadius * xRadius - x * x)
Line (CX + x, CY - y)-(CX + x, CY + y), , BF
Line (CX - x, CY - y)-(CX - x, CY + y), , BF
Next
End Sub[/qbjs]
[qbjs]'Option _Explicit
'_Title "Saucer Zap" ' for QBJS by James D. Jarvis
' A mod of Plasma Laser Canon demo prep for GUI 2020-11-11
Screen _NewImage(1200, 600, 32)
Randomize Timer
Dim Shared As Long ShipLights
Dim Shared As _Unsigned Long ShipColor
Dim As Long cx, cy, mx, my, mb, sx, sy, ix, iy
Dim As Single ma, md, dx, dy, damage
Dim targetx(10), targety(10), targetvx(10), targetvy(10), targetalive(10)
Dim targetcolor(10) As _Unsigned Long
Dim ik$
cy = _Height / 2: cx = _Width / 2
ShipColor = &HFF3366AA
' _MouseHide '??? not supported and bad idea anyway
sx = cx
sy = cy
For x = 1 To 10
Do
targetx(x) = Int(Rnd * _Width)
targety(x) = Int(Rnd * _Height)
targetvx(x) = Int(Rnd * 2) - Int(Rnd * 2)
targetvy(x) = Int(Rnd * 2) - Int(Rnd * 2)
targetcolor(x) = _RGB32(Int(100 + Rnd * 150), Int(100 + Rnd * 150), Int(100 + Rnd * 150))
targetalive(x) = 10
Loop Until Int(targetx(x) / 30) <> Int(sx / 20) And Int(targety(x) / 30) <> Int(sy / 30)
Next x
_FullScreen
Do
_Limit 300
Cls
ik$ = InKey$
While _MouseInput: Wend
mx = _MouseX: my = _MouseY: mb = _MouseButton(1)
Select Case ik$
Case "W", "w"
iy = iy - 4
ix = 0
Case "A", "a"
iy = 0
ix = ix - 4
Case "S", "s"
iy = iy + 4
ix = 0
Case "D", "d"
iy = 0
ix = ix + 2
End Select
dx = mx - sx ' ship avoids collision with mouse
dy = my - sy
ma = _Atan2(dy, dx)
md = Sqr(dy * dy + dx * dx)
If md < 80 Then md = 80
'sx = cx + md * Cos(ma + 3.1415)
' sy = cy + md * Sin(ma + 3.1415)
sx = sx + ix
sy = sy + iy
ix = ix / 2
iy = iy / 2
drawShip sx, sy, ShipColor
If mb Then
If md < 301 Then PLC sx, sy, mx, my, 10 ' Fire! aaa w
ShipColor = _RGB32(Int(Rnd * 100) + 150, Int(Rnd * 100) + 150, Int(Rnd * 100) + 150)
For x = 1 To 10
If Int(targetx(x) / 20) = Int(mx / 20) And Int(targety(x) / 20) = Int(my / 20) And targetalive(x) > 0 Then
damage = 1 + Abs((10 - Int(Rnd * Sqr(md))))
targetalive(x) = targetalive(x) - damage
cdiv = (20 - targetalive(x)) / 2
targetcolor(x) = _RGB32(Int(Rnd * (100 / cdiv)) + (150 / cdiv), Int(Rnd * (100 / cdiv)) + (150 / cdiv), Int(Rnd * (100 / cdiv)) + (150 / cdiv))
Beep
If targetalive(x) <= 0 Then score = score + 1
End If
Next x
End If
For x = 1 To 10
targetx(x) = targetx(x) + targetvx(x)
targety(x) = targety(x) + targetvy(x)
If Int(targetx(x) / 30) = Int(sx / 30) And Int(targety(x) / 20) = Int(sy / 20) And targetalive(x) > 0 Then
_PrintString (sx, sy), "BOOM!!!!"
killflag = 13
End If
If Rnd * 100 < 30 Then
Select Case Int(Rnd * 20)
Case 1, 2, 3
'seek ship
If targetx(x) < sx Then targetvx(x) = 2
If targetx(x) > sx Then targetvx(x) = -2
If targety(x) < sx Then targetvy(x) = 2
If targety(x) > sx Then targetvy(x) = -2
Case 4, 5
'flee ship
If targetx(x) < sx Then targetvx(x) = -2
If targetx(x) > sx Then targetvx(x) = 2
If targety(x) < sx Then targetvy(x) = -2
If targety(x) > sx Then targetvy(x) = 2
Case 7
'rando change
targetvy(x) = targetvy(x) + Int(Rnd * 3) - Int(Rnd * 3)
targetvx(x) = targetvx(x) + Int(Rnd * 3) - Int(Rnd * 3)
End Select
End If
If targetx(x) < -20 Then targetx(x) = _Width
If targetx(x) > _Width + 20 Then targetx(x) = 0
If targety(x) < -20 Then targety(x) = _Height
If targety(x) > _Height + 20 Then targety(x) = 0
If targetalive(x) > 0 Then drawtarget targetx(x), targety(x), targetcolor(x)
Next x
_Display
_Limit 60
Loop Until _KeyDown(27) Or killflag = 13
_AutoDisplay
_Delay 1
Cls
Color _RGB32(255, 255, 255)
Print "GAME OVER"
Print "Score "; (score * score) * 1000
Sleep
Sub PLC (baseX, baseY, targetX, targetY, targetR) ' PLC for PlasmaLaserCannon
Dim r, g, b, hp, ta, dist, dr, x, y, c, rr
r = Rnd ^ 2 * Rnd: g = Rnd ^ 2 * Rnd: b = Rnd ^ 2 * Rnd: hp = _Pi(.5) ' red, green, blue, half pi
ta = _Atan2(targetY - baseY, targetX - baseX) ' angle of target to cannon base
dist = _Hypot(targetY - baseY, targetX - baseX) ' distance cannon to target
dr = targetR / dist
For r = 0 To dist Step .25
x = baseX + r * Cos(ta)
y = baseY + r * Sin(ta)
c = c + .3
Color _RGB32(128 + 127 * Sin(r * c), 128 + 127 * Sin(g * c), 128 + 127 * Sin(b * c))
fcirc x, y, dr * r
Next
For rr = dr * r To 0 Step -.5
c = c + 1
Color _RGB32(128 + 127 * Sin(r * c), 128 + 127 * Sin(g * c), 128 + 127 * Sin(b * c))
fcirc x, y, rr
Next
End Sub
Sub drawShip (x, y, colr As _Unsigned Long) 'shipType collisions same as circle x, y radius = 30
' shared here ShipLights
Dim light As Long, r As Long, g As Long, b As Long
r = _Red32(colr): g = _Green32(colr): b = _Blue32(colr)
Color _RGB32(r, g - 120, b - 100)
fEllipse x, y, 6, 15
Color _RGB32(r, g - 60, b - 50)
fEllipse x, y, 18, 11
Color _RGB32(r, g, b)
fEllipse x, y, 30, 7
For light = 0 To 5
Color _RGB32(ShipLights * 50, ShipLights * 50, ShipLights * 50)
fcirc x - 30 + 11 * light + ShipLights, y, 1
Next
ShipLights = ShipLights + 1
If ShipLights > 5 Then ShipLights = 0
End Sub
Sub drawtarget (x, y, colr As _Unsigned Long) 'shipType collisions same as circle x, y radius = 30
' shared here ShipLights
Dim light As Long, r As Long, g As Long, b As Long
r = _Red32(colr): g = _Green32(colr): b = _Blue32(colr)
Color _RGB32(r, g - 120, b - 100)
fEllipse x, y, 3, 15
Color _RGB32(r, g - 60, b - 50)
fEllipse x, y, 9, 11
Color _RGB32(r, g, b)
fEllipse x, y, 15, 7
For light = 1 To 3
Color _RGB32(ShipLights * 50, ShipLights * 50, ShipLights * 50)
fcirc x - 30 + 11 * light + ShipLights, y, 1
Next
ShipLights = ShipLights + 1
If ShipLights > 5 Then ShipLights = 0
End Sub
' these do work in QBJS without mod see le bombe
Sub fcirc (CX As Long, CY As Long, R As Long)
Dim subRadius As Long, RadiusError As Long
Dim X As Long, Y As Long
subRadius = Abs(R)
RadiusError = -subRadius
X = subRadius
Y = 0
If subRadius = 0 Then PSet (CX, CY): Exit Sub
' Draw the middle span here so we don't draw it twice in the main loop,
' which would be a problem with blending turned on.
Line (CX - X, CY)-(CX + X, CY), , BF
While X > Y
RadiusError = RadiusError + Y * 2 + 1
If RadiusError >= 0 Then
If X <> Y + 1 Then
Line (CX - Y, CY - X)-(CX + Y, CY - X), , BF
Line (CX - Y, CY + X)-(CX + Y, CY + X), , BF
End If
X = X - 1
RadiusError = RadiusError - X * 2
End If
Y = Y + 1
Line (CX - X, CY - Y)-(CX + X, CY - Y), , BF
Line (CX - X, CY + Y)-(CX + X, CY + Y), , BF
Wend
End Sub
Sub fEllipse (CX As Long, CY As Long, xRadius As Long, yRadius As Long)
Dim scale As Single, x As Long, y As Long
scale = yRadius / xRadius
Line (CX, CY - yRadius)-(CX, CY + yRadius), , BF
For x = 1 To xRadius
y = scale * Sqr(xRadius * xRadius - x * x)
Line (CX + x, CY - y)-(CX + x, CY + y), , BF
Line (CX - x, CY - y)-(CX - x, CY + y), , BF
Next
End Sub[/qbjs]