Read my initial thoughts as well as the design document for the game I’m creating in Part 1 of this series.
I made a mistake.
Quite a few, actually, but one that is prevalent to this series of articles. In my design doc, I stupidly laid out an over-ambitious creation schedule. I essentially said that “Step 1” would be to program in the controls for the player. HAHAHAHAHADOHASDIFJOASIDJFWEIOFIJSVN it took far more steps than one. As a result, I have updated the new steps for the controls. They are as followed:
Steps for Creating Controls:
- Insert all sprites that will be used as placeholders. I will use the basic character outline from the YoYo Game Resource page as my character for now. Also add basic level-building blocks.
- Make the character move left and right, worry about gravity later.
- Add collision, worry about friction later. Add blocks into a test level.
- Realize friction is too important, re-prioritize to add friction now.
- Realize that I want to add gravity now and add gravity.
- Animate the character so he isn’t looking like a statue while moving.
- Add feel-good controls like acceleration, deceleration, and controllable jump-height.
- Add an attack button.
- Add the cling/climb on walls feature.
- South Park reference.
Even this is bad structuring, because after doing all of these (except for 9 and beyond), I realize there are a million little steps in between and they all cause their own little problems and conflict with one another in ways I never thought possible. I’m not going to go into heavy detail, mainly because it’s been weeks* of working on this stuff and I don’t remember it clearly, and I also don’t want to relive the hell, but I’ll give a basic rundown of each step, its problems, and the solutions to those problems (as well as crediting the people with help for those certain problems).
“Step 1”: The resource page has a template for a platformer character. I downloaded it, ripped out all of the sprites that I wanted, and uploaded them into Game Maker. Since they were green, I had to color them all in. Each… and every… frame. I colored them as basic as possible. See here:
Yes, it’s another white protagonist. I know, I’m part of the problem.
I had to color him exactly that way in every frame I wanted to use, which was quite a few. It wasn’t hard, but it was tedious, boring work. The worst came when I wanted to import an attack animation with a sword and the stupid template didn’t have one when I had already imported so many images from it. I didn’t want to start over with a new template, so I had to draw a crappy sword into one of the animations. It looks like balls, but it’ll do for now.
With all of the player sprite in, colored correctly, and with the proper “mask” added, I created a simple pink block that would be used as my test level’s walls and floors. I then created a yellow one that would be where all of the code is held and would be invisible to the player, so I guess I don’t know why I needed to make it yellow but I did so there.
“Step 2”: This part was easy, until it wasn’t. I added the variables I knew I would want to change (move speed, etc.) and used them to create a basic movement scheme for the character. It looked super awkward, but it was doing what I had intended and you have to start somewhere. Easy.
“Step 3”: Until it wasn’t. Collision is a huge jerk. Tom Francis did a whole post about collision in his blog about the development of Gunpoint. I’m not going to dedicate a whole post about it, but know that it sucks. He was doing far more complicated collision than I am, too. He wanted to launch horizontally and collide flat with walls and stuff like that. I just want my character to stop when he hits something. Simple (sounding) enough, but unless I wanted to live with crappy looking collision, I had to find some more tutorials. Benjamin Anderson has a course on Udemy that goes through the steps of making a basic platformer. It is wonderfully taught and has helped me tremendously, and the course goes on sale for dirt cheap (I got it for about $10), so if you’re at all interested in this kind of stuff, it’s a good place to start. Essentially, I gave about 30 attempts on collision by myself until I finally just stole his code. I stole a few lines of his code, actually, and I can always tell which is his because his is nice, neat, and readable and mine is a jumbled mess of experiments that somehow work through blind luck. I appreciate the help that he has given me. I wouldn’t have gotten as far as I have without him and his course.
“Step 4”: With the collision out of the way, I realized that the next logical step was to make sure I could slide along the walls appropriately. I tried far fewer times on my own this time and just opted for stealing Benjamin’s code once again (see above) so this didn’t take nearly as long.
“Step 5”: So I actually got gravity to work on my own. This is a basic math thing. If my character is in the air, add “speed” to his Y axis to drop him down. Once he reaches to the ground, remove the speed that he had. I looked at Benjamin’s code and he did it in a similar, although much neater, way as I did. So I was feeling pretty good about myself at this point. It’s a bit more complicated than I am describing here, but I wasn’t stuck here for very long.
“Step 6”: This took far longer than I thought it would. I figured it would be easy. “If character is doing this, play this sprite animation!” Done and done. Except you have to take into account player direction, animation loops and ends, and other actions overwriting each other. For example, if I were to hit “right” while in the air, he would start his walking right animation, which is wrong. So I had to do a series of “ifs” and “nots” and “ands” to get this stuff to work properly. And it does. It was starting to feel a lot better.
“Step 7”: When I started looking up Game Maker tutorials in the old days of the early 2000s, I tried to create a basic platformer like I am now. This is the step where I gave up every time. I would look for hours and hours and hours for a tutorial on how to control the jump height, something I knew every platformer absolutely had to have (with few exceptions). Even downloadable platformer engines didn’t have that functionality at the time. Fortunately, through a combination of new tutorials (like Benjamin’s) and my increased knowledge, I got this stuff to work. I refuse to create a game that does not have this functionality. It ended up being a lot easier than I thought it would be. Putting it simpler than it actually is, basically I tell the game, “if the player is holding the jump button, keep his speed until he reaches maximum height; if he reaches maximum height, reverse his speed; if he lets go early, reverse his speed.” That is far simpler than what the actual code reads, but that’s essentially what I’m saying.
“Step 8”: The freaking attack button. Man… I went through an embarrassing range of emotions while working on this. This alone took me weeks. All I wanted to do was have the character swing his freaking sword when the button was pressed and stop when he was done. I wanted to make sure the player could jump to cancel the animation. I wanted to make sure you could attack in the air, while still being able to control the jump height, and while walking. The range of problems this thing had and/or created includes but is not limited to: completely breaking gravity, completely removed gravity, completely breaking collision, completely removing collision, completely breaking friction, completely removing friction, remove acceleration (?), adding acceleration (!?), adding the ability to infinitely jump, having the animation not play, having the animation play too long, having the animation play too fast, having the animation play too slow, having the animation play indefinitely, and just straight up crashing the game for no discernible reason.
What I ended up needing to do, and again, this is oversimplifying it, is create an entirely new page of code, tell it to ignore everything that came before it while it ran this code, and then to go back to the old code once this one was done. As a result, I had to rewrite gravity, friction, and collision with minor tweaks to work within this new branch of code. In order to send it back to the old code, I told the game, “once the animation reaches (or exceeds) the final frame, revert back to old code.” The “old code” I keep referring to is the movement code. So essentially, when the player hits the attack button, he becomes a new being entirely, but one that shares a lot of similar traits. Once the attack is done, he switches back to his original self. If he’s on the ground and the player hits the jump button and during the attack, he switches back to his original self.
I could write memoirs about my experience with this stuff. I went through existential crises with this issue. I started Googling stuff like “why is programming so hard” and “am I stupid for not understanding code” just to hopefully see other people struggling in similar situations and make me feel better. I found a pretty funny article by Erik Trautman that kind of sums up what’s been happening to me. When I wrote the first post of this series, I was in Phase I. I was confident, my needs were few and were met with a wealth of information, and I was making significant progress (as this post will reflect). Now I am somewhere between phases II and III, where knowledge is becoming more limited and my exact needs are not nicely laid out for me in a tutorial (like the attack button). The more and more stuff I want to add, the less and less likely that stuff is going to be there for me to find as a resource. The struggles will continue to get greater, and I fear for my sanity.
A lot of the issues I stated above I’ve been venting to my friends. Each and every time I found myself ending with the line “…and I don’t know how to fix it.” Each wall that I ran into seemed to be made of an indestructible force, but each time I overcame! Until the next time where I inevitably find something that’s impossible to fix.
So this post covered a lot and just writing this stuff out makes me feel pretty good. I keep comparing this stuff to learning to play guitar and I like that comparison. Starting off learning this stuff is terrible. You make no progress and what you do actually create is embarrassing and shameful. Eventually, though, something clicks in you and you start to make progress and it becomes weirdly satisfying, and then the satisfaction is no longer “weird” and it’s just satisfying. Playing a song on real guitar that I only used to play on air guitar while growing up is an amazingly satisfying feeling. I’m not the greatest guitarist, but when I see someone else pick up a guitar who has never played in their life and I see how pathetic they are and how much they complain that their fingers hurt, it really puts into perspective how far I’ve come. That’s what writing these articles is doing. When I first started coding, I couldn’t do any of the things documented here, but here I am with a functional set of controls that I could make a pretty solid game out of if I decided to stop now. That’s not bad! I should probably keep going!
While I have touched “Step 9,” I haven’t made significant progress on it yet, and I feel like I need to start breaking these posts up into smaller chunks, so the next article will be on the cling feature. Stay tuned!
*The times reflected in this post do not line up with the times of the post dates of these articles. That is because I opted to not post the initial post until I was sure I was going to keep working on the game. I wrote the initial post about a month and a half before this one.