Results 1 to 7 of 7

Thread: Object points in the direction of Mouse Cursor!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    6
    Hail VB'ers

    I need som help. I writing a game. And i need the player to Face the direction that the mousecursor is in. Its just a 2D tile based game. Really simple. Could someone email me the code that enables me to do this. I know its not simple, but i know that others of you would of had the same problem, and i'm asking if you could help me out.

    Sending your reply to my Email address is preferable. But i don't really mind. JUST HELP ME!!

    Thanks.

    --------------
    Rowie

  2. #2
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    I have a basic Idea, I'm just not sure of the exact code!!!
    you could make it that the program finds where the person (or object) in the game is. Then it could fiqure out that if the x coordinates of the mouse are from one range to another the person (object) looks one way
    NXSupport - Your one-stop source for computer help

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    well, this might help:

    Code:
                         '| <- mouse pointer here
                       '  |
                     '    |
                   '      |
                 '        |
      player -> X---------|
    1: Find the offset of the pointer from the player
    x = Abs(pointer.x - player.x)
    y = Abs(pointer.y - player.y)

    2: You will now have an x-offset, and a y-offset
    then to find the angle: ArcTan(y / x)

    3: Rotate the image of the player through that angle.

    (I don't know how to do this, but it is fairly easy with DX and I'm sure there's a tutorial on rotating bitmaps.

    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Rotating images is hard, check out planet source code.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I would recommend not to use rotating image procedures since they drain a lot of performance, instead rotate them manually with paintshop or photoshop,and load them into an array or imagelist or put them in a res file.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    6
    Hail,

    Thanks for your replies. I've already got the basic idea. But it would be easier if someone had the code already.

    Once again - thanks!

    ---------------
    Rowie

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I think if you use mine, but round the angle to the nearest pi/6 radians or something like that, then load the image from an imagelist, it should speed it up quite a bit.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

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



Click Here to Expand Forum to Full Width