Monday, November 21, 2016

Imma charging mah potato!

    Last week I coded the infrastructure for field crops. My first victim was the fabled potato.

Is it me, or does the little fella look like he's just
escaped from the asylum?
    Crops can be either one-time, or they can provide additional yields every X days. There will be a large variety of crops, and some crops will be available once players meet certain criteria, like having shipped specific amounts of other crops or having befriended certain individuals. Crops are also prone to destruction by weather effects and other perils.

    Also, remember about talking about the potential to be able to move while charging a tool? It's already done! Now combat should be much more fluid. But that's not all: Special "run-and-hit" animations, as well as an ultra-powerful strike have been added! Oh, and a rolling animation too! I guess at this point I should rename the game to Dark Crops or Crop Souls or whatever. Stay tuned for an upcoming demonstration of combat!

Saturday, November 12, 2016

Sprite multi-recoloring shaders and Game Maker: Studio implementation

Today we will get a little bit technical. Using a simple set of fragment shaders and color maps, we will entirely recolor a sprite on the fly.

Although the idea is implemented in Game Maker Studio, its principles should be applicable in any other shader-enabled application. Note that in Game Maker: Studio you may need to turn off "Interpolate colors between pixels" in the Global Game Settings for this to work!

This tutorial is aimed mainly at people with a basic or intermediate (like me) understanding of shaders. The method presented is not intended to be the fastest or more compact and efficient, and is broken down in steps that would be avoided by more experienced programmers, but I chose this structure in order to a) Make the method easier to understand and b) Highlight some specific things like texture coordinates, shader values and parameters[*]If there is one thing I hate in tutorials, it's this: "How to draw a kickass elf warrior: Step 1. Draw three circles. Step 2. Draw the rest of the kickass elf warrior.".

First of all we need a character sprite. It can contain many sub-images but it's not mandatory. Here is our guy:



Since the sprite will be recolored, we don't necessarily have to use good-looking colors: In fact, it helps if we use distinguishable hues to separate visually the various body parts and/or potential body accessories. For the same body part, we can use different brightness values to visualize that variance in the final sprite. But really, one can just paint a sprite with "normal" skin colors and everything: As long as all possible different colors are set up correctly, we are ok.

This is our "base sprite": It serves as the precursor to our "color mapped" sprite. But how exactly does this method work?

At first, we set up a "color mapping" shader and, using this shader, we draw all of our sprite's subimages on an empty surface. The only "additional" info for this first shader is a color map. The color map is simply a one-pixel-height sprite containing every color value in the base sprite that we created, in no particular order (but some hue grouping helps). If you want a value of the base sprite to be unchanged, like the sprite's outline, you can omit this color from the color map.



For our example, I am using a 32x1 sprite as the color map. Remember, if you are using Game Maker Studio, check the "use for 3d" box in the sprite properties of the color map! This will create a separate texture page for it and thus getting the texture coordinates of every pixel in the shader will be much easier[*]Other sprite dimensions will work, but for the "use for 3d" option to be available, they must be integer powers of two, like 1, 2, 4, 8, 16, 32, 64 etc.. Also, not all pixels of the color map have to be used: If you have a 20 different colors sprite, you can use a 32x1 color map where the first 20 pixels will be the various sprite colors and the rest can be a color not used anywhere in the base sprite.

Friday, November 4, 2016

Coffee and planned features

    It's Friday, I'm sitting at my desk with a hot cup of chestnut-flavoured coffee, and figured I should be talking a bit about the game so far: Development, features and goals. Plus my CEO[*]Due to a shortage on suitable (read: affordable) candidates, I appointed my cat as CEO. She has the attitude, after all. insisted I should be more vocal about what's going on.


    Regarding the game's duration, there will be no time limit. You will be able to run your farm forever. However there is a "main plot". For now, plans are that it should be resolved during the second year. You can choose to ignore the main plot and just play happy farmer. Or you may engage it and go deeper, thus discovering the true world of Gleaner Heights. There are also sub-plots involving the local townsfolk. In contrast to your average farming sim, you have the ability to change their lives forever, and I am not talking about a different line of dialogue here and there. But then again, I can't give more info, can I?