The general idea here is that I have an Orb object that contains an array of four numbers, each number is an integer from zero upwards and represents a count of a certain kind of element. For example the first element in the points array can represent a count of Earth elements, then Wind, Fire, and Water when it comes to that kind of idea with elements in a game. There is then the ratio of these elements that is of interest for example an Orb object with a points value of 14,4,2,2 would have a simple ratio of 7,2,1,1. The ratio could be a kind of recipe, for a special kind of Orb, with special attributes, or it could just be an unknown ratio that does not have any special meaning.
1 - The orb Module
When it comes to this module the main public method of interest is the create from points method, all the other methods that are used to create an orb will end up calling this method in an indirect way. This method is used by passing an array of numbers like 4,8,8,0 which will be used directly as the points property of the orb, the simple ratio of the points array would then be 1,2,2,0, and this type of orb would then be composite.
At the top of the file I have my find type method that is used to, well kind out what the current type of an orb is based off the ratio of the orb. For example a ratio that is 1,0,0,0 or 0,0,1,0 would be an example of a pure orb as all of the points are of a single element. However an orb with a ratio like 1,0,0,1 pr 0,1,1,0 would be an example of a dual orb as it has an even number of pints between two elements. Any ratio like 1,0,7,3 is a composite orb for now, but I have plains for additional features when it comes to orbs with this kind of ratio if I ever get around to it.
I then have some additional methods for creating orbs, including one where I given a simple ratio and a level as a way to create a points value, and another that will create a new orb from a collection of orbs.
That is it for now when it comes to my orbs module, I am sure that I will add a bit more in time but to really know what is missing I will want to start creating at least a few projects using this module. There is not just thinking in terms or the features that I want to add, there is also thinking if a feature should be a part of this module to begin with. I would like to try to keep this module as simple as possible by not adding anything that should be part of another module. For example I am sure than many of the games that I will be using this with will involve a collection of display objects, as such I could make properties like x, y, width, and height part of this orb module, however I think that I should not do that, and rather just make that all part of a whole other module.
2 - The ratio module
I have a custom made ratio module that I made primarily for my orbs module, however this ratio module contains some methods that I might want to use in additional projects. So I will be pulling a lot of code that had to do with ratios out of the orb module and into this module unlike what I have done in previous attempts at making this kind of module.
A certain method to this module, and thus also the orb module is the Greatest Common Divisor method. This method will find a number that is the highest number that two numbers can be divided by. For example the GCD of 15 and 5 is 5, and the GCD of 7 and 3 is 1. This can then in turn be used as a way to create a simple ratio form of a set of numbers, for example getting 1,1,4,0 from 3,3,12,0 thanks to an array function form of this kind of method.
My all non zero equal method serves as a way to know when kind of type an orb should be depending on the simple ratio form of its points. I then have a while bunch of other useful methods that have to do with working with a set of numbers.
3 - Testing out the orb module
So now that I have an Orb module worked out I will want to take a moment to just test it out to make sure that it is working as expected. I could make some full blown project around this Orb module, and in time I might get around to doing just that. However for now it might be best to just work out some simple test script of sorts.
So far it would seem that my orb module is working more or less the way that I expect it to. However I have yet to make a real project on tp of this module. A few bugs that I am managing to miss might still be there, and in any case I will likely want to add a few more features in the event that the mouse seems to work fine. In any case I will of course update this section once I have a nice simple little game of some kind for this.
3 - Conclusion
There is still maybe a great deal more work to do with this module, but maybe more so with what it is that I would pile on of of it rather than the core of what it is. There are some additional features that I would like to add this this Orb module, but much of the additional work that will be involved in turning this into an actual game of some kind would involve additional modules such as an object pool, and a state machine.
I am thinking that the objects that I create with the orb module should be part of a data object of a display object, rather than a kind of display object. There is also a lot of little things when it comes to how the properties of an orb objects effect other properties of this display objects that have to do with game mechanics. I am thinking that I might want to keep all that apart from the orb module itself, but maybe that is something that will prove to be hard to avoid. In which case each time I use this module in a game I am going to want to hack over the source code of it just a little, so that makes creating an maintaining a clean version of the file that much more important.
For the moment there is checking out my many canvas examples that I have made thus far when it comes to the various game prototypes that I have put together.