Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 308
» Latest member: Donaldvem
» Forum threads: 1,741
» Forum posts: 17,901

Full Statistics

Latest Threads
The QB64 IDE shell
Forum: Utilities
Last Post: JasonPag
09-16-2024, 05:37 PM
» Replies: 9
» Views: 764
Importance regarding Ches...
Forum: Utilities
Last Post: JasonPag
09-01-2024, 06:34 PM
» Replies: 0
» Views: 31
Chess and Analysis and En...
Forum: Utilities
Last Post: JasonPag
08-28-2024, 02:37 PM
» Replies: 0
» Views: 32
DAY 009:_PutImage
Forum: Keyword of the Day!
Last Post: grymmjack
09-02-2023, 02:57 PM
» Replies: 54
» Views: 2,034
Fall Banner Contest?
Forum: Site Suggestions
Last Post: grymmjack
08-31-2023, 11:50 PM
» Replies: 36
» Views: 1,262
ColorPicker - Function th...
Forum: Dav
Last Post: Dav
08-31-2023, 11:04 PM
» Replies: 3
» Views: 316
Goals(1) = New Tile()
Forum: Works in Progress
Last Post: RhoSigma
08-31-2023, 09:45 PM
» Replies: 3
» Views: 127
micro(A)v11
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:14 PM
» Replies: 90
» Views: 3,589
Updating The Single Most ...
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:13 PM
» Replies: 7
» Views: 254
QBJS Image Question
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 05:49 PM
» Replies: 5
» Views: 155

 
  Everything in Degrees instead of Radians
Posted by: bplus - 10-12-2022, 10:31 PM - Forum: Utilities - Replies (23)

Would it make understanding graphics easier to follow, specially employing Sin, Cos and _Atan2?

Here I've converted Sin, Cos, _Atan2, DrawArc and ArrowTo to using Degree Units in the Call to the Sub and internalized all the radian conversions inside the Sub.

Here is main Demo:

Code: (Select All)
' OK let's be rid on the confusion caused by Radians
' by using User Defined Functions SinD and CosD that take Degrees 0 to 360 for whole circle,
' and having replaced _Atan2 by returning an angle in Degrees between 2 points: DAtan2(baseX, baseY, angleToX, angleToY)

_Title "Degrees for everything" 'b+ 2022-10-12
Screen _NewImage(800, 600, 32) ' standard screen size 800 wide, 600 height for quick QB64 Demos with full color potential (the 32)
_ScreenMove 250, 50

cx = _Width / 2 ' middle of the screen point  center x
cy = _Height / 2 ' center y
radius = 250 ' max is 300 for height 600
ArrowTo cx, cy, 0, radius - 3, &HFFFFFFFF
For degrees = 0 To 359 Step 10 ' go around a full circle in degrees in steps of 10 degrees

    ' calculate and draw points around the center of the screen
    x = cx + radius * CosD(degrees) ' use CosD for x dimensions
    y = cy + radius * SinD(degrees) ' use SinD for y dimensions
    Circle (x, y), 1 ' draw bigger points than single pixel

    ' labeling the degree angles before or after the point ?
    If x < cx Then Xoffset = -10 * Len(_Trim$(Str$(degrees))): YOffset = 0
    If x > cx Then Xoffset = 4 * Len(_Trim$(Str$(degrees))): YOffset = 0
    If x = cx Then
        Xoffset = -4 * Len(_Trim$(Str$(degrees)))
        If y > cy Then YOffset = 20 Else YOffset = -20
    End If
    _PrintString (x + Xoffset, y - 8 + YOffset), _Trim$(Str$(degrees))
Next

' save our compass dial to image
dial& = _NewImage(_Width, _Height, 32)
_PutImage , 0, dial& ' screen to dial image stored

' Getting use to seeing angles mouse makes to center of screen
Do
    Cls
    _PutImage , dial&, 0
    While _MouseInput: Wend ' this checks where mouse is right now!
    mx = _MouseX: my = _MouseY: mb1 = _MouseButton(1) ' left mouse down  ' saves mouse status to common variable names
    'lets's the angle in degrees the mouse is to the center of the screen
    dAngle = DAtan2(cx, cy, mx, my)
    Print "The mouse pointer is "; _Trim$(Str$(dAngle)); " Degrees from the screen center." ' then center point is first the mouse point is second
    ArrowTo cx, cy, dAngle, radius - 3, &HFFFFFF00
    drawArc cx, cy, 70, 0, dAngle, &HFFFFFF00
    _Display ' stop the blinking
    _Limit 60 ' only loop 60 times per second
Loop Until _KeyDown(27)


' use angles in degrees units instead of radians (converted inside sub)
Function CosD (degrees)
    ' Note this function uses whatever the default type is, better not be some Integer Type.
    CosD = Cos(_D2R(degrees))
End Function

' use angles in degrees units instead of radians (converted inside sub)
Function SinD (degrees)
    ' Note this function uses whatever the default type is, better not be some Integer Type.
    SinD = Sin(_D2R(degrees))
End Function

