QB64 Phoenix Edition
Arcade Spinner Emulator - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Programs (https://qb64phoenix.com/forum/forumdisplay.php?fid=7)
+---- Thread: Arcade Spinner Emulator (/showthread.php?tid=3085)



Arcade Spinner Emulator - TerryRitchie - 09-29-2024

I want to add arcade spinner control (think Tempest) to the game library I'm working on. I whipped up this proof of concept code to see if emulating a spinner with a mouse was possible. It works fairly well.

Has anyone else approached this? If so please share your code so I can see how you implemented this.

The ZIP below contains the demo code and libraries needed to run the code.

Code: (Select All)
OPTION _EXPLICIT

' Arcade Spinner - proof of concept

'$INCLUDE:'lib_math_sintable.bi'
'$INCLUDE:'lib_math_vec2deg.bi'

CONST CENTERX% = 399 '  x center of screen
CONST CENTERY% = 299 '  y center of screen
DIM Degree AS INTEGER ' current spinner location
DIM v AS TYPE_SPOINT '  vector of mouse deflection
DIM Angle AS INTEGER '  angle of mouse deflection
DIM sAngle AS INTEGER ' shortest angle between spinner location and mouse deflection

SCREEN _NEWIMAGE(800, 600, 32) '                                                    graphics window
_MOUSEHIDE '                                                                        hide the mouse pointer
DO '                                                                                begin spinner demo loop
    CLS '                                                                           clear screen
    _LIMIT 60 '                                                                     60 frames per second
    _MOUSEMOVE CENTERX, CENTERY '                                                   force mouse to center of screen
    WHILE _MOUSEINPUT: WEND '                                                       get latest mouse update
    v.x = _MOUSEX - CENTERX '                                                       get mouse x deflection
    v.y = _MOUSEY - CENTERY '                                                       get mouse y defelction
    IF v.x OR v.y THEN '                                                            was there mouse deflection?
        Angle = MATH_Vec2Deg(v) '                                                   yes, calculate angle of deflection
        sAngle = MATH_ShortAngle(Degree, Angle) '                                   get shortest angle between spinner and deflection
        Degree = INT(MATH_FixDegree(Degree + sAngle * .1)) '                        add the deflection to the spinner value
    END IF
    CIRCLE (CENTERX + MATH_SIN(Degree) * 50, CENTERY - MATH_COS(Degree) * 50), 10 ' draw a circle at spinner location
    LOCATE 2, 2 '                                                                   print instructions
    PRINT "Use the mouse to emulate an arcade spinner"
    LOCATE 4, 2
    PRINT "Press ESC to exit"
    LOCATE 6, 2
    PRINT "Degree ="; Degree; "  "
    _DISPLAY '                                                                      update screen with changes
LOOP UNTIL _KEYDOWN(27) '                                                           leave demo when ESC pressed
SYSTEM '                                                                            return to the operating system

'$INCLUDE:'lib_math_vec2deg.bm'
'$INCLUDE:'lib_math_fixdegree.bm'
'$INCLUDE:'lib_math_shortangle.bm'