Need component and game organization advice

Started by
-1 comments, last by Waylander 10 years, 5 months ago

I wasn't sure where to post this...the beginner area or here since I'm working in XNA.

I've made good progress as a programmer. I'm either an advanced beginner or on the bottom half of being an intermediate programmer. That said, I am working on some simple games in XNA and have gotten some basic things working (working, but probably coded very inefficiently). So I've been scouring the internet trying to find ways to organize classes and my search has me uncovering things like components and gamestates.

So here is what I need help with. The mantra is to organize your code into efficient, manageable pieces/classes/components so they can be reused. But the more "pieces" I make, the more trouble I am running into trying to get those pieces to "see" each other. When my code is inefficient and bloated, at least I could access what I wanted when I wanted to.

I am making a very simple 2D sci-fi shooter game (think old-school "Lifeforce" for the NES and Space Invaders and Megamania for the Atari 2600). While technically I have the basics working, I'm wanting to make my code more efficient and reusable for future features in the game as well as a good learning experience for future projects.

Right now I have 5 sprites. The player's ship, the enemies (in a List<Sprite>), the player's shots and the enemies' shots (each in their own respective lists), and a list for asteroids to randomly come across the screen for an additional hazard.

Here are my questions (for starters :) ):

(and keep in mind that I've done quite a bit of experimenting but the process is extremely frustrating)

1) Should each of those sprites be their own component (drawable maybe?) and updated/drawn from those components?

2) If so, how would a player component work with a shot/projectile component? I know I can do that via making a projectile object in the player class and updating the shots in there. Is that the way to go? Or can the projectile class update itself? And if that is the way to go, I can't figure out how to get them to see/work with each other.

3) Where do you draw the line to separate those things into separate classes or components?

4) Right now I have a drawable game component that has all these classes feeding into it. Objects of all of those classes are created in that class and used in there (that's the bloated part). Bad idea?

5) And would someone mind showing me a "best practice" on how to organize a simple game like this? I've seen the "there are many different ways to go about it" line often but what I haven't been able to find is a "here is how you can do this". If I can see that, then I'll have a jumping off point for more testing/experimenting/learning/etc.

Any help is greatly appreciated :).

Ulfhedhin

This topic is closed to new replies.

Advertisement