Monday, August 31, 2020

RPG: Start of Tile Map, Respawning

Tile Map

Despite the game having poor graphics, I was still having major frame rate issues when the player zoomed out to view the whole map. And each additional feature was making the situation worse. (Surprise, surprise - making over 360x180=64,800 draw calls every frame was slow.)

The solution in SFML (Simple Fast Media Library, the library I'm using) is to make a TileMap. Create a single texture that has all the images your map is going to use. Then instruct the TileMap of which image from the TileMap texture are to be added on the larger game world and where. Have the video card handle all the rendering in one draw call from the TileMap as opposed to 64,800 individual draw calls. (It was actually far more calls than that...)

The result is an order of magnitude increase in performance. Previously when zoomed out frame rates were low single digits. Now I'm reliably getting upper 30s. Performance is still lower than it should be, but there is much room for improvement to pull that up to 60.

The drawing overhaul is not complete. Fog of war and terrain borders aren't even implemented yet, but the new drawing is such a major improvement that it's on the short list to be finished.


Previously once a monster was killed, its equipment could be picked up by the player but future versions of that monster wold not have the equipment. For example, only the first instance of the rat killed had a rat hide. The load code has been reworked such that monsters that have been recreated regain their default equipment. This same rat has now been killed twice, leaving behind 2 rat hides.

Lots of other small changes have been made this past month: fixes to networking code, cleanup of items, and the start of a more user friendly store.

The goal for next month is to complete the new drawing routines and the store revamp.

Friday, July 31, 2020

RPG: Hover Info Over Objects

Not too much to show on this RPG update. I am now adding mouse hover labels / hit point bars (when appropriate) to objects on the map.

Mouse over an item tells you what it is...

Mouse over the bed to tell you what happens when you interact with it (including health bar on the off chance you want to break your bed)...

If you mouse over a NPC, it tells you what happens when you interact with it...

If you mouse over an enemy, then you see its health (and nothing happens if you try to interact with it)...

I'm still not entirely sure how I want to handle labels and if they should include what happens when you click to interact, but the options are there now to tweak it.

Other than some minor code cleanup, that's the whole update this month!

Saturday, June 27, 2020

RPG: Multiplayer Items & Effects

Items and effects are now communicating over the network!


The server or the client can pickup or drop an item and that change is reflected across the network. Anything on the ground is managed by the server. Anything held by a player is managed by that game's client.

Next I command the lower right game client to pick up the sword and the upper left game server to pickup the healing potion.

Changes reflect on both games! Lots of cleanup to do in the code, but it's working great.


Effects are not purely visual (drawing of flames on the ground), they also include abilities such as healing or damaging.

Screenshot of the client putting down a flame wall...

I let my server player get injured...

Then my client player heals him...

A visual effect is drawn on the player receiving the heal on both games and the target player's health increases.

Sunday, May 31, 2020

RPG: Multiplayer Characters

Player and non-player characters are now communicating over the network!

As you can see in the screenshot, items are not being shared between game instances yet.

The type, position, speed, heading, armament, animation, and killed state of characters are sent between games. The position of network characters are dead-reckoned based off the speed and heading of their last update packet to keep the movement smooth and limit packets on the network.

I'm actually quite happy with how smooth the motion is over the network. It's on par with similar network games. Up next will be to send effects and items over the network.

Wednesday, April 29, 2020

RPG: Multiplayer Connect & Chat

Multiplayer work has begun in the RPG!

After selecting your character, you pick if you're single player or networked.

My goal is that you will be able to seamlessly go between a single player experience and playing with your friends.

- If "Single Player", then it starts as normal.
- If "Private Server", then it starts the game as a TCP server and will accept client connections.
- If "Private Client", then it will connect to a TCP server.
- If "Public Client", then it will connect to an Internet accessible server. I don't know how feasible this mode will be. For now I'm intending the game to be primarily LAN (Local Area Network) play like Diablo 1. Even if the Internet play shows promise, I want to keep the LAN play fully functional.

I started 2 instances of the game. One as a "Private Server" with a player called "Host". The second instance is with the player called "Player" connecting as a "Private Client" to the server.

And when I click "Start", it attempts to connect to the server. If successful, it starts the game for the client!

On the Server (left window), it announces "Player" has arrived.

You can see sharing character positions is not yet working, but I do have chat messages between the servers and clients functioning. Press enter to bring up the chat box, type in your message, press enter, and it gets sent.

There is no set limit to the number of players that may connect. It'll be interesting to see how well it scales as the numbers of players grow.

Tuesday, March 31, 2020

RPG: Hit Indication, Debug Mode, Dropping Coins

Hit Indication

When you got hit in the game, the only way you knew was from the health bar going down. But that health bar is in the corner of the screen and easy to miss. I'll eventually have sounds for getting hit, but there are plenty of situations when someone won't be able to hear the game. So I wanted something more apparent to the user that they were taking damage.

Solution I came up with turned out very nice. When you get hit, the border of the map pulses red. The harder the hit, the worse the red pulse. Multiple small hits in a short period of time will also cause the red pulse to grow larger.

I also have some lingering red shading if you're injured to give a reminder that you're not at full health.

Debug Mode

As the game get more feature rich, I've been needing to change more and more variables at runtime. The solution was a debug mode. Pressing F10 brings up a little input symbol in the corner.

I can now type commands such as "framerate" or "coins=30".

And adding more commands is very very quick. To support this, I had to add support for text boxes in my SFML windowing system. Which means I could also add the ability to drop coins on the ground!

Dropping Coins

If you click on the player's purse icon, a dialog box now appears asking how much to drop.

Type the new value and push enter and it appears as a purse bag on the ground...

Several other little improvements here and there to the game as well... slow but steady progress.

Friday, February 28, 2020

Rocket Stand

A couple years ago I built a rocket launcher (turn key, push button, liftoff!), but just sticking a metal rod into the ground wasn't exactly an ideal way to keep them vertical. A local Makerspace opened up and started offering welding classes. I always wanted to learn how to weld, so took the short class and then had an hour one-on-one session to work on whatever project I wanted. Remembering that need for a rocket stand, that was the project I went with.

They taught MIG welding (and since I'm a beginner), I went with all steel for the material. Home Depot had square bars, sheet metal, and a steel rod relatively cheap and in stock. Around $20 for all the materials.

No progress pics, but the final product...

The rod is way too thin to just weld onto the sheet metal. So I welded a shorter square bar vertically to the sheet metal then the rod onto the bar.


I highly recommend checking out if you have a nearby Makerspace/similar that offers the one day welding classes. Very fun and educational.