Gw Temp


Tutorial - 'Shooting' by polski

An item about RPGMaker 2000 posted on


Learn how to make an object shoot a bullet, or anything for that matter!


Shooting an Object

In this tutorial I will explain how to make your character, tank, whatever -- Shoot an object. This is good if you want to make a game where your character shoots bullets or something along those lines.

NOTE: If you need a tutorial on the basics of moving and creating a character, please read this tutorial.

Creating the Player

You will need some kind of object that bullets will shoot from, I don't want to go into full detail on how to make a player because my other tutorial already explains it so check it out.

Creating the Bullet

First thing you will need to do is create a sprite for the bullet. Go to Add Sprite, Create a new sprite called Bullet or something and select a nice looking image for it (Preferably, a round bullet!)

Now you have the sprite, create a new object and set the objects sprite as the bullet you just made.

Moving onto coding

In the bullet object, under the Create section, Enter the following code:

direction = objShip.direction;
speed = 9;

What does this do? It makes it so when the bullet is created it goes in the direction of the ship object and at the speed of 9 (Pretty fast).

That is all the code you will need for the bullet object, open up the object that contains your ship/person movement and select Alarm 1 and execute this piece of code:

timerBullet = true -- If you don't understand Alarms, I hope you check them out in the help file.

One final thing, in the Create Event of the ship object, enter the following code:

timerBullet = true; -- This just creates the variable so you don't get errors later on.

Ok, we did all the variable work now we need to shoot the object! Go to the Space section from the movement area. (I prefer Space for shooting but anything is fine) Now execute a new piece of code, it will look like this

if (timerBullet = true) then
instance_create(x, y, objBullet);
timerBullet = false;
alarm[1] = 15;

Now what does it all mean? First, it will check if timerbullet is true, It will only be true if alarm[1] sets it as true. Then it creates the bullet at the ships x/y position using the instant_create(); command. Now is the alarm stuff.

It sets timerBullet to false and sets alarm[1] to 15, this means that you wont be able to shoot the bullet again for another 15 frames (This is kind of how alarms work). 15 is pretty fast though but you can fiddle around with the number to your liking.

...And that is it! Very simple way to create a shooting object. If you want to add more, it is very easy all you have to do is change the Key and then some references.