-
Notifications
You must be signed in to change notification settings - Fork 0
/
coin.c
48 lines (40 loc) · 1.08 KB
/
coin.c
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
#include "coin.h"
void generate_coin(){
int add_to_score;
static int coin_occurance = COIN_5_OCCURANCE;
// Define type of coin
srand((unsigned)time(NULL));
add_to_score = rand() % COIN_5_LIMIT;
coin.add_to_score = (add_to_score < coin_occurance) ? 5 : 1;
if(coin.add_to_score == 1){
coin_occurance += COIN_5_OCCURANCE / 2;
} else {
coin_occurance = COIN_5_OCCURANCE;
}
srand((unsigned)time(NULL));
coin.point.x = 1 + rand() % (MAX_COLUMN - 3);
srand((unsigned)time(NULL));
coin.point.y = 1 + rand() % (MAX_ROW - 3);
}
void add_coin_tail_score(Player *player){
(*player).coin_score += coin.add_to_score;
(*player).max_coin_score += coin.add_to_score;
add_tail_child(player);
}
void collect_coin(){
short collected = 0;
// First player
if(coin_collider(&player1) == 1){
add_coin_tail_score(&player1);
collected = 1;
}
// Second player
if(coin_collider(&player2) == 1){
add_coin_tail_score(&player2);
collected = 1;
}
// Generate new coin if coin was collected
if(collected > 0){
generate_coin();
}
}