Hyper-noob question: firing a MM-syle bullet

tirkaro

  • *
  • Posts: 9
So, I'm making a Mega-man styled game, and I thought the act of firing a bullet in a side-scroller should have been simple enough. But no, I can't seem to find any behaviors that work properly. The closest one I could find was Shooting Around the Clock, but even that's pretty messy, and I have no idea how to get it to work via a button press.

So can somebody help a sucker out here? I've done everything I could!

Joe

  • *
  • Posts: 2480
Welcome to Stencyl!

You want something like:

[Always]
  <if key is pressed>
     [create bullet actor at (x,y)]
     [set x-speed of last created actor to (number)]

tirkaro

  • *
  • Posts: 9
Thanks!

I tried that, but for whatever reason, the bullet now just wont appear upon pressing the button. I'm almost certain I'm missing something incredibly simple here, but I just don't know what. Sorry ´;ω;`

Joe

  • *
  • Posts: 2480
I tried that, but for whatever reason, the bullet now just wont appear upon pressing the button.

Can you post a screenshot of the Behavior you're using? (You can use the camera button in the lower right-hand corner of Design Mode.)

xmagicx60

  • Posts: 213
I created a test of that behavior on my page, make sure you attach that behavior to your PLAYER actor, not the bullet.

http://www.stencyl.com/game/play/5737

EDIT: stupid me, z to fire XD

« Last Edit: July 24, 2011, 12:31:28 pm by xmagicx60 »

Joe

  • *
  • Posts: 2480
The bullet appears just fine for me. You'll want to choose "was pressed" in your if condition, though. Right now it's spawning a bullet as long as the button is held down.

The other thing you'll want to do is destroy the bullets when they leave the screen to keep your game from slowing down. I recommend using recycling for that, as mentioned in the following article:

http://www.stencyl.com/help/viewArticle/51

xmagicx60

  • Posts: 213
Yea, actually, keeping it to isdown might be better and just add a time delay so that the player can keep firing.

vadersdemise93

  • *
  • Posts: 14
Yea, actually, keeping it to isdown might be better and just add a time delay so that the player can keep firing.


Personally, I would keep that as an upgrade type of thing. That is if your game has upgrades (which everyone seems to love if it does, lol).
"Do or do not, there is no try."
- My Jedi Master, Yoda

"Look, I have your fodder!"
-Revan to Komad Fortuna

tirkaro

  • *
  • Posts: 9
I tried that, but for whatever reason, the bullet now just wont appear upon pressing the button.

Can you post a screenshot of the Behavior you're using? (You can use the camera button in the lower right-hand corner of Design Mode.)

Sorry for the slight delay, this is what I'm trying to do:


Go and tell me where I'm messing up, because I'm sure it's an obvious oversight on my part ._.

Oh, and it is attached to the playable character, and not the bullet itself.

« Last Edit: July 24, 2011, 03:19:11 pm by tirkaro »

xmagicx60

  • Posts: 213
I tried that, but for whatever reason, the bullet now just wont appear upon pressing the button.

Can you post a screenshot of the Behavior you're using? (You can use the camera button in the lower right-hand corner of Design Mode.)

Sorry for the slight delay, this is what I'm trying to do:


Go and tell me where I'm messing up, because I'm sure it's an obvious oversight on my part ._.

Oh, and it is attached to the playable character, and not the bullet itself.
you need to replace x {0} and y {0}
With {x position of [Self]} and {y position of [Self]} That is the first block in the actors section I believe.

tirkaro

  • *
  • Posts: 9
Great! It worked.

Though I do have to ask, how can I make it so the bullet will shoot in the other direction if I'm facing left? It seems it only works one way.

Joe

  • *
  • Posts: 2480
You'll want to keep track of which direction your character is facing and then set the bullet speed accordingly.

{Always}
    <if key is pressed>
        [create bullet actor at (x,y)]
        <if direction = right>
            [set x-speed of last created actor to (number)]
        <otherwise>
            [set x-speed of last created actor to [negate (number)]

tirkaro

  • *
  • Posts: 9
You'll want to keep track of which direction your character is facing and then set the bullet speed accordingly.

{Always}
    <if key is pressed>
        [create bullet actor at (x,y)]
        <if direction = right>
            [set x-speed of last created actor to (number)]
        <otherwise>
            [set x-speed of last created actor to [negate (number)]

I'd hate to be one of those guys, but I can't seem to find a way to implement direction of my character into the design mode. (I'm using attributes btw, since that seems to be the only way.)

Since I'm so hopeless like that, could someone perhaps give me a more detailed picture of what I'm supposed to do here?

jamesvhyde

  • Posts: 25
One way to do it is the following:
  • Add a hidden attribute to your behavior called "Direction"
  • You have a movement behavior that makes the player actor move when the player hits some key, correct? In this behavior, you can add code to set the Direction attribute of the shooting behavior.
Take a look at the screenshot for an example.

Also, the Run and Gun Example Game has blocks to do exactly what you want, so you can take a look at that for ideas. It uses actor values to solve this particular problem, rather than attributes.

tirkaro

  • *
  • Posts: 9
ALRIGHTY NOW!
I finally got it to work after toying around with the "Gun Firing" behavior a bit. However, I've been seriously stuck on one part for a while now. (And I really hope it falls within the same subject, since it's a bit of a stretch.)
When my character fires a bullet, he's supposed to switch to a "gun firing" animation, which is only one frame long. He's also supposed to shoot while running, which also changes his animation to such. But I have no clue how to place it in without it either going too fast, or just being generally messed up. (And don't even get me started on the running while shooting animation.)



This is my current, animation-less shooting setup. Think I can do anything about it? I've been contemplating making another behavior entirely for the animation, but I don't think that's necessary. (And would probably end up with the same problems.)

« Last Edit: July 26, 2011, 06:31:20 pm by tirkaro »