Jump to content


Photo

How to shoot arrows in a platformer


  • Please log in to reply
1 reply to this topic

#1 Zyrac

Zyrac

    GMC Member

  • New Member
  • 31 posts
  • Version:Unknown

Posted 29 July 2012 - 01:19 PM

hey, i'm making a 2d-platformer using gamemaker lite. i really am having trouble getting it so when I click "spacebar", arrows come out of my sprExplorer sprites bow, depending on which way im facing. eg. facing left, press space, fire left, facing right , press space, fire right.
I also want to make it so I can only fire 1 arrow per 2 seconds (to prevent Overpoweredness)

please, be VERY detailed.
DragNdrop or GML code is fine,
but if you do GML please be very specific on the coding, im new.

thanks
  • 0

#2 SuperComplex Games

SuperComplex Games

    Complex Game Creator

  • GMC Member
  • 151 posts
  • Version:GM8.1

Posted 29 July 2012 - 02:44 PM

Well, you have to make a 2-second alarm after you shoot an arrow. In more detail:

First, initialize a variable and you can call the variable global.arrow_shoot. Basically, put this code in the Explorer's Create Event:
{global.arrow_shoot=1}

Now, you specify that is you press Space, and if global.arrow_shoot=1, create an instance of the arrow object, and then turn global.arrow_shoot to 0. Put this in the Step Event of the Explorer:
if (global.arrow_shoot==1)  {instance_create(x,y,obj_arrow); global.arrow_shoot=0; alarm[0]=60}

Then, you have to specify the speed and direction of the arrow object whenever one of its instances is created. Put this in the Create Event of the arrow object:
{speed = /*insert speed here*/; if (obj_explorer.direction==180) {sprite_index = /*insert name of arrow sprite facing left*/; direction=180;} else if (obj_explorer.direction==0) {sprite_index= /*insert name of arrow sprite facing right*/; direction=0;};}

You can see above that I put alarm[0]=60. This means that whatever we have set in the Alarm 0 event is going to occur in 60, and there are 30 steps in 1 second, so basically 2 seconds. Now, since we haven't done so already, we must set the Alarm 0 event of the Explorer, which will have the same code as we put in the Explorer's Create Event:
{global.arrow_shoot=1

That means that 2 seconds after you press Space, global.arrow_shoot will equal 1, thus, you will have the ability to shoot arrow again.

-SuperComplex Games

Edited by SuperComplex Games, 29 July 2012 - 02:45 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users