Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I was searching for XNA tutorial in Youtube and I found this http://www.youtube.com/watch?v=MxucTn2HYxY

I was wondering if this is a good way to design the overall structure/classes for my game I'm trying to do. Basically, my game is almost the same as what this tutorial teaches ( A top down shooter ) , except that mine has inventory system. And is this some sort of design pattern or something? I can't really identify it IF it is...

For code example,

class Obj  { 
    public Obj(Vector2 pos) {
        this.pos = pos;
    }
    public virtual void LoadContent(ContentManager Content) {
        // Load Texture , spriteIndex
    }
    public virtual void Update() {
        // Update
    }

    public virtual void Draw(SpriteBatch sb) {
        // draw
    } 
}

class Items  {
    public static List<Obj> objList = new List<Obj>();

    public static void Initialize() {
        for (int i = 0 ; i < 64; i++ ) {
            Obj o = new Bullet(Vector2.Zero);
            o.alive = false;
            objList.Add(o);
        }
        objList.Add(new Wall(new Vector2(100, 120)));
        objList.Add(new Wall(new Vector2(550, 130)));
        objList.Add(new Man(new Vector2(50, 50)));
        objList.Add(new Cursor(new Vector2(50, 50)));
    } 
}

class Man : Obj  {
    public Man(Vector2 pos) : base(pos) 
    {
        pos = this.pos;
        speed = 2;
        spriteName = "P";
    }

    public override void Update() {
        // Update
        base.Update();
    }

    public override void Draw(SpriteBatch sb) {
        // Draw the HUD
        base.Draw(sb);
    }
 }
share|improve this question

closed as not constructive by Byte56, Josh Petrie, bummzack, Anko, Trevor Powell Apr 9 '13 at 8:58

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

3  
If you understand it, and you're not having any problems with it, use it. –  Byte56 Apr 6 '13 at 15:27
1  
XNA should have no bearing on how you design 'classes.' It's just a framework or 'toolbox'. Your language is C#. An Object Oriented / Managed language. Know C# and you will know how to design your classes. –  Dialock Apr 6 '13 at 15:42
    
Hmm, okay then. Thanks :D –  Xeon Apr 6 '13 at 15:52
    
Though you might want to look into general design strategies for games, especially the debate on entity systems vs deep class hierarchies (both can be suitable). –  Roy T. Apr 6 '13 at 16:10
    
@RoyT. I suppose Component-Entity-Systems counts as Entity System? Will continue reading about them though .. Thanks for the examples! :) –  Xeon Apr 6 '13 at 16:37

1 Answer 1

The best way to learn good and bad design is to read and write lots of code, as well as reading books and blog articles and watching videos. Eventually you'll have a feel for (and an opinion on) what's good and what's not. Asking "is this good" on a Q&A site isn't going to help you much.

For readability, I might change the way you're naming things. In general, abbreviations (like Obj and pos) should be avoided for clarity's sake. And Hungarian notation doesn't add much benefit, especially if you're using tools like Visual Studio and Resharper.

Put some thought into your naming. What is an Obj or an Item? Can they be any old thing, or are they "game entities" or "inventory items"? Be as specific is possible, because in a year when you come back to this code base, you're going to rely on good naming to understand what the heck is going on.

share|improve this answer
1  
I'm not a professional, just asking from the experienced to check. I purposely removed the code contents so that you won't be focusing in the contents but the overall design (Just to clear it out before you edit the answer) .Yes I will rename all these codes once I have finished following the tutorial. I'm following his code because I don't want to have any confuse/conflict with the tutorial. Yup, good naming is really important! Thus I added "And is this some sort of design pattern or something?I can't really identify it IF it is" since I don't know whether Obj is like a factory or whatever. –  Xeon Apr 6 '13 at 16:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.