There are a number of canvas examples that I would like to improve with a system such as this, and a whole bunch of additional ides for canvas element powered games that might make use of this feature in one way or another. So for this post for starters I would like to get a solid starting point for this kind of system up and running. Once I have that it is just a matter of shoehorning it into a project.
1 - The wave module
At the top of the module I have some constant values that have to do with the size, as well as the min and max speed at which the wave buttons move. When I start using this in some games I might want to make some of these settings that I can change in the create method of the module. However for now I think I will just leave them as hard coded settings, I just wanted to get the basic idea that I had in mind up and running fast and did not get to doing things like that.
I then have the spawn and update methods that I will be using when creating an instance of the object pool that will be used for this module. I will nt be getting into detail with the object pool module here of course, but I will be getting to the file that I am using for this example in a later section.
I then have my create, update and on click public methods.
There might be a few more things that I might want to add here and there, but I do not want to go to nuts with this for now. When it comes to all the other little ideas that come to mind many of them might change a little form one project to another. So maybe I should hold off for now at least, and get to that kind of stuff when I start to use this in a real game of some kind.
2 - A utils.js unilty library
3 - Object pool module
In this example I am also making use of an object pool module, this is something that I first worked out for my canvas example on objects pools, and take with me from one canvas example to another. I am using it to create wave bar buttons, and I am also using it to create enemy units for this example in the game module that I will be getting to a little later in this post.
4 - A game module
I made a quick place holder game module for this example, for now this is just a very simple game where units spawn at the top of the canvas and move to the bottom of the canvas. I did not put much time into this because the main thing I wanted to work out for this post is of course the wave control module. However In a real game I might only built so much more on top of this.
Just like with the wave module I am using the object pool module, however here I am using it to create a collection of units that will spawn when a wave button reaches the top of the canvas.
5 - A draw module
I made the full example of this a canvas example, so I have a draw module that I put together real fast. Most of what i have here I copied over from one of my canvas examples, called pop the lock when it comes to the draw pool methods. For this example I am just going to want to have draw pool methods for the wave buttons, and the units that will spawn into the canvas when a wave button reaches the top of the canvas. In the event That I start to make some kind of real example with this I might have a few more things that i use the object pool library for that have to do with navigating menus and displaying all kinds of info and so forth.
7 - Conclusion
I just wanted to have a nice starting point for this kind of system, something that I can copy and past to a folder and start to hack over to make something else that will prove to be more interesting. As I start to make and update some of my canvas examples with this I will be sure to link to those examples in this post when I get around to editing.