' use angles in degrees units instead of radians (converted inside sub)
Function DAtan2 (x1, y1, x2, y2) ' The angle in degrees a 2nd point (x2, y2)  makes to a first point (x1, y1)
    ' Note this function uses whatever the default type is, better not be some Integer Type.
    ' Delta means change between 1 measure and another for example x2 - x1
    deltaX = x2 - x1
    deltaY = y2 - y1
    '  To find the angle point(x2, y2) makes to (x1, y1) in Degrees
    ' Take DegreeAngle = DAtan2(y2 - y1, x2 - x1)
    rtn = _R2D(_Atan2(deltaY, deltaX))
    If rtn < 0 Then DAtan2 = rtn + 360 Else DAtan2 = rtn
End Function

' use angles in degrees units instead of radians (converted inside sub)
Sub ArrowTo (BaseX As Long, BaseY As Long, dAngle As Double, lngth As Long, colr As _Unsigned Long)
    Dim As Long x1, y1, x2, y2, x3, y3
    Dim As Double rAngle
    rAngle = _D2R(dAngle)
    x1 = BaseX + lngth * Cos(rAngle)
    y1 = BaseY + lngth * Sin(rAngle)
    x2 = BaseX + .8 * lngth * Cos(rAngle - _Pi(.05))
    y2 = BaseY + .8 * lngth * Sin(rAngle - _Pi(.05))
    x3 = BaseX + .8 * lngth * Cos(rAngle + _Pi(.05))
    y3 = BaseY + .8 * lngth * Sin(rAngle + _Pi(.05))
    Line (BaseX, BaseY)-(x1, y1), colr
    Line (x1, y1)-(x2, y2), colr
    Line (x1, y1)-(x3, y3), colr
End Sub

' use angles in degrees units instead of radians (converted inside sub)
Sub drawArc (xc, yc, radius, dStart, dMeasure, colr As _Unsigned Long)
    ' xc, yc Center for arc circle
    ' rStart is the Radian Start Angle, use _D2R for conversion from Degrees to Radians
    ' rMeasure is the measure of Arc in Radain units, use _D2R for conversion from Degrees to Radians
    ' Arc will start at rStart and go clockwise around for rMeasure Radians

    Dim rStart, rMeasure, rEnd, stepper, a, x, y
    rStart = _D2R(dStart)
    rMeasure = _D2R(dMeasure)
    rEnd = rStart + rMeasure
    stepper = 1 / radius ' the bigger the radius the smaller  the steps
    For a = rStart To rEnd Step stepper
        x = xc + radius * Cos(a)
        y = yc + radius * Sin(a)
        If a > rStart Then Line -(x, y), colr Else PSet (x, y), colr
    Next
End Sub

   

Print this item

  Building sounds with _SNDPLAYCOPY?
Posted by: james2464 - 10-12-2022, 09:04 PM - Forum: Help Me! - Replies (15)

With QB64PE V3.3 having new parameters for _SNDPLAYCOPY, I wondered if building a sound and saving it was possible.   I mean in the same sort of way that you can build an image by using pset, line, circle etc and then saving it into an image using _PUTIMAGE.   I assume there's no way but I thought I'd ask here, just in case.

For example, here is a sort of doppler/fading beep routine:

Code: (Select All)
Dim blip&
blip& = _SndOpen("G025.mp3")

v1 = 0
switch = 0
Do
    _Limit 8
    If switch = 0 Then
        v1 = v1 + .499
        If v1 > 1 Then
            v1 = 1
            switch = 1
        End If
    Else
        v1 = v1 - .1
        If v1 < 0 Then
            v1 = 0
            switch = 0
            _Delay 2.
        End If
    End If
    _SndPlayCopy blip&, v1
Loop


If you were making a game and wanted to repeat this overall routine, would you just repeat the routine or try to capture it into a sound file and just use that?   Hope I'm making sense.  Just curious what a good strategy would be.



Attached Files
.zip   G025.zip (Size: 22.34 KB / Downloads: 33)
Print this item

Star Recurring Star Power
Posted by: bplus - 10-12-2022, 04:14 PM - Forum: Programs - Replies (11)

Code: (Select All)
_Title "Recurring Star Power" ' b+ 2022-10-12
_Title "Recurring Star Power" ' b+ 2022-10-12
Const xmax = 700
Const ymax = 700
Randomize Timer
Screen _NewImage(xmax, ymax, 32)
_ScreenMove 360, 5
Dim Shared cx, cy, cr, ra, inc
cx = xmax / 2: cy = ymax / 2: cr = ymax / 5.5: inc = _Pi(1 / 360)
Color _RGBA(100, 255, 100, 40), _RGB32(0, 0, 0)
For n = 5 To 5
    a = 0
    ra = _Pi(2) / n
    While 1
        Cls
        levels = 5 '12 - n
        RecurringCircles cx, cy, cr, n, a, levels
        a = a + inc
        _Display
    Wend
    Sleep
    Cls
    RecurringCircles cx, cy, cr, n, 0, levels
    _Display
    _Limit 5
Next

Sub RecurringCircles (x, y, r, n, rao, level)
    star x, y, .4 * r, r, 5, _R2D(_Pi / 10), &HFFFFFF00 ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If level > 0 Then
        For i = 0 To n - 1
            x1 = x + 1.5 * r * Cos(i * ra + rao + _Pi(-.5))
            y1 = y + 1.5 * r * Sin(i * ra + rao + _Pi(-.5))
            RecurringCircles x1, y1, r * .45, n, 2 * rao, level - 1
        Next
    End If
