User Tag List

Results 1 to 10 of 10

Thread: Cause a shield to be destroyed when the enemy holding the shied it killed? Example.

  1. #1
    Clicker Fusion 2.5
    Jocastus's Avatar
    Join Date
    Jan 2008
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cause a shield to be destroyed when the enemy holding the shied it killed? Example.

    Here's an example file of what I'm working on:

    Enemies with shield example file..mfa

    There are enemy objects vulnerable to attack. The are shields that are not. The shields stick to the enemies and when the enemies paired with shields are destroyed, the shields should be too.

    I'm using a fast loop to pair objects that I've spread values over. It may be easier to just take a look and see. The problem is, I don't know how many times to make the loop run. If I enter an arbitrarily large number, it works, but lots of loops are wasted. I need to know just how many times the loop need to run in order to keep the pairs correct.

    In the file, I've inactivated one line. This is the line I mentioned which runs the loop 500 times. You can swap that line for the other line defining the number of loops to see the difference.

    I feel like if I just knew how to tell the code how many times to run this loop it would work. Any help would be greatly appreciated. Thanks.

  2. #2
    Clicker Fusion 2.5Android Export ModuleSWF Export Module
    Ziplock's Avatar
    Join Date
    Oct 2013
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could just tell your program to create a shield if you have less shields than enemies and destroy a shield if you have more.

    Is this what you were looking for?
    Attached files Attached files

  3. #3
    Clicker Fusion 2.5 DeveloperiOS Export ModuleMac Export ModuleSWF Export Module
    Hydra's Avatar
    Join Date
    May 2012
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont know if you have any familiarity with for each loops but you could also assign a unique ID to each enemy and shield. The ID of course needs to be the same for each enemy and his shield. Then when the enemy is destroyed, run a loop and have a condition:

    +on loop of shield
    +AND when ID is the same as enemy,
    -destroy the shield as well!

  4. #4
    Clicker Fusion 2.5
    Jocastus's Avatar
    Join Date
    Jan 2008
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ziplock View Post
    You could just tell your program to create a shield if you have less shields than enemies and destroy a shield if you have more.

    Is this what you were looking for?
    I'm checking out your example now, Ziplock, thanks. It seems to function at first glance.

    One question: In this example, will pairs of enemy and shield ever become scrambled? If I start with enemy A with shield A, enemy B with shield B, and enemy C with shield C, will there ever be a time when an enemy is destroyed and I wind up with an AC pair or a BA pair?

    I ask because in other places, I'm using this code with shield parts that also have hp and can be destroyed. If I did two damage to shield A, then killed enemy A, then shield A must be destroyed. It wold be a problem if shield A were shuffled down to enemy B, because he'd be stuck with an inexplicably damaged shield instead of the full shield he had at the start. I just need to make sure that a pair, one established, never has its component parts swapped for others.

    Thanks again for your help.

  5. #5
    Clicker Fusion 2.5
    Jocastus's Avatar
    Join Date
    Jan 2008
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hydra View Post
    I dont know if you have any familiarity with for each loops but you could also assign a unique ID to each enemy and shield. The ID of course needs to be the same for each enemy and his shield. Then when the enemy is destroyed, run a loop and have a condition:

    +on loop of shield
    +AND when ID is the same as enemy,
    -destroy the shield as well!
    I've only used the For Each extension a few times, Hydra, so I don't know how to implement what you're describing, but if you've looked at my example file, I do set a unique number to each instance of enemy and shield at the start with a "run this event once" command to spread a value.

    Is that in line with what you meant?

  6. #6
    Clicker Fusion 2.5Android Export ModuleSWF Export Module
    Ziplock's Avatar
    Join Date
    Oct 2013
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that would happen.

    For example, you have enemies 1-5 and shields 1-5. With this code, when you destroy enemy 3, shield 5 would be destroyed, enemy 4 would replace and become enemy 3. Also, the code is set to create a new shield any time you have less shields than enemies, so you couldn't erase one if you wanted to.

    What you're talking about here is very tricky with separate shields and enemies. I didn't realize the shields would have health as well. Why not just have enemy animations with shields and without, and when HP drops below a certain level, switch to the animation without the shield?

  7. #7
    Clicker Fusion 2.5
    Jocastus's Avatar
    Join Date
    Jan 2008
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for clarifying, Ziplock. I thought that might be the case.

    My code does what I described, except that I'm not sure how many times to run the loop that does it. It seems to need to run a couple times more than the number of shield-bearing enemies on the screen, so at present I have my loops set to run "number of shield-bearing enemies" + 10 times, just to be safe.

    I'll post of a screenshot of the effect I've created. It works, but like I said, I'm unsure about how many times the loop has to run in order to work and having a line you're unsure about can come back to bite you later.


    http://justingamedesign.deviantart.c...mies-501103708

    If you can view the animated gif or the link above, you'll see what I've done. The shields are the blue bits, and the main bodies are purple. I can fire at the shields and they do not disappear, but if a main body takes two hits, its shields die with it. In this example the shields have 99999999 HP, which my code interprets as invincible, but on other similar enemies, I'll actually let the player destroy the shield independently.

    If I tried to do this with animations instead of separate objects, it would be more difficult to have the shields destroy projectiles. Not to mention, certain shields have their own movement patterns as you seen in the linked image.

  8. #8
    Clicker Fusion 2.5Android Export ModuleSWF Export Module
    Ziplock's Avatar
    Join Date
    Oct 2013
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice Graphics.

    OK, I came up with something that might help. This will give every shield an id that matches the enemy's id, both at the start of the frame and when a new enemy is created. If a shield is destroyed, the enemy lives on. If the enemy is destroyed, the shield dies with him.

    Here's some paraphrasing of the code:

    Start of frame - create a shield for every existing enemy and spread values in both enemy and shield. Set an id value in an independent object that equals the value of the number of current enemies.

    Always - attach a shield to an enemy if the id values match.

    If an enemy is destroyed - check to see if the shield with a matching id value still exists. If so, destroy it.

    If new enemy is created - create a shield with it. Set the id value in both new created objects to the id value of the independent object. Add 1 to that value.

    In the example, you can 8-direction move the red dot to slam into shields and enemies to destroy them separately. You can also left-click on an enemy to destroy him with the shield. Right-click to create a new enemy. Respond if there's any particular part of the code you don't understand.
    Attached files Attached files

  9. #9
    Clicker Fusion 2.5
    Jocastus's Avatar
    Join Date
    Jan 2008
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. It does seem to work so far.

    I did have some questions. Here's one: Is it necessary to create the shield objects in a start of frame loop? If they were created outside the loop would they not be assigned a spread value ID?

  10. #10
    Clicker Fusion 2.5Android Export ModuleSWF Export Module
    Ziplock's Avatar
    Join Date
    Oct 2013
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it is. If you say:

    Start of frame
    + Number of "Shield" < Number of "Object"
    -> Create Shield

    It will only create 1. If you have 7 enemies, only 2 of them will have shields - your default and 1 new one. The loop is necessary to make as many shields as you have enemies.

    And if you tried it this way and took away the "start of frame" condition, every time you had less shields than objects, you would create shields to compensate for the objects.

    Now you might be conflating your idea with this code:

    Start of Frame
    + Number of "Shield" > Number of "Object"
    -> Destroy Shield

    The reason this is possible without a loop (although it's not really necessary - just tidy) is because you will always start with exactly 1 shield. It's only there for if you have 0 enemies to start. If you have 0 enemies, the shield will be destroyed. If you have 1 or more, it won't apply. You could get rid of this code and just throw the shield off-screen if you wanted.

Similar Threads

  1. Need Help For My Game- All Enemies killed-next frame
    By LoneWulfGames in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 28th November 2014, 12:06 PM
  2. Nvidia Shield
    By wii1mii in forum Android Export Module Version 2.0
    Replies: 0
    Last Post: 31st July 2013, 10:24 PM
  3. Destroyed enemy vanishing, not playing "disappearing" animation
    By Sterling7 in forum The Games Factory 2 - Technical Support
    Replies: 5
    Last Post: 17th July 2013, 03:21 AM
  4. A Bug in MMF2 killed my widget
    By dragonguy in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 28th November 2008, 01:10 PM
  5. hazard shield
    By chan in forum Vitalize
    Replies: 0
    Last Post: 22nd January 2008, 09:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •