• Register

King under the Mountain is a simulation-based strategy/management game where you design, build and run a settlement in a fantasy world. Then, once you're up and running, you can send out groups of adventurers to explore and loot other players' creations, playing out through turn-based tactical combat. You start a game on a randomly-generated area map with a few settlers, tools and other provisions, and slowly grow into a self-sustaining village, town, or eventually, a city. You play as one of several fantasy races each with their own unique gameplay mechanics.

  • View media
  • View media
  • View media
  • View media
  • View media
  • View media
Post article RSS Articles

Welcome to the first King under the Mountain dev update for 2021! This month has been entirely focused on implementing a particle effect system into the game. But that might lead you to ask...

What are particle effects?

Particle effects are a graphics technique where lots of small and usually simple images or models are rendered and often animated to produce a single complex effect. Here's an example from the official Unity tutorial (the particle effect is the pink glow and sparks):

unity example

In the above example, a simple coloured sprite is being used lots of times for each of the particles flying off the main large effect on the kart's wheel. If you look closely you'll notice they're also decreasing in size as well as moving in an arc until they disappear entirely. Simply put, a particle effect is created by applying several effects on lots of instances of small "particles" like this. Particle effects are used extensively in games, for explosions, spell casting visuals, impact effects, almost any visual effect you can think of is often done using particles, though in other cases techniques such as using shaders give a better result. As an aside, a shader is a program that runs on the graphics card to adjust the geometry of models/shapes, or the colour of individual pixels - sort of - which can have some incredibly powerful effects, see shadertoy.com for some good examples to play around with. The dynamic lighting and flowing water in King under the Mountain are both achieved using a shader.

Particle Effects in LibGDX

King under the Mountain is written using LibGDX, which is a game development framework, which is a bit different to a game engine - an engine is a bit more prescriptive about asset formats you have to use, how levels/maps are handled and that kind of thing, whereas LibGDX is at a lower level than an engine, giving you access to underlying graphics and audio programming interfaces (OpenGL and OpenAL) with a good amount of "helper" code on top for common game development tasks. That said there's much, much less that you get "out of the box" for using LibGDX compared to a standard engine, for example I had to implement something as seemingly basic as multi-line text in LibGDX!

One of the utilities that LibGDX does provide is a good particle effect implementation and GUI editor for defining your own effects:

libgdx editor

You can see some of the many parameters that can be applied to a set of particles in an effect (you can have different sets of particles each with their own "emitter"), such as the angle of emission from the starting point and the range of velocity they have. The blue-line-graphs are used to adjust these values over the life of the particle. There are more parameters which have not been used in this example such as rotation, gravity and "wind" that can be applied (all with the ability to have a different amount over different times).

When you load up the particle effect editor, it starts with an example particle effect of lots of semi-transparent red circles (up to 200) used to create a flame effect:

default particle


The first particle I decided to implement myself was a simple but important one for a game about dwarves digging into a mountainside - chipping away bits of rock while mining!

rock particle gif


Unlike the example flame effect, this uses far less particles at once, but also makes use of rotation and gravity to give the effect of a chip flying away from a point.

But what about lighting?

In most games the above would be great and all you'd probably need to look at with particle effects in a game built using LibGDX. In the case of King under the Mountain however, things are made a bit more difficult by the dynamic lighting system. If you've ever looked in the data files, you'll likely have seen that almost every sprite in the game has a matching "NORMALS" version, like with the following:

anvil and normals


The _NORMALS file is a visual normal map (or bump map) that uses the red, green and blue colour channels to describe which direction each part of the "surface" is pointing in 3 dimensions. This information is combined with light sources - each light source is casting light from a certain point, and this is combined with the normal map to figure out how much light will be hitting any given point. At least, that's my attempt at explaining normal mapping without getting too technical into vector maths! It's much more commonly used in 3D games rather than 2D ones, but one of the very first things I wanted to implement in King under the Mountain was a truly dynamic lighting system so that a dwarf carrying a lantern around tunnels and halls would be suitably evocative, and help distinguish the game from its peers.

It helps to see everything combined in-game:

lighting example

In the above screenshot, the top left is the game world rendered without lighting, using the sprites as they exist in the data files, also known as the diffuse sprites/layer. Top-right is the same scene but using all the _NORMALS versions of the same sprites to build a normal map of the entire scene. Note that the sack in the lower-right does not have a normals-sprite for the label on the sack, so this is not rendered in the normal map scene, meaning it will be lit the same as the layer below (the sack itself in this case). Bottom-left is the lighting information, which is made by using a shader to add an amount of light based on the normal-map version and data from point lights in the scene (a white light from the cursor in the upper left, a yellow light from the miner's helmet in the lower right, and a small amount of global lighting so unlit areas are not pitch black). The lower-right is the combined final result that you see in-game, which is made by simply combining the two images on the left hand side.

That's a very quick run-through of the lighting system, but I bring it up because it occurred to me that I wanted the lighting system to work with the particle effect system, at least for some particle effects that want to be "in the game world" compared to ones which should not be affected by the lighting and would be more like UI information (for example, thought bubbles above settler's heads).

