JavaScript While Plant Grid idle game prototype example
There is getting started with javaSscript and learning all kinds of various features to work with in a client side web development environment. However sooner or later One will need to get into making one or more actual projects with the skills acquired when learning to code. So I have mad a number of javaScript example type post and this would be one of these such projects. This week I have been working on two projects that are additional game prototypes that might progress into some kind of final product. Today I will be writing on the current state of one of them that I am just calling wild plant grid idle for now. The general idea of the game was to just have a grid in which wild plants grow, and the player just harvests what is grown for points. These points can then be used to make improvements to the state of the grid.
So then this is yet another game prototype idea that I will add to the stack of my simple JavaScript example projects that are in various stats of completion. This is one of them where I did not get as far as I would like to have in part because of time, and focusing more so on the other project that I was working on this week.
1 - The utils module
First off here is the utils module that I have for this javaScript example that will contain a number of methods that I will be using thought the over all project. In other words this is the general utility module that I have made for this game that will differ a little from one project to a next when I make this kind of project. I have another javaScript example in which I go over a general from of this utils module that has many of the usual suspect methods that will end up in this module.
For this project I need a bounding box collection detection method to find out if a cell in the grid has been clicked or not. The rest of the methods that to do with quickly setting up a canvas element, and attaching event handers to it. For now that is more or less just about it, this module does also just serve as a general dumping ground for methods that I will be using across one or more modules, and I can not think of any other place to put the method. Often I might make some new additions when it comes to these kinds of methods, but not for this project it would seem.
|
|
2 - The grid module
Even If I do not work on this project any more one good thing that came out of this is coming up with a nice basic grid module. This is a module that I can use to create a base object for a grid, to which I can then use in my plant grid module that I will be getting to in a later section in this post. For now this module just has three public methods one of which is a create method that will just create and return a grid object. Another public method is to get a cell in the gird given a canvas relative pixel location, and I have another to select or deselect an orb.
When it comes to working out the nature of the grid object I went with a design where I have just an array of objects for each cell. I thought of using bounding box as a way to find what cell was clicked, but decided to instead go with expressions rather than looping.
|
|
There is a great deal more to write about when it comes to making this kind of module. Also this is the kind of module that I would like to just get solid for once and move on because I am getting tired of making this kind of module over and over again when it comes to starting a new vanilla javaScript project from the ground up. So I have wrote a new post on another javaScript module where the focus is on making a solid grid module.
3 - The grid-plants module
Here I have the main module of interest when it comes to this game, where I am creating a grid with the grid module, but then creating some custom objects for each cell, and adding additional features that are specific to this game. So then at the top of the module I have a hard coded object that is the beginnings of a hard coded plant database. I then have a public create method to create a plant grid object, and also a main update method of this module that I will be calling to update the state of this grid.
|
|
4 - The game module
It is a usual practice of mine to have a main game state object module. However when it comes to this game so far there is not much to write about with this module just yet.
|
|
5 - The draw module
This is the current state of the draw module that is used to render things to the canvas element that is used for this.
|
|
6 - The main JavaScript file
I then have a main javaScrit file where I have what is the beginnings of a state machine, and the main app loop.
|
|
7 - Conclusion
I did not put as much time into this prototype as I would have like to have, mainly because I have been working a lot more on my other prototype that is a game based off of my orb module that I started a while back. In fact the current state of the game prototype that I am just calling orb match for now is a kind part of the project folder for that module. At this time I think this project should be shelfs so I can focus better on that project, however in the event that I get burnt out on that one maybe this project would be a good thing to get back into.
At this time I think I am going to need to focus on just one game at a time, and make these blog posts a weekly rather than daily thing for a while. The full vision of this game might not be that much more complex than what it currently is, but there is still a great deal more to work on with this before the example starts to even look like a done deal. The other project I was working on this week is in far better shape so far, so I will be working more so on that one for a while in the near future.