-
Notifications
You must be signed in to change notification settings - Fork 0
/
power_up.c
145 lines (108 loc) · 3.16 KB
/
power_up.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "roomba.h"
#include "tools.h"
#include "usart.h"
#include <stdio.h>
#include <stdlib.h>
#include "power_up.h"
#include "radio.h"
#include "outOfCourseController.h"
#include "drivecontrol.h"
uint8_t bigRoombaActive = 0;
uint8_t mushroomActive = 0;
int16_t powerUpDisplayCounter = POWCONST;
uint64_t powerUpTimer = 0;
/**
* Hold the tick count of a wheel to calculate a random number
*/
uint16_t tickCountRandGlobal = 1;
void getPowerUp(uint16_t tickCountRand) {
if (currentPowerUp != NO_POWERUP || powerUpDisplayCounter != POWCONST || bigRoombaActive || mushroomActive) {
return;
}
tickCountRandGlobal = tickCountRand;
char result[4] = {'P', 'O', 'W', 'R'};
set_Display(result);
my_msleep(500);
powerUpDisplayCounter = 0;
showRandomizeSign();
}
void shootPowerUp() {
if (currentPowerUp == NO_POWERUP) {
return;
}
//sendString("Shoot...\r\n");
// Make shooting sound
playSong(0);
// If we have a red tank --> send shooting over radio
if (currentPowerUp == RED_TANK) {
sendRadio(RED_TANK_SHOT, 3);
} else {
// If Big roomba or mushroom is active --> set global variable
if (currentPowerUp == MUSHROOM) {
mushroomActive = 1;
} else if (currentPowerUp == BIG_DADY) {
bigRoombaActive = 1;
}
// Initialize timer variable so we can use the power up for a nr. of seconds
powerUpTimer = 1;
}
// Delete display
clear_Display();
currentPowerUp = NO_POWERUP;
}
void powerUpIsOver() {
//sendString("Power up is over...");
// When we had a mushroom, check if we are outside the course
if (mushroomActive == 1 && outsideCourse == 1) {
// Game over
playSong(3);
drive_stop();
char result[4] = {'O', 'V', 'E', 'R'};
set_Display(result);
while(1);
}
bigRoombaActive = 0;
mushroomActive = 0;
outsideCourse = 0;
}
void showRandomizeSign() {
if (powerUpDisplayCounter == POWCONST) {
return;
}
my_msleep(30);
// Infinity sign in 7 segments
uint8_t infinitySign[16][4] = {{0x10, 0x0, 0x0, 0x0}, {0x30, 0x0, 0x0, 0x0},
{0x31, 0x0, 0x0, 0x0}, {0x31, 0x1, 0x0, 0x0}, {0x31, 0x3, 0x0, 0x0},
{0x31, 0x7, 0x0, 0x0}, {0x31, 0x7, 0x8, 0x0}, {0x31, 0x7, 0x8, 0x8},
{0x31, 0x7, 0x8, 0xC}, {0x31, 0x7, 0x8, 0xE}, {0x31, 0x7, 0x8, 0xF},
{0x31, 0x7, 0x9, 0xF}, {0x31, 0x7, 0x9, 0xF}, {0x31, 0xF, 0x9, 0xF},
{0x39, 0xF, 0x9, 0xF}, {0x0, 0x0, 0x0, 0x0}};
set_Display_raw(infinitySign[powerUpDisplayCounter % 16]);
powerUpDisplayCounter++;
// Stop when we reached array length
if (powerUpDisplayCounter > 16*2) {
// Get random nr.
srand((unsigned int) tickCountRandGlobal);
powerUp_type powerup_type = rand() % 3;
// For testing
//powerup_type = MUSHROOM;
// Display what power up we have
uint8_t tank[4] = {0x00, 0x5c, 0x40, 0x00};
uint8_t mushroom[4] = {0x61, 0x1D, 0x43, 0x00};
uint8_t bigDaddy[4] = {0x5c, 0xff, 0x40, 0x00};
uint8_t *pUSymbols[3] = {tank, mushroom, bigDaddy};
set_Display_raw(pUSymbols[powerup_type]);
currentPowerUp = powerup_type;
powerUpDisplayCounter = POWCONST;
}
}
void handleTimerVariable() {
if (powerUpTimer == 0)
return;
if (powerUpTimer == POWER_UP_TIME) {
powerUpIsOver();
powerUpTimer = 0;
return;
}
powerUpTimer++;
}