Author Topic: David H. Ahl BULLSEYE (Dart Game) Revisited :-)  (Read 8514 times)

0 Members and 1 Guest are viewing this topic.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #15 on: November 13, 2021, 03:18:35 pm »
I'll finish this on another computer in a bit (maybe never)

Code: [Select]
deflng a-z

const sw = 1000
const sh = 700

dim shared pi as double
pi = 4*atn(1)

dim shared mx, my, mbl, mbr, mw

dim shared aa(19)
aa( 0) = 6
aa( 1) = 10
aa( 2) = 15
aa( 3) = 2
aa( 4) = 17
aa( 5) = 3
aa( 6) = 19
aa( 7) = 7
aa( 8) = 16
aa( 9) = 8
aa(10) = 11
aa(11) = 14
aa(12) = 9
aa(13) = 12
aa(14) = 5
aa(15) = 20
aa(16) = 1
aa(17) = 18
aa(18) = 4
aa(19) = 13

'draw board once
screen _newimage(sw, sh, 32),, 1, 0

for y=-0.800*sh/2 to 0.800*sh/2
for x=-0.800*sh/2 to 0.800*sh/2
        dim a as double
        a = _atan2(y, x) + pi
        r = sqr(x*x + y*y)
        if r <= (0.800*sh/2) then
                am2 = (a*20/(2*pi)) mod 2
                if r >= 0.765*sh/2 or r >= 0.465*sh/2 and r <= 0.500*sh/2 then
                        if am2 = 0 then
                                c = _rgb(0,180,0)
                        else
                                c = _rgb(210,0,0)
                        end if
                else
                        if am2 = 0 then
                                c = _rgb(230,230,200)
                        else
                                c = _rgb(0,0,0)
                        end if
                end if
                if r<=0.060*sh/2 then
                        if r<=0.025*sh/2 then
                                c = _rgb(210,0,0)
                        else
                                c = _rgb(0,180,0)
                        end if
                end if
                pset (sw/2 + x, sh/2 + y), c
        end if
next
next

circle (sw/2, sh/2), sh/2 - 1, _rgb(50, 50, 50)

circle step(0,0), 0.800*sh/2
circle step(0,0), 0.765*sh/2

circle step(0,0), 0.500*sh/2
circle step(0,0), 0.465*sh/2

circle step(0,0), 0.060*sh/2
circle step(0,0), 0.025*sh/2


for i=0 to 19
        dim x as double, y as double
        x = cos(2*pi*(i/20) + 2*pi/40)
        y = sin(2*pi*(i/20) + 2*pi/40)
        pset  (sw/2 + (0.060*sh/2)*x, sh/2 + (0.060*sh/2)*y)
        line -(sw/2 + (0.800*sh/2)*x, sh/2 + (0.800*sh/2)*y)

        x = cos(2*pi*(i/20))
        y = sin(2*pi*(i/20))
        _printstring (sw/2 + (0.900*sh/2)*x - (8*len(ltrim$(str$(aa(i))))/2) - 8, sh/2 + (0.900*sh/2)*y - 8), str$(aa(i))
next

for i=0 to sh
        line (0, i)-step((sw - sh)/2 - 0.05*i*1000/sh, 0), _rgb(50 + 50*2*(atn(0.01*(sh/2 - i)))/pi,50 + 50*2*(atn(0.01*(i - sh/2)))/pi,0)

next

'main screen
screen ,, 0, 0

do
        t = timer*1000
        getmouse

        pcopy 1,0

        locate 1,1
        '? mx, my, mbl, mbr, mw
        ? t

        'for i=0 to 500+500*sin(2*pi*0.5*(t mod 10000)/1000)
                i = 500+500*sin(2*pi*0.5*(t mod 10000)/1000)
                line (0, i*sh/1000)-step((sw - sh)/2 - i*0.05, 0)
        'next

        _display
        '_limit 100
loop until _keyhit=27

sleep
system

sub getmouse()
        do
                mx = _mousex
                my = _mousey
                mbl = _mousebutton(1)
                mbr = _mousebutton(2)
                mw = mw - _mousewheel
        loop while _mouseinput
end sub

sub circlef (x, y, r, c as long)
        x0 = r
        y0 = 0
        e = 0
        do while y0<x0
                line(x-x0,y+y0)-(x+x0,y+y0),c,bf
                line(x-x0,y-y0)-(x+x0,y-y0),c,bf
                line(x-y0,y-x0)-(x+y0,y-x0),c,bf
                line(x-y0,y+x0)-(x+y0,y+x0),c,bf
                if e<=0 then
                        y0=y0+1
                        e=e+2*y0
                else
                        x0=x0-1
                        e=e-2*x0
                end if
        loop
end sub

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #16 on: November 13, 2021, 03:36:05 pm »
now thats cool bplus!

I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #17 on: November 13, 2021, 09:05:16 pm »
Nice start @_vince

Fixed mouse to draw hit +- Rnd*10 of mx and my + Rnd*30, the mouse waits until you release the left button before it exits the GetMouse routine (meanwhile updating mx, my until button is released).

Need me to calc scores too?

Code: QB64: [Select]
  1. DefLng A-Z
  2.  
  3. Const sw = 1000
  4. Const sh = 700
  5.  
  6. pi = 4 * Atn(1)
  7.  
  8. Dim Shared mx, my, mbl, mbr, mw
  9.  
  10. Dim Shared aa(19)
  11. aa(0) = 6
  12. aa(1) = 10
  13. aa(2) = 15
  14. aa(3) = 2
  15. aa(4) = 17
  16. aa(5) = 3
  17. aa(6) = 19
  18. aa(7) = 7
  19. aa(8) = 16
  20. aa(9) = 8
  21. aa(10) = 11
  22. aa(11) = 14
  23. aa(12) = 9
  24. aa(13) = 12
  25. aa(14) = 5
  26. aa(15) = 20
  27. aa(16) = 1
  28. aa(17) = 18
  29. aa(18) = 4
  30. aa(19) = 13
  31.  
  32. 'draw board once
  33. Screen _NewImage(sw, sh, 32)
  34. _ScreenMove 100, 40
  35.  
  36. For y = -0.800 * sh / 2 To 0.800 * sh / 2
  37.     For x = -0.800 * sh / 2 To 0.800 * sh / 2
  38.         Dim a As Double
  39.         a = _Atan2(y, x) + pi
  40.         r = Sqr(x * x + y * y)
  41.         If r <= (0.800 * sh / 2) Then
  42.             am2 = (a * 20 / (2 * pi)) Mod 2
  43.             If r >= 0.765 * sh / 2 Or r >= 0.465 * sh / 2 And r <= 0.500 * sh / 2 Then
  44.                 If am2 = 0 Then
  45.                     c = _RGB(0, 180, 0)
  46.                 Else
  47.                     c = _RGB(210, 0, 0)
  48.                 End If
  49.             Else
  50.                 If am2 = 0 Then
  51.                     c = _RGB(230, 230, 200)
  52.                 Else
  53.                     c = _RGB(0, 0, 0)
  54.                 End If
  55.             End If
  56.             If r <= 0.060 * sh / 2 Then
  57.                 If r <= 0.025 * sh / 2 Then
  58.                     c = _RGB(210, 0, 0)
  59.                 Else
  60.                     c = _RGB(0, 180, 0)
  61.                 End If
  62.             End If
  63.             PSet (sw / 2 + x, sh / 2 + y), c
  64.         End If
  65.     Next
  66.  
  67. Circle (sw / 2, sh / 2), sh / 2 - 1, _RGB(50, 50, 50)
  68.  
  69. Circle Step(0, 0), 0.800 * sh / 2
  70. Circle Step(0, 0), 0.765 * sh / 2
  71.  
  72. Circle Step(0, 0), 0.500 * sh / 2
  73. Circle Step(0, 0), 0.465 * sh / 2
  74.  
  75. Circle Step(0, 0), 0.060 * sh / 2
  76. Circle Step(0, 0), 0.025 * sh / 2
  77.  
  78.  
  79. For i = 0 To 19
  80.     Dim x As Double, y As Double
  81.     x = Cos(2 * pi * (i / 20) + 2 * pi / 40)
  82.     y = Sin(2 * pi * (i / 20) + 2 * pi / 40)
  83.     PSet (sw / 2 + (0.060 * sh / 2) * x, sh / 2 + (0.060 * sh / 2) * y)
  84.     Line -(sw / 2 + (0.800 * sh / 2) * x, sh / 2 + (0.800 * sh / 2) * y)
  85.  
  86.     x = Cos(2 * pi * (i / 20))
  87.     y = Sin(2 * pi * (i / 20))
  88.     _PrintString (sw / 2 + (0.900 * sh / 2) * x - (8 * Len(LTrim$(Str$(aa(i)))) / 2) - 8, sh / 2 + (0.900 * sh / 2) * y - 8), Str$(aa(i))
  89.  
  90. For i = 0 To sh
  91.     Line (0, i)-Step((sw - sh) / 2 - 0.05 * i * 1000 / sh, 0), _RGB(50 + 50 * 2 * (Atn(0.01 * (sh / 2 - i))) / pi, 50 + 50 * 2 * (Atn(0.01 * (i - sh / 2))) / pi, 0)
  92.  
  93. board& = _NewImage(_Width - 1, _Height - 1, 32)
  94. _PutImage , 0, board&
  95.  
  96. 'main screen
  97.  
  98.  
  99.     t = Timer * 1000
  100.     getmouse
  101.  
  102.     _PutImage , board&, 0
  103.  
  104.     Locate 1, 1
  105.     '? mx, my, mbl, mbr, mw
  106.     If mbl Then
  107.         rx = Rnd * 20 - 10: ry = Rnd * 30
  108.         For i = 0 To 10 Step 2
  109.             Circle (mx + rx, my + ry), i, _RGB32((11 - i) * 25, (11 - i) * 25, 0)
  110.         Next
  111.         _PutImage , 0, board&
  112.     End If
  113.  
  114.     Print t
  115.  
  116.     'for i=0 to 500+500*sin(2*pi*0.5*(t mod 10000)/1000)
  117.     i = 500 + 500 * Sin(2 * pi * 0.5 * (t Mod 10000) / 1000)
  118.     Line (0, i * sh / 1000)-Step((sw - sh) / 2 - i * 0.05, 0)
  119.     'next
  120.  
  121.     _Display
  122.     _Limit 30
  123.  
  124.  
  125. Sub getmouse ()
  126.         mw = mw - _MouseWheel
  127.     Wend
  128.     mx = _MouseX
  129.     my = _MouseY
  130.     mbl = _MouseButton(1)
  131.     mbr = _MouseButton(2)
  132.     If mbl Then
  133.         Do 'wait for release of mousebutton before leaving this sub
  134.             While _MouseInput: Wend  'poll mouse
  135.             mx = _MouseX
  136.             my = _MouseY
  137.             mbl = _MouseButton(1)
  138.         Loop Until mbl = 0
  139.         mbl = -1
  140.     End If
  141.  
  142. Sub circlef (x, y, r, c As Long)
  143.     x0 = r
  144.     y0 = 0
  145.     e = 0
  146.     Do While y0 < x0
  147.         Line (x - x0, y + y0)-(x + x0, y + y0), c, BF
  148.         Line (x - x0, y - y0)-(x + x0, y - y0), c, BF
  149.         Line (x - y0, y - x0)-(x + y0, y - x0), c, BF
  150.         Line (x - y0, y + x0)-(x + y0, y + x0), c, BF
  151.         If e <= 0 Then
  152.             y0 = y0 + 1
  153.             e = e + 2 * y0
  154.         Else
  155.             x0 = x0 - 1
  156.             e = e - 2 * x0
  157.         End If
  158.     Loop
  159.  
  160.  

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #18 on: November 13, 2021, 10:01:39 pm »
Cool game! Believe it or not, I actually won!

