Characters Attacking Other Chars

0 favourites
  • 4 posts
From the Asset Store
Ninja char for your game! Make your own Shinobi game with this art.
  • I'm making a turn based rpg game with white damage, where characters attack a random enemy every so often.

    I'm trying to write a set of events which makes any character attack its target whenever it is time to do so.

    AttackProgress - How many second has elapsed since this character last attacked.

    AttackTime - How many seconds must elapse between attacks (before the next attack, starting from the last time it attacked)

    AttackDamage - How much damage is dealt to the target with each attack.

    CurrentLocation - The spawn point that the character is occupying in the current combat (this is a number, each character has a unique CurrentLocation).

    CurrentTarget - The spawn point (or CurrentLocation, if you prefer) of the enemy that this character will attack.

    So, logically, whenever a character's AttackProgress > its AttackTime, it should deal it's AttackDamage to an enemy whose CurrentLocation = the attacker's CurrentTarget.

    Here's how I'm currently trying to do this with events:

    My first event says that for each Character whose AttackProgress > Self.AttackTime, add information to an array called "TheStack" (yes, I play Magic the Gathering). Set value at Characters.UID,1 to Characters.CurrentTarget, and Set value at Characters.UID,2 to Characters.WhiteDamage.

    This gives us an array where for each Character that has AttackProgress > Self.AttackTime there are two values stored at X,1 and X,2, where X = the character's UID. Thus, we've stored the incoming damage amount and targets for each outgoing attack.

    However, I can't seem to find a way to compare each character's CurrentLocation to this array for all values of X where Y = 1, then reduce their CurrentHP (another instance variable) by the value at Y = 2 for the same value of X, if there's a match.

    Hopefully that all makes sense. If you have any questions, I'll do my best to clear up any confusion. I'm open to doing this other ways too. I'm trying to support a game with multiple party members and multiple enemies, which seems to be my problem.

  • I'm not sure I followed 100%. It would be much easier if you could make a simplified capx that demonstrates the problem.

    Would it help if you make use of "temporary" arrays, and loop through TheStack looking, for example, for those UIDs where Y=1 and pushing them onto the new array? That gives you an array with just the qualifying UIDs to look at. Then you could loop through that array, and for each UID compare the character's CurrentLocation to whatever you want to compare it to. When the next turn starts, clear the "temporary" array and start over.

    How is CurrentTarget selected for each character?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Something like this:

    <img src="https://dl.dropbox.com/u/8367729/construct/pics/theStack.png" border="0" />

    Though I wouldn't use the UID to index the array because your array will be much bigger than you need. Instead you could create a queue. Start with a zero sized array and push the attacks onto it. Then when you process the attack you can pop it off.

  • Thanks!

    I ended up doing what Ramones suggested in his post and it's working great.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)