Game Maker 7

10/12
87

Game Maker 7

Posted in:

litesoftstats.bitballoon.comGame Maker 7 ▼ ▼ ▼

Game Maker Tutorials Platformer Basics ArticlePosted on May 4, 2. Assumptions This tutorial assumes you have basic knowledge of Game Maker Studio. You should know how events and actions work at a very basic level, understand very simple GML code and that you know how to make sprites and objects and organize them in rooms. Download the project files for this tutorial. Making a platformer seems to be an incredibly common stumbling block in the career of many a budding game designer. TgLZtMBKDaw/sddefault.jpg' alt='Game Maker 7' title='Game Maker 7' />Hi SmilingTeacherRock, Can you see the black arrow shapes on the left side of the game Click on those to change the head, body and legs of the animal. Check out all of the amazing features of RPG Maker VXThey want to start simple they tell themselves. So they task themselves with putting together a basic platform game only to run headfirst into a lot of problems. Beginners find it hard to realize that a platform game is not an inherently simple thing. And using the built in gravity and collision tools like solid can sometimes be flimsy and hard to work with. This tutorial hopes to show you how to put the basics of a platform engine together in pure GML code, without pulling your hair out and using only about 4. Game Maker does make platformers easily, but its perhaps not as intuitively easy as many would guess. The basic set up. So lets start with the essentials. Were going to need a room, two sprites and two objects. Name the sprites sprplayer and sprwall and the objects objplayer and objwall. Game Maker 7 Release NotesLink the sprites to the objects and make sure to center the origin coordinates on your player and wall sprites. Now we have all of the pieces, how do we start to build the logic for our platformer Well we need to start out by establishing a few variables numbers in our player object, that we can use to decide how quickly to move, how high to jump, how powerful gravity will be and so on. So go ahead and open up objplayer and add the create event. The only action we need for this event is the good old Execute a piece of code action found in the control tab of actions, under code. Its this little icon Now you can insert the following code Initialize Variables. Using three slashes for a comment instead of two changes the name of the action in the object editor which can be useful for tracking what the code does. Now instead of using gravity, hspeed and vspeed which are built in GM variables you can see weve opted to use our own made up variables for these effects called grav, hsp and so on. This is because were going to implement gravity and movement by ourselves so that we keep complete control over whats going on in the game. All were doing here is setting up some numbers for our code in the step event to use. Player Inputs. Now that we have these variables ready, go ahead and add the step event to objplayer and create another execute code action. Chicken Invaders 4 Plus 5 Trainer. This is where the rest of the code will go and is what will be executed by the player object on every single frame. The first thing we need to do is get the players inputs at the start of the frame. This is to ask the question What keys are currently being pressed. Get the players input. So were doing more of the same really. Filling up variables with numbers. You can substitute vkright, vkleft and so on with ordA and ord D or whatever other keyboard letters you want to use. We do this in the step event because the state of our keys changes on every frame. So we need to know at the start of every frame what buttons are being pressed. Key left is set up to return either 1 or 0 instead of 1 or 0 by putting a negative sign infront of keyboardcheck. This is so that we can add keyright and keyleft together and end up with either 1 for right, 1 for left, or 0 for neutralboth keys. Which is exactly what we do next React to inputs. So now we know what buttons are being pressed, we can add our variables together to tell us which direction the player is trying to move on this frame. After the first line, the variable move now very conveniently contains either a 1, 0 or 1. We can now simply multiply this by our original movespeed variable which we set up in the create event to give us our intended horizontal speed for this frame. So if we were holding left, keyleft keyright would equal 1. And then move would equal 1 multiplied by 4. Giving us a horizontal speed of 4Now we know how were planning to move horizontally we need to work out the same vertically. Now because we dont want gravity to accelerate infinitely were going to check that our vertical speed on this frame isnt already greater than 1. If our current vertical speed is LESS than ten, then we can continue to increase it by our grav variable. Meaning we steadily fall faster and faster each frame. If were currently standing on the ground, then we want the ability to jump. So we use if placemeetingx,y1,objwall to check if there would be a collision with a wall object exactly one pixel below our player. If there is, then we can allow the player to jump. All we have to do is multiply keyjump which will be 1 or 0 by our jumpspeed negatively, because negative vertical speed moves us upwards. Collisions. So that was all the easy stuff. The thing that throws most people about making platform games is handling collisions. So heres how to do it, pixel perfect, without ever using the solid functionality. Make sure your wall objects have solid turned off by the way, as that could cause you all sorts of problems later. The idea is not as many people think, to detect a collision and then correct your position afterwards. The idea were using here is to detect the collision before it happens and adjust our movement accordingly. Remember, up until this point weve only been filling variables with numbers, objplayer hasnt actually moved anywhere. Weve just worked out how much we would ideally like to move and weve put those numbers into hsp and vsp. So, lets handle one direction at a time. First of all, horizontal movement Horizontal Collisionifplacemeetingxhsp,y,objwall. All we need to do is check whether or not there would be a collision if we were to move horizontally using our hsp variable. Million Dollar Money Drop there. We do this with the line if placemeetingxhsp,y,objwall. This checks, at the coordinates we would be about to move to x hsp, and our current y coordinate. If we would, then it carries out the code contained in the curly braces. Now we know theres about to be a collision, we want to still move in that direction as much as we can without hitting the wall. Otherwise wed stop with a gap between our player and the wall. So to do this, we use a while loop that moves us one pixel at a time towards the collision and stops just before we would hit it. I should explain that the function sign returns 1 or 1 depending on whether the variable it is given is positive or negative. Meaning that if we are moving to the right, signhsp should equal 1 and if were moving left it should equal 1. Also, the exclamation mark infront of the placemeeting check represents not. Metropolismania 2 For Pc'>Metropolismania 2 For Pc. So instead of checking to see if the collision WOULD happen, we are looking to see if it would NOT happen. Meaning we can translate the whole while line to mean While there is NOT a collision, one pixel in our direction of movement, with objwallAnd while that condition happens to be true, we increase our x coordinate actually moving the player object now by 1. Until were right next to the wall, at which point the while condition is false, and the code will carry on as normal.