Happy new year everyone! After a bit of extended effort that needed to be pushed at work, and a delightfully restful holiday season, itâs back to the grind! Week 9 took longer than I would have liked (I forgot to take my code with me on holiday so I could work on it), but now itâs finished.
The first day consisted of removing a bunch of the old tile-based code so that we could focus on moving into a spatial partition setup. This means that instead of tile chunks, weâre using new entity chunks that hold 16 entities each (for now), starting at their relative position in the world. That means that any given âroomâ, we might have 4 or more chunks, depending on how many entities are in that room.
I think. Iâm not entirely sure how this plays out, because Iâm much more a visual learner, and I donât have a good visual for it, but I estimate thatâs how its working.
From there, we started using the spatial partitioning to place entities in the world. We also removed the background so we could start setting up the walls using actual entities/art instead of the white blocks from before. That meant creating some new happy little trees to serve as a test wall for the time being. As I go along, itâs nice to have a coding break and work on the art, which led to this happy little guy:
Incidentally, itâs the first tree Iâve been able to make so far that I didnât feel looked like absolute crap. Itâs not perfect, but itâs a step in the right direction. Nature is apparently difficult for me to grok sometimes.
Once the tree was created, that meant I was able to replace my white wall squares with them. It started with the trees being offset in the wrong position and so the whole âroomâ looked odd, but after some tweaking, I was able to get it into the right position:
Now that we have entities set up and working (collision in the right spot and everything), it was time to add an enemy and a basic familiar that could follow the player. Since I had already partitioned the character into body, hat, and shadow, I was able to easily create the enemy without a hat (so you know itâs not the player) and a familiar using only the hat and shadow.
The enemy doesnât do anything at the moment except exist, but the familiar we wanted to feel a bit more alive, so we made it bob. It was just a matter of adjusting its Z position to appear as though it were floating using a sine wave to simulate the motion of the bob. One tiny other little thing was to introduce shadow fade dependent on where in the bob the hat to add to the effect.
Because our familiar is supposed to follow us, we input our first AI following mechanism to get the familiar to follow the player.
And once we had one familiar working, it only made sense to have many following us!
So that was fun to do. In our current renderer though, this many (or more) entities all trying to move around starts to slow things down a bit. Weâll come to that later.
For today, we started rearranging how we were drawing things. Whereas before we were drawing each thing directly, now we were going to start pushing each entity that needed to be drawn into a group to be drawn as a group. This should also hopefully allow us easier Z-ordering when it comes to fixing our draw order later on.
Today was also when we decided to introduce the first concept of hitpoints for our characters. Not only having them, but displaying them on screen in the form of blocks. In typical Zelda-like form, the character will start with three âheartsâ and each heart block will have multiple pieces, such that you could take multiple hits per heart of health.
And we finally started introducing Vec3 and Vec4 into the code, so that we can more easily handle those objects that require 3- and 4- component information (RGB/RGBA, XYZ, etc.).
Now that we had the health, it was time to put together a simple attack. Once again, that meant going to the drawing board and putting together a weapon. I chose to make a simple wooden sword, if only for simplicityâs sake at the time.
We linked a button press to the sword and it emitted! But only once per game. Well, weâll get to having it disappear and being reusable tomorrow, I think.
Oh hey, what do you know? We put some motion into the sword and had it fly out from the character when you press the button. Weâve got some quirky action that happens if you attack before the previous sword finishes its path, but weâll fix that later. In the mean time, we have another piece of our Zelda clone in!
It even has a shadow. Awww.
And on our final day of the week, we started moving away from the concept of Low and High frequency entity sets... sort of. What we wanted with the high frequency objects was a set of entities in the immediate play field that would move, play animations and update every frame.
Obviously this kind of update would slow the game down at any kind of scale, so it was then important to have the rest of the entities in the world just kind of hang out until they were in range of the player. However, we still wanted these low frequency entities to simulate certain things, such as having a delivery guy wandering from point to point out of the range of the player (and possibly passing through the immediate play field).
Well, the way we have been doing it up til now was not the cleanest way to handle things, pulling them into high and pushing them back out into low. This also meant that some functionality was duplicated to work on both the high frequency and low frequency entities; doubling work like that is never what you want.
So to replace it, weâre moving to the idea that all entities are âstoredâ entities, and that weâll be setting up a moving sim region across the playable world that will simulate what entities in that region might do during that frame. The sim region is likely going to be about the size of the camera region, but will occur off screen. This is apparently going to simplify things, but weâll see how it all works in the coming week.
For now, the codeâs a bit broken because our last change has thrown a bunch of little wrenches into the works. Weâll get it working again soon, but for now, itâs nice that we have a character, an enemy, and a familiar all moving about. Itâs also good to have a basic attack set up so we can start to get a feel for some more basic mechanics along the way.
Itâs a good start to the new year. Letâs see whatâs next!