Hi Shashwat,

On 09/08/2017, at 7:27 AM, Shashwat Mishra wrote:

> I am actually not sure how one can build games that use mouse to interact 
> with it on C++? 

First, continue this discussion on  KDE games development 

Re the use of the mouse, first you need to get familiar with
the Qt library classes and KDE Frameworks library classes
used in many KDE apps including KDE Games.  There are
tutorials on this. Qt also has example code. And you can read
the source code of some of the simpler games.

Games also use the KDE Games library, especially for
games-appropriate actions and icons (menus, buttons
and keystrokes).  For example, games have a Game sub-menu
(provided by class KStandardGameAction from the KDE Games
library) instead of the standard File sub-menu.

The source code of individual games (start with a simple one)
will show you how to program mouse usage.  Often this involves
only the QAction or derived KStandardGameAction classes.  QAction
objects can be triggered by by various events, such as clicking on
a menu item or toolbar button or hitting a particular keystroke. This
signal can be connected to any code you like, using Qt's "signals
and slots" mechanism. This approach will cover quite a lot of what
you need in a simple game.

If you wish to interact with the graphics part of a game, several Qt
classes implement protected handlers for mouse events which you
can re-implement in your own code: see QWidget, QGraphicsView
and QGraphicsScene (in that order of sophistication). Look for methods
with "mouse" in their names. Also look for examples of re-implementations
of these methods in KDE Games code. Again, start with simple games.

Hope this helps,
Ian W.

Reply via email to