Re: Newb Needing Help With Classes In BGT
Hi,
if you have a single instance of the trampoline class, this could also be done in a much simpler way, although possibly dirtier when looked at from the perspective of what is good coding practice and what is not. :-)
If you do in deed have only a single trampoline instance per level, let's assume it's called, say, tramp, because a class instance (object) is not allowed to have the same name as the class itself. So, you've already declared the class itself elsewhere, and now you are going to create your object:
trampoline tramp;
Now, your check to see if the player is currently standing on the trampoline could look something like this:
if (playerposition == tramp.TrampolinePosition)
{
alert ("Oops!", "There's a trampoline right here. Jump on it!");
}
Of course, this would have to be checked every time the player takes a step. You could have it somewhere in your main loop but then that would perform unnecessarily too many checks, even when the player has not moved at all on this iteration of the main loop, and thus create unwanted performance overheat, however slight it might be. So, if you decide to use this approach, the best place for this check would probably be inside the function where player movement is handled, after everything else such as possible wall collisions has been taken care of and you are sure the player has in fact successfully taken a step.
By the way, how is your map currently represented? Are you using an array or a dictionary for it, or do you just store the position of everything in its own separate variable and then check where the player is currently standing, like in the above example? For many types of games, experience has taught me that this can in fact be the most suitable approach to handling the map. The numbered approach Magur described in the previous post, where the number on each tile represents a certain terrain or item type, is the second obvious, probably most often used, and also very good solution, but you should probably ask yourself what you need and what you don't need for the map, how you are going to use it (i.e. will you allow the player to browse the map for the whole level, pausing gameplay in the meantime, will you allow for the map to be saved to a text file, etc). Answering these questions should probably help you to answer the main question of whether you will need an array or worse a dictionary to represent the various tiles with their terrain/item type numbers, or whether this is not going to be necessary at all. By the way, dictionaries are only worse than arrays in that they are slightly more tedious to code and they are a tiny bit slower in performance than arrays.
Hope this has actually provided some helpful tips rather than just more confusion. :-)
Lukas
_______________________________________________ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector