Rapid Fire Powerup

xactoxacto Member Posts: 146
edited November -1 in Working with GS (Mac)
So.... I just switched my game to "hold space down" auto-fire and now I am working on a Rapid Fire Powerup. I thought this part would be easy.

I created a game variable called "game.PlayerFireRate" to hold the speed of fire variable. I set up my powerup and when my player collides with it - it changes the game.playerFireRate to a smaller number for 8 seconds.

Now that a user has the "space down" autofire - it does not register unless they let go and then hold down the space bar again. Is there a way to adjust an attribute (like restrain attribute) within the rule?

My code:

Rule: Actor receives event key space keyboard is down:
Timer: every game.playerFireRate
(code to spawn laser, ect)

Comments

  • harrioharrio Member Posts: 234
    what's cookin,

    i think you could create a fire rate rule that depends not only on the space key being down, but also a boolean variable that is established when you collide with the power up...

    <All>
    event - space bar - is down
    attr - game.power up activated - true

    have your special fire rates listed before your standard one. that way they will always check first for what the fire rate should be.

    you can also attach a negative to your standard fire to seperate it from the power ups...

    <All>
    event - space bar - is down
    attr - game.power up activated - false

    that way the boolean condition helps to control fire rate. not just pressing the space.

    i don't know for sure if this will work. but it's worth a...i can't resist...shot
    <bad pun police knocking at door...got to go...noodles>
  • xactoxacto Member Posts: 146
    I think I have something like this... (see code)
    http://farm4.static.flickr.com/3490/3970006867_58e9b3cae0_o.png

    Note: powerup 1,2,3 are different types of weapons.

    Again, it does work - however it will not work unless I lift up the space bar and press it again. Any ideas now that you see my code?
  • xactoxacto Member Posts: 146
    Anyone.... anyone... Bueller.... Bueller....
  • harrioharrio Member Posts: 234
    what's cooking,

    this is just a guess, but try putting either powerup1 or 2 inside the otherwise statement for powerup0 and see if it will switch between those two.

    noodles...
  • xactoxacto Member Posts: 146
    I do not have a problem with the game selecting the right power-ups. This works great. What I am having issues with the are auto-fire portions.

    Example: If I have the space bar down and it is currently shooting with the powerup2 and my player catches the powerup3. It will not shoot with powerup3 until I lift my finger from the spacebar and press it again. I need it to change as soon as a new powerup has changed. (see my code above, shouldn't this work?)

    Anyone have any ideas?
  • quantumsheepquantumsheep Member Posts: 8,188
    Have you thought of using a toggle? That way, it should change immediately I'm pretty sure.

    Do a forum search for 'toggle' - I'm sure there's something there...

    Cheers,

    QS

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • harrioharrio Member Posts: 234
    what's cookin,

    i understand what your problem is and i'm not trying to break your game. i'm trying to help you find what the differentiator for your auto-fire is.

    someone this week had four buttons that assigned different values. but when they pressed any button they always got the same value. it was because they did not understand the particular differentiator for that problem. his problem was that he checked for a keypress, but not for 'over' the particular actor. so it seemed like it should work, even though it did not.

    you have kind of the same situation. it works but not completely. and the answer is in the powerup definition.

    you either have to create attributes, like i first suggested, that seperate the fire definitions. or you have to set up the powerups so that if one is not true it will default to the others.

    as it looks right now, the only defining parameter for your firing is the 'space key down'. you might have to define each powerup individually, or else space key will always be down and never change.
    the reason i asked you to try putting either p1 or p2 in the otherwise part of p0, is so you could see if it switches without having to unpress the spacekey. you have > if game.powerup = 0 then do ... so if game.powerup <> 0 then it might default to the otherwise statement. right now they are not defaulting at all because you have them as seperate statements.

    it seems like it should be able to work as you want it to. but to make sure, just do some quickie demo in a scene with an actor that can move and changes color when it touches other stationary actors. put the stationary ones in a straight line and have the moving actor pass over them, keeping your finger on the movement key and see if it changes color as it passes over the stationary ones. that way, you'll know better if it might be a bug or some strange condition with gs.

    hope this helps.

    noodles...
  • harrioharrio Member Posts: 234
    what's cookin,

    thanks qsheep, i think i just took way too long to describe what you just said in a word.

    noodles...
  • xactoxacto Member Posts: 146
    @harrio/qsheep

    Hmm.... I tied moving the two powerups in the otherwise section - no change there. I will explore the "defining" / toggle like both of you said. (i am sure I will have more questions) :)
  • harrioharrio Member Posts: 234
    what's cookin,

    actually, because of the way your code is setup, i wanted you to only put one of the powerups in the 'otherwise' of the powerup0 rule. if it switches between the zero and the one you put in there without raising the spacebar then i would tell you how to add the third powerup. but it won't work at all if you put both in the powerup0 rule. so you may have to do it again. to make sure wether it works or not.

    noodles...
  • xactoxacto Member Posts: 146
    (grin) ok, so... I created a defining/toggle for the space bar... and after some time I got it to work! It will now change my type of weapon while my space bar is being pressed. Thank you!!!

    ... however...(ugh) now I have another problem (sorry) I have a powerup that changes the rate of fire (see my screen capture above)

    The default game.PlayerFireRate is .4 and it changes to .1 when the player collides with the powerup. There is a timer in the rule that changes the game.PlayerFireRate back to .4 after 8 seconds.

    Again, I get the same problem that I had with the space-bar/change type of weapon, but this time its the game.PlayerFireRate that will not work until I lift my hand from the space bar.

    Is this the same problem? (one step forward - one step back) :)

    Thanks for the help!
  • harrioharrio Member Posts: 234
    what's cookin,

    i'm glad you got the first part working. that's always a good feeling.

    it sounds like it might be a similar problem. if it's possible, you might want to separate the two different fire rates, into their own rule code instead of just changing the variable. if you can get it to work that way, then you may be able to figure out how to combine them. or just keep them separate.

    glad you're making progress.

    noodles...
Sign In or Register to comment.