How do I make 2 sprites "engage"

0 favourites
  • 4 posts
From the Asset Store
Pixel Sprites ala ReactorCore - Builder Hardware - Large pack of sprites!
  • I need this for a combat system, so i have 2 sprites, Red and Blue.

    They both have the variable Chance to attack(CTA), Chance to deffend(CTD)

    When they get close I want them to share values of those variables to determine how will the fight turn out

    For example:

    They enter each others ranges

    -Red's CTA is 5, Blue's CTA is 4

    -1 for Red he now has 10% percent chance to go first (10% for each CTA point)

    -The chance paid off Red goes first and attackes

    Now, they "shared" CTA, but CTD is unique to each

    -Blue's CTD is 4 (40% to effectivly deffend)

    -he deffends himself

    And then it goes again, until one of them loses

    So, I am not sure how actually complex it is, it seems pretty hard to me, I tried but nothing good ever comes out of that , i usually end up here lol, so thanks in advance

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm not really understanding what you are mean by "sharing" the variables?

    You can use expressions to compare them, or use math.

    ex:

    While Red and Blue are in range -

    If Red.CTA > Blue.CTA

    And If random(100) < (Red.CTA-Blue.CTA)*10

    And If random(100) > Blue.CTD*10 ACTION - Blue loses life

    If Blue.CTA > Red.CTA

    And If random(100) < (Blue.CTA-Red.CTA)*10

    And If random(100) > Red.CTD*10 ACTION - Red loses life

    Else repeat, until one is destroyed.

    Except I think you've got some problems with your game logic to begin with.... If red has a higher CTA than blue, it only has a 10% chance to go first? Which means blue has a 90% chance to go first? You should probably work out your game logic a little more solidly before trying to code it.

  • Thanks this works nicely, but what i meant when i said shared was the situtation when i have more than one red and blue,

    If i had 7 Reds vs 7 Blues and they engage each other how will it play out, I am not sure if the "for each"condition will be enough

    P.S When i said 10% i meant 10% more, so 60% in total, But yes i did make a mistake, i just add 50 into the equation.

  • It's OK to have multiple instances of objects. Construct works by "picking" instances. In this case, you don't want a for each. The first condition that checks if red and blue are in range picks those instances - all following conditions and actions only affect the picked instances and the others are ignored.

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