This week I wanted to aim for making at least one new canvas example post even if it is just another clone of something, or even just an attempt at a clone of something. I have this idea in my head that if I make enough of these I will end up with one or two that I will end up moving forward with into some kind of long term, interesting project that will be worth further investment of time. In the process of doing so I will likely end up with a whole bunch of canvas examples that will never progress beyond a simple prototype state of sorts.
I do not spend that much time playing games these days, but I do have a few installed on my phone and one that I have been playing around with a little is called a planet of mine for android.
The game is a pretty cool concept you have a starting world and two starting workers that can be used to build structures on land tiles of the world. There are many resources that can be gathered, one of which is used to power a rocket ship that can be used to go to another world in a solar system. There is even more to it than that, but that is the basic idea of the game.
I liked the game so much that I though I would start to work on a clone of the game that is not all that different from it. I was not able to clone every aspect of the game, but I did get to a very basic working first prototype of the concept thus far. If I get around to it I might come back to this one at some point in the future as i keep making canvas examples like these in a effort to try to find something that I would not mind working on for a while longer.
For this canvas example I went with using a basic state machine design that I worked out in a previous post on canvas and state machines. I added a few changes though so this will not just be a copy and past type thing from that project. I do not always bother with adding a state machine asset of some kind with many of these canvas examples, but I have found that this one might need it if I continue working on this one to the point that it would be a done deal.
Now that I have my state machine I can get to work with a main game state object for this project. I will want a module that is used for a world object, and then another that will be for the solar system that will be a collection of world objects and thus will be a top level object.
There will need to be a module that will contain all the logic that is needed to create, and update a state object for all the properties that have to do with a world. A world will contain a number of land objects, each land object might have one ore more workers on it.
A land Object might have one of several items built on it. the choice of items have to do with extracting resources from the land tile, or producing some kine of renewable resource.
At the top of the module I have a crude item database in the form of an array literal. I am not completely sure how this might evolve as I continue to work on this example now and then, so for now each item just has a description, a max workers property, and some additional values that outline what the item does.
So I have helpers that are used to create a single worker object, and a single land object. The worker object thus far is just values that have to do with the size of the display object that repentants the worker. Beyond that it is more about where the worker is rather than its values, at least so far when it comes to this canvas example.
These are methods for setting land tile index, and creating a new worker that is to be pushed to the free workers array.
Position the workers of the given area so that they are stacked relative to the current position of the area.
This helper method is what is called to create the lands array of the world object.
So for the public API of the world module thus far I just have a create method.
Although I did not get around to developing this part of the game, here is the current standing solar module. If I get around to it this module will eventually turn into everything tht has to do with a collection of world objects.
Now for the draw module that is used to draw the current state of the solar and current world object.
So now for the state object for the main game state, and some HTML to pull this all together into a working canvas example.
Although at the time of this writing I was able to get the basic idea of the game working there is still much more work that would need to be done in oder to make this more of a true clone of the game. This is also taking the time to do what comes to mind when it comes to making the game more distinct so that it is not just a rip off of the original.
So far I am not happy with how this canvas example came out, it would need a lot more work, and maybe even a top to bottom overhaul in order to get it back on track. I might get around to doing that at some point in the future, but there are so many other ideas for projects, and so many other great ideas that I would like to clone as a starting point.