Computer Science Canada Allegro Game Help |
Author: | DrummaBoyFB [ Sun Jul 18, 2010 9:42 pm ] |
Post subject: | Allegro Game Help |
Hi I am currently making a game in allegro. I have many .bmp files for my characters and they're moves. I know how to implement them and make them work. But I do not want to make different classes for each person because that seems unecessary. Is it possible to do like all the players in one player class? without to much work? because i mean each character has a different amount a .bmp files for walking , attack and so on . So I don't know how I'd be able to put all the characters in one class. If you can find a way to do it I'd be very grateful.n If you don't understand the question then say so , n I'll give you an example |
Author: | Tony [ Sun Jul 18, 2010 10:15 pm ] |
Post subject: | RE:Allegro Game Help |
How well do you understand the difference between "a class" and "a class instance"? Also, and perhaps more importantly, the difference between there, their, and they're? |
Author: | DemonWasp [ Mon Jul 19, 2010 9:06 am ] | ||
Post subject: | RE:Allegro Game Help | ||
The mechanism you're looking for is parameters. Your classes all have constructors, yes? Well, the constructors should take some means of identifying the images to be loaded, such as an image name or a base name (for example, "fred" might imply that it should load "fred_walking.bmp", "fred_eating.bmp", etc). Then when you instantiate all these classes, you have:
each of which loads the images that it uses. They then exhibit the same behaviour (because behaviour is determined by the Player class), but use different images because the Player class will load different images based on the argument passed into its constructor. |
Author: | TerranceN [ Mon Jul 19, 2010 5:05 pm ] | ||||||
Post subject: | Re: Allegro Game Help | ||||||
Considering other responses, I hope I am understanding you right, you want a way for your player class to handle different amounts of frames to load dynamically. Also note my code may not be syntactically correct, and I don't use allegro so I hope I used the right type and function for handling bitmaps. Use dynamic memory. Since you know the name of the player (because of DemonWasp's Post) and you should know the amount of frames each animation has because you made them, you can dynamically load the images. In your player class you will need a pointer to a pointer to type BITMAP which will point to the array of pointers that point to the images, and an int to hold the number of frames the animation has, do this for each animation.
Then in your constructor, have a parameter for the number of frames. From there you can create your array and proceed to load all the images (make sure your images have a set pattern like name_type_framenumber.bmp so you can use string concatenation to create the image file names in your code)
And finally don't forget to free the dynamically allocated memory
Hope that helps. |