The naïve approach would be to have two sets of my rock chipping particle effect running at the same time in the same place, one with the diffuse (standard colour) rocks and one with the normal maps (even though normal maps don't really work when rotated - this is an issue I'm going to live with for now). Unfortunately, there's a lot of randomness in a particle effect but there's no way to set a "seed" (an initial value used to make a random number generator give the same sequence of results multiple times - like the map seed when starting a new game) in the LibGDX particle effect library, and in fact the randomness is buried quite deep within the workings of the library so there wasn't a simple option of just replacing all the random number generation with random number generation using a supplied seed.

Instead I had no option but to take a copy of the main part of the LibGDX particle effect codebase and modify a lot of it, I ended up making it be aware of an optional extra set of sprites for the normal maps, and any randomness would apply to both sets of particles that were created at the same time. It doesn't seem like much but it took a lot of effort to have a particle effect which could spit out diffuse and normal-map versions of the particle in the same way at the same time!

particle with normals

And a little extra on top

There was just one main hurdle remaining - the particle effect shows chips or rock flying away to the right, but what if the miner is facing a wall from the left, or above, or below? But also where should the particle be positioned relative to the entity in game that is creating it (if it's even attached to an entity at all)? The LibGDX particle editor saves and loads in its own file format, named by convention as a .p file. It would be a bad idea for me to add or make changes in this file as then I wouldn't be able to load the .p files in the visual editor in the future, so each particle effect in King under the Mountain is defined with a type in JSON (like almost every "type" of thing in the game files) that looks like the following:

{
  "name": "Chipping rock",
  "particleFile": "rockparticle.p",
  "scale": 0.4,
  "usingParentOrientation": "LEFT",
  "isLooping": true,
  "isAffectedByLighting": true,
  "usesTargetMaterialAsTintColor": true,
  "distanceFromParentEntityOrientation": 0.8,
  "offsetFromParentEntity": {
    "x": 0,
    "y": 0.3
  },
  "attachedToParent": false
}

The key to the direction problem is the "usingParentOrientation" property with a value of LEFT - I then added some code which readjusts some parts of the particle effect, like the initial angle of emission based on this property for use with other orientations. "attachedToParent" with a value of false means the particles won't move (once created) when the parent entity moves - this would be true for things like speech and thought bubbles which would also have "isAffectedByLighting" as false so they appear above everything else and are not affected by the lighting system.

Putting it all together, we can now have rocks chipping away with any mining direction!

final chipping

What's Next?

All the particle effects! Or at least, a good set of effects for where the game is now, focused around different job types and crafting types. It's always been a long-held ambition to have leaves falling from trees in autumn according to the changing colour of deciduous trees during autumn, and this finally makes that possible (or rather, fairly easy instead of some long-winded and complex way of achieving it with a different approach). However many particle effects I come up with at this point, I'm sure there'll be lots more that could be added to the game as it is - just looking at the animation above, when a wall block is removed it could really do with a burst of clouds of dust type of effect, things like that. I'd absolutely love for the player community to suggest more that they'd like to see - now that the particle system is in place it should be fairly straightforward to add more effects - so get involved via the Discord server.

It's a bit of a shame that after the initially swift progress of Alpha 5 that I've had to spend the entire month adding this single feature, though it is quite a big one which will add a lot in the future, and was a bit of hurdle to get over but we're there now! The intention was always that this can also be used for the "Visible job progress" item on the roadmap but there's also lots more that could be included now or later. Hopefully, particle effects are wrapped up soon, then constructing flooring, roofing and rooms is the next step to complete Alpha 5. See you next month!

King under the Mountain December 2020 update

King under the Mountain December 2020 update

News

Monthly dev update for King under the Mountain - a simulation-based strategy game inspired by Dwarf Fortress, The Settlers and Prison Architect.

King under the Mountain November 2020 Update

King under the Mountain November 2020 Update

News

Monthly dev update for King under the Mountain - a simulation-based strategy game inspired by Dwarf Fortress, The Settlers and Prison Architect.

King under the Mountain October 2020 Update

King under the Mountain October 2020 Update

News

Monthly dev update for King under the Mountain - a simulation-based strategy game inspired by Dwarf Fortress, The Settlers and Prison Architect. Back...

King under the Mountain June 2020 Update

King under the Mountain June 2020 Update

News

Monthly dev update for King under the Mountain - a simulation-based strategy game inspired by Dwarf Fortress, The Settlers and Prison Architect.

Add file RSS Files
King under the Mountain win32 v0 3 3

King under the Mountain win32 v0 3 3

Demo

Early playable prototype of King under the Mountain, for Windows 32 bit.

King under the Mountain linux64 v0.3.3

King under the Mountain linux64 v0.3.3

Demo

Early playable prototype of King under the Mountain, for Linux.

King under the Mountain mac v0.3.3

King under the Mountain mac v0.3.3

Demo

Early playable prototype of King under the Mountain, for Mac.

King under the Mountain win64 v0.3.3

King under the Mountain win64 v0.3.3

Demo

Early playable prototype of King under the Mountain, for Windows

Comments  (0 - 10 of 12)
Lord_Baal
Lord_Baal

Can't download demo to pay yet, but it has several levels like DF or just one like the old DF?

Reply Good karma Bad karma+2 votes
RomanianReaver
RomanianReaver

No beer? And yet you say they're dwarves?! **opens the grudge book**

Reply Good karma Bad karma+4 votes
RocketJumpTechnology Creator
RocketJumpTechnology

Ah but the beer is coming, with a very detailed production chain and a major part of the economy! :) Just not in this version sadly, but the next major one I'm sure it will be.

