Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Equation For Specific Line Length Needed
#2
(08-16-2022, 12:53 AM)SierraKen Wrote: Hi all,

I'm in the middle of making my Explorer game with scrolling maps. The game uses the mouse to use your sword with. But I'm stuck at what the equation is to make a limited line (sword) from your character toward the area you point your mouse at. I can easily make a line from your character to the mouse coordinates, but I can't make it a limited length. Does anyone out there know how to do this? I think I will keep the sword at 100 pixels long. Let's say the guy is XX by YY coordinates (never mind the scrolling map part, that should be easy to add). And let's say the mouse is using mouseX and mouseY. I just want the sword to reach toward that mouse point but only 100 pixels toward it and no more. Thanks.

Code: (Select All)
Option _Explicit
Screen _NewImage(800, 600, 32)
Dim heroX, heroY, A, mx, my, sx, sy
Do

    Cls
    ' lets say hero is right in middle of screen and points a 100 pixel sword in direction of mouse
    heroX = 400: heroY = 300
    While _MouseInput: Wend 'poll mouse
    mx = _MouseX: my = _MouseY
    A = _Atan2(my - heroY, mx - heroX)
    sx = heroX + 100 * Cos(A)
    sy = heroY + 100 * Sin(A)
    Line (heroX, heroY)-(sx, sy), &HFFFFFF00
    _Display
    _Limit 60
Loop
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Messages In This Thread
RE: Equation For Specific Line Length Needed - by bplus - 08-16-2022, 02:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fibonacci Help needed! Unseen Machine 18 1,411 12-26-2025, 09:05 PM
Last Post: Petr
  Setting Line _RGB colours PhilOfPerth 10 1,989 11-03-2024, 05:37 AM
Last Post: PhilOfPerth
  help needed BloodyHash 9 1,861 05-01-2024, 08:11 PM
Last Post: TerryRitchie
  Loading font from memory help needed... Dav 6 1,416 09-16-2023, 04:03 PM
Last Post: SMcNeill
  Having trouble Windows command line SORT via SHELL GTC 19 4,491 08-26-2023, 04:19 AM
Last Post: GTC

Forum Jump:


Users browsing this thread: 1 Guest(s)