Note that there are some explanatory texts on larger screens.

plurals
  1. PO'Self-aware' classes?
    primarykey
    data
    text
    <p>long time reader first time poster. Please be gentle.</p> <p>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.</p> <p>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...) </p> <p>Okay imagine this, you have a space game and the following objects</p> <ul> <li>clsShip</li> <li>clsMissile</li> <li>clsAsteroid</li> <li>clsSpaceJunk</li> </ul> <p>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</p> <p>for each ship in a list of ships<br> check each clsMissile in a list to see if it collides with it and if so, reduce health<br> check each clsAsteroidin a list to see if it collides with it and if so, reduce health<br> check each clsSpaceJunka list to see if it collides with it and if so, reduce health<br> ... and so on and so on for every object next</p> <p>ect ect ect...</p> <p>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.</p> <p>Now my question to the experienced programmers out there.</p> <p>Is there a way in OOP to do the following...</p> <p>for each thing that inherits from clsSpaceEntity<br> check against every other object that inherits this type (except itself) and if they collide then reduce health<br> next</p> <p>?</p> <p>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.</p> <p>Any assistance/help or feedback on this would be very appreciated. Thank you for your time, sorry for the long read.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload