Skip to main content
GameDev.net gamedev.net
🔒 Locked

Engine mouse help!

Started by Dale Oct 24, 2001 at 8:33 PM 1 replies 150+ views
Original Post
Dale
Dale
Hey all. Background: I''ve got a C++ iso-engine running with scrolling, dynamic maps (loaded from text files) and a dynamic terrain loader (from text files too). The pics are just a basic BMP which I refer to. At the moment I''ve got the scrolling happening using keyboard msgs (VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN). Problem: I want to set up the scrolling so when the mouse is at the screen edges the map scrolls, but I don''t know what the msgs are to check. Also, how do I get the screen(x, y) location of the mouse? Any help appreciated. ----------------------------- Student - "How do I make my first game?" Lecturer - "Based on your marks from your last assessment?"
-----------------------------Empires! Visit online at http://www.daleszone.comProgramming for a funner world.
kmsixpence
kmsixpence
I got this from TANSTAAFL''s book Iso Game Prog with DX7. I''m assuming you''re doing this in 2d.

Mouse Positions Getting:

In the windows messages, where you do VK_LEFT and such, create a new case. ptMouse is a POINT.
case WM_MOUSEMOVE:
{
ptMouse.x = LOWORD(lparam);
ptMouse.y = HIWORD(lparam);
}

Now you have the mouse position in a POINT;

Theres also WM_LBUTTONDOWN and WM_LBUTTONUP but they both work the same way.

Mouse mapping:

First you need to take the tile in paint or whatever graphics program and sort out the different parts for example, you have a diomand tile <>. Well you make the inside of it all blue and the different corners different colors but make sure its the same size as the tile. Then you load it in directx. You have to create a array or something of RECT''s that hold every other tile. You can''t get every tile because their diomand shaped. Now when your mouse cursor passes over the rect, test it against the colored tile to check which part its in. Then you can determine what tile youre mouse is in. To check the color, you use GetPixel() but I forget the parameters so you''ll have to ask around.

Scrolling:

This is easy. Lets say you have a map 800x600. Just test if ptMouse.x < 10 and ptMouse.x > 790 and the same for the y axis. Then you just do the scrolling like you did with the keydowns. You can place this in your main game loop or in the MOUSEMOVE case. Either way is fine.

Hope this helps!
Dale
Dale
Thanks heaps kmsixpence. Works perfectly. :D

-----------------------------
Student - "How do I make my first game?"
Lecturer - "Based on your marks from your last assessment?"
-----------------------------Empires! Visit online at http://www.daleszone.comProgramming for a funner world.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.