Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Thread: Tower defence Range

  1. #1
    No Products Registered

    Join Date
    Oct 2008
    Posts
    5

    Tower defence Range

    I am attempting to make a tower defense game, I have the basic format set up, the towers, the damage, the placement, ext.

    I am having a issue making a range. How do I get specific towers to fire only when enemies are within ___ pixels? I tried to only have the towers fire when the "creeps" are within __ pixels, but it didn't work. The towers are created as copies, not clones, so if one of the creeps come close to one of towers, they all fire.

    I would appreciate any advise for this, thanks in advance.

  2. #2

    Re: Tower defence Range

    Hi, i don't know if it would be any help but i just made a widget recently that checks if an input is in a range, maybe it might help somehow

    http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=112668#Post1126 68

  3. #3
    No Products Registered

    Join Date
    Oct 2008
    Posts
    5

    Re: Tower defence Range

    I have a rudimentary range set up, a few more events than the widget you set up, but it still works. The problem is setting up a separate range for each tower, so that the towers only fire at objects in their range. I am at a loss as to how to do that.

  4. #4
    Clicker Multimedia Fusion 2

    Join Date
    Sep 2006
    Location
    Britain, South Coast
    Posts
    1,030

    Re: Tower defence Range

    Ok, I'm just writing this as I think, so let's see what we come up with shall we?!

    ALTERABLE VALUES(@)/STRINGS($)
    TOWER
    @- ID Number //The iD number of the tower (all towers)
    @- Range //The range of this tower
    @- Working Buffer //A little spot in the Tower's memory for any calculations we need to do.
    $- Enemy In Range //Is enemy in range? Takes a val of YES or NO

    ENEMY
    @ ID Number //The iD number of the enemy (all enemies)
    @ Working Buffer //Working space

    THE CODE
    Code:
    //This will give all towers and enemies an ID
    ALWAYS
    --- Tower: Spread 0 in 'ID Number'
    --- Enemy: Spread 0 in 'ID Number'
    
    //This will do a loop for each tower
    ALWAYS
    --- Start loop "Tower Range Check" 'nObjects("TOWER")' times
    
    //That loop.
    //We're gonna make every enemy work out its distance to 
    //each tower one by one.
    
    //Select the current tower, and all enemies.
    //Set WORKING value of enemies to distance between them and tower
    ON Loop "Tower Range Check"
    + Tower: 'ID Number' = loopindex("Tower Range Check")
    --- Enemy: Set 'Working Buffer' to:
    
          sqr( (x("TOWER") - x("ENEMY")) pow 2
              + (y("TOWER") - y("ENEMY")) pow 2 )
    
    //Now select the current tower again.
    //Check if any enemies have Working Buffer lower than 'Range'
    //of the tower.
    //If so, tell the tower that it has enemies in range.
    ON loop "Tower Range Check"
    + Tower: 'ID Number' = loopindex("Tower Range Check")
    + Enemy: 'Working Buffer' < Range("TOWER")
    --- Tower: Set 'Enemy In Range' to "YES"
    
    //At the above event, you could add an extension to pass the
    //fixed value of the closest enemy (the one with the lowest
    //Working Buffer) to the Tower. This would enable the tower to
    //target its enemies in real time.
    That should get your tower to check if it has enemies in its range (yes or no) and with a simple extension added, you should be able to pass the ID of the closest enemy as well. And it shouldn't be too slow about it either

  5. #5
    No Products Registered

    Join Date
    Oct 2008
    Posts
    5

    Re: Tower defence Range

    AH! Sorry, I meant to reply to this, but my internet was not cooperating.

    This helped a TON! I completely forgot about the spread function, that's what I needed.

    I have one question, (anyone can answer this for me) how can I detect the tower in range with the lowest working buffer?

  6. #6
    Clicker Multimedia Fusion 2

    Join Date
    Sep 2006
    Location
    Britain, South Coast
    Posts
    1,030

    Re: Tower defence Range

    Ah, yes, that. Well I've had a look but I'm afraid I can't find the original object that could do it for MMF1.5. There must be another around there somewhere for MMF2.

  7. #7
    Clicker Multimedia Fusion 2

    Join Date
    Sep 2006
    Location
    Britain, South Coast
    Posts
    1,030

    Re: Tower defence Range

    OK, it's the Select Object Extension. You have to rewrite the code to be more like the following. You also need to add a new alterable value to the towers:

    "Target" //The fixed value of the target object

    The last event is the one with the changes

    Code:
    //This will give all towers and enemies an ID
    ALWAYS
    --- Tower: Spread 0 in 'ID Number'
    --- Enemy: Spread 0 in 'ID Number'
    
    //This will do a loop for each tower
    ALWAYS
    --- Start loop "Tower Range Check" 'nObjects("TOWER")' times
    
    //That loop.
    //We're gonna make every enemy work out its distance to 
    //each tower one by one.
    
    //Select the current tower, and all enemies.
    //Set WORKING value of enemies to distance between them and tower
    ON Loop "Tower Range Check"
    + Tower: 'ID Number' = loopindex("Tower Range Check")
    --- Enemy: Set 'Working Buffer' to:
    
          sqr( (x("TOWER") - x("ENEMY")) pow 2
              + (y("TOWER") - y("ENEMY")) pow 2 )
    
    //Now select the current tower again.
    //NEW: Using Select Object, you select the enemy with lowest value 'Working Buffer'
    ON loop "Tower Range Check"
    + Tower: 'ID Number' = loopindex("Tower Range Check")
    + SELECT: Select ENEMY with lowest 'Working Buffer'
    --- Tower: Set 'Enemy In Range' to "YES"
    --- Tower: Set 'Target' to 'fixed("ENEMY")'
    The tower should now target its closest enemies within a certain range.

  8. #8
    No Products Registered

    Join Date
    Oct 2008
    Posts
    5

    Re: Tower defence Range

    ok, thanks!

  9. #9
    No Products Registered

    Join Date
    Feb 2008
    Location
    uk
    Posts
    367

    Re: Tower defence Range

    hi, just messed about with this,i followed the code, but how would i get the tower to fire?? i should know, but im dumb

  10. #10
    No Products Registered

    Join Date
    Oct 2008
    Posts
    5

    Re: Tower defence Range

    put an event,

    every second
    --TOWER: fire object -- toward ENEMY at speed --

Page 1 of 2 1 2 LastLast

Similar Threads

  1. 1000 creep tower defence
    By SolarB in forum Multimedia Fusion 2 - Technical Support
    Replies: 14
    Last Post: 30th March 2012, 06:48 AM
  2. Issues with Programing a FPS Tower Defence.
    By DriftingFable in forum Multimedia Fusion 2 - Technical Support
    Replies: 21
    Last Post: 1st May 2010, 11:20 PM
  3. Tower Defence Help
    By Destroyer0203 in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 1st January 2010, 12:33 AM
  4. how do you make a tower defence game?
    By brad in forum Multimedia Fusion 2 - Technical Support
    Replies: 25
    Last Post: 22nd November 2009, 07:53 PM
  5. Tower defence
    By Algul in forum File Archive
    Replies: 14
    Last Post: 1st June 2009, 12:22 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
  •