• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tony Sharp

Mouse Events for a Board Game in SDL

6 posts in this topic

After hours of trying to figure this out on my own, I've given up... I need help.

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.
0

Share this post


Link to post
Share on other sites
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).

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.
1

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1324339164' post='4895540']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).[/quote]
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.

[quote]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.[/quote]
Very clever. I'll look around for some non-SDL tutorials to detail this.

[quote]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.
[/quote]
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.

Thank you for your time and help.
0

Share this post


Link to post
Share on other sites
I use something like this for doing Mouse events is this is what you mean. All this does is catch any times the mouse is moved over the image area. This only works for rectanges though.
Haven't gotten round to writing something for different shapes yet. for the rest of the code look at sourceforge and search for newdawn.

[code]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;
}
}
}[/code]
0

Share this post


Link to post
Share on other sites
You can just take a look at this tutorial [url="http://lazyfoo.net/SDL_tutorials/lesson09/index.php."]http://lazyfoo.net/S...on09/index.php.[/url] The first half of it just describes the class he used to describe each of the screen parts(which i guess would be useful as u'd have to do the same with ur game board) and the second talks about the SDL mouse events. It's not a very difficult concept, if u were able to do the rest this shouldn't be any trouble.
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.
0

Share this post


Link to post
Share on other sites
[quote name='Tony Sharp' timestamp='1324341540' post='4895549']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.[/quote]Give allegro some 5min reading, it has a great events system for mouse and keyboard (and others) while is also free and cross-platform!
0

Share this post


Link to post
Share on other sites
Allegro, by itself, will not give the OP the kind of high level input they were originally outlining. That is, it doesn't offer a significant improvement over SDL in this area.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0