How to set probability for a targetSprite shooting accuracy in shooting game ?
Posted
by srikanth rongali
on Stack Overflow
See other posts from Stack Overflow
or by srikanth rongali
Published on 2010-03-30T10:14:34Z
Indexed on
2010/03/30
10:23 UTC
Read the original article
Hit count: 369
cocoa-touch
|cocos2d-iphone
Hi, My code is ion cocos2D. I have written code for generating the bullets from the enemy gun for every 0.3seconds. The enemySprite is in right side of the screen in (land scape mode) at winSize.height/2. the bullet starts from the same point and reach the player's end. I used rand() to generate y-coordinate for the bullet to hit on player side. Now, if the bullet bounded rectangle meets the player bounded rectangle the enemy won. If it misses enemy shoots again after 0.3 seconds. Every thing is fine up to here for me. But I have 10 enemies and each have accuracy of hitting player of probabilities ranging from 0.80 to 1.0. First enemy probability is .80 and 10 enemy's is 1.0. How can I adjust the probability for enemy such that it runs according to its probability. Player also hits the enemy.
© Stack Overflow or respective owner