1

My game is a small shooting game in cocos2d. The enemy generates the bullets to shoot player at intervals of time. I have created a random y , so that bullets touch the opposite edge at random heights. If the bullet touches the player the enemy wins.
But, I need to set probability for the enemy accuracy. If the probability of enemy is given as 80% accuracy? How can I set in my program? For 10 shots 8 should be straight towards player.
How can I decide which ones should go straight in 10 which one should miss. In mean time player also shoots the enemy.

Thank You.

4

1 に答える 1

2

私はこのようにします。

プレーヤーの位置が y であるとします。80% の精度を得るには、間隔 から乱数を選択します。[y - height*0.2, y + height*0.2]ここheightで、 は画面の高さです。一般に、精度を得るには、 から数値を選択します [y - height*(1-p), y + height*(1-p)]。p = 1.0 (100%) の場合、弾丸は正確にプレイヤーの位置に向けられます。

これは、80% の精度の敵が 10 発中 8 発を正確にプレイヤーに向けて発射するという意味ではありませんが、弾丸が近くにあるほど精度が高くなります。

もちろん、これは弾丸が移動する時間を無視していますが、それほど手間をかけずに含めることができます。

于 2010-04-08T09:13:30.030 に答える