Enemies dropping items/powerups

butterbeanbutterbean Member Posts: 4,315
edited November -1 in Working with GS (Mac)
Has anyone already done this on their game? If so, can you explain how you did yours?

I was wondering for my situation, what would be the best way to implement this:

So I have random enemies flying from the top of the screen to the bottom... when they reach the bottom, I have the destroy behavior, so they don't reappear at the top again and keep cycling. And my player is at the bottom of the screen shooting the enemies above... if the player misses them, they are destroyed once they reach Y axis below zero.

I was originally going to create a global game attribute called "I am enemy number" and keep track of how many enemies were destroyed, and drop items randomly according to how many enemies were destroyed (a percentage of items)

The problem with this is that I have the destroy behavior when the enemies reach the bottom screen, so that is being accounted into the equation, and items are being dropped on the floor once the enemies are destroyed.

I only want items to drop according to how many enemies are destroyed by myself

Could I implement this based on score? Like everytime the score reaches 5,000 points, 10,000 points, an item drops?

Just trying to figure out the easiest way to implement this, if anyone has done this, I appreciate your help :)

Comments

  • JGary321JGary321 Member Posts: 1,246
    You could still do it based on kills. I assume your actor shoots the enemies. So when enemy collides with laser (or whatever you shoot) +1 to kills. Do not use when enemy actor is destroy + 1 to kills. This should solve your riddle. That way only enemies you kill will spawn power-ups.
  • nulonulo Member Posts: 315
    yeah, you can do by points (which will be almost the same as number of kills)
    or as jgary said. see whats best for your game, but both ways would work.
    the "advantage" about using the score, is that you already have that working. so you will only use a attribute that already exists to spawn the items.
  • JGary321JGary321 Member Posts: 1,246
    Yea, personally I try to use Global Attributes that already exist. It's less work in some ways. More math involved though. If you just wanted to have a powerup every 100 points, thats easy, just use score. But for instance you wanted to have it random you could do something like...

    when enemy kills = Random(1,25) spawn powerup
    change attribute enemy kills = 0

    This should work in theory, it may need a bit of tweakin. I'm not at home to try it, but this way it would be random. This would spawn the powerup & then randomly pick a new number & spawn again after those kills. Lemme know if this works (if you try it) Again it may need to be tweaked.
  • butterbeanbutterbean Member Posts: 4,315
    I may try it with score, but I think I like the idea of having the powerup drop randomly with kills.

    So I could create a global game attribute, "enemy kills" as integer

    Should I then place a rule under the main actor that kills the enemies, that for every kill, it's +1

    Then create another rule, when enemy kills= Random (1,25) spawn powerup- or just play with the numbers

    If I put Random (1,25), what percentage of enemies will drop items? Does that mean between 1 and 25 enemy kills, that an item will drop?

    And then by putting a change attribute to enemy kills=0 after item drops, is that resetting the count for enemy kills so it starts over again at random?

    Thanks guys!
  • JGary321JGary321 Member Posts: 1,246
    It would randomly pick a number & when enemy kills = thats number it would spawn. It may pick 25 one time, but 2 the next. 1,25 was just an example. Honestly I would do something more like 10,25 at least, or maybe higher (play with it). You don't want the spawn to happen every 2 kills ya know? And yes changing it to 0 would reset it.

    Also I must stress this is only some guidelines, you may need another rule or 2 to make it work. Try it & lemme know what happens. I can help if it needs tweaking.
  • butterbeanbutterbean Member Posts: 4,315
    Yeah I've been trying to play with the idea of spawning the items when: score reaches certain increments, or with number of enemy kills, or even just randomly dropping various items based on a timer might be even better.... So I'm going to play around with those and see which I prefer... I'm trying to keep this game as simple as possible :)

    Also, I tried creating a rule, and said when enemy kills = number, it won't let me insert a random (n,n) function, do I need to use a different attribute to do this?
  • JGary321JGary321 Member Posts: 1,246
    under the rule use when attribute changes-game.Kills = random (10,25)

    Make sure to hit the "e" (for expression editor) then click arrow for drop down. Then under insert function. is random.
  • butterbeanbutterbean Member Posts: 4,315
    So under the enemy itself I placed under the collides with weapon rule (Destroy actor), I put change attribute, game.enemykills to game.enemy kills +1

    I went under the powerup item itself, and tried to create the rule like you said, when any conditions are valid, an attribute changes: Game.Enemykils equals:( number,number random) It only allows me to put one number or variable in there... there isn't a checkbox that allows you to enter : Random (n,n) I even tried manually entering it, but it erases the info.

    So how would I go about doing this? Do I create this rule somewhere else? Let me know if you figure out a way, in the meantime I'm going to keep trying different things

    I know it is simple, I'm just not seeing it!
  • ZourathZourath Member Posts: 16
    Try expanding the Gamesalad window. I've noticed that the Editor button is often one of the first things to be cut off if the window is too small. If you see the button that looks like a large, lowercase e, click it. Expand the new window with the blue arrow button, then find random in the insert function list.
  • butterbeanbutterbean Member Posts: 4,315
    Yea I tried that, it won't let me put a random function in there.

    I think there's another way of doing it, and it's to create 3 attributes, (codemonkey helped me with this)

    Create 3 game attributes:
    Spawn X, Spawn Y, and RandomDrop, Spawn X and Spawn Y are of Real attributes, and RandomDrop is of integer I believe

    Under the destroy behavior for the enemy:

    Put in these rules

    Change attribute: Game.Spawn X to self position X

    Change attribute: Game.Spawn Y to self position y

    Change attribute: Game.randomdrop to Random (n,100) where N can be used for the percentage of drops

    Then you could expand the rule by creating this:

    These rules could be added into the spawn weapon behavior:

    > Rule 1.1: If 'RandomDrop' is greater than 0 and less than 11 (2 conditions)
    -> -> Change Attribute: 'game.RandomDrop' to 0.
    -> Rule 1.2: If 'RandomDrop' is greater than 10 and less than 21
    -> -> Spawn Actor: '9mm' at position 'game.SpawnX' and 'game.SpawnY' relative to scene.
    -> -> Change Attribute: 'game.RandomDrop' to 0.

    Well I did all this, and it worked, (courtesy of Codemonkey), but do you have to reset an attribute if an item does in fact drop? Or does this keep cycling?

    In other words, do I need a respawn weapon or powerup rule?

    I think after all this, I may just release weapons or powerups on a timer, which would be much easier, require less rules, and works for me, but we shall see :)
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    The way I have it is that you need to reset RandomDrop because if you happen to randomly get the same number twice in a row(or even in the same category(e.g. between 1 and 10 to drop a medikit) , then it won't see that it has changed from false to true.
Sign In or Register to comment.