Thread: Storing Monster Stats For Zelda Game

  1. #1
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310

    Storing Monster Stats For Zelda Game

    We (us at Tarasque) are making a top down game in SDL. It's similar to the old Zelda, except the player is always in the middle of the screen (kinda like Diablo). I've got movement, map loading, a HP bar, and pausing up, but I'm stuck on monsters. Currently, monsters can be placed and you take damage if you move into them, but it's just like any other tile, in that it does not move. I'm trying to think up a way to store monster stats (HP, max HP, armor, XP it gives, coordinates, etc), and I'm thinking I'll make a class. But the problem is I'm not sure how to create a whole bunch of classes (ie: create a class when the monster comes on the screen, destroy it when it goes off). Or should I have 20 "monster" classes and just have a bunch of them be empty, and use those over and over for each monster? Any suggestions would be GREATLY appreciated

    Thanks,

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I would use a linked list so I could create any amount of monsters I want whenever I want it. That way there is no upper limit in how many monsters you can have (except limitations in your hardware of course ).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    you could specify monster starting points in your map or make them random. when the 'player' enters a part of the screen where a monster position is visible, create the monster. after the monster is killed (or is outside the screen if thats what you want) then delete that instance of the monster object. just keep checking through your list of monsters to see if they are still needed (viewable/alive).

  4. #4
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Thanks alot Magos and Perspective I'm going to learn linked lists and probably implement something like Perspective said.

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  5. #5
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    I use structs a lot. They're really easy to use for what you're doing. And since there won't be many mosters on the screen at a time (less than 50 i assume) you could:

    A) Create 50 different variables of the struct type you made

    B) Create an array of the struct type you made (much better than above answer)

    C) Use a linked list with struct (More modular)

    D) Use a class and linked list rather than struct and linked list

    ...there are other options as well. For the given situation I would think choice B is the simplest to implement

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    If you want the enemies to be created when appearing on the visible screen and destroyed when leaving it, make sure that each "enemy spawner" creates a max of one enemy at a time.

    Imagine if a spawner appears on the screen, an enemy is created. Then you walk a little so the spawner dissapears from the screen but the enemy doesn't. If you walk so the spawner appears again it should not create a new enemy this time (unless this is what you want, but the screen could easily be flooded with enemies this way).

    This can be done if every spawner and enemy has an ID number, and comparing if any existing enemy has the same ID as the spawner before creating a new enemy. If one does, don't create a new one. If no one has, create a new one.

    Just a suggestion...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Ah, very good idea. If I have monster spawn points I will definently have to do that. Thanks

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  8. #8
    STL Vectors will work as well.

  9. #9
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    STL vectors? Are they hard to implement?

    [edit]I can make arrays of classes correct?[/edit]

    //napKIN
    Last edited by napkin111; 01-23-2003 at 07:43 PM.
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  10. #10
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Vectors---

    http://www.pixelate.co.za/issues/5/5...stl/part1.html

    http://www.pixelate.co.za/issues/6/6...tl2/part1.html

    both of those links have multiple parts to them...find the link go to the next part of the tutorial look down at the bottom of the page

    as for using arrays with classes here is an example...

    Code:
    class Bla
     {
       public:
        short yippy;
        Bla::Bla();
        bool function();
     };
    
    Bla bla[10];
    Also, basically you're constructor is pretty much useless when having an array of objects.

  11. #11
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >"Also, basically you're constructor is pretty much useless when having an array of objects"


    isnt the constructor called for each object in the array when it is declared?

  12. #12
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Originally posted by TechWins
    Vectors---

    http://www.pixelate.co.za/issues/5/5...stl/part1.html

    http://www.pixelate.co.za/issues/6/6...tl2/part1.html

    both of those links have multiple parts to them...find the link go to the next part of the tutorial look down at the bottom of the page

    as for using arrays with classes here is an example...

    Code:
    class Bla
     {
       public:
        short yippy;
        Bla::Bla();
        bool function();
     };
    
    Bla bla[10];
    Also, basically you're constructor is pretty much useless when having an array of objects.
    No it's not. If you don't initialize the array then the default constructor is called. You cAn CAll AN OvERLOADED CONSTRUCTOR BY GOING CRAZY AND DOING THIS!!!!!

    Code:
    #include <iostream>
    using std::cout;
    
    class test
    {
    public:
    	test() { cout << "Default construct"; }
    	test(int i) { cout << "Overloaded construct"; }
    
    	~test() { cout << "Please don't kill me!"; }
    };
    
    int main(int argc, char **argv)
    {
    	test mytest[] = { test(2), test(4), test(6) };
            
        return 0;
    }
    Output:
    Overloaded constructOverloaded constructOverloaded constructPlease don't kill me
    !Please don't kill me!Please don't kill me!Press any key to continue

    Nifty.

  13. #13
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    No it's not. If you don't initialize the array then the default constructor is called. You cAn CAll AN OvERLOADED CONSTRUCTOR BY GOING CRAZY AND DOING THIS!!!!!
    Em, I didn't explain that very well. What I meant is when you initialize the array of objects (i.e. Bla bla[10] ) you don't need to call the constructor any longer. In fact you're not supposed to call the constructor, and you're not supposed to include any sort of processes in the constructor. At least that's true in the method I use, however, I could very well be wrong. I'm not all that up to date on my programming skils right now (haven't been programming for about a month now).

    EDIT: Ok, I'm really tired right now, and I think I read your post wrong, too. sad lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Open-source Game Project
    By Glorfindel in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 03-24-2009, 01:12 AM
  2. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 03:46 PM
  4. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM