#1 Members - Reputation: 100
Posted 19 December 2011 - 03:31 PM
I'm making a board game. All the "hard work" like graphics, gameplay, AI are done. The only thing that's in my way now are mouse events. I haven't been able to find a tutorial that gets to the point of what I'm trying to do.
How do I define the coordinates of a clickable area on a graphic (my board image)?
And how do I give the user control to put pieces in that area?
Your help would be greatly appreciated.
#2 Moderators - Reputation: 5027
Posted 19 December 2011 - 05:59 PM
For instance, you could have a collection of rectangles, and write or find a function that can do a point/rectangle intersection test. You need to listen for mouse events, and test the mouse pointer position against this rectangle set when a click or drag is detected.
It is hard to give more than a broad overview to such a broad question. The details are up to you - but given how far you've gotten you should be capable. If you have a specific question about how to achieve any particular piece of this puzzle then it will be easier to provide a more detailed answer.
#3 Members - Reputation: 100
Posted 19 December 2011 - 06:39 PM
That sucks... I may just have to look for another cross-platform multimedia library, or just make a CLI-based game. Trying to connect everything to these graphics is the only thing that's getting in my way.Unfortunately, no such high level input exists in SDL. You need to do it yourself, or find a higher level library (possibly written in terms of SDL).
Very clever. I'll look around for some non-SDL tutorials to detail this.For instance, you could have a collection of rectangles, and write or find a function that can do a point/rectangle intersection test. You need to listen for mouse events, and test the mouse pointer position against this rectangle set when a click or drag is detected.
I just want the mouse to work with the board. When the player clicks a spot, I want a piece to show up in that spot. And once the computer calculates its move, I want a piece to show up there. I'll eventually figure it out. You've pointed me in a better direction.It is hard to give more than a broad overview to such a broad question. The details are up to you - but given how far you've gotten you should be capable. If you have a specific question about how to achieve any particular piece of this puzzle then it will be easier to provide a more detailed answer.
Thank you for your time and help.
#4 Members - Reputation: 100
Posted 23 December 2011 - 10:10 AM
Haven't gotten round to writing something for different shapes yet. for the rest of the code look at sourceforge and search for newdawn.
void OnHover() { // whilst mouse is over any of list items
if(event.type ==SDL_MOUSEMOTION) {
int xoff;
int yoff;
xoff = event.motion.x;
yoff = event.motion.y; //Get the mouse offsets
bool hover_first = false;
if((xoff > tileterrain[0].getX()) && (xoff < tileterrain[0].getX() + tileterrain[0].box.w) && (yoff > tileterrain[0].getY()) && (yoff < tileterrain[0].getY() + tileterrain[0].box.h)) {
hover_first = true;
}
if(hover_first) {
// Only after has inital focus
hover_first = false;
}
}
}
#5 Members - Reputation: 100
Posted 23 December 2011 - 04:31 PM
So what you'd do is initialize a SDL_Rect (which contains a top left described by x, y and then width and lenght to give the bottom right) and u'd just use the mouse events to see if it's inside that rectangle and know which 1 to activate.
#6 Members - Reputation: 152
Posted 25 December 2011 - 10:31 PM
Give allegro some 5min reading, it has a great events system for mouse and keyboard (and others) while is also free and cross-platform!That sucks... I may just have to look for another cross-platform multimedia library, or just make a CLI-based game. Trying to connect everything to these graphics is the only thing that's getting in my way.






