Skip to main content
gamedev.net
🔒 Locked

Getting somewhere...

Started by hammerstein_02 Jun 15, 2002 at 4:14 AM 0 replies 200+ views
Original Post
hammerstein_02
hammerstein_02
Right, have been working on my first actual game project for about a week now. I have my graphics functions starting to come along nicely, I can create surfaces etc.. I have written a cImagelist class to handle a list of DirectDraw surfaces, and am now working on using that list in my sprite classes. I am now starting to create my general sprite class, cSprite. From which I would like to create cPlayer, cEnemy, cPickup. Each one having different attributes but being based mainly on a sprite object. When I finally write the game, I would like to control all the cEnemy''s on my screen by calling a single function.. so I thought why not create a sprite manager, but I want the sprite manager to be able to control cEnemys and also control cSprites and cPickups. I have been told to look at virtual functions and I think that is what I am requiring. If I create a cManager list of cEnemies and then I create one of say, bullets coming out of the players weapon, firstly will it slow my code down, are there more efficient ways of doing this? Secondly, can I create functions specific to my cPlayer and cEnemy classes, but still invoke them using my Manager class? This is new to me and the design is something I want to get pretty much right..
Zorodius
Zorodius
quote:
Original post by hammerstein_02
If I create a cManager list of cEnemies and then I create one of say, bullets coming out of the players weapon, firstly will it slow my code down, are there more efficient ways of doing this?

Doing any processing is always slower than doing no processing That aside, though, the method you are describing is not more inherently prone to cause slowdowns than any other.
The problem with OOP that makes it slower than procedural programming is function overhead. It is very easy to use OOP to make something that sounds cool from a design standpoint, but performs poorly in implementation because of the excessive amount of jumping around in the program flow. It does not sound like you''ll have that problem with your design.


quote:
Original post by hammerstein_02
Secondly, can I create functions specific to my cPlayer and cEnemy classes, but still invoke them using my Manager class?

I don''t think so. If your manager class is designed to work with the superclass (Sprite), it''s not going to be able to invoke methods unique to the subclasses. (It will be able to manage a list of them, though, through the use of pointers and some typecasting.)
There are ways around this, however. For instance, if a Player and an Enemy both have things that are done every frame, you could lump this stuff under the general heading of "Update". Then, a Sprite can have an Update method, and the Player and Enemy classes both overwrite the Update method to do something different (maybe when a Player''s Update method is executed, it checks for input and moves the players location, whereas when an Enemy''s Update method is executed, it vectors towards the player, and shoots at the player if a certain amount of time has passed. Just an example.)
If your manager has to do something different when processing enemies versus processing players, you may instead want to make a seperate manager class for each type - a cEnemyManger, a cPlayerManager, and so on. Then you''d easilly be able to write specific code for each class you want to manage, and wouldn''t have to worry about the ugly syntax involved in casting to and from superclass pointers.

Good luck! Sounds like you''ve got a cool game started!
You don't need to vote for the "lesser of two evils"! Learn about Instant Runoff Voting, the simple cure for a broken democracy!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.