Hmm... Now that I think about it...  If "I" could win, you have obviously made the game too easy... lol

Perhaps with a little twisting of your arm, the next version, could possibly have some graphics... Nudge, nudge, wink, wink... Say no more... lol

well keep in mind this is just a direct rewrite of the original code - just cleaned up a bit and readable. I suppose if your hankerin for punishment you could tweak it, since the spaghetti is all cleaned up
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #19 on: November 14, 2021, 01:21:16 am »
xra7en,

My comment was not intended to question your skills in converting one basic to another. If I caused offence, then I apologise. The comment that I made, "you have obviously made", was poorly and inaccurately chosen. Direct conversion of the game does not and should not imply that you are the direct cause of my winning or losing. If that implication left you with that conclusion, then for that, I also apologise.

J
Logic is the beginning of wisdom.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #20 on: November 14, 2021, 04:42:54 am »
Scoring should be as easy as drawing the board itself.  I was planning to use this system https://en.wikipedia.org/wiki/Darts#/media/File:Dartboard_heatmap.svg and all those numbers can be generated just from the outside nums which I put in array aa(19).  I'm also going to stick all the radii in an array to make the game code entirely flexible.  But I don't care for all the formalities of an actual game, I won't go into that.

Mainly, I'm trying to think up of a good scheme for animating the darts and also the game/skill aspect.  The original game goes for the shaky hand and a deterministic power bar that over/underthrows.  There's also no physics or 3D rendering of any sort, it appears to be a single bitmap array animation of the dart in flight that just gets panned around.  This is what I wanted to play around with, not yet sure what I should go with there.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #21 on: November 14, 2021, 05:02:42 am »
xra7en,

My comment was not intended to question your skills in converting one basic to another. If I caused offence, then I apologise. The comment that I made, "you have obviously made", was poorly and inaccurately chosen. Direct conversion of the game does not and should not imply that you are the direct cause of my winning or losing. If that implication left you with that conclusion, then for that, I also apologise.

J

oooo nooo, no offense.I understood. after reading that I can see how that came out that way - sooooory!
your fine. :-P

I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!