End Sub

Sub star (x, y, rInner, rOuter, nPoints, angleOffset, K As _Unsigned Long)
    ' x, y are same as for circle,
    ' rInner is center circle radius
    ' rOuter is the outer most point of star
    ' nPoints is the number of points,
    ' angleOffset = angle offset IN DEGREES, it will be converted to radians in sub
    ' this is to allow us to spin the polygon of n sides
    Dim pAngle, radAngleOffset, x1, y1, x2, y2, x3, y3, i As Long

    pAngle = _D2R(360 / nPoints): radAngleOffset = _D2R(angleOffset)
    x1 = x + rInner * Cos(radAngleOffset)
    y1 = y + rInner * Sin(radAngleOffset)
    For i = 0 To nPoints - 1
        x2 = x + rOuter * Cos(i * pAngle + radAngleOffset + .5 * pAngle)
        y2 = y + rOuter * Sin(i * pAngle + radAngleOffset + .5 * pAngle)
        x3 = x + rInner * Cos((i + 1) * pAngle + radAngleOffset)
        y3 = y + rInner * Sin((i + 1) * pAngle + radAngleOffset)
        ftri x1, y1, x2, y2, x3, y3, K
        'triangles leaked
        Line (x1, y1)-(x2, y2), K
        Line (x2, y2)-(x3, y3), K
        Line (x3, y3)-(x1, y1), K
        x1 = x3: y1 = y3
    Next
    Paint (x, y), K, K
End Sub

Sub ftri (x1, y1, x2, y2, x3, y3, K As _Unsigned Long)
    Dim D As Long
    Static a&
    D = _Dest
    If a& = 0 Then a& = _NewImage(1, 1, 32)
    _Dest a&
    _DontBlend a& '  '<<<< new 2019-12-16 fix
    PSet (0, 0), K
    _Blend a& '<<<< new 2019-12-16 fix
    _Dest D
    _MapTriangle _Seamless(0, 0)-(0, 0)-(0, 0), a& To(x1, y1)-(x2, y2)-(x3, y3)
End Sub

Complete with the occasional twinkle!

EDIT: remove extra sub

Print this item

  Circular Pattern Using Triangles
Posted by: SierraKen - 10-12-2022, 12:35 AM - Forum: Programs - Replies (2)

I've seen this before, probably from B+, but I wanted to see if I could do it from a fresh start. After a few attempts I figured it out! I used radians on the circle and also saved the points in memory so I could then go to a DO/LOOP to use them how I wish. Smile After many triangles it starts over again with a random color again.

Code: (Select All)
'Circular Pattern Using Triangles by SierraKen
'October 11, 2022
'
'Thanks to B+ and others for the inspiration to make my own.

Dim x(1000), y(1000)
Screen _NewImage(800, 600, 32)
_Title "Circular Pattern Using Triangles by SierraKen - Esc to quit"
For t = 0 To 1000 Step 1 / 3
    x(t) = (Sin(t) * 180) + 400
    y(t) = (Cos(t) * 180) + 300
    Circle (x(t), y(t)), 2, _RGB32(0, 255, 0)
Next t
Randomize Timer
c1 = (Rnd * 155) + 100: c2 = (Rnd * 155) + 100: c3 = (Rnd * 155) + 100
Do
    _Limit 20
    'This uses radians in the circle. I used a radian chart online to get each formula with _PI
    Line (x(7 * (_Pi / 6) + a), y(7 * (_Pi / 6) + a))-(x(11 * (_Pi / 6) + a), y((11 * _Pi / 6) + a)), _RGB32(c1, c2, c3)
    Line (x(11 * (_Pi / 6) + a), y(11 * (_Pi / 6) + a))-(x((_Pi / 2) + a), y((_Pi / 2) + a)), _RGB32(c1, c2, c3)
    Line (x((_Pi / 2) + a), y((_Pi / 2) + a))-(x(7 * (_Pi / 6) + a), y(7 * (_Pi / 6) + a)), _RGB32(c1, c2, c3)
    a = a + 1 / 3
    If a > 300 Then
        a = 0
        Cls
        For tt = 0 To 2000 Step 1 / 3
            xx = (Sin(tt) * 180) + 400
            yy = (Cos(tt) * 180) + 300
            Circle (xx, yy), 2, _RGB32(0, 255, 0)
        Next tt
        c1 = (Rnd * 155) + 100: c2 = (Rnd * 155) + 100: c3 = (Rnd * 155) + 100
    End If
Loop Until InKey$ = Chr$(27)

Print this item

  Creeping Elegance
Posted by: doppler - 10-11-2022, 12:50 PM - Forum: General Discussion - Replies (13)

Creeping Elegance - Yes it's a thing.  It's a description of things which at the request of unqualified people (namely salesmen).  Want things for a project which takes away engineering time and costs money with no immediate return.

