MCPcopy Create free account
hub / github.com/android/ndk-samples / Generate

Method Generate

endless-tunnel/app/src/main/cpp/obstacle_generator.cpp:21–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19#include "game_consts.hpp"
20
21void ObstacleGenerator::Generate(Obstacle* result) {
22 static const int PROB_TABLE[] = {
23 // EASY MED INT HARD
24 100, 0, 0, 0, // difficulty 0
25 75, 25, 0, 0, // difficulty 1
26 50, 50, 0, 0, // difficulty 2
27 25, 75, 0, 0, // difficulty 3
28 0, 100, 0, 0, // difficulty 4
29 0, 75, 25, 0, // difficulty 5
30 0, 50, 50, 0, // difficulty 6
31 0, 25, 75, 0, // difficulty 7
32 0, 0, 100, 0, // difficulty 8
33 0, 0, 75, 25, // difficulty 9
34 0, 0, 50, 50, // difficulty 10
35 0, 0, 25, 75, // difficulty 11
36 0, 0, 0, 100 // difficulty 12+
37 };
38 result->Reset();
39 result->style = 1 + Random(7);
40
41 int d = Clamp(mDifficulty, 0, 12);
42 int easyProb = PROB_TABLE[d * 4];
43 int medProb = PROB_TABLE[d * 4 + 1];
44 int intermediateProb = PROB_TABLE[d * 4 + 2];
45 int roll = Random(100);
46 if (roll <= easyProb) {
47 GenEasy(result);
48 } else if (roll <= easyProb + medProb) {
49 GenMedium(result);
50 } else if (roll <= easyProb + medProb + intermediateProb) {
51 GenIntermediate(result);
52 } else {
53 GenHard(result);
54 }
55 result->PutRandomBonus();
56}
57
58void ObstacleGenerator::FillRow(Obstacle* result, int row) {
59 for (int i = 0; i < OBS_GRID_SIZE; ++i) {

Callers 1

GenObstaclesMethod · 0.80

Calls 4

RandomFunction · 0.85
ClampFunction · 0.85
PutRandomBonusMethod · 0.80
ResetMethod · 0.45

Tested by

no test coverage detected