Shoot like mega man

boy656

Member
do you know how i can make the player shoot projectiles whenever i press a letter like megaman does? please help!
 

Slyddar

Member
Type bullet into the search and you'll find many examples on the forum of people asking a similar thing. Maybe try one of those first, then come back with your code, and we can help you further if needed.

If you are going to learn how to do things in Gamemaker, try searching here or Google for your question, as many times it may have already been answered. It will at least give you a starting point, and you'll learn more.

Good luck!
 
E

Edwin

Guest
That's pretty easy to implement. You need a boolean variable that will answer your "can I shoot or not?" question. Then if you press the shoot key (for example, spacebar), it will create a bullet, make shooting impossible and then call the alarm to wait some frames before shooting will be possible (10 frames for example).

Create event (performed at object's creation):
Code:
can_shoot = true;
Step event (performed every frame):
Code:
if (keyboard_check(vk_space)) {
    if (can_shoot) {
        // Create a bullet
        instance_create(x, y, obj_bullet);

        // Shooting is unavailable
        can_shoot = false;

        // Set timer to make shooting available
        alarm[0] = 10;
    }
}
Alarm 0:
Code:
can_shoot = true;
 
Last edited:
E

Edwin

Guest
it created the bullets, but how do i make them move?
In my opinion, you should read the basic guide for GameMaker: Studio 2. Like I said before, use Step event to perform your code every step (frame). Just add +1 your bullet object's x position. There is bunch of video / blog tutorials about basics of GM:S 2.
 
Top