Backstory: I used to work for a company, which wrote from bottom up an Operating system which duplicated a major vendor in the field and did one better.  We were the first to do it in software.  Other guy did it in eproms, lots and lots of eproms.  The O/S was called Pick O/S.  It did all the things the fortune 500/100 companies wanted that IBM did not provide.  At the milestone of V2.0, a large number of features was requested in a short time frame and a want to be fixed all known and unknown bugs.  Unknown bugs ??? WTF ???.  Well that set in motion a whole new department dedicated to breaking the O/S.  As time pasted (including the first targeted deadline.)  Bugs, unknown bugs (fixed) and features were being created.  At record pace IMHO.  But an ending was no where in sight.  The department head of engineering could see what was happening "Creeping Elegance".  Fed up with missed deadlines all around.  A little meeting was done.  The outcome from the meeting, Sales was given the task of defining what was "REALLY NEEDED" to complete V2.  A few top level meets later with our largest users.  A shorten list of "needs" was created.  And a longer list of "wants".  V2 went out quicker and customers got a hint at V3.  Everyone was happy with V2.

Bottom line: There was a lot of wasted time trying to give Sales features that customers didn't want or would use.

Here is the question:
Are we getting diverted by Creeping Elegance with QB64pe ?
Should we survey which features to create ?

Don't get me wrong here, I think QB64pe, has a lot of good things and features.  Just my 3 cents here.

Print this item

  Ranking Poker Hands
Posted by: bplus - 10-11-2022, 05:52 AM - Forum: Programs - Replies (21)

Code: (Select All)
' Poker.bas 2022-10-10 b+ try ranking hands
Dim Shared Order$
Order$ = " A 2 3 4 5 6 7 8 910 J Q K"
Dim Shared Deck$(52), rankCount(10)
makeDeck
'For i = 1 To 52
'  Print i, Deck$(i)
'Next
'end

shuffle
'For i = 1 To 52
'  Print i, Deck$(i)
'Next
'end

'make sure we detect rare occurances
h$ = " AC10C JC QC KC"
Print h$; " = "; RankName$(Rank(h$))
h$ = " KS10S JS QS AS"
Print h$; " = "; RankName$(Rank(h$))
h$ = " AC 3C JC QC KC"
Print h$; " = "; RankName$(Rank(h$))
h$ = " AC 2C 3C 4C 5C"
Print h$; " = "; RankName$(Rank(h$))
h$ = " AS 2C 3C 4C 5C"
Print h$; " = "; RankName$(Rank(h$))
Cls
tests = 10000000
While fini = 0
    For k = 0 To 9
        h$ = ""
        For i = 1 To 5
            h$ = h$ + Deck$(k * 5 + i)
        Next
        r = Rank(h$)
        rankCount(r) = rankCount(r) + 1
    Next
    hands = hands + 10
    If hands >= tests Then fini = 1 Else shuffle
    'input "Quit? ";a$
    'if a$ = "y" then fini = 1 else  shuffle
Wend
For i = 1 To 10
    Print rankCount(i); ", "; Int(rankCount(i) / tests * 100); "%, "; RankName$(i)
Next

Function RankName$ (RNumber)
    Select Case RNumber
        Case 1: RankName$ = "Royal Flush"
        Case 2: RankName$ = "Straight Flush"
        Case 3: RankName$ = "Four of a Kind"
        Case 4: RankName$ = "Full House"
        Case 5: RankName$ = "Flush"
        Case 6: RankName$ = "Straight"
        Case 7: RankName$ = "Three of a Kind"
        Case 8: RankName$ = "Two Pair"
        Case 9: RankName$ = "Pair"
        Case 10: RankName$ = "High Card"
    End Select
End Function

Function Rank (hand$)
    Dim arrange(13)
    For i = 1 To 5
        v$ = Mid$(hand$, i * 3 - 2, 2)
        f = (InStr(Order$, v$) + 1) / 2
        arrange(f) = arrange(f) + 1
    Next
    For i = 1 To 13
        Select Case arrange(i)
            Case 2: pair = pair + 1
            Case 3: three = 1
            Case 4: four = 1
        End Select
    Next
    If four = 1 Then Rank = 3: Exit Function
    If three = 1 And pair = 1 Then Rank = 4: Exit Function
    If three = 1 Then Rank = 7: Exit Function
    If pair = 2 Then Rank = 8: Exit Function
    If pair = 1 Then
        Rank = 9: Exit Function
    Else ' check flush and straight
        suit$ = Mid$(hand$, 3, 1): flush = 1
        For i = 2 To 5
            If Mid$(hand$, i * 3, 1) <> suit$ Then flush = 0: Exit For
        Next
        i = 1: straight = 1 ' find lowest card i
        While arrange(i) = 0
            i = i + 1
        Wend
        If i = 1 Then
            If arrange(10) = 1 And arrange(11) = 1 And arrange(12) = 1 And arrange(13) = 1 Then
                straight = 1: royal = 1: GoTo FinishRank
            End If
        End If
        If i >= 10 Then
            straight = 0
        Else
            straight = 1
            For j = i + 1 To i + 4 ' check next 4 cards in sequence
                If arrange(j) <> 1 Then straight = 0: Exit For
            Next
        End If
        FinishRank:
        If (straight = 1) And (flush = 1) And (royal = 1) Then Rank = 1: Exit Function
        If (straight = 1) And (flush = 1) Then Rank = 2: Exit Function
        If (flush = 1) Then Rank = 5: Exit Function
        If (straight = 1) Then
            Rank = 6
        Else
            Rank = 10
        End If
    End If
