Sunday, 3 May 2015

I Think It's A Game

Looks like I ended up taking a bit of time away from GameMaker. No real reason apart from I'm a lazy bastard. Still, tonight, I got back into it for a bit and although I don't think I really added much, I think it's now at a stage where it can be called a "game". Basic, unbalanced, in need of tweaking, but still - just about - a game.

Since the last post, I've mostly been adding in player interactions. Before today, it was more of a simulation of sorts - the little computer people ran around and did their own thing but there was no means of interacting with them. I've now made changes so that you can use your light resource to influence them to your side and that light resource is tracked and displayed. You can run back to your home building to replenish it, too.

Animating a Status Change

There is also a very short animation when an NPC* changes allegiance, basically just showing it changing colour between it's previous state and the new state- eg, dark (black) to neutral (mid-grey). It turns out GameMaker actually has a built in thingy (to use the technical term) to generate certain animations, one of which - Fade to Colour - was what I used. Here's how I used it:

The first animation I made was a dark NPC changing to a neutral NPC, so I'll use that as an example. Firstly, the dark NPC already had a sprite, sPersonDark, which looks like this:

Stunning artwork, right? Sometimes I amaze myself with my own creative genius... Anyway, if you go to the sprite in GameMaker and edit it, there's an Animation menu. In this menu is the Fade to Colour option. On clicking it, you're asked for an RGB value to fade to. In my case, that's 128,128,128, or mid-grey. Then you tell it how many frames to animate it across (I used 16), and then GameMaker will automatically generate the animation frames for you:

Yeah, so that would probably have been better laid out horizontally, but I'm not sure how to do that in Blogger without messing about with the CSS and I frankly cannot be arsed doing that. One important note: remember to duplicate the sprite first before adding the animation. In my case, I made a duplicate and renamed it sPersonDarkAnimToNeutral. Seemed catchy at the time. Actually, another important note: GameMaker seems to forget the offset information of the original when you duplicate a sprite, so you may have to specify that manually afterwards.

So now we've got the animation, how do we apply it to the object? Through the wonders of sprite_index... In oPersonDark's create code, I put the following:

 transformAnim = 16;

Then the following was added to oPersonDark's step code:

// Transformations based on Lightmeter

if ( lightMeter > 0 )
    //transform to oPersonNeutral
    sprite_index = sPersonDarkAnimToNeutral;
    transformAnim = transformAnim - 1;
    x = xprevious;
    y = yprevious;
    if (transformAnim = 0 )
        instance_change (oPersonNeutral, true);

So, once the lightMeter value is more than zero, it triggers the transformation from oPersonDark into oPersonNeutral. To change the old sprite to the new animated one, we use sprite_index. This animation is 16 frames long, so I've used  the transformAnim value, originally set as 16, as a countdown timer. Now the animation plays, the object is frozen in place (x = xprevious, y = yprevious) and, each step, transformAnim is reduced by one. When it reaches zero, the oPersonDark object is replaced by oPersonNeutral (using instance_change). Something similar was also added to the other objects, so all the state changes are now animated.

I should say that I'm not 100% sure this is the best way to do it, but its the way I've done it. In testing, I've noticed that occasionally some of the people run around with the transformation animations running, which isn't supposed to happen.

The Light Resource

As I said, I also added in some functionality for the player to convert people to their side. Now, the different kinds of people could already influence each other, so a lot of the variables were already in place. For more details on that, have a look at this earlier post:

Possibly the Point of No Return

There's one difference when it's the player doing the converting, and that is that the player uses a resource to convert others. I've done this in the following way. First of all, in my global variables (basically an object called oGlobal with all global variables declared in it's create code), I've set a maximum value of 250 for maxPlayer Light. Then, in the create code for oPlayer, I've set a starting value of 50 for playerLight.

I won't go into the details, as they were basically explained in the previously mentioned post, but basically what happens is this:

When the player gets within range of a neutral person, playerLight is reduced by 1 each step. As long as playerLight is above 0, the person's lightMeter value is increased by 1 each step. Here's the code in oPersonNeutral's step code bit:

// Influenced by Player

if distance_to_object (oPlayer) < influenceDistance
    if playerLight > 0
        lightMeter = ( lightMeter + influenceSpeed);
        playerLight = ( playerLight - influenceSpeed );

As a reminder, influenceSpeed is a global value set as 1 and is basically just a way for me to modify how fast conversion takes place. Similarly, influenceDistance is a global value (currently 20) so I can vary how close people need to be in order to influence each other. So anyway, once playerLight's value reaches zero, the player is incapable of influencing any person. In order to increase playerLight, the player has to head back to their home building (the white one). This also uses the same technique as previously - if the player is close enough to the building, then playerLight is increased by influence speed. Just for the heck of it, I also added a collision event - if the player collides with the building, they get an extra +1 playerLight each step.


There's currently no sound or music in the game. Today I was going to remedy that, but after loading up Sonar, I got distracted with some past projects instead of making something for the game. I have some vague ideas on what I want. I should probably think about it more before getting down to work on it, anyway. Hopefully I'll get round to that soon. Anyways, time for me to head off.


*Not sure if "NPC" is too grand a term for what is basically a randomly moving coloured dot!

No comments:

Post a Comment