Board Game Technique?
by Scott Johnson · in Torque Game Builder · 05/21/2008 (5:07 pm) · 18 replies
I've been entertaining the idea of creating a Risk-Like type of board game.
I'm wondering what technique I could use to represent the individual territories for the map.
Specifically, I'm wondering how to do territory selection via click, preferably with a selection highlight.
I think that If I could get the map type functionality, I can probably figure out how to do the piece placement and movement (similar to the chess demo).
Anything to get me started in the right direction, a high level description would be appreciated!!
I've entertained the thought of creating a seperate sprite for each territory, with another sprite as an overlay for selection highlighting. However with the possibility of creating upwards of a hundred or so territories by hand, I figured I would ask here on the forum.
Thanks in advance for any help!
I'm wondering what technique I could use to represent the individual territories for the map.
Specifically, I'm wondering how to do territory selection via click, preferably with a selection highlight.
I think that If I could get the map type functionality, I can probably figure out how to do the piece placement and movement (similar to the chess demo).
Anything to get me started in the right direction, a high level description would be appreciated!!
I've entertained the thought of creating a seperate sprite for each territory, with another sprite as an overlay for selection highlighting. However with the possibility of creating upwards of a hundred or so territories by hand, I figured I would ask here on the forum.
Thanks in advance for any help!
About the author
#2
I can certainly see the usefulness of individual sprites per territory. The parallaxing idea for 3D effects are a good idea! The use of particles is also good, and I could see it applied to unit creation/destruction as well.
This would also help when using an embedded scenegraph to do a "mini map".
One immediate question comes to mind, which is how to do territory picking in this scenario. Considering that the shape of a territory is generally irregular, which means the sprite bounding boxes of adjacent territories could be overlapping, how to determine which territory has been picked (i.e. clicked)
I can also see a usefulness in having a sprite with multiple frames where each frame denotes a different display state for the territory, i.e. Selected (with a border highlight), Occupation (the background color is chosen for the player that own it) etc...
05/22/2008 (12:27 am)
Thanks for the feedback Brian,I can certainly see the usefulness of individual sprites per territory. The parallaxing idea for 3D effects are a good idea! The use of particles is also good, and I could see it applied to unit creation/destruction as well.
This would also help when using an embedded scenegraph to do a "mini map".
One immediate question comes to mind, which is how to do territory picking in this scenario. Considering that the shape of a territory is generally irregular, which means the sprite bounding boxes of adjacent territories could be overlapping, how to determine which territory has been picked (i.e. clicked)
I can also see a usefulness in having a sprite with multiple frames where each frame denotes a different display state for the territory, i.e. Selected (with a border highlight), Occupation (the background color is chosen for the player that own it) etc...
#3
05/25/2008 (4:46 am)
You can set the collision polygon on a sprite. Depending on how much detail you need, you can click each corner on the sprite and now when you pass your mouse over the sprite without the collision polygon the sprite will get a callback from the mouse. Even if bits of the sprite are outside of the polygon, those outside bits are ignored.
#4
I had thought of using the collision polygon, however due to the fact that convex collsion polys aren't supported (right?) I would be forced to create many sprites per territory in this model. additionally with hundreds of potential territories and detailed borders this would be a BIG task for me.
One Idea that I had, if possible, would be to drill down through the sprites at a given coordinate and detect the pixel color for each sprite... if I have a transparent background for each territory, this should detect only color for the territory under the selected point. This would allow me to have overlapping sprites with no collision polys... and I would need to insure that my territory sprites are aligned with no overlapping colors.
I would appreciate any feedback on this idea, as well if there's a way to detect the color given a point, and how to iterate through all sprites under a given point...
Thanks!!
05/25/2008 (2:20 pm)
Nikos,I had thought of using the collision polygon, however due to the fact that convex collsion polys aren't supported (right?) I would be forced to create many sprites per territory in this model. additionally with hundreds of potential territories and detailed borders this would be a BIG task for me.
One Idea that I had, if possible, would be to drill down through the sprites at a given coordinate and detect the pixel color for each sprite... if I have a transparent background for each territory, this should detect only color for the territory under the selected point. This would allow me to have overlapping sprites with no collision polys... and I would need to insure that my territory sprites are aligned with no overlapping colors.
I would appreciate any feedback on this idea, as well if there's a way to detect the color given a point, and how to iterate through all sprites under a given point...
Thanks!!
#5
You could just make the visible map a single image. Then you handle mouse events and resolve the position to a territory. One idea to do this could be a second texture the same size as the visible map that can be used as a "lookup". You could either do some kindof color key, or since this is "your" texture, you could even store the territory name (abbrev.) encoded into a ColorI.
05/25/2008 (5:55 pm)
FYI An elegant solution for this will probably require C++ work.You could just make the visible map a single image. Then you handle mouse events and resolve the position to a territory. One idea to do this could be a second texture the same size as the visible map that can be used as a "lookup". You could either do some kindof color key, or since this is "your" texture, you could even store the territory name (abbrev.) encoded into a ColorI.
#6
And every country needs a different colour, however slight. And once you have highlight colours, selection colours, active colours... that's a lot of colours to keep track of and what each means.
I remember reading somewhere about multiple polygons on a sprite. Any concave polygon can be decomposed into two convex polygons. That way you're using the engine to do the heavy lifting.
05/26/2008 (9:16 am)
You can certainly modify the engine to look at pixel colours.And every country needs a different colour, however slight. And once you have highlight colours, selection colours, active colours... that's a lot of colours to keep track of and what each means.
I remember reading somewhere about multiple polygons on a sprite. Any concave polygon can be decomposed into two convex polygons. That way you're using the engine to do the heavy lifting.
#7
www.santareparata.org/img/map_italy.gif
Not to mention the islands which are also a part of italy and should all be selected together...
05/26/2008 (12:37 pm)
You can decompose a concave into convex(s), but its not necessarily one. For example, how can you divide italy into only two convex(s)?www.santareparata.org/img/map_italy.gif
Not to mention the islands which are also a part of italy and should all be selected together...
#8
Thanks for the feedback, unfortunately I don't own the pro version, and probably won't for a while.
From what I'm reading I guess it's safe to assume that there are no script exposed functions to return pixel color at a given point? I wasn't able to find anything useful in a search of the fourms and docs, however I'm hoping I missed something.
I think using the collision poly method, and having to decompose my territories into multiple concave sprites will be out of scope for me. I see a need for a tool to do this work in order to speed the process of creating maps of this sort.
So far I'm leaning towards the single "color keyed lookup" image for territory selection and identification. Seperate layers will hold individual territory shaped sprites for backgroud image, selection highlight, fog of war, etc..
Once again, thanks for the feedback!!
05/26/2008 (4:24 pm)
James, Nikos,Thanks for the feedback, unfortunately I don't own the pro version, and probably won't for a while.
From what I'm reading I guess it's safe to assume that there are no script exposed functions to return pixel color at a given point? I wasn't able to find anything useful in a search of the fourms and docs, however I'm hoping I missed something.
I think using the collision poly method, and having to decompose my territories into multiple concave sprites will be out of scope for me. I see a need for a tool to do this work in order to speed the process of creating maps of this sort.
So far I'm leaning towards the single "color keyed lookup" image for territory selection and identification. Seperate layers will hold individual territory shaped sprites for backgroud image, selection highlight, fog of war, etc..
Once again, thanks for the feedback!!
#9
If you want direct access to a texture, it might be useful to implement your entire game in a custom gui control, or perhaps multiple custom controls. A risk game does tend to look and behave more like a gui than a "scene".
But that also requires the source...
If you want to make a risk like game in just script, I'd recommend using static sprites for territories and just avoid any concave shaped countries. Maybe in your game world all countries are perfectly rectangular.
05/26/2008 (11:31 pm)
No you can't get that information in script without modifications.If you want direct access to a texture, it might be useful to implement your entire game in a custom gui control, or perhaps multiple custom controls. A risk game does tend to look and behave more like a gui than a "scene".
But that also requires the source...
If you want to make a risk like game in just script, I'd recommend using static sprites for territories and just avoid any concave shaped countries. Maybe in your game world all countries are perfectly rectangular.
#10
1) Set up all the countries as sprites. Do this as static sprites or if the countries have little flags waving etc, animated sprites
2) Set up all the animated roll over sprites for the countries, ie when a player clicks on this country play this animation.
3) Create a new level workspace and position the countries as best you can, maybe using a backdrop to line them up. This step would be a pain in the butt a little but shouldn't be too difficult
4) In your code setup the onmousedown function to select the object by using the pick point function. IE, in psuedocode:
5) Write your select country function to do what ever you need to do when you select a country.
This should get around all the collision issues. Don't forgot, collisions should only be used and active if you are moving objects and to need to handle what happens when they hit each other. As far as I can see a risk style game would have all collisions turned off as everything is "static". This would also help the performance of the game.
Post up if this makes no sense.
05/27/2008 (11:57 am)
You shouldn't need to do any collisions. Here is what I would be doing:1) Set up all the countries as sprites. Do this as static sprites or if the countries have little flags waving etc, animated sprites
2) Set up all the animated roll over sprites for the countries, ie when a player clicks on this country play this animation.
3) Create a new level workspace and position the countries as best you can, maybe using a backdrop to line them up. This step would be a pain in the butt a little but shouldn't be too difficult
4) In your code setup the onmousedown function to select the object by using the pick point function. IE, in psuedocode:
t2dscenegraph::onmousedown(%this,$worldpoint) %objects = pickpoint($worldpoint, %layer) if %objects < 1 or %objects > 1 do nothing / error else selectcountry(%objects)
5) Write your select country function to do what ever you need to do when you select a country.
This should get around all the collision issues. Don't forgot, collisions should only be used and active if you are moving objects and to need to handle what happens when they hit each other. As far as I can see a risk style game would have all collisions turned off as everything is "static". This would also help the performance of the game.
Post up if this makes no sense.
#11
Thanks for the feedback. However I believe that the collision suggestion was being tossed about due to the fact that when clicking on overlapping static sprites, there's no way to determine the intended sprite, and having a collision polygon defined could help "select" the intended sprite.
So,I'm tossing out the collision issue altogether, due to the other factors mentioned above (need for convex collision, or decomposition into convex polys, time to outline each territory, etc).
Which leaves me with static sprites like you mentioned.
For example I'm using oklahoma and texas to test with. Using code similar to what you provided using pickPoint, my result is that I can click on the southern part of texas, and I get a list of one sprite. but when I click in oklahoma, I get both states in the object list returned. This is because the oklahoma sprite is mostly covered by the texas sprite (although the overlapping portion is transparent).
If I put the onmousedown within each state, I get similar results in that both state's callback is fired when I click on oklahoma.
This is where the crux of the problem lies. How do I determine the intent of the user clicking, I have 2 states to choose from, however no reliable way to know which state was actually chosen via code.
The suggested solution so far is to modify the engine to create a script accessible function that will return the color of a point local to a sprite, and use this color to determine which sprite was chosen. This would of course imply each color would need to map one to one with a territory. This would be accomplished with a single large color keyed image underlying the actual individual territories. Once the territory selection is determined, the appropriate actions can occur using specific territory sprites.
Anyhow, I just wanted to expand upon this issue, just in case anyone was following this thread!
Thanks.
05/27/2008 (4:03 pm)
Glenn,Thanks for the feedback. However I believe that the collision suggestion was being tossed about due to the fact that when clicking on overlapping static sprites, there's no way to determine the intended sprite, and having a collision polygon defined could help "select" the intended sprite.
So,I'm tossing out the collision issue altogether, due to the other factors mentioned above (need for convex collision, or decomposition into convex polys, time to outline each territory, etc).
Which leaves me with static sprites like you mentioned.
For example I'm using oklahoma and texas to test with. Using code similar to what you provided using pickPoint, my result is that I can click on the southern part of texas, and I get a list of one sprite. but when I click in oklahoma, I get both states in the object list returned. This is because the oklahoma sprite is mostly covered by the texas sprite (although the overlapping portion is transparent).
If I put the onmousedown within each state, I get similar results in that both state's callback is fired when I click on oklahoma.
This is where the crux of the problem lies. How do I determine the intent of the user clicking, I have 2 states to choose from, however no reliable way to know which state was actually chosen via code.
The suggested solution so far is to modify the engine to create a script accessible function that will return the color of a point local to a sprite, and use this color to determine which sprite was chosen. This would of course imply each color would need to map one to one with a territory. This would be accomplished with a single large color keyed image underlying the actual individual territories. Once the territory selection is determined, the appropriate actions can occur using specific territory sprites.
Anyhow, I just wanted to expand upon this issue, just in case anyone was following this thread!
Thanks.
#12
I dont have access to TGB right now so I cant test this but I think you should be able to create the border point list for each country using the collision polygon tool, even though you're not creating convex polygons. Just dont click on the 'make into convex hull' button or what ever it's called. Also remember to turn off the native collision detection. On a mouse click event you can then cycle through your countries and get the point lists using the getCollisionPoly() method.
For isolated islands which you wish to be selected as part of the country, such as those of Italy, you will need to make seperate point lists for each land mass.
05/28/2008 (12:50 am)
I have one potential solution if you're unable to modify the source to include pixel picking and dont wish to implement multiple convex poly collision. The idea would be to go around the edge of each country laying down points to give a rough outline of that countries borders. Therefore each country ends up with an array of points. When the mouse is clicked, for each country you cycle through all its points and accumulate the angle which your clicked mouse position point makes with the countries border points. If the resultant accumulated angle is equal to 360 degrees then the mouse point lies within that countries borders. If however the accumulated angle is less than 360 degrees then the mouse point lies outside that countries borders.I dont have access to TGB right now so I cant test this but I think you should be able to create the border point list for each country using the collision polygon tool, even though you're not creating convex polygons. Just dont click on the 'make into convex hull' button or what ever it's called. Also remember to turn off the native collision detection. On a mouse click event you can then cycle through your countries and get the point lists using the getCollisionPoly() method.
For isolated islands which you wish to be selected as part of the country, such as those of Italy, you will need to make seperate point lists for each land mass.
#13
05/28/2008 (7:54 am)
If you are going to modify the engine it might be better to add pixel perfect sprite detection rather than some sort of colour detection and link it to a specific function. It would be a lot more usefull than just a pure colour picker.
#14
06/02/2008 (9:36 am)
Maybe not as fun as territory clicking, but I would use clickable towns or landmarks instead. For example, capitol city as country selector.
#16
There really is no reason to make the entire area of the territory clickable. If for no other reason, the computer version of the board game already does it this way.. /yawn.
You would be far better served using a cool floating selection item over the region.
06/29/2008 (11:03 am)
I have to agree with Love and Melvin.There really is no reason to make the entire area of the territory clickable. If for no other reason, the computer version of the board game already does it this way.. /yawn.
You would be far better served using a cool floating selection item over the region.
#17
To check if a point is inside the poly try this:
*Note this is untested, but it is based on a common formula (I cannot remember the name)*
If you combine this with the onMouseMove callback, you've got a great little highlight technique.
07/07/2008 (9:09 am)
If you really want the entire region to be selectable, I suggest that you use a "t2dShapeVector" who's poly outlines the territory. The poly does not need to be convex either.To check if a point is inside the poly try this:
function t2dShapeVector::isPointInPoly(%this, %worldPoint)
{
%inPoly = false;
%polyList = %this.getPoly();
%polyCount = getWordCount(%polyList) / 2;
for (%i = 0; %i < %polyCount; %i++)
%polyPoint[%i] = %this.getWorldPoint(getWords(%polyList, 2 * %i, 2 * %i + 1));
%j = %polyCount - 1;
for (%i = 0; %i < %polyCount; %i++)
{
if (%polyPoint[%i].Y < %worldPoint.Y && %polyPoint[%j].Y >= %worldPoint.Y
|| %polyPoint[%j].Y < %worldPoint.Y && %polyPoint[%i].Y >= %worldPoint.Y)
{
if (%polyPoint[%i].X + (%worldPoint.Y - %polyPoint[%i].Y) / (%polyPoint[%j].Y - %polyPoint[%i].Y) * (%polyPoint[%j].X - %polyPoint[%i].X) < %worldPoint.X)
%inPoly = !%inPoly;
}
%j = %i;
}
return %inPoly;
}*Note this is untested, but it is based on a common formula (I cannot remember the name)*
If you combine this with the onMouseMove callback, you've got a great little highlight technique.
#18
Thanks for the heads up on the t2dShapeVector, I'll have to play around with this as it sounds like it might just do the job. I'll probably have to build some kind of tool to create the territory outlines as doing this by hand would be pretty cumbersome.
As for the use of a floating selection item, although I think that it's cool in certain situations, the expectation that I have, and I figure most other folks who play computer board games, is that when you mouse over a territory (or click on it) that there should be a highlight to denote the territory.
Besides, having a floating selector over several hundred possible territories, would be a bit much, especially sea zones, and zones with no significant value...
07/07/2008 (11:48 am)
Phillip,Thanks for the heads up on the t2dShapeVector, I'll have to play around with this as it sounds like it might just do the job. I'll probably have to build some kind of tool to create the territory outlines as doing this by hand would be pretty cumbersome.
As for the use of a floating selection item, although I think that it's cool in certain situations, the expectation that I have, and I figure most other folks who play computer board games, is that when you mouse over a territory (or click on it) that there should be a highlight to denote the territory.
Besides, having a floating selector over several hundred possible territories, would be a bit much, especially sea zones, and zones with no significant value...
Torque Owner Brian Wilson
i.e.:
- zooming(resizing) the selected territor instead of just highlighting it
- pushing a new instance of the selected and/or imporant territories a few layers above the static map and using parallaxing as you scroll around the map to give a 3-d effect
- layering and parallaxing with each territory as a sprite add a drop-shadow on the static map
- particles using the territory sprite in the color of the conquering team to show transition of ownership