Limiting Actor Spawns

artmonkeeartmonkee Member Posts: 7
edited November -1 in Working with GS (Mac)
Hello,

I am just learning my way around GS. I am creating (or recreating) an Asteroids game and used the Space Rock tut as a guide. I seem to have the basic game working fine and am experimenting with tweaking various aspects of game play.

My question... I would like to know how can I limit the total numbers of missiles that can appear on screen at a time. In other words, I would like to only allow 3-5 missile to be shot at a time. Currently, its too easy to just spam the fire button and spray missiles everywhere. I feel limiting the missile count would at least create some challenge.

Thanks!

artmonkee

Comments

  • steve86steve86 Member Posts: 806
    maybe there is an easier way.. but the first thing that comes to my mind is that you could create a new attribute and use it as a counter, each time a shot is fired the count would go up and when the shot leaves the screen or hits something the count would go down.

    Then just put a rule that if the counter is < 3-5 (depends the number of missiles you want) the fire button will work
  • forkliftforklift Member Posts: 386
    Set a game attribute called game.maxshots or something.

    Then in the 'bullet' actor, have a rule that changes the game.maxshots attribute to game.maxshots+1

    Set a rule in the ship that says when game.maxshots is less than or equal to (whatever number you want as a limit), spawn bullet actor.

    Set a rule in the bullet actor that makes the game.maxshots-1 before the bullet is destroyed.
  • artmonkeeartmonkee Member Posts: 7
    Thanks for the quick replies guys. Your suggestions were also what I had in mind....I just wasn't exactly sure how to apply the attributes. Thanks for the clarification, forklift! Works great!

    Just for future reference to help anyone else looking to do something similar, here's what i did:

    -Created an attribute "game.MissileCount"
    **This attribute will keep tally of "Missile" actors.

    In the "Missile" actor:
    -Add a Change Attribute "game.MissileCount" to "game.MissileCount+1"
    **This adds(+1) to the MissileCount on screen each time a Missile actor is spawned.
    -Add a Change Attribute "game.MissileCount" to "game.MissileCount -1" to each rule that has a Destroy behavior.(i.e Collide w/Enemy Rule, Timer, Destroy if Off Screen)
    **This subtracts(-1) to the MissileCount on screen each time a Missile is Destroyed. Essentially, these attributes keep tally of how many missiles are on screen at a time and keeps track of them under the "game.MissileCount" attribute which can then be referenced later by the "Press Space, Spawn Missile" rule under the "Player" actor(or the ship).

    In the "Player" actor (the ship):
    -Add an Attribute "game.MissileCount < 4" to the "Press Space/Spawn Missile" rule.
    **This attribute basically says, if the "game.MissileCount" is LESS THAN 4, then "Missile" can be launched by pressing SPACE. If there are already 4 Missiles on screen, then pressing SPACE further will not spawn anymore missiles until 1 or more of the 4 current missiles is destroyed.

    Excuse the wordy explanations, but as someone who is not all too familiar with programming and some of the programming logic behind making games I thought it would be helpful to provide some explanations to How?What?Why? behind some of these behaviors/attributes/rules. ;)

    Hope this helps!

    artmonkee

    Please be on the lookout for my game, VEKTORIODS. I'm still making tweaks, but I should be posting it soon!
Sign In or Register to comment.