Good Entity Manager Handling - C# XNA/MonoGame -
i'm quite new monogame/xna , first actual game, thought try , recreate space invaders. handle invaders movement, created "invadermanager" class handle this. created class called "entitymanager" handle other kinds of entities such bullets.
this works alright though classes can accessed within "maingame" class handles actual game meaning if example when want collision code in "bullet" class remove invader when it's collided 1 (meaning has access "invadermanager" class), becomes little awkward , has lead me making functions in these manager classes static outside classes can access call them without instance.
for(int = 0; < invadermanager.spaceinvaders.count; i++) { if(collisiondetect(invadermanager.spaceinvaders[i])) { entitymanager.remove(this); invadermanager.remove(invadermanager.spaceinvaders[i]); } }
this works of course telling me isn't way go thought ask forum if there possibly better way handle this? or alright make function static purpose stated?
when make state globally visible , modifiable, various code accessing , modifying state, , become difficult make code changes without affecting entire program.
restrict visibility as makes sense to.
static functions fine. global static state (like static public array) not.
if you're not sure class should doing, don't write class. invadermanager
seems little more list of entities. use list
then.
good object-oriented design hard, , don't need space invaders. think of problem in terms of data types , functions rather manager classes.
it's difficult give more specific advice such general question.
Comments
Post a Comment