Summer LASER Challenge
#27
Sure let's blow the dust off your CPU!

Bolts Star Burst!
Code: (Select All)
Option _Explicit
_Title "Bolts Star Burst" ' b+ 2023-07-15  started as Bloom.bas
' 2023-07-16 rename to Bolt from Bloom and comment better and make more generic
' 2023-07-17 Bolts 2: move the bolt down the BoltLine by speed like a bullet.
' 2023-07-18 Bolts 2 tweaks: tweak numbers for more transparency and then more solid little rays.
' But Mark how do we detect hits from lasers, OK added x, y, r to track the current location
' and radius of the laser bolt.
' BoltLine: Imagine a line with a thickness at one end and a different thickness at then other.
' Colored like I imagine a Laser beam yellowish white core with bluish tinge around the edges.
' Now draw sections of that BoltLine according to the frames of display in main loop.
' This is a demo of that!
' Bolts 3 Colorized
' 2023-07-20 Bolts Star Burst

Const NBolts = 200 ' max number of Bolt slots available, just like bullet science
Const PulseLength = 80 ' length of light pulses as they travel down BoltLine
Type BoltType 'see NewBolt for description of these variables
    As Single x1, y1, r1, dx, dy, dr, d, frames, frame, active, speedX, speedY, x, y, r, red, grn, blu
End Type
Dim Shared Bolts(1 To NBolts) As BoltType
Dim i, back, minR, d, cx, cy, ang

Randomize Timer
Screen _NewImage(1200, 700, 32)
_ScreenMove 50, 20
back = _NewImage(_Width, _Height, 32)
For i = 1 To 150
    Line (Rnd * _Width, Rnd * _Height)-Step(Rnd * 100, Rnd * 70), _RGB32(Rnd * 100, Rnd * 100, Rnd * 100), BF
Next i
_PutImage , 0, back
cx = .5 * _Width: cy = .5 * _Height ' center
minR = _Hypot(cx, cy)
Do
    Cls
    _PutImage , back, 0
    For i = 1 To NBolts
        If Bolts(i).active Then
            DrawBolt (i) ' draws the bolts still active
        Else
            d = Rnd * minR + 10: ang = Rnd * _Pi(2)
            NewBolt cx, cy, 30, cx + d * Cos(ang), cy + d * Sin(ang), 1, 30
        End If
    Next '                                     according to what frame they are on
    _Display
    _Limit 60
Loop Until _KeyDown(27)

Sub NewBolt (x1, y1, r1, x2, y2, r2, ppfSpeed) ' sets up for the DrawBolt Sub
    'x1, y1, r1 = location and radius at start of beam
    'x2, y2, r2 = target location and radius at beam end
    'ppfSpeed = how many pixels per frame in main loop  to transverse
    Dim i, ang
    For i = 1 To NBolts
        If Bolts(i).active = 0 Then
            Bolts(i).x1 = x1 ' start x, y, radius
            Bolts(i).y1 = y1
            Bolts(i).r1 = r1
            Bolts(i).active = 1 ' bolt is activated
            Bolts(i).dx = x2 - x1 ' drawing the bolt line and thickness
            Bolts(i).dy = y2 - y1 ' as it changes from x1, y1, r1 to x2, y2, r2
            Bolts(i).dr = r2 - r1
            Bolts(i).d = _Hypot(Bolts(i).dx, Bolts(i).dy) ' distance of the bolt line
            Bolts(i).frames = Int(Bolts(i).d / ppfSpeed) + 1 ' divide that distance by pulse = PulseLength
            Bolts(i).frame = 1 ' set the frame you are on to locate the pulse in drawing
            ang = _Atan2(y2 - y1, x2 - x1)
            Bolts(i).speedX = ppfSpeed * Cos(ang)
            Bolts(i).speedY = ppfSpeed * Sin(ang)
            Bolts(i).x = x1 ' track leading x, y, r of current bolt for collision detection
            Bolts(i).y = y1
            Bolts(i).r = r1
            Bolts(i).red = Rnd ^ 2
            Bolts(i).grn = Rnd ^ 2
            Bolts(i).blu = Rnd ^ 2
            Exit Sub
        End If
    Next
End Sub

Sub DrawBolt (idx) ' needs FCirc (Fill Circle) routine
    ' This sub draw a pulse of light on the BoltLine from .x1, .y1 on the way to .x2, .y2
    ' The start radius is .r1 and the end radius is .r2 and the pulse is thinned or thickened
    ' as it proceeds down the boltLine.
    'All this is setup in the NewBolt Sub and uses DIM Shared Bolts() as BoltType and Constants
    ' NBolts = max amount of activated Bolt "slots" available and PulseLength the length of
    ' BoltLine sections to draw in each frame.
    Dim i, d, stepper
    ' new lead position for tracking location for collision detection
    Bolts(idx).x = Bolts(idx).x1 + Bolts(idx).speedX * Bolts(idx).frame
    Bolts(idx).y = Bolts(idx).y1 + Bolts(idx).speedY * Bolts(idx).frame
    d = _Hypot(Bolts(idx).x1 - Bolts(idx).x, Bolts(idx).y1 - Bolts(idx).y)
    If Abs(Bolts(idx).dr / PulseLength) < .2 Then stepper = .5 Else stepper = 2
    Bolts(idx).r = Bolts(idx).r1 + d * Bolts(idx).dr / Bolts(idx).d
    For i = d - PulseLength To d Step stepper
        If i >= 0 Then
        FCirc Bolts(idx).x1 + i * Bolts(idx).dx / Bolts(idx).d, Bolts(idx).y1 + i * Bolts(idx).dy _
        / Bolts(idx).d, Bolts(idx).r1 + i * Bolts(idx).dr / Bolts(idx).d, &H05DDDDFF
        FCirc Bolts(idx).x1 + i * Bolts(idx).dx / Bolts(idx).d, Bolts(idx).y1 + i * Bolts(idx).dy _
        / Bolts(idx).d, .65 * Bolts(idx).r1 + i * .65 * Bolts(idx).dr / Bolts(idx).d, _
        Plasma~&(Bolts(idx).red, Bolts(idx).grn, Bolts(idx).blu, i)
        End If
    Next
    Bolts(idx).frame = Bolts(idx).frame + 1 ' update frame number
    If Bolts(idx).frame > Bolts(idx).frames Then Bolts(idx).active = 0 ' job done!
End Sub

Function Plasma~& (r, g, b, cN)
    Plasma~& = _RGB32(127 + 127 * Sin(r * cN), 127 + 127 * Sin(g * cN), 127 + 127 * Sin(b * cN), 20)
End Function

Sub FCirc (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
    Dim Radius As Integer, RadiusError As Integer
    Dim X As Integer, Y As Integer
    Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
    If Radius = 0 Then PSet (CX, CY), C: Exit Sub
    Line (CX - X, CY)-(CX + X, CY), C, 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), C, BF
                Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
            End If
            X = X - 1
            RadiusError = RadiusError - X * 2
        End If
        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
    Wend
End Sub

   
b = b + ...
Reply


Messages In This Thread
Summer LASER Challenge - by TerryRitchie - 07-15-2023, 07:32 PM
RE: Summer LASER Challenge - by bplus - 07-15-2023, 08:10 PM
RE: Summer LASER Challenge - by TerryRitchie - 07-15-2023, 09:48 PM
RE: Summer LASER Challenge - by justsomeguy - 07-15-2023, 09:27 PM
RE: Summer LASER Challenge - by TerryRitchie - 07-15-2023, 09:49 PM
RE: Summer LASER Challenge - by Dav - 07-15-2023, 11:44 PM
RE: Summer LASER Challenge - by TerryRitchie - 07-16-2023, 01:34 AM
RE: Summer LASER Challenge - by GareBear - 07-15-2023, 11:54 PM
RE: Summer LASER Challenge - by Dav - 07-16-2023, 01:42 AM
RE: Summer LASER Challenge - by TerryRitchie - 07-16-2023, 01:58 AM
RE: Summer LASER Challenge - by bplus - 07-16-2023, 02:34 AM
RE: Summer LASER Challenge - by mnrvovrfc - 07-16-2023, 03:35 AM
RE: Summer LASER Challenge - by bplus - 07-16-2023, 02:21 PM
RE: Summer LASER Challenge - by TerryRitchie - 07-17-2023, 02:12 AM
RE: Summer LASER Challenge - by bplus - 07-17-2023, 02:47 PM
RE: Summer LASER Challenge - by TerryRitchie - 07-17-2023, 02:58 PM
RE: Summer LASER Challenge - by SpriggsySpriggs - 07-17-2023, 03:29 PM
RE: Summer LASER Challenge - by TerryRitchie - 07-17-2023, 04:51 PM
RE: Summer LASER Challenge - by bplus - 07-17-2023, 04:22 PM
RE: Summer LASER Challenge - by TerryRitchie - 07-17-2023, 04:34 PM
RE: Summer LASER Challenge - by bplus - 07-17-2023, 05:00 PM
RE: Summer LASER Challenge - by bplus - 07-17-2023, 06:38 PM
RE: Summer LASER Challenge - by bplus - 07-17-2023, 06:43 PM
RE: Summer LASER Challenge - by bplus - 07-18-2023, 02:58 PM
RE: Summer LASER Challenge - by bplus - 07-19-2023, 01:14 AM
RE: Summer LASER Challenge - by James D Jarvis - 07-20-2023, 02:28 AM
RE: Summer LASER Challenge - by bplus - 07-20-2023, 12:44 PM
RE: Summer LASER Challenge - by Dav - 07-21-2023, 03:00 AM
RE: Summer LASER Challenge - by bplus - 07-21-2023, 03:56 PM
RE: Summer LASER Challenge - by grymmjack - 07-21-2023, 04:46 PM
RE: Summer LASER Challenge - by bplus - 07-21-2023, 04:59 PM
RE: Summer LASER Challenge - by SierraKen - 07-27-2023, 02:38 AM
RE: Summer LASER Challenge - by bplus - 07-27-2023, 01:49 PM
RE: Summer LASER Challenge - by SierraKen - 07-27-2023, 02:41 AM
RE: Summer LASER Challenge - by TerryRitchie - 07-27-2023, 11:56 PM
RE: Summer LASER Challenge - by Dav - 07-28-2023, 12:48 AM
RE: Summer LASER Challenge - by bplus - 07-28-2023, 01:20 PM
RE: Summer LASER Challenge - by dbox - 07-28-2023, 06:56 PM
RE: Summer LASER Challenge - by bplus - 07-28-2023, 09:23 PM
RE: Summer LASER Challenge - by SierraKen - 07-29-2023, 10:13 PM
RE: Summer LASER Challenge - by OldMoses - 07-30-2023, 01:02 PM
RE: Summer LASER Challenge - by bplus - 07-30-2023, 02:28 PM
RE: Summer LASER Challenge - by bplus - 07-30-2023, 06:57 PM



Users browsing this thread: 4 Guest(s)