End Function

Sub shuffle
    For i = 52 To 2 Step -1
        r = Int(Rnd * i) + 1
        t$ = Deck$(i)
        Deck$(i) = Deck$(r)
        Deck$(r) = t$
    Next
End Sub

Sub makeDeck
    suit$ = "CDHS"
    For s = 1 To 4
        For i = 1 To 13
            Deck$((s - 1) * 13 + i) = Mid$(Order$, (i - 1) * 2 + 1, 2) + Mid$(suit$, s, 1)
        Next
    Next
End Sub

'      rank name   calc %   calc odds
'1data  "  Royal Flush", 0.000154, 649740
'2data  " Straight Flush", 0.00139 , 72193.33
'3data  " Four of a Kind", 0.0240 ,  4165
'4data  "   Full House", 0.144  ,  694.17
'5data  "     Flush", 0.197  ,  508.8
'6data  "    Straight", 0.392  ,  254.8
'7data  "Three of a Kind", 2.11  ,   47.3
'8data  "    Two Pair", 4.75  ,   21.03
'9data  "      Pair", 42.3   ,   2.36
'10 data  "   High Card", 50.1   ,   1.995

   

Print this item

  What's in a Reputation?
Posted by: PhilOfPerth - 10-11-2022, 04:45 AM - Forum: General Discussion - Replies (26)

I'm curious about how "Reputation" is calculated (no, I'm not really worried about mine -  I just tag along).
As an example, take Vince (nothing personal, Vince, just an example).

Total Reputation: 8
From  Members:0
From Posts: 10

 Obviously 2 extra "Reputation" points from somewhere, but where?

Print this item

  QB64 Phoenix Edition v3.3.0 Released!
Posted by: DSMan195276 - 10-11-2022, 02:24 AM - Forum: Announcements - Replies (73)

QB64 Phoenix Edition v3.3.0!
https://github.com/QB64-Phoenix-Edition/...tag/v3.3.0

Enhancements

  • #201 - Source files provided on the command line can now be relative to the current working directory - @DualBrain, @mkilgore
    • The executable name specified by -o is always relative to the location of the source file.
    • The previous behavior of specifying the source file relative to the location of QB64-PE still works.
  • #145, #204 - QB64-PE can now generate a ".license.txt" file beside your program - @mkilgore
    • This file contains the text of all the software licenses that apply to your program based on the dependencies you are using. You can then distribute the license file alongside your program to meet the requirements of those licenses.
    • The file can be generated either via a toggle option in the
      Run
      menu, or via the new
      -f:GenerateLicenseFile=[true/false]
      command line option.
  • #185, #208 -
    _SNDPLAYCOPY
    now takes
    x
    ,
    y
    , and
    z
    parameters to change the balance of the copied sound - @a740g

Bug Fixes
  • #177, #197 - Using undeclared variables in a CONST expression now properly gives an error - @mkilgore
  • #194, #195, #197 - _BLUE and _RGBA now work in CONST expressions - @mkilgore
  • #202 - Fixed
    String * n
    and
    Bit * n
    types when used with Static arrays - @DualBrain, @mkilgore
  • #199, #203 - Fixed the command line options listed in manpage - @mkilgore

Full Changelog: https://github.com/QB64-Phoenix-Edition/...1...v3.3.0

Print this item

  Zoom_Trek
Posted by: James D Jarvis - 10-10-2022, 06:16 PM - Forum: Works in Progress - Replies (1)

Building a Trek shooter based on the zoom_circle program I posted a few days ago.   Currently the player space ship can just zoom about the screen while an enemy craft crawls along. 

Code: (Select All)
'Zoom Trek
'by James D. Jarvis, still very ealry in development
'
'low end control example with angular navigation, dubious physics, and screenwrap
' w - accelerate
' s - decelerate
' a - turn to port
' d- turn to starboard
't - activate tracking to tragte alien vessel
'<esc>  - end program
Screen _NewImage(900, 680, 32)
_FullScreen
Dim Shared klr As _Unsigned Long
Type shiptype
    shape As Integer
    nm As String
    fuel As Double
    hdg As Double
    hc As Double
    mr As Double
    px As Double
    py As Double
    shield As Integer
    shieldmax As Integer
    shieldregen As Integer
    shieldrc As Integer
    sregenon As Integer
    hull As Integer
    k As _Unsigned Long
    br As Double
    beamname As String
    torpname As String
    bcost As Integer
    tcost As Integer
    tnum As Integer
    bdam As Integer
    tdam As Integer
    brange As Integer
    trange As Integer
End Type
Dim Shared ps As shiptype
Dim Shared AV(10) As shiptype
Dim Shared na As Integer
Dim Shared stardate, target

defineship 0, ps 'player starting as commonwealth  you can chage this but missions will not reflect change beyond player ship

