Basic idle game canvas example
There is a lot that I like about idle or incremental games as there is the artistic side of game development, and then there is the business side of things. When it comes to the artistic side maybe game development is about some kind of expression, making some kind of statement, or just simply having fun. However with the artistic side of game development aside there is also the business side of the endeavor, and when it comes to the business side all that really matters is if a game can make you money or not. Sp then when it comes to the business side of game development a game does not have to be some kind of ground breaking statement, emotional expression, or anything profound, it just needs to make money.
When it comes to the business side of game development I have found that a game does not only not need to be some kind of emotional expression, or some grand original idea that no one has really tough of before, no not at all in fact it does not even need to be fun or interesting actually oddly enough. With the business side of game development a game just needs to be addictive, people need to just start playing it and get hooked. So I thought I would make another canvas example post that is a basic idle game. Nothing fancy with this one, just a bland, unbranded idle game starting point that is noting to write home about, but might still prove to be slightly addictive.
This canvas example makes use of a custom trailered utility library that has a method that creates a button layout, which is one way that I go about making menus in a canvas project. I wrote a post in which I get into this button layout method in detail, but will be covering it here also just not in detail.
1 - The utils lib for the basic idle game canvas example
So in this section I will be gong over the utility library that I worked out for this canvas example of a basic idle game. Considering the nature of the game the user interface of the game will just consist of a static button layout in the canvas element. This button layout will be composed of buttons that preform a manual gather action, as well as upgrades and will be a box like area in the canvas. So with that said I will need some methods for collision detection, and working with mouse and or touch events in addition to a method that can be used to create this button layout to be used as the games interface.
Now that I have a utility module I can get to the game state module, and then the code that draws a state object created with that module to the canvas.
2 - The game module
Now to get into the actual game module of this basic idle game canvas example. This module is used to create and update a state object, but not to render that state object to the canvas. This way I am pulling logic that has to do with state away from logic that renders that state to the canvas.
2.1 - The start of the game module and the upgrade data array
The module follows an IIFE pattern and at the very top of the self executing function expression I have an upgrade data array. This array contains an object for each upgrade that I would like to have for the idle game. For now there is just an upgrade for the rate at which money is gathered manually, and for the rate at which it is gathered automatically. I do after all want to try to keep this canvas example basic.
2.2 - A Make upgrade state object
So the upgrade data array is an array of hard coded values for each upgrade, but it is not a current state object of sorts. I am going to need another object that is the current state of an upgrade, such as the current level, and values that have to do with the current cost of the next upgrade.
2.3 - Set the cost of an upgrade state object
So I worked out some methods that are used to set the current cost of an upgrade. One method is used to get an object that is a breakdown of the base cost along with values for an incremental and power based value. The other method is used to set the current cost of an upgrade based on these values.
2.4 - Set the current upgrade level
I have some methods for setting the level of an upgrade state object. There is setting the effect of an upgrade state object, setting the upgrade level, and applying for all.
2.5 - Create a new state object helper
I have just one method that is used to create a new game state object as it currently stands.
2.6 - The public API of the game module
Now that I have the private helper methods out of the way it is now time to get to the public api that is returned at the bottom of the IIFE.
3 - The Draw module for drawing the button layout and other features.
Now for the draw module of this canvas example that is used to draw the current state of the button layout, as well as many other features thus far with this project.
4 - The main.js file and html
So now that I have my utility library, game module, and draw module it is time to tie everything together with a main.js file and a single HTML file. In the main.js file I create a canvas element and inject it into the html.
5 - Conclusion
Well I set out to make a basic Idle game and this is more or less what it is. The only question now is where to go from here when it comes to making this a more interesting project even if it is to remain very basic and unbranded. There is adding a reset feature which is one major part of an idle game that I think the game should have. Also there is still adding very basic features such as just a save state system. Still when it comes to making a fork of this I will want to come up with at least some kind of theme also.