Saturday, 23 August 2014

Ludum Dare 30 Part 3: On The Quirks of Gamemaker Studio and Isometric Walls.

Gamemaker Studio is, I've found, pretty cool to work with. But like any program, it's going to have finicky moments, and being rusty at coding/scripting doesn't help. So let's talk a little about that. Right now, it's been almost 12 hours, I have a plan (which I've cut), I've had a sleep, and I'm on my way to coding the darn thing properly.

Which leads to the first obstacle, and something I've done that's bloody stupid, for me. I've gone for an Ultima style isometric movement. And it ain't steps. What problems does that create? Well, I'm still only moving in eight directions, that's fine, and that was easily coded round with just the basic event handling that GMS is good at (and I fondly remember from my Games Factory days back in school.) But collision, and how you handle butting your head into a wall, is another matter entirely. That requires some scripting, and I've got to write this stuff down to make sure I've got it right. Also, y'know, test it...

Duder McMann in... The Dimension of I'm Getting Used To That Pattern Now...

In any case, what I have right now is that if you hit a wall, you just stop. Dead stop. You can't move along the wall, you can't move into the wall, and only half of that is what I want. But there isn't a way to do that with basic event handling. You can bounce, or you can stop, those are your choices. So something has to be done, and it can only be done in script. I just checked that, to be certain.

So the key to any program thing is what, precisely and logically, do you want to happen? In this particular case, I want the following to get checked, in order:

  1. Is there a collision between my dude and the wall?
  2. If so, am I holding a diagonal (IE - up-left, up-right in the case of a wall I bumped into from the bottom.)?
  3. If I'm holding a diagonal, keep me moving horizontally, but not vertically (or vice versa, in the case of a side collision)
But how in blue blazes do we do that, eh? Well, here's where it gets fun. See, to check whether I'm holding a diagonal, I could either make eight separate checks for a combination of two keypresses (UP AND LEFT, for example), or... I could check which side the collision is, and if it's with a wall, I could say "am I holding up? good. Am I not holding left or right?"

...Bet that didn't make sense, did it? But in a programming sense, yes, it does. Because if we were to check for up, and then left or right at the same time, if we pressed either, it would act as if we pressed all three at the same time. If you check for left, then right, you're adding unnecessary steps. Come to think of it, I haven't tested what happens when you hold up and down, or left and right, both at the same time.

...Cool, it did exactly what I expected it to do (the relative position changes cancelled each other out, as they should.) Don't expect a program to do what you expect it to do if you wrote it. Always check. Anyways... If you check things a little differently, you can cut between eight and sixteen direction checks down to four.

  1. Okay, I'm hitting something. Am I still moving in the direction of the wall? (1)
  2. Yes, I am. Is the keyboard telling the PC that left and right aren't being held down? (2)
  3. Ah, okay, it isn't. Is it moving left or right? (3, 4)
  4. If it's moving left, move me left while not letting me move up. If it's moving right, move me right without letting me move up. Simple!
It's still kludgy, because collision checks are a thing GMS is always looking for, and it checks every wall each time (afaik), but for now, it'll serve my purposes.

This, ladies and gentlefolks, is just one of the many mini dilemmas you face when your scripting is somewhat rusty (I'm not going to call it programming), and you need more than what simple tools will provide. Speaking of, I still haven't checked out how to rebind keys... :D

POST SCRIPTUM: For some reason, Duder McMann (my generic name for a protagonist) is having a little trouble standing facing down-right. The moment I hit right, he faces away... I suspect cutting even more might be an idea if I want to make this by sunday evening... Time to change the concept some more.

Duder McMann, in the pose you'll never see unless you move diagonally down-right.

No comments:

Post a Comment