Gw Temp

Menu

Tutorial - 'Rotation Movement' by polski

An item about RPGMaker 2000 posted on

Blurb

Learn how to create 360 Degree Movement in Gamemaker

Body

Rotation Movement in Gamemaker

This tutorial will explain how to make a simple type of movement in Gamemaker. The movement is basically rotation movement where if you press Left or Right the sprite rotates instead of going east or west. If you don't understand, just read the tutorial!

First make a Spirte

First thing you will need to do is create a sprite that already has all the rotation positions created. I have one right here for you so save it:



Now you have a sprite, Open up Gamemaker and click on Add Sprite. Name it whatever you want, Load the shipani.gif as the sprite for it then hit ok.

Sprite is done, Make the object

The sprite for the ship is now created, Make a new object and call it whatever you wish. Select the sprite you just created as the sprite for this object. And now the coding for rotation will begin.

The first bit of code will need to be done in the Step section of the object. Open that up, Go down to the Code tab and add a new Execute a Piece of Code object into the area. A new window will popup that you can type in, Type the following code inside:

image_single = direction /(360 / image_number);

This code basically displays the correct image depending on your direction. Now open up the area where it says No Key. For this you will just need to execute a small piece of code, it will be:

speed = 0; -- Which will make the ship stop if you are not touching any keys.

Now pick the Left option. Do the same thing as you did before, Code tab -- Execute a Peice of code but this time type in the following:

direction += 360 / image_number;

This will make it so when you press left it will change the direction. Now do the same for Right except add this code:


if (direction > 0)
{
direction -= 360 / image_number;
}
else
{
direction = 360 - 360 / image_number;
}


Test your game out, you should be able to rotate the ship left and right, But we want to move don't we? Select the Up option for movement and simply enter:

speed = 5;

For the Down option you can do one of two things, You can enter..

speed = 0; -- Which will stop the ship instantly if you press the down arrow or..
speed -= 1; -- Which will decrease the speed of the ship to the point that it begins moving backwards.

Putting the ship onto a map
Before we can see the ship at all we will have to place it into a room, Create a new Room in Gamemaker and select the Objects tab. Now where it says Object to add with left mouse, Pick the Spaceship object and then click ONCE anywhere in the room. Save it, and test your game out.

That is it, you are done! Your ship should be able to spin 360 degrees and move around freely on the map. If for some reason it is not working for you, recheck your code and make sure you understand the basics of Gamemaker.