Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualKuxe

Posted 06 May 2013 - 02:57 PM

Components are objects stored within a class as members, components are not inherited and thus it's not a component based system.

 

Assuming Foo is inheriting SolidObject and GameplayObject you could do something like:

 

vector<Foo> solidsAndGameplayObjects; //A container of the class inheriting from SolidObject and GameplayObject

...

for(auto foos1 = solidsAndGameplayObjects.begin(); foos1 != solidsAndGameplayObjects.end(); ++foos1)  //Iterate through all foos
{
    for(auto foos2 = foos1+1; foos2 != solidsAndGameplayObjects.end(); ++foos2)   //Nestled for-loop to compare all Foo's with eachother exactly one time
    {
        if( collision( foos1, foos2) == true) //Check for collision
        {
            foos1.hitpoint -= foos2.collisionDamage;  //collisionDamage lives in Foo
            foos2.hitpoint -= foos1.collisionDamage;
        }
    }
}

 

While I wouldn't recommend this approach since you will find yourself programming HORRIBLY TERRIFYING CODE which is not maintainable whence you create more classes inheriting from SolidObject, as you would need another vector for each subclass of SolidComponent...

 

This is a simple and direct approach to solve your issue though, but I wouldn't recommend it as it will be difficult to maintain.


#2Kuxe

Posted 06 May 2013 - 02:55 PM

Components are objects stored within a class as members, components are not inherited and thus it's not a component based system.

 

Assuming Foo is inheriting SolidObject and GameplayObject you could do something like:

 

vector<Foo> solidsAndGameplayObjects; //A container of the class inheriting from SolidObject and GameplayObject

...

for(auto foos1 = solidsAndGameplayObjects.begin(); foos1 != solidsAndGameplayObjects.end(); ++foos1)  //Iterate through all foos
{
    for(auto foos2 = foos1+1; foos2 != solidsAndGameplayObjects.end(); ++foos2)   //Nestled for-loop to compare all Foo's with eachother exactly one time
    {
        if( collision( foos1, foos2) == true) //Check for collision
        {
            foos1.hitpoint -= foos2.collisionDamage;  //collisionDamage lives in Foo
            foos2.hitpoint -= foos1.collisionDamage;
        }
    }
}

 

While I wouldn't recommend this approach since you will find yourself programming HORRIBLY TERRIFYING CODE which is not maintainable whence you create more classes inheriting from SolidObject, as you would need another vector for each subclass of SolidComponent...

 

This is a simple and direct approach to solve your issue though, but I wouldn't recommend it as it will be difficult to maintain.


#1Kuxe

Posted 06 May 2013 - 02:54 PM

Components are objects stored within a class as members, components are not inherited and thus it's not a component based system.

 

Assuming Foo is inheriting SolidObject and GameplayObject you could do something like:

 

vector<Foo> solidsAndGameplayObjects; //A container of the class inheriting from SolidObject and GameplayObject

...

for(auto foos1 : solidsAndGameplayObjects)  //Iterate through all foos
{
    for(auto foos2 = foos1+1; foos2 != solidsAndGameplayObjects.end(); ++foos2)   //Nestled for-loop to compare all Foo's with eachother exactly one time
    {
        if( collision( foos1, foos2) == true) //Check for collision
        {
            foos1.hitpoint -= foos2.collisionDamage;  //collisionDamage lives in Foo
            foos2.hitpoint -= foos1.collisionDamage;
        }
    }
}

 

While I wouldn't recommend this approach since you will find yourself programming HORRIBLY TERRIFYING CODE which is not maintainable whence you create more classes inheriting from SolidObject, as you would need another vector for each subclass of SolidComponent...

 

This is a simple and direct approach to solve your issue though, but I wouldn't recommend it as it will be difficult to maintain.


PARTNERS