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
b = b + ...
Reply


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



Users browsing this thread: 7 Guest(s)