Reply Good karma+4 votes
RomanianReaver
RomanianReaver

That'll do laddie, that'll do.

Reply Good karma Bad karma+3 votes
EarlyAccessGamer
EarlyAccessGamer

Hi, I was really enjoying playing your game. Even so early in development the mechanics are tight and fun. However, the demo crashed shortly after I started using it and I noticed that I was up to 3GB of memory usage from the game. I think you might have a memory leak :(

Reply Good karma Bad karma+3 votes
RocketJumpTechnology Creator
RocketJumpTechnology

Here's a quick look at memory management under the hood - it's very spikey due to the Java garbage collector but over time seems to use the same amount of memory for the duration, dropping down to about 250MB on average. How much memory do you have on your machine? Any info helps!

Kingunderthemounta.in

Reply Good karma+2 votes
RocketJumpTechnology Creator
RocketJumpTechnology

Thanks a lot for bringing that to our attention! Looking into it now! The game does seem to hover around 2.8GB of memory usage normally (not been at all conservative with memory usage at this stage) which is a lot but shouldn't be a problem for modern desktops/laptops. Will do some debugging now to see if I can find a memory leak.

Reply Good karma+2 votes
EarlyAccessGamer
EarlyAccessGamer

Hi, I have 32GB of memory so it shouldn't be a problem at all (and I'm not even entirely sure it was the cause of the crash - I looked for a log file just now but couldn't find anything). My suspicion is that not enough memory is being assigned to the JVM which could cause it to crash if memory usage spiked. I'm really keen to make a video on this game so I'll try again this evening (GMT+13) and get back to you with an update.

Reply Good karma Bad karma+1 vote
Rasip
Rasip

The windows demo is using 32bit java. It doesn't matter how much ram your computer has 32bit java will not be able to address more than 4GB, but in most OS it is closer to 3GB.

Reply Good karma Bad karma+2 votes
RocketJumpTechnology Creator
RocketJumpTechnology

Actually every platform only comes with a 64-bit launcher, mostly due to this memory constraint.

Reply Good karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Profile
Icon
King under the Mountain
Platforms
Windows, Mac, Linux
Engine
libGDX
Contact
Send Message
Release date
Game watch
Follow
Share
Style
Theme
Fantasy
Players
Single Player
Project
Indie
Twitter

Latest tweets from @rocketjumptech

All about the particle effect system in January's King under the Mountain dev update Indiedb.com #indiegame #gamedev

Jan 26 2021

Particle effects are here! Some much-needed visual feedback in the world of Kingunderthemounta.in now to add them… T.co

Jan 26 2021

Thank you so much to @nookrium to revisiting King under the Mountain with a nice mini-series for Alpha 5! That said… T.co

Jan 11 2021

The December dev update for King under the Mountain is now live at Indiedb.com covering the bumper Alph… T.co

Dec 24 2020

Huge update released! #twitchtv integration, embark options, multiple saved games, flooring visuals, stockpile mana… T.co

Dec 19 2020

RT @RocketJumpTech: #gamedev How it started / How it's going T.co

Dec 3 2020

#gamedev How it started / How it's going T.co

Dec 2 2020

Neat freaks, rejoice! In Alpha 5 of Kingunderthemounta.in you'll have full control of which items go to which sto… T.co

Dec 2 2020

Embed Buttons
Link to King under the Mountain by selecting a button and using the embed code provided more...
King under the Mountain
Statistics
Last Update
Watchers
169 members
Files
4
Articles
47
You may also like
Trollskog
Trollskog Real Time Strategy
Banners of Ruin
Banners of Ruin Real Time Strategy
Heroes of Delum
Heroes of Delum Real Time Strategy
DwarfCorp
DwarfCorp Real Time Strategy
Oberon's Court
Oberon's Court Real Time Strategy