For msn = 1 To 1
    View Print 35 To 40
    tx = ps.px + 3.5 * Sin(0.01745329 * hdg)
    ty = ps.py + 3.5 * Cos(0.01745329 * hdg)

    stardate = Timer
    missions msn
    Cls
    Do
        Line (0, 0)-(_Width, 535), _RGB32(0, 0, 0), BF
        _Limit 30
        ' Circle (ppx, ppy), 4, _RGB32(250, 250, 100) 'the zoom_circle saucer
        ' drawcraft 1, ppx, ppy, hdg, _RGB32(250, 250, 250)
        drawcraft ps.shape, ps.px, ps.py, ps.hdg, ps.k
        shipdatadisplay
        handlealiens "draw"
        Line (1, 1)-(535, 535), _RGB32(100, 200, 100), B
        Line (10, 10)-(525, 525), _RGB32(100, 200, 100), B
        'Circle (tx, ty), 2, _RGB32(255, 255, 255) 'this nubbin is to show where the cricle is heading
        kk$ = InKey$
        'Locate 1, 1: Print "Fuel : "; Int(ps.fuel)
        'Locate 1, 20: Print "Velocity :"; Int(ps.mr * 200)
        _Display
        Select Case kk$
            Case "w"
                If ps.fuel > 0 Then
                    ps.mr = ps.mr + 0.05 * (100000 / ps.fuel)
                    ps.fuel = ps.fuel - (1 * ps.br)
                End If
            Case "s"
                If ps.fuel > 0 Then
                    ps.fuel = ps.fuel - Sqr(ps.mr / (0.05 * ps.br))
                    ps.mr = ps.mr - 0.05
                    If ps.mr < 0 Then ps.mr = 0
                End If
            Case "a"
                If ps.fuel > 0 Then
                    ps.fuel = ps.fuel - Sqr(Sqr(ps.mr / (0.05 * ps.br)))
                    ps.hc = ps.hc + 2
                    ps.mr = ps.mr * 0.995
                End If
            Case "d"
                If ps.fuel > 0 Then
                    ps.fuel = ps.fuel - Sqr(Sqr(ps.mr / 0.05))
                    ps.hc = ps.hc - 2
                    ps.mr = ps.mr * .995
                End If
            Case " ", "b" 'fire beam weapon
                If target < 1 Then
                    Sound 880, 3
                    Print "NO TARGET DECLARED (Press T to activate target tracking)"
                End If
            Case "t" 'activate or shift tracking
                If na > 1 Then Print "SENSORS REPORT VALID TARGETS"
                For a = 1 To na
                    Print a; ") "; AV(a).nm,
                Next a
                Print
                Input "Enter Target # "; target
                If target > 0 Or target <= na Then
                    For t = 1 To na
                        If t = target And AV(t).px > 0 Then
                            Print "TARGET TRACKING FOR "; AV(t).nm; " CONFIRMED!"
                        Else
                            Print "NO VALID TARGET SELECTED"
                            target = 0
                        End If
                    Next t
                Else
                    Beep
                    Print "NO VALID TARGET SELECTED"
                    target = 0
                End If

        End Select


        handlealiens "move"

        ps.px = ps.px + ps.mr * Sin(0.01745329 * ps.hdg)
        ps.py = ps.py + ps.mr * Cos(0.01745329 * ps.hdg)

        ps.hdg = ps.hdg + ps.hc
        ps.hc = ps.hc * .75
        If ps.px < 15 Then ps.px = 500
        If ps.px > 515 Then ps.px = 15
        If ps.py < 15 Then ps.py = 500
        If ps.py > 515 Then ps.py = 15
        tx = ps.px + 3.5 * Sin(0.01745329 * ps.hdg)
        ty = ps.py + 3.5 * Cos(0.01745329 * ps.hdg)
    Loop Until kk$ = Chr$(27) Or kk$ = "ABORT"
    If kk$ = "ABORT" Then
        Print "MISSION "; msn; " ABORT"
        Print
        Print "Attempt next mission? (Y or N)"
        Do
            ask$ = Input$(1)
            ask$ = UCase$(ask$)
        Loop Until aks$ = "Y" Or ask$ = "N"
        If ask$ = "N" GoTo endgame
    Else
        GoTo endgame
    End If
Next msn
endgame:
End
Sub drawcraft (craftid, cx, cy, hdg, klr As _Unsigned Long)
    Select Case craftid
        Case 1
            Draw "bm" + Str$(cx) + "," + Str$(cy) + "C" + Str$(klr) + "ta" + Str$(hdg) + " bu5l4d5u10br8d10u5l4d10"
            tx = cx + 5 * Sin(0.01745329 * hdg)
            ty = cy + 5 * Cos(0.01745329 * hdg)
            Circle (tx, ty), 3, klr
        Case 2
            Draw "bm" + Str$(cx) + "," + Str$(cy) + "C" + Str$(klr) + "ta" + Str$(hdg) + " bu5l4d5u6br8d6u5l4d10"
            tx = cx + 5 * Sin(0.01745329 * hdg)
            ty = cy + 5 * Cos(0.01745329 * hdg)
            Circle (tx, ty), 2, klr
        Case 3
            Circle (cx, cy), 6, klr
            Draw "bm" + Str$(cx) + "," + Str$(cy) + "C" + Str$(klr) + "ta" + Str$(hdg) + " l6u6br12d6l6u6"
        Case 4
            Circle (cx, cy), 9, klr
            Circle (cx, cy), 3, klr
            tx = cx + 6 * Sin(0.01745329 * hdg)
            ty = cy + 6 * Cos(0.01745329 * hdg)
            Circle (tx, ty), 2, klr
    End Select

