advice on a long range shooting game-VBForums
Results 1 to 7 of 7

Thread: advice on a long range shooting game

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    2

    advice on a long range shooting game

    I usually don't do any games, but I thought it might be fun to first see if I could make just a rifle scope reticle looking down range from a shooters perspective. But I am at a loss on how to actually do it. First I was thinking a transparent image but I don't have photo editing tools at this time. Can I just draw it in VB?

    Thanks for any advice on how to go about this.

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,316

    Re: advice on a long range shooting game

    Yes, you can draw it, and use clipping regions to give you a circle view.
    I posted an example of drawing an avionics type instrument, which uses a clipping region to limit drawing to an area of the face of the instrument. In this case the area was circular, but flat on the left and right edges, so was a combination of a circle and rectangle. Just doing a circle would be that much easier. The example has a "step" mode, where you can step through the drawing sequence and it shows you the commands being done at that step and you can see the results. The instrument is still interactive, i.e. you can rotate and pitch the display while in the step mode, so you can further see how the drawing is effected by the steps that have been executed up to that point. It is attached to Post #3 here.

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,622

    Re: advice on a long range shooting game



    Here's an example of how to do it purely by drawing primitives as shown in the image above:-
    vbnet Code:
    1. Public Class Form1
    2.  
    3.     Private _scopeRadius As Integer = 50
    4.     Private _scopeCentre As Point
    5.  
    6.     Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    7.         _scopeCentre = e.Location
    8.         Me.Refresh()
    9.     End Sub
    10.  
    11.     Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    12.         Dim scopeRect As RectangleF = CreateCircleRect(_scopeCentre, _scopeRadius)
    13.         Dim lineLen As Single = _scopeRadius
    14.  
    15.         Dim pt1 As PointF
    16.         Dim pt2 As PointF
    17.  
    18.  
    19.         Using p As New Pen(Brushes.Black, 2)
    20.             e.Graphics.DrawEllipse(p, scopeRect)
    21.  
    22.             pt1.X = scopeRect.X + scopeRect.Width / 2
    23.             pt1.Y = scopeRect.Y - lineLen / 2
    24.  
    25.             pt2.X = scopeRect.X + scopeRect.Width / 2
    26.             pt2.Y = scopeRect.Y + lineLen / 2
    27.  
    28.             e.Graphics.DrawLine(p, pt1, pt2)
    29.  
    30.             pt1.X = scopeRect.X + scopeRect.Width / 2
    31.             pt1.Y = scopeRect.Bottom - lineLen / 2
    32.  
    33.             pt2.X = scopeRect.X + scopeRect.Width / 2
    34.             pt2.Y = scopeRect.Bottom + lineLen / 2
    35.  
    36.             e.Graphics.DrawLine(p, pt1, pt2)
    37.  
    38.  
    39.             pt1.X = scopeRect.X - lineLen / 2
    40.             pt1.Y = scopeRect.Y + scopeRect.Height / 2
    41.  
    42.             pt2.X = scopeRect.X + lineLen / 2
    43.             pt2.Y = scopeRect.Y + scopeRect.Height / 2
    44.  
    45.             e.Graphics.DrawLine(p, pt1, pt2)
    46.  
    47.  
    48.             pt1.X = scopeRect.Right - lineLen / 2
    49.             pt1.Y = scopeRect.Y + scopeRect.Height / 2
    50.  
    51.             pt2.X = scopeRect.Right + lineLen / 2
    52.             pt2.Y = scopeRect.Y + scopeRect.Height / 2
    53.  
    54.             e.Graphics.DrawLine(p, pt1, pt2)
    55.  
    56.         End Using
    57.  
    58.     End Sub
    59.  
    60.     Private Function CreateCircleRect(ByVal circleCentre As Point, ByVal radius As Single) As RectangleF
    61.  
    62.         Return New RectangleF(circleCentre.X - radius, circleCentre.Y - radius, radius * 2, radius * 2)
    63.  
    64.     End Function
    65.  
    66. End Class

    You can move the mouse around the form to simulate aiming.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  4. #4
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    901

    Re: advice on a long range shooting game

    Not sure what kind of simulation your attempting but if its 3D then some other tips regarding implementing a 3d world to show in your window look into RayCasting which is actually very easy to do and doesnt require that much work, or go one better and look into using DirectX which is also pretty simple after a little practice...

    studying some simple newton physics is also recommended if you want to implement gravity etc to your bullets.


    3D engine in 250 lines (this is almost exactly how i created my first one)

    DirectX.Com


    Physics , this will help, but this doesnt show the position/at time but thats easy to find
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  5. #5
    PowerPoster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,084

    Re: advice on a long range shooting game

    Good posts...we aim to please here
    Please remember next time...elections matter!

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    2

    Re: advice on a long range shooting game

    OK guys I am back and thank you all for those great posts! I been spending some time researching this and reading all the comments and suggestions and testing out the code posted by Niya above, (very cool by the way!) one question though is there a way to shut off the windows mouse pointer on your code?

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,722

    Re: advice on a long range shooting game

    You can hide the mouse cursor by using:
    Code:
    Cursor.Hide()
    ...and to show it again:
    Code:
    Cursor.Show()
    Make sure you don't run either of those more often than you wanted, because they "add up" (eg: calling .Hide twice then .Show once will mean that it is hidden, because there is one more .Hide)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width