Friday, March 10, 2017

Interesting combat in a farming game

    February was Combat month. This means that I had to setup attack hitboxes, special moves and enemies. I didn't design and implement as many enemies as I wanted. So far there are 9 "normal" enemies and a "boss" one. There is definitely room for more content there and, besides, some enemies not done yet are crucial to the main story.


    Since the game's atmosphere is more akin to this of a suburban gothic 90's TV series, a certain degree of realism is expected of the game world. Sure, there may be mysterious entities and a hint of otherworldly powers, but their impact will be much greater when contrasted with a more down-to-earth environment. Would the encounter of killer BOB by the main characters in Twin Peaks be such a harrowing event if in the rest of the series we watched townsfolk fighting zombies?

Monday, January 16, 2017

Creating townsfolk schedules


    In order to make the game world livelier, the inhabitants of Gleaner Heights have to be on the move every day. Maybe they will leave home and go to the town square in the morning, then enjoy a meal at the Diner, then visit a friend, and so on, until nightfall approaches and they return home to rest. We've seen this in games before. The older Harvest Moon games did it. Modern AAA open-world RPGs do it. And now I'm doing it. Unsurprisingly, this section of game design is rife with challenges as well.

A few characters from our main cast. Sorry for the messy upscaling.
    I'll remind you that I am using Game Maker: Studio to develop the game so some technical jargon will refer to this specific application, but the gist of the article isn't confined by it, as always. Any software development tool supporting data structures can be used to implement the ideas discussed below.[*]People who write in programming languages utilizing classes and pointers are probably laughing so hard right now after having skimmed through this article that I can probably hear them from here. But this is Game Maker we're talking about, and we'll have to make do with whatever hand we've been dealt.

    So...we have a bunch of villagers (over thirty, actually). And we want to set up a daily schedule for each and every one or them, bearing in mind the following guidelines:
  1.     Townsfolk (or Non-Player Characters or NPCs) should have different schedules during certain days of the week. Also, their daily routines differ each season of the year.
  2.     Each NPC must have a clearly defined schedule, that is a list specifying where they should be at any given time. This means that if the mayor leaves home at 8:00 in the morning and he needs 10 game minutes to go to the general store, if at 8:05 you exit a building and you spawn at the town map near the general store, you should see the mayor exactly halfway there. Also, NPC schedules should be declared in a brief, yet human-readable way. Writing tons of borderline nonsensical -to your future self reading them- parameters for over 30 NPCs can cease to be fun very, very quickly.
  3.     NPCs must pause their route briefly when the player character is very close to them, in order to lend some attention to the player. Maybe we want to chat or give them an item. Of course we can do all that when an NPC is on the move, but chasing them around to do so isn't the smoothest option. In any case, they stop for a set amount of time, beyond which they resume their route.
  4.     NPC schedule infrastructure must be set up in such a way, that it will be possible for the game to alter a given day's schedule under special circumstances. For example, if it's snowing an NPC will stay home, if it's a festival day an NPC must be at the town square etc.
    So...my approach is the following:

Saturday, January 7, 2017

Game music attempts #1

    Is it too late to wish you all the best for 2017? Have I exceeded the New Year Wishing time limit? Either way, have a great new year!

    I have no formal music education. I have no idea what a C note sounds like, or what scale can get on well with another. But decades of listening to video game[*]And movies/series soundtracks. And ambient music. Generally anything without lyrics music and replaying all those tunes in my head has given me some internal composing ability. Why internal, you ask? Well, I might have this great melody running around in my head for some time. To actually produce something out of it, with my aforementioned lack of musical education and experience, well, that's the real challenge.

The theater man in the beginning of the game has some brooding mysterious saxophone music going on. Or at least I think it sounds like that.
    I am using (mainly) soundfonts for my composing attempts. I find them more straightforward and besides I don't think I could afford any expensive VST, my poor ol' computer wouldn't probably handle 5 Gigs of ultra-quality instruments loaded up all at once, and I wouldn't be able to put them to any good use anyways. Besides, I believe that a retro-looking game doesn't have to have ultra realistic music with top-notch instruments. Soundfonts are easy to look and categorize and pretty easy to use, but I reckon we are talking about a nearly extinct species here.

    So I have tried to write some music for the game. This isn't my first time of fiddling with music, although we are talking about really amateur levels here. Since I am going for the classic cutesy farming sim, but with some more...ahem...surreal stuff underneath, I am trying to inject some mysterious jazzy vibes into various music tracks, like how the music of a 90s mystery TV series would sound, so I am using the saxophone soundfont on many occasions. Does it work? Well, why don't you listen yourselves and give me a heads up:

       

    The tracks are set up for looping (listening to them on the Soundcloud website gives you the ability to loop them).The main question is: Would you play a game fitting the above description with such a soundtrack? Or is the music intolerable? Plan B is to hire a musician which is fine too since I'll have more time for development. I am designing the game, writing all the code, making all the graphics, so I don't expect any time soon to be a master composer. But if those tracks seem ok for the task, or could be tweaked for the better, let me know!

Tuesday, December 27, 2016

How many sprites can make an animal happy?


    Of course the real question is "After how many sprites that you've drawn for all the various animal states will you start feeling depressed?"

    A large animal, like a cow or a sheep, can move in any of the four cardinal directions (up, down, left, right). It can move its tail or head. It can sit down for some time, then stand up again. This is not an enormous amount of frames to draw. But then, an animal may be pregnant. Or sick. Or both! Or a sheep can have its fur cut. Since there have to be some visual cues for those states, this means you have to modify or recolor your existing animation frames, then export them, then import them to your game assets...

    There has to be a shorter way to deal with this. It makes me wonder: In some older Harvest Moon games, a cow could be pregnant or sick, but not both. Was it some gameplay design decision, or was it in order to avoid drawing another set of graphics where cows were both pregnant and sick? Anyway, let's summon our trusted friend, Sheepio, and see if we can "derive" some extra graphics from our basic ones.

Hey man. How you doin'.

    So we have Sheepio's basic animations: Standing, walking, moving, sitting, moving its head etc. in all four directions. In these animations Sheepio has its fur all grown. What we are going to do is grit our teeth and make another set of animations, modifying our original set, where Sheepio is pregnant. Since this will be our only other anination set, apart from the bigger belly, we can make its snout redder, as a more visible cue that this particular animal is pregnant.

    The question now is, can we manipulate those two sets to introduce sheepio being sick or having its fur cut, either when pregnant or not? Once again, shaders come to our aid.

Friday, December 16, 2016

Chickens and cows: A tale of collisions and betrayal

 
We'll get to you in a minute, dear cows and baby cows. hang in there!

    One of the first steps of adding livestock to your farm game is to determine how they interact with the Player Character (PC) and among themselves. The difficulty with this aspect of design is the future problems and/or conflicts that will appear because of the path you took. Problems which you didn' t see coming, and for which you come up with a solution that eventually spawns even more problems. To wit:

    1) Let's design chickens in the following way: They are not considered as obstacles, so PCs can pass right through them. Additionally, one can pick them up, carry them around and drop them anywhere! Neat! Only...

    A) How will I display the character holding the chicken up like an item? Oh yes! Items! I will create a dummy item that looks exactly like a chicken! In reality, when players pick up the chicken, it vanishes, and a "chicken item" is created that players immediately get to hold in their hands. Phew! That wasn't so hard!

It's so dense, every single image has so many things going on.

    B) Shit. I pressed the "back" button while holding Chica, and she went straight into my backpack! This isn't right! I can't be running around carrying chickens in my pockets! Why is this happening?!??!?

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.