Tuesday, 7 June 2016

Week 9 - Production Part 1

Unit 8


Part 1 - The Overworld Movement


To begin creating my game I had to import all my sprites into Game Maker. I did this in one of two ways, first was simply importing individual images, this was done if the sprite didn't need any animation. The next option was to import from a strip. This is something you can do with sprite sheets or strips, It allows you to take several images and put them together to make an animated sprite. I also had to name each sprite, which was done in lower case and no spaces and had "_spr". This was to help with the coding later on which one mistake could cause the whole game to stop working.



Next was to make an object version of some of them, which I gave the same name but ended in "_obj" to differentiate. These are the parts that make up the bulk of the game, its where you add code and what you control in game. Think of them as the engines and the sprites being the body.



I then created a room, which is the area of the game. Inside this room I placed the objects to build the level, this included background objects and walls. Next I placed the character objects, both NPC and Player.



Once I was happy with the look of the level I could get into the coding of the game.



I began by adding a simple collision event on the player character. I had to make one for each of the wall objects. These will stop the player from walking through the walls. This works due to the programs built in physics system, which means that I don't need to use lots of code to get the same effect.



Due to the way this system runs I need to add a Create event. Inside this event I add a piece of code to fix the rotation of the object. This will stop collisions from rolling the object.



Now it was time to add code to make the character move. The code goes as follows:




The notes above each part explain what they do, but to explain it in more depth I will break down the first one.

Code is in Blue

var D_key = keyboard_check(ord('D'));
This is whats known as a variable. its an action that can be referenced in later parts of the code. This is telling the computer that if a piece of code has D_key, in then check for the D key being pressed.

//Move Right
This is whats known as a comment, this is not technically part of the code and is usually notes wrote by the developer to explain parts of the code.
if (D_key) {
This is telling the computer that if the D key is pressed...
      phy_position_x += 4;
Then change the position of the object, increaing by 4 along the x axis.
      sprite _index = mcrightw_spr;
This is telling the computer to change the sprite of the object to mcrightw_spr
      image_speed = .2:
}
And this is telling the computer how fast the animation of the image is to play.

This code allows the character to not only move, but to have an animated walk cycle, but another piece of code is needed to tell the computer to stop the animation at the standing frame if no key is pressed.

//stop animating
if (!D_key and !W_key and !A_key and !S_key) {
If the D key, W key, A key, or S key is not being pressed...
      image_speed = 0
Set the image animation speed to 0...
      image_index = 0
}
and set the sprite to frame 0.

This one part of the code means that when the player is not pressing a key then the character will stop animating and the animation will go to frame 0 and stop, making the character appear to stand still.

No comments:

Post a Comment