Wednesday, January 22, 2014

GML: 8 Directional Movement Part 2

In the last segment on movement in Game Maker, you built a small, simple little object that moved around an empty space.  It was pretty neat, sure, but only the starting point.  After all, what's a game without walls!

Now, you'll need to make a new object in that same thing from before.  You can call it obj_wall, or you could just name it ROCK.  Once that's done, you'll need to give it a sprite.  Probably just go with a square again.  32X32, or whatever fits with the things you've made already.

Back to your obj_player, you're going to want to create a collision with obj_wall event.  Inside, put in an "execute code" block.  Inside, put something like this:

x = xprevious;
y = yprevious;

This sends the player back to his last position anytime it hits a wall.  It's quick, it's simple, and it works. Obviously, it's not the most elegant solution, but with these two simple objects you can have the basic top down system going for you.

You can do this in different ways, and we'll cover them sometime in the future.

I'm hoping this one helps you guys, as that 8 directional tutorial is one of the most popular things on here.  If you have any questions, or want to know how to do a specific thing with it, feel free to ask in the comments!

No comments:

Post a Comment