How do I make 2 sprites "engage"

Get help using Construct 2

Post » Thu Feb 04, 2016 7:52 pm

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
B
7
S
2
Posts: 102
Reputation: 975

Post » Thu Feb 04, 2016 11:53 pm

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.
Mistakes were made.
B
47
S
23
G
107
Posts: 1,571
Reputation: 60,133

Post » Fri Feb 05, 2016 9:58 am

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.
B
7
S
2
Posts: 102
Reputation: 975

Post » Sat Feb 06, 2016 1:26 am

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.
Mistakes were made.
B
47
S
23
G
107
Posts: 1,571
Reputation: 60,133


Return to How do I....?

Who is online

Users browsing this forum: amaloneboys, jance0405, tetuan and 10 guests