Original Post
Hi guys... long time reader first time poster. Please be gentle.
I avidly create games in VB.net. Being a hobby programmer I give my games away for free. Since I'm a hobbiest without formal training I do try and educate myself on proper programming principles and follow them when programming such as OOP. There are however some things I have obviously missed being self-taught that perhaps I would know if I were formally educated.
Once such issue that has really been my bane is how different classes (from now on referred to as objects) 'know' about each other WITHOUT programming specific interaction (stay with me here... please...)
Okay imagine this, you have a space game and the following objects
clsShip
clsMissile
clsAsteroid
clsSpaceJunk
Now each one of these objects has a Health, X,Y and Z private members and properties that are all inherited from clsSpaceEntity for argument sake. Now one way of programming collision between them would be to code out the following logic in the main game loop
for each ship in a list of ships
check each clsMissile in a list to see if it collides with it and if so, reduce health
check each clsAsteroidin a list to see if it collides with it and if so, reduce health
check each clsSpaceJunka list to see if it collides with it and if so, reduce health
... and so on and so on for every object
next
ect ect ect...
Now this might seam okay if your talking about the simple example above but some of my games have tens or even HUNDREDS of objects that interact in this basic way.
Now my question to the experienced programmers out there.
Is there a way in OOP to do the following...
for each thing that inherits from clsSpaceEntity
check against every other object that inherits this type (except itself) and if they collide then reduce health
next
?
This sort of ability for a type of objects/class or whatever to be 'aware' of another and how they are the same/different and interact would save me tonnes and tonnes and TONNES of coding.
Any assistance/help or feedback on this would be very appreciated. Thank you for your time, sorry for the long read.
I avidly create games in VB.net. Being a hobby programmer I give my games away for free. Since I'm a hobbiest without formal training I do try and educate myself on proper programming principles and follow them when programming such as OOP. There are however some things I have obviously missed being self-taught that perhaps I would know if I were formally educated.
Once such issue that has really been my bane is how different classes (from now on referred to as objects) 'know' about each other WITHOUT programming specific interaction (stay with me here... please...)
Okay imagine this, you have a space game and the following objects
clsShip
clsMissile
clsAsteroid
clsSpaceJunk
Now each one of these objects has a Health, X,Y and Z private members and properties that are all inherited from clsSpaceEntity for argument sake. Now one way of programming collision between them would be to code out the following logic in the main game loop
for each ship in a list of ships
check each clsMissile in a list to see if it collides with it and if so, reduce health
check each clsAsteroidin a list to see if it collides with it and if so, reduce health
check each clsSpaceJunka list to see if it collides with it and if so, reduce health
... and so on and so on for every object
next
ect ect ect...
Now this might seam okay if your talking about the simple example above but some of my games have tens or even HUNDREDS of objects that interact in this basic way.
Now my question to the experienced programmers out there.
Is there a way in OOP to do the following...
for each thing that inherits from clsSpaceEntity
check against every other object that inherits this type (except itself) and if they collide then reduce health
next
?
This sort of ability for a type of objects/class or whatever to be 'aware' of another and how they are the same/different and interact would save me tonnes and tonnes and TONNES of coding.
Any assistance/help or feedback on this would be very appreciated. Thank you for your time, sorry for the long read.