I have been neglecting my content on threejs, so I thought it would be a good idea to put an end to that by writing some new content on threejs this week, and edit a few posts also while I am at it. I have all ready wrote a bunch of posts on the very basics of threejs, and although there might sill be more for me to learn about the library itself I think I am at a point now where I should start working on some actual examples using threejs. So to start off this week I thought I would at least start an example that is another way of displaying the basic idea of my Mr Sun game that I have been working on and off for a while.
The basic idea of my Mr Sun game is to have a display object that represents a sun, and then a bunch of land sections surrounding the sun. It is then possible to move the sun object around and by doing so that effects the surrounding land section objects. There is then all kinds of other ideas that branch off from there and I have many projects that are just that. Still the basic idea is simple enough and I think it would not be so hard to make a basic threejs example that is another way to go about creating that basic idea at least.
The source code for this example is also up on my github.
When I first write this post and the underlaying source code of the example that I was writing about I was using three.js version r125. The last time I came around to do a little editing of this post I made a few changes to get things working okay with r146. In future versions of three.js it is possible that code breaking changes might be introduced that will cause this example to no longer work.
First off I just worked out a simple game object module that creates a game object that is formated like many of the modules that I have created for this game thus far. If often end up with a main game state object where I have a sun object that contains the current position of the sun, and an array of section objects that share a common set of values for position and radius.
This game module is then not intended to be a replacement for a game module that has all the features of the game. I just want the basic set of values for the objects that have to do with the position of them relative to a center point or origin.
I made a sections.js file that will create and return a threejs group object based off of a game object that I pass to a create method. The idea here is to make a standard game object that I can use in a plain 2d view of the game, but I can also use the same game object to create a basic 3d view of the game with threejs. So I just need a module that will create a bunch of groups of mesh objects to which I can then add to a scene in the main.js file. I am pretty sure I am going to go with a plain 2d view, but it would be nice to play around with a 3d option also, and maybe even some kind of project that is a hybrid of sorts actually.
I then just have a main.js file that makes use of the game module and sections modules to create this basic three.js example of my Mr sun game idea. In this file I create the main scene, and add a camera to use of the scene. I create a main group object with the sections module and pass the game object to it. For now I just update the state of the main group once also, and set up a renderer for the example.
I am making use of the orbit controls provided in the three.js repo. I will not be getting into this feature in depth here as I have wrote a post on the threejs orbit controls before hand. I then also have a main app loop and for now the only reason why is because of the orbit controls until I add a way to change the sun position.
I might get around to working on this example a little more at some point, but yet again I might not ever go much beyond what I have together here. I am trying to work out the core logic of what the game should be that is independent of having a 2d or 3d view of the game. When it comes to that I have a land sections vuejs example actually where I am trying to focus on working out what might be fun when it comes to the basic logic of the game.
If I get somewhere with what the core of the game is I might get around to working out some kind of 3d view of the game with this example. However it might be best to stick to a more simple 2d view when it comes to my basic 2d canvas examples. Yet another idea is some kind of hybrid actually where I am using an 2d overlay canvas, and then use threejs as a way to create a 3d view with a fixed camera angle in the background.