Best way to handle input

Posts: 9
Joined: 2009.07
Post: #1
How should I handle mouse clicks using GLUT? There are so many things that a mouse click can do that honestly I am overwhelmed. For example, it could select a item in a menu, a level, or do something in the game.

I just want to ask the opinion of this community, and I will try to string together a custom method for my program.

Also, I want to know what design patterns you follow, if any. I know of MVC and the Observer pattern, and I want to know if anyone used that or something different in their game.
Quote this message in a reply
Posts: 86
Joined: 2008.04
Post: #2
Mouse input is part of event driven code.

Typically, you process the mouse event by using the location of the mouse and button state, taking into account game state.

For example, if you click on window coord x,y, then you determine what menu element contains those coordinates.
if (mouse.x>menuButton.x1)&&(mouse.x<menuButton.x2)
Quote this message in a reply
Posts: 9
Joined: 2009.07
Post: #3
Okay, so in general I would test if the mouse is in an area (each "view" that is drawn already has a class method to do that), let the view know (so that it can highlight on a mouse over, etc), then perform the right action (like change the state, load the views, update position, start game, etc).

So in my program it might look like:

Event----->Hit detection----->Update View and change game state
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Lua: Creating a scripting engine to handle sprite actions link_jr97 9 8,574 Mar 6, 2005 01:41 AM
Last Post: DoG