Another conversion, this time from Cobra to BlitzMax NG

Started by SToS, November 15, 2024, 20:57:14

Previous topic - Next topic

SToS

I am currently attempting to convert a more complicated shooter from PureBASIC to BlitzMax NG and while I'm taking a break I thought I'd just convert something whimsical.

Code: BASIC
SuperStrict

' Title: Wobbly Draw Thing
' Original Cobra code by Fluke
'

Type TPoint
    Field x:Int ' x position
    Field y:Int ' y position
    Field c:Int ' Connected To the previous point?
End Type

Global mx:Int, my:Int, total:Int, x:Int, y:Int, x2:Int, y2:Int
Global r:Float, t:Float, tS:Float
Global LBdown:Int

Global list_of_points:TList = CreateList()
Global point:TPoint = New TPoint

Graphics 800, 600, 0

' Create a blank dummy point For the start of the list. We need this as the
' main loop always checks To see If a drawn point is connected To a
' previous point in the list.
ListAddLast(list_of_points, point)

' At the start, nothing is wobbling.
r = 0.0
t = 0.0

Repeat
    ' Store the current mouse coordinates so that they are consistant
    ' For this iteration of the main loop.
    mx = MouseX()
    my = MouseY()

    If MouseDown(1) Then
        If (mx <> point.x) And (my <> point.y)
            ' If the mouse pointer is at a New position, Then add a New
            ' point To the list.
            point = New TPoint
            point.x = mx
            point.y = my

            ' If the LMB was held down before Then the New point needs To
            ' be connected To the previous point.
            If LBdown = True Then
                point.c = True
            EndIf

	    ListAddLast(list_of_points, point)
            ' Flag that the LMB is currently held down.
            LBdown = True
        EndIf       
    Else
        ' The mouse button isn't held, so flag that.
        LBdown = False 
    EndIf           

    ' If the RMB is pressed, reset the radius For the wobble effect.
    If MouseDown(2) Then
	r = 16
    EndIf

    ' Clear the Screen
    Cls
               
    ' Loop through the points And draw lines between them.
    t = tS
    For point = EachIn list_of_points
        x2 = r * Sin(t) + point.x
        y2 = r * Cos(t) + point.y

        ' A line is only drawn If the current point is connected To the
        ' previous point.
        If point.c = True Then
            SetColor(255, 255, 255)
	    DrawLine(x, y, x2, y2)
	EndIf

        ' Store the current x And y point so we can draw To it after
        ' calculating the Next point.
        x = x2
        y = y2

        ' Increase the angle For the Next point on the list.
        t :+ 16
    Next

    ' Increase the starting angle of the wobble For the Next time through
    ' the loop.
    tS :+ 1

    ' Decrease the radius of the wobble And make sure it stops at zero.
    r :- 0.01
    If r < 0.0 Then
	r = 0.0
    EndIf

    ' Some simple instructions And Then Flip To the screen.
    DrawText("Left mouse button To draw, Right mouse button To wobble!", 0, 0)
    Flip
Until KeyHit(KEY_ESCAPE) Or AppTerminate()
End

It is what it is and nothing more. No contest for OOP/Functional/Procedural or any kind of best practice. It's just for fun!

Baggey

Keep em coming STOS. This is just the sort of thing BlitmaxNG need's.

This is what BlitzMaxNG sadly lacks lots of nice worked examples so people can learn and play to there hearts content. Tweaking and altering things, and most importantly Learning from it. ;)

Looking forward to Cobra already  ;D

QuoteIt's just for fun!

Kind Regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

RemiD