forked from thoth-tech/DXBallGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.cpp
More file actions
71 lines (67 loc) · 2.23 KB
/
Copy pathutilities.cpp
File metadata and controls
71 lines (67 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "utilities.h"
int high_score_position() {
for (int i = 0; i < 10; i++) {
if (json_read_number_as_int(game_data.score_rows[i], "score") < game_data.score) {
return i;
}
}
return 10;
}
void update_scores() {
int position = high_score_position();
for (int i = 9; i > position; i--) {
json_set_number(game_data.score_rows[i], "score", json_read_number_as_int(game_data.score_rows[i - 1], "score"));
json_set_string(game_data.score_rows[i], "initials", json_read_string(game_data.score_rows[i - 1], "initials"));
}
json_set_number(game_data.score_rows[position], "score", game_data.score);
string initials = initials_entry.characters[initials_entry.character1] + initials_entry.characters[initials_entry.character2];
json_set_string(game_data.score_rows[position], "initials", initials);
for (int i = 0; i < 10; i++) {
json_set_object(game_data.scores, "row" + std::to_string(i), game_data.score_rows[i]);
}
json_to_file(game_data.scores, "scores.json");
}
block_data create_block(double x, double y, block_kind kind, powerups powerup) {
block_data block;
block.x = x;
block.y = y;
block.kind = kind;
switch (kind) {
case SINGLE_HIT:
block.hitpoint = 1;
block.block_bitmap = "block_single_hit";
break;
case DOUBLE_HIT:
block.hitpoint = 2;
block.block_bitmap = "block_double_hit_1";
break;
case HIDDEN:
block.hitpoint = 2;
block.block_bitmap = "block_hidden_1";
break;
}
switch (powerup) {
case NO_POWERUP:
block.powerup_bitmap = "block_hidden_1";
break;
case MULTI_BALL:
block.powerup_bitmap = "block_multi_ball";
break;
case SCORE_MULTIPLY:
block.powerup_bitmap = "block_multiplier_2";
break;
default:
block.powerup_bitmap = "block_multi_ball";
break;
}
block.powerup = powerup;
return block;
}
ball_data create_ball(double x, double y, bool up, bool right) {
ball_data ball;
ball.x = x;
ball.y = y;
ball.up = up;
ball.right = right;
return ball;
}