lundi 17 juillet 2017

Player, Enemies and bullets Interaction ( Game Design )

I made a bullet hell game. Everything works as intended. Since I've never had any game design courses etc. I have concerns about the code ( quality wise and design wise).

What I do is store all the objects in GLOBAL VECTORS(i know its bad). such as

EnemiesArray

bulletsArray //enemy bullets

playerBullets //player bullets

And for collision i have a Manager that checks collisions in update

for (auto playerBullet : playerBullets)
{
 for(auto enemy : EnemyArray)
    {


        if(enemy->checkCollision(playerBullet->bulletSprite->getPosition()) )
        {
           //collided
         }
    }
}

So when there is collision of bullets with enemies lots of things get effected. e.g. Background objects move, Player gets xp and Hud changes etc.

Manager contains the reference to bg hud and everything it needs.

Problem 1:

How do I get rid of global vectors. ( It allows me to create bullets/enemies from anywhere in the code).

Problem 2: Should there be a manager to check bullet collisions? Or the object itself should check it? if so how do i give reference of enemies to the bullet.

Problem 3: Manager is managing too many objects like I mentioned. (Sorry I sound stupid here). I hear one manager should be managing one kind of job.

Aucun commentaire:

Enregistrer un commentaire