Making a turn based RPG game javaScript project example
This week the plain is to expand my collection of simple JavaScript project examples, this time a simple turned based rpg based on the source code of another javaScript project example that has to do with grid unit movement. When it comes to the source code of the grid unit movement example I mad a whole lot of improvements to the source code of that example, and I thought that I should take the time to continue to expand on that source code but as a whole other project folder. This example is then that project as it currently stands, and as of this writing I still have a lot of work to do with this when it comes to turning this source code into yet another project that might end up being some kind of final product.
I have a lot of ideas of what I would like the final product to be when I get to that point. This time around I may in fact make a final product with this one because I still seem to still be stuck in that awful start something but never finish something loop, and I want to break out of it. So I will be getting into making art assets, and external json files that hold things like scene data and so forth, but at the time of this writing that just happens to be what I am working on now.
So when it comes to writing a blog post about what I have together at this point the focus will be on the various features that I have added at the time that I stopped working on my improved form of the previous example, and started working on this example. With that said one improvement thus far has to do with breaking things down a little when it comes to units, pulling logic out of the main game state module and into a units module. Another talking point has to do with starting a custom state machine, and a few files that are state objects for said state machine. The main feature thus far though is my game state menu system that is inspired by the circle menu system in from the super Nintendo game called Secret of Mana. As of this writing it is not a clone of that just yet, and I will want to make chances that will work well when it comes to having a web based game version of it, but thus far I would say that is the best feature thus far with this one.
- What to know first before reading more
This is a javaScript example that aims to be a kind of turn based RPG game, the source code of which is still not in a finished state. However there is a whole lot to write about it when it comes to what I have worked out thus far, and there is only so much more to do when it comes to further refining what I have in place. The example is as of revision 5 starting to feel like a finished game, but I still have at lase a little more work to do with it to ay the least when it comes to new features.
So there are two main points to take into account with this, one of which is that this is not at all any kind of getting started with javaScript type post. So if you are new to javaScript this post may prove to be a little to advanced. The other main point that I think I should cover in this section is that I am still very much working on this example and intend to continue doing so for at least a little while longer so the source code examples in this post do not reflect the current state of the example.
The up to date source code, and any additional assets ca be found at my test vjs repository
The up to date source code, along with any additional assets that I am not writing about here can be found in the folder that corresponds to this post in my test vjs repository on Github. As of this writing I am writing about revision 5 of the source code there, I am currently working on r6, and have things planed out to at least r15 for now and I do not have everything written down just yet when it comes to the todo list. This test vjs repository is also where I park many other javaScript project examples, as well as the examples for my various posts on javaScript in general.
1 - The game javaScript file and renderer
In this section I will be writing about that main game module that is used to create and mutate a main game state object, as well as the library that I use to draw various parts of this state to a canvas element.
1.1 - The game.js module to creating and mutating the main game state object
This is the source code for a main game state module for the turn based game as currently stands. As with my many other javaScript and canvas example projects there is a public method that is used to create a main game object, and a method that is called in a loop to update that game object. On top of that I also have public methods for just setting things up for a game object rather than creating a whole new one, and also some methods that have to do with pointer events.
|
|
1.2 - The draw.js fire for drawing to the canvas
Later in this source code I have a canvas element reference that is what will be used to draw the current state of a game object. I have got into the habit a long time ago to septate logic that has to do with a game object from logic that has to do with drawing that game state object. SO then this is that Logic that has to do with drawing the current map of a game world map, as well as various other things that I wanted rendered to the canvas.
|
|
2 - Core libraries of this example
I have took a moment to think in terms of what it is that I can pull out of my main game module and into a library that is its own independent thing. With that said thus far I have a general utilities library, as well as libraries that have to do with units, the game world map, and an object pool system that I am currently using with my menu system thus far. As I continue working on this example I am sure that this is a collection that will just continue to grow for the sake of keeping things fine grain and modular.
2.1 - The utils.js lib that contains various utilty methods
This is what I have together for a general untiles library thus far when it comes to this turn based game example. The general idea here is to have something like lodash, only it is composed of methods that I am actually using in my various other libraries and javaScript files that have to do with the over all logic of this project. This is a usual library that will be found in just about any of my javaScript or canvas examples another the collection of methods will change up a little from one example to another. I do however have another utils javaScript example in which I have one that is composed with a whole much of usual suspect type methods such as the distance formula and bounding box.
|
|
2.2 - The units.js lib for now
This is a lib in which I have pulled a lot of logic out from game.js and has to do with units that will be found in a map. I have expanded on it a little more sense then, and will likely continue doing so in future revisions so I think I should not write to much about this one at this time.
|
|
2.3 - The map.js lib
This is the map.js lib from my other javaScript example that has to do with grid unit movement, that also includes path detection code based on what I worked out for my post on that subject also. I have not changed much with this lib sense then and at this point I think that any future work might just involve fixing any unseen bugs, and various other improvements rather than adding new feature to this.
|
|
2.4 - The pool.js file
This is a object pool library that I puled from my game framework project that I have been working on for a while. As such I am seeing some things that I think I would like to change and add from that thus far, and when I do I will likely add those changes to future revisions of that framework.
|
|
3 - The state machine, and main.js
For this example I made a new kind of state machine from the ground up rather than making use of what I have all ready made for this sort of thing. Still I am reproducing certain standards that I think such a system should have. I do this because I think that making a state machine from the ground up is just one of those things that I have have not got down to a science just yet. So I end up making a new one for each stand alone example thus far. That is not to say that I have not made an effort to make my own versions of a end all state machine library or framework rather. I have a javaScript example where the focus is to work out some things that I should have in such a project, and I also have a canvas example in which I touch base on this topic. I also to have a game framework project that I have been working on a little jow and then, so this is a wheel that I keep reinventing,and will likely continue doing until I have something that will worm well for me.
3.1 - The root sm.js file
This is the main state machine file thus far.
|
|
3.2 - The title state object
The title screen state object of the state machine.
|
|
3.3 - The game state object
The main game state object of the state machine.
|
|
3.4 - The main.js file
The main javaScript file thus far where I am starting the main javaScript loop.
|
|
4 - Conclusion
So far I have to say that I like this example, and I would like to keep working on it at least a little while longer. In fact I might even make this the main thing that I am working out outside of this blog for a while. I do not want this to end up being the kind of project that I end up spending years of my life working on touch at least not in the form of what I have in mind of this specific javaScript project example at least. There is the idea of taking what I have worked out with this example thus far and once again starting a whole other project in which I continue to expand on this, but even when it comes to that I want to try my best to not go nuts with features. The project is all ready getting a little involve and less is often more when it comes to making a game.