Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |
robots-4 [2023/10/06 02:28] – appledog | robots-4 [2023/10/06 02:33] (current) – appledog |
---|
| |
So for example if we want to add robot hit points, in the old gameMap 'r'/'R' based model we need a separate 2d array to hold monster hit points, or we need a way to attach it to the gameMap -- such as 'r7' for a robot with 7 hit points -- but then only print the 'r'. This kind of programming is known as a 'kludge'. Eventually either codependent arrays will be used, or something akin to 'struct'. Therefore, the easiest way to start using classes is to treat them as structs and try to collect information only. This allows us to use one array and not codependent arrays and the code will feel very 'comfortable'. It is likely never necessary to move past this point in optimization unless there is a serious problem with the code or th logic of the code. | So for example if we want to add robot hit points, in the old gameMap 'r'/'R' based model we need a separate 2d array to hold monster hit points, or we need a way to attach it to the gameMap -- such as 'r7' for a robot with 7 hit points -- but then only print the 'r'. This kind of programming is known as a 'kludge'. Eventually either codependent arrays will be used, or something akin to 'struct'. Therefore, the easiest way to start using classes is to treat them as structs and try to collect information only. This allows us to use one array and not codependent arrays and the code will feel very 'comfortable'. It is likely never necessary to move past this point in optimization unless there is a serious problem with the code or th logic of the code. |
| |
| == How to start |
| First write the SpriteSheet and Sprite classes and have them draw the primary image in drawGame(). |
| |
| Next add thing classes, which contain a character -- and flags for 'seen' etc. so we don't need to do r/R (or just use r/R). Then start by adding a class to gameMap and not a character. Don't worry about a 'tile' class for now, but you could do that now, if required. Just add tiles to the map in setup and then add things to the tile's inventory. This also eases collision detection because we can first check if 'anything' is there vs. checking many things individually, or check only places which contain more than one object (instead of every space). |
| |
| This, if done correctly, should only take one class (1.5h) with Roger. |