Thursday, August 21, 2014

"Depth" - Showing Appreciation for the Drag and Drop

The "focus mechanic proved to be much simpler than I thought.  GameMaker Studio has a handy function in it's Drag and Drop U.I. simply titled "Change Instance".

The "Change Instance" function was all I needed to make this mechanic really work.  Using similar platforming control code I've used in past tutorials,  all I needed to do was create a blurred version of the sprite used for the object that the player would be colliding with.  As the "blurred block" isn't mentioned anywhere in the player object code, the player simply doesn't react with it.

I've tied the "Change Instance" action to a key release event, in this case, the letter "Q".  So, once a player presses and releases the Q key, that causes the instance of the blocks to switch.


Now, the problem I am running into is my own lack of coding experience.  As you can see in the above .gif, all of the block I have used are, well, blocks.  There is no "floor" for the player to land on, as once the "focus" key is hit, ALL of the other blocks would go out of focus.

Now I have tried to add a floor object and tie it into the players collision code, but so far, this has been the result:


I sort of though it would be as simple as adding an "or" statement:

if (place_meeting(x+hsp, y, obj_block or obj_floor))
{
    while (!place_meeting(x+sign(hsp), y, obj_block))
    {
        x += sign(hsp);
    }
}
x += hsp;

But that proved to be incorrect, as the player would simply fall through the floor.

Once again, GameMaker's Drag and Drop U.I. has come to the rescue.  I finally figured out that all I needed to do was add a collision event to the player object with the instance of the floor.  Applying that same code this time to the floor object, the only issue I had bumped into was that the player would get stuck in the floor if he/she fell through one of the "blurred" blocks.  This time, I was able to fix it using that same script that was used in the tutorial for "Breakout":

while (place_meeting(x, y, argument0))
{
x += lengthdir_x(1, argument1);
y += lengthdir_y(1, argument1);

}

This keeps the player pushed above the instance of the floor and allows the player to control the character normally.

**On a side note, I'm taking note of the functions used in this script as well as my coding issue with floor collision.  Expect another one of them "Lesson Learned" posts in the future.

I think it is safe to say I have a nice stepping stone for this project.  It may not seem like much to most of you, but I can't explain how exciting it is to actually make progress on something.  Now, I have a lot I still need to learn.  I would very much like to get to a point where I can rely strictly on code and not the drag and drop, but it does really help to push you along if you get stuck.




The nest step I think will require a little more research/tutorials.  What I hope to look at next are:

  1. Creating a finishing line.
  2. Creating a health system/objects that harm or hinder the player.
  3. Overall level design.
So to get an idea of whats coming up for the blog, I will more than likely have a couple of "Lesson Learned" posts as I review some code and dive into a few tutorials relevant to these projects.  Heck maybe I'll even throw in a few Rant/Opinion posts when I have the time...


-JWest

No comments:

Post a Comment