End Sub
Sub defineship (id As Integer, ds As shiptype)
    Select Case id
        Case 0 'Commonwealth cruiser
            ds.shape = 1
            ds.fuel = 100000
            ds.hdg = 90
            ds.br = 1.1
            ds.hc = 0
            ds.mr = 0
            ds.px = 0
            ds.py = 0
            ds.shield = 1000
            ds.shieldmax = 1000
            ds.shieldregen = 10
            ds.shieldrc = 10
            ds.sregenon = 1
            ds.hull = 3000
            ds.k = _RGB32(250, 250, 250)
            ds.nm = "Commonwealth Cruiser"
            ds.beamname = "Maser"
            ds.torpname = "Proton Torpedo MII"
            ds.bcost = 1
            ds.tcost = 1
            ds.tnum = 300
            ds.bdam = 300
            ds.tdam = 1500
            ds.brange = 200
            ds.trange = 300
        Case 1 'Kraal Destroyer
            ds.shape = 2
            ds.fuel = 90000
            ds.br = 1.0
            ds.hdg = 90
            ds.hc = 0
            ds.mr = 0
            ds.px = 0
            ds.py = 0
            ds.shield = 900
            ds.shieldmax = 900
            ds.shieldregen = 9
            ds.shieldrc = 10
            ds.sregenon = 1
            ds.hull = 2000
            ds.k = _RGB32(250, 50, 0)
            ds.nm = "Kraal Destroyer"
            ds.beamname = "UVaser"
            ds.torpname = "Proton Torpedo MI"
            ds.bcost = 1
            ds.tcost = 1
            ds.tnum = 300
            ds.bdam = 250
            ds.tdam = 1000
            ds.brange = 100
            ds.trange = 200
        Case 2 'Gorgon Raider
            ds.shape = 3
            ds.fuel = 125000
            ds.br = 2
            ds.hdg = 90
            ds.hc = 0
            ds.mr = 0
            ds.px = 0
            ds.py = 0
            ds.shield = 500
            ds.shieldmax = 500
            ds.shieldregen = 8
            ds.shieldrc = 15
            ds.sregenon = -1
            ds.hull = 5000
            ds.k = _RGB32(100, 250, 50)
            ds.nm = "Gorgon Imperial Raider"
            ds.beamname = "Laser"
            ds.torpname = "Atomic-WarpStorm"
            ds.bcost = 1
            ds.tcost = 3000
            ds.tnum = -99
            ds.bdam = 200
            ds.tdam = 3000
            ds.brange = 150
            ds.trange = 200
        Case 3 'Andromeda Invader
            ds.shape = 4
            ds.fuel = 250000
            ds.br = 1
            ds.hdg = 90
            ds.hc = 0
            ds.mr = 0
            ds.px = 0
            ds.py = 0
            ds.shield = 2000
            ds.shieldmax = 2000
            ds.shieldregen = 20
            ds.shieldrc = 10
            ds.sregenon = 1
            ds.hull = 6000
            ds.k = _RGB32(100, 250, 50)
            ds.nm = "Andromeda Invader"
            ds.beamname = "Demat Beam"
            ds.torpname = "Quark Torpedo"
            ds.bcost = 1
            ds.tcost = 30
            ds.tnum = 1000
            ds.bdam = 400
            ds.tdam = 5000
            ds.brange = 150
            ds.trange = 100
        Case 4 'Kraal Corsair
            ds.shape = 2
            ds.fuel = 100000
            ds.br = 1.05
            ds.hdg = 90
            ds.hc = 0
            ds.mr = 0
            ds.px = 0
            ds.py = 0
            ds.shield = 950
            ds.shieldmax = 950
            ds.shieldregen = 10
            ds.shieldrc = 11
            ds.sregenon = 1
            ds.hull = 1800
            ds.k = _RGB32(240, 50, 40)
            ds.nm = "Kraal Corsair"
            ds.beamname = "UVaser"
            ds.torpname = "Proton Torpedo MI"
            ds.bcost = 1
            ds.tcost = 1
            ds.tnum = 100
            ds.bdam = 250
            ds.tdam = 1000
            ds.brange = 100
            ds.trange = 200
        Case 5 'Kraal
            ds.shape = 2
            ds.fuel = 150000
            ds.br = 1.2
            ds.hdg = 90
            ds.hc = 0
            ds.mr = 0
            ds.px = 0
            ds.py = 0
            ds.shield = 1150
            ds.shieldmax = 1150
            ds.shieldregen = 12
            ds.shieldrc = 15
            ds.sregenon = 1
            ds.hull = 2500
            ds.k = _RGB32(240, 50, 40)
            ds.nm = "Kraal BattleCruiser"
            ds.beamname = "Overcharged UVaser"
            ds.torpname = "Proton Torpedo MII"
            ds.bcost = 2
            ds.tcost = 1
            ds.tnum = 200
            ds.bdam = 300
            ds.tdam = 1500
            ds.brange = 150
            ds.trange = 280

    End Select
