Advertisement

rpg problem

Started by October 08, 2001 08:42 PM
4 comments, last by vasagralem 23 years, 2 months ago
Hey guys, i''m proggraming an rpg.. well kindof.. i''ve got NO problem doing advanced graphics 3d or 2d, so i''m not worried about that. so i started doing the programing. I built a map editor. Then i built a tool to create the characters to go in the game. now the problem. i started programming the game but i realized a problem early on. subroutining. every time you clik the mouse my program runs through a series of ifelse statements or case statements. problem is it''s slowing the entire process down so much the graphics are no longer smooth. the reason i have so many testing statements on the click message is that i have to be able to click on every character, every dynamic object, the menu''s ect.. so my question. how do you test whether you clicked on somthing without putting 50 million if statements on the lbutton wm? (to prevent questions- c++ 6.0, directX 8, 16 bit at 800x600) i would apreciate any tips & tricks, you;ve compltetely missed the mark, or you''re screwed''s that anybody can give. thanks, ---vas
If you are expecting a kick in the balls, and you get a slap in the face... it's a victory.
a.) A switch statement helps if the cases evaluate to constants. However, a switch statement compiles to the same tests and jumps that if statements compile to.

b.) Only test plausible cases. I can''t be specific without more information, but the principle is that you only test what you absolutely need to test. For example, if you want to find out which object is under the mouse, convert the mouse coordinates to game coordinates and find what section of the background (ie, tile) is under the mouse. Then ask the tile what objects are on/in it. This requires tiles being able to know when an object gets on/off.
Advertisement
There are a couple of different ways to approach it. The "objective" of course is to circumvent as much testing as possible without skewing your logic. I don''t know all the details of your specific problem but I would probably approach it along the lines of subclassing all your actors via an ancestor class that implements an Observer or Chain of Responsibility. Determine a messaging structure that fits your needs while eliminating as much "unnecessary" information as possible so that when your observers see a message they can choose to ignore request or query it for more relevant information to do any additional processing to fulfill the original request. Like a stated previously, that''s only one of many.

YAP-YFIO

-deadlinegrunt

~deadlinegrunt

so you add a flag on the tile for object_on, and then you test if you clicked in the map area and if you did, which tile. then you test if there was an object on it, and if so, which one. so there is my new question.. how out of somthing like 50 obj''s so far, do you get the program to figure that out, should i make another flag in the tile, to hold a handle to the object?

thanks --vas
If you are expecting a kick in the balls, and you get a slap in the face... it's a victory.
If you use an observer pattern from my previous post for example you wrap all your objects up in a dynamic container and broadcast the message etc. The objects will take care of themselves if coded properly.

YAP-YFIO

-deadlinegrunt

~deadlinegrunt

That''s a rather high-level description, deadlinegrunt.

vasagralem: Whenever an object moves, have it check for where it is and notify that tile (in other words, every tile maintains a list of which objects are on it).

This topic is closed to new replies.

Advertisement