End Sub
Sub shipdatadisplay
    _PrintString (580, 10), "Stardate " + Str$(Timer)
    _PrintString (580, 60), ps.nm
    _PrintString (580, 80), "Fuel " + Str$(Int(ps.fuel))
    _PrintString (580, 100), "Velocity " + Str$(Int(ps.mr * 200))
    _PrintString (580, 120), "Shields " + Str$(ps.shield)
    _PrintString (580, 140), "Hull Integrity " + Str$(ps.hull)
    _PrintString (580, 160), ps.torpname
    If ps.tnum > -1 Then
        _PrintString (580, 180), "Ammo: " + Str$(ps.tnum)
    Else
        Select Case ps.tnum
            Case -99
                _PrintString (580, 180), "-- Online --"
            Case -13
                _PrintString (580, 180), "** OFFLINE **"
        End Select
    End If
    If target > 0 Then
        _PrintString (580, 200), "************************"
        _PrintString (580, 216), " TARGET TRACKING REPORT "
        _PrintString (580, 232), "************************"
        _PrintString (580, 250), AV(target).nm
        If Int(Rnd * 100) < 20 Then
            msg$ = "Shields : ?????????????????"
        Else
            msg$ = "Shields : " + Str$(AV(target).shield)
        End If
        _PrintString (580, 270), msg$
        If Int(Rnd * 100) < 20 Then
            msg$ = "Hull   : ?????????????????"
        Else
            msg$ = "Hull   : " + Str$(AV(target).hull)
        End If
        _PrintString (580, 290), msg$
        dx = Abs(ps.px - AV(target).px): dy = Abs(ps.py - AV(target).py)
        dd = Sqr(dx * dx + dy + dy)
        _PrintString (580, 310), "Range to Target :" + Str$(Int(dd))


    End If
End Sub
Sub missions (m)
    Select Case m
        Case 1
            Print "**** STARWATCH COMMAND to "; ps.nm; " ****"
            Print "!!!! NEUTRAL ZONE VIOLATION DETECTED !!!!"
            Print "!!!!  ENGAGE HOSTILE KRAAL VESSEL    !!!!"
            Print
            Print " <press any key to engage warp drive> "
            _KeyClear
            any$ = Input$(1)
            na = 1
            defineship 1, AV(1)
            AV(1).hdg = 90: AV(1).mr = .1: AV(1).px = 300: AV(1).py = 100: AV(1).hull = AV(1).hull / 2
            For a = 2 To 10
                defineship 1, AV(a)
                AV(a).fuel = 0: AV(a).px = 0
            Next a
            ps.px = 250: ps.py = 250: ps.hdg = 90: ps.hc = 0: ps.mr = 0
            target = 0
    End Select
End Sub
Sub handlealiens (sequence$)
    Select Case sequence$
        Case "draw"
            For a = 1 To na
                If AV(a).px > 0 Then
                    drawcraft AV(a).shape, AV(a).px, AV(a).py, AV(a).hdg, AV(a).k
                End If
            Next a
        Case "move"
            For a = 1 To na
                If AV(a).px > 0 And AV(a).mr > 0 Then

                    xtp = AV(a).px - ps.px
                    ytp = AV(a).py - ps.py
                    dtp = Sqr(Abs(xtp) * Abs(xtp) + Abs(ytp) * Abs(ytp))
                    AV(a).hdg = AV(a).hdg + AV(a).hc
                    AV(a).hc = AV(a).hc * .75
                    AV(a).px = AV(a).px + AV(a).mr * Sin(0.01745329 * AV(a).hdg)
                    AV(a).py = AV(a).py + AV(a).mr * Cos(0.01745329 * AV(a).hdg)

                    If AV(a).px < 15 Then AV(a).px = 500
                    If AV(a).px > 515 Then AV(a).px = 15
                    If AV(a).py < 15 Then AV(a).py = 500
                    If AV(a).py > 515 Then AV(a).py = 15
                End If
            Next a
    End Select
End Sub

Print this item

  Aliens Among Us
Posted by: bplus - 10-10-2022, 05:20 PM - Forum: Works in Progress - Replies (4)

I just saw a video and hey they are right here in this!

Code: (Select All)
_Title "Pascal Triangle display exercise 2018-01-13 bplus"
'2018-01-13 Pascal Triangle.txt for JB 2015-10-31 MGA/B+

_Define A-Z As _INTEGER64

Const xmax = 1200
Const ymax = 400

Screen _NewImage(xmax, ymax, 32)
_ScreenMove 100, 60

printline = 2
For row = 0 To 20
    build$ = ""
    printline = printline + 1
    For column = 0 To row
        build$ = build$ + Right$(Space$(7) + Str$(binom(row, column)), 7)
    Next
    Locate printline, (150 - Len(build$)) / 2
    Print build$
Next
Sleep

Function binom (n, m)
    binom = fac(n) / (fac(m) * fac((n - m)))
End Function

Function fac (n)
    f = 1
    For i = 1 To n
        f = f * i
    Next
    fac = f
End Function

To be continued... as soon as I get it coded  ;-))

Meanwhile wonder WTH?

Oh better yet, try to anticipate where I am going with this.

Print this item