Armageddon - a missile commad clone by Wuuff, originally for Gamebuino. Conversion by Jonne
Dependencies: PokittoLib
Fork of Asterocks by
ageddon.cpp@6:22d706e5dd6e, 2017-10-14 (annotated)
- Committer:
- HomineLudens
- Date:
- Sat Oct 14 14:24:06 2017 +0000
- Revision:
- 6:22d706e5dd6e
- Parent:
- 5:56c4f2f12ec0
- Child:
- 13:b133c46dbda7
- Swap launch missile button; - Colored ammo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pokitto | 5:56c4f2f12ec0 | 1 | /* This file was automatically parsed from an Arduino sourcefile */ |
Pokitto | 5:56c4f2f12ec0 | 2 | /* by PokittoParser v0.1 Copyright 2016 Jonne Valola */ |
Pokitto | 5:56c4f2f12ec0 | 3 | /* USE AT YOUR OWN RISK - NO GUARANTEES GIVEN OF 100% CORRECTNESS */ |
Pokitto | 5:56c4f2f12ec0 | 4 | |
Pokitto | 5:56c4f2f12ec0 | 5 | #include "PokittoCore.h" |
Pokitto | 5:56c4f2f12ec0 | 6 | /* Auto-generated function declarations */ |
Pokitto | 5:56c4f2f12ec0 | 7 | void setup(); |
Pokitto | 5:56c4f2f12ec0 | 8 | void nextStage(); |
Pokitto | 5:56c4f2f12ec0 | 9 | void nextLull(); |
Pokitto | 5:56c4f2f12ec0 | 10 | void drawScore(); |
Pokitto | 5:56c4f2f12ec0 | 11 | void drawTargets(); |
Pokitto | 5:56c4f2f12ec0 | 12 | void drawCities(); |
Pokitto | 5:56c4f2f12ec0 | 13 | void drawAmmo(); |
Pokitto | 5:56c4f2f12ec0 | 14 | void drawMissiles(); |
Pokitto | 5:56c4f2f12ec0 | 15 | void drawDetonations(); |
Pokitto | 5:56c4f2f12ec0 | 16 | void launchMissile(uint8_t); |
Pokitto | 5:56c4f2f12ec0 | 17 | void tryLaunchEnemy(); |
Pokitto | 5:56c4f2f12ec0 | 18 | void stepMissiles(); |
Pokitto | 5:56c4f2f12ec0 | 19 | void stepDetonations(); |
Pokitto | 5:56c4f2f12ec0 | 20 | void stepCollision(); |
Pokitto | 5:56c4f2f12ec0 | 21 | void checkMenu(); |
Pokitto | 5:56c4f2f12ec0 | 22 | void checkWin(); |
Pokitto | 5:56c4f2f12ec0 | 23 | void checkLose(); |
Pokitto | 5:56c4f2f12ec0 | 24 | void stepGame(); |
Pokitto | 5:56c4f2f12ec0 | 25 | void drawLull(); |
Pokitto | 5:56c4f2f12ec0 | 26 | void stepLull(); |
Pokitto | 5:56c4f2f12ec0 | 27 | void stepDead(); |
Pokitto | 5:56c4f2f12ec0 | 28 | void stepPregame(); |
Pokitto | 5:56c4f2f12ec0 | 29 | void loop(); |
Pokitto | 5:56c4f2f12ec0 | 30 | void loadHighscores(); |
Pokitto | 5:56c4f2f12ec0 | 31 | uint8_t isHighscore(uint32_t); |
Pokitto | 5:56c4f2f12ec0 | 32 | void saveHighscore(char); |
Pokitto | 5:56c4f2f12ec0 | 33 | void drawHighscores(); |
Pokitto | 5:56c4f2f12ec0 | 34 | void initSound(); |
Pokitto | 5:56c4f2f12ec0 | 35 | void playSound(uint8_t); |
Pokitto | 5:56c4f2f12ec0 | 36 | Pokitto::Core gb; |
Pokitto | 5:56c4f2f12ec0 | 37 | |
Pokitto | 5:56c4f2f12ec0 | 38 | int main() { |
Pokitto | 5:56c4f2f12ec0 | 39 | setup(); |
Pokitto | 5:56c4f2f12ec0 | 40 | while (gb.isRunning()) { |
Pokitto | 5:56c4f2f12ec0 | 41 | loop(); |
Pokitto | 5:56c4f2f12ec0 | 42 | } |
Pokitto | 5:56c4f2f12ec0 | 43 | } |
Pokitto | 5:56c4f2f12ec0 | 44 | |
Pokitto | 5:56c4f2f12ec0 | 45 | const byte armageddon[] PROGMEM = {64,36, |
Pokitto | 5:56c4f2f12ec0 | 46 | B11111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00001111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 47 | B11111100,B00001111,B11111111,B11111111,B11111111,B11111111,B11110000,B00111111, |
Pokitto | 5:56c4f2f12ec0 | 48 | B11100011,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11000111, |
Pokitto | 5:56c4f2f12ec0 | 49 | B10011111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111001, |
Pokitto | 5:56c4f2f12ec0 | 50 | B01110111,B10011110,B11101110,B11111001,B11000010,B01111001,B11110111,B10111010, |
Pokitto | 5:56c4f2f12ec0 | 51 | B01110111,B10101110,B01001110,B11110110,B11011110,B10111010,B11101011,B10011010, |
Pokitto | 5:56c4f2f12ec0 | 52 | B01101011,B10001110,B01001101,B01110111,B11000110,B11011011,B01011101,B10101010, |
Pokitto | 5:56c4f2f12ec0 | 53 | B01100011,B10101110,B10101100,B01110100,B11011110,B11011011,B01011101,B10110010, |
Pokitto | 5:56c4f2f12ec0 | 54 | B01101011,B10100110,B11101101,B01110110,B11011110,B10111010,B11101011,B10111010, |
Pokitto | 5:56c4f2f12ec0 | 55 | B01001001,B10110110,B11101001,B00111001,B11000010,B01111001,B11110111,B10111010, |
Pokitto | 5:56c4f2f12ec0 | 56 | B10111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111101, |
Pokitto | 5:56c4f2f12ec0 | 57 | B11011111,B11111111,B11100000,B11111111,B11111111,B00000111,B11111111,B11111011, |
Pokitto | 5:56c4f2f12ec0 | 58 | B11100011,B11111110,B00011111,B00011111,B11111000,B11111000,B01111111,B11000111, |
Pokitto | 5:56c4f2f12ec0 | 59 | B11111000,B11100001,B11111111,B11101111,B11110111,B11111111,B10000111,B00011111, |
Pokitto | 5:56c4f2f12ec0 | 60 | B11111110,B00001111,B11111111,B11110111,B11101111,B11111111,B11110000,B01111111, |
Pokitto | 5:56c4f2f12ec0 | 61 | B11111111,B11111111,B11111111,B11110111,B11101111,B11111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 62 | B11111111,B11111111,B11111111,B11111011,B11011111,B11111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 63 | B11111111,B11111111,B11111111,B11111011,B11011111,B11111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 64 | B11111111,B11111111,B11111110,B00000011,B11000000,B01111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 65 | B11111111,B11111111,B11100001,B11111011,B11011111,B10000111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 66 | B11111111,B11111111,B11011111,B11110011,B11001111,B11111011,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 67 | B11111111,B11111111,B11011111,B11110011,B11001111,B11111011,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 68 | B11111111,B11111111,B11011111,B11110011,B11001111,B11111011,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 69 | B11111111,B11111111,B11100001,B11110011,B11001111,B10000111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 70 | B11111111,B11111111,B11111110,B00010111,B11101000,B01111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 71 | B11111111,B11111111,B11111111,B11100000,B00000111,B11111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 72 | B11111111,B11111111,B11111111,B11110111,B11101111,B11111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 73 | B11111111,B11111111,B11111111,B11100111,B11100111,B11111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 74 | B11111111,B11111111,B11111111,B11100111,B11100111,B11111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 75 | B11111111,B11111111,B11111111,B11101111,B11110111,B11111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 76 | B11111111,B11111111,B11111111,B11101111,B11110111,B11111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 77 | B11111111,B11111111,B11111111,B11101111,B11110111,B11111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 78 | B11111111,B11111111,B11111111,B11011111,B11111011,B11111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 79 | B11111111,B11111111,B11111111,B10111111,B11111101,B11111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 80 | B11111111,B11111111,B11111110,B01111111,B11111110,B01111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 81 | B11111111,B11111111,B11111101,B11111111,B11111111,B10111111,B11111111,B11111111, |
Pokitto | 5:56c4f2f12ec0 | 82 | }; |
Pokitto | 5:56c4f2f12ec0 | 83 | |
Pokitto | 5:56c4f2f12ec0 | 84 | /*const byte city[] PROGMEM = {8,8, |
Pokitto | 5:56c4f2f12ec0 | 85 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 86 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 87 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 88 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 89 | B00100010, |
Pokitto | 5:56c4f2f12ec0 | 90 | B01110110, |
Pokitto | 5:56c4f2f12ec0 | 91 | B01111110, |
Pokitto | 5:56c4f2f12ec0 | 92 | B11111111, |
Pokitto | 5:56c4f2f12ec0 | 93 | };*/ |
Pokitto | 5:56c4f2f12ec0 | 94 | |
Pokitto | 5:56c4f2f12ec0 | 95 | const byte city[] PROGMEM = {8,8, |
Pokitto | 5:56c4f2f12ec0 | 96 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 97 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 98 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 99 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 100 | B01100100, |
Pokitto | 5:56c4f2f12ec0 | 101 | B01101110, |
Pokitto | 5:56c4f2f12ec0 | 102 | B01111111, |
Pokitto | 5:56c4f2f12ec0 | 103 | B11111111, |
Pokitto | 5:56c4f2f12ec0 | 104 | }; |
Pokitto | 5:56c4f2f12ec0 | 105 | |
Pokitto | 5:56c4f2f12ec0 | 106 | const byte deadcity[] PROGMEM = {8,8, |
Pokitto | 5:56c4f2f12ec0 | 107 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 108 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 109 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 110 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 111 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 112 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 113 | B00100000, |
Pokitto | 5:56c4f2f12ec0 | 114 | B01100010, |
Pokitto | 5:56c4f2f12ec0 | 115 | }; |
Pokitto | 5:56c4f2f12ec0 | 116 | |
Pokitto | 5:56c4f2f12ec0 | 117 | const byte launcher[] PROGMEM = {8,8, |
Pokitto | 5:56c4f2f12ec0 | 118 | B00011000, |
Pokitto | 5:56c4f2f12ec0 | 119 | B00011000, |
Pokitto | 5:56c4f2f12ec0 | 120 | B00011000, |
Pokitto | 5:56c4f2f12ec0 | 121 | B00100100, |
Pokitto | 5:56c4f2f12ec0 | 122 | B00100100, |
Pokitto | 5:56c4f2f12ec0 | 123 | B01000010, |
Pokitto | 5:56c4f2f12ec0 | 124 | B01000010, |
Pokitto | 5:56c4f2f12ec0 | 125 | B10000001, |
Pokitto | 5:56c4f2f12ec0 | 126 | }; |
Pokitto | 5:56c4f2f12ec0 | 127 | |
Pokitto | 5:56c4f2f12ec0 | 128 | const byte deadlauncher[] PROGMEM = {8,8, |
Pokitto | 5:56c4f2f12ec0 | 129 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 130 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 131 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 132 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 133 | B00000000, |
Pokitto | 5:56c4f2f12ec0 | 134 | B01100110, |
Pokitto | 5:56c4f2f12ec0 | 135 | B01011010, |
Pokitto | 5:56c4f2f12ec0 | 136 | B10000001, |
Pokitto | 5:56c4f2f12ec0 | 137 | }; |
Pokitto | 5:56c4f2f12ec0 | 138 | |
Pokitto | 5:56c4f2f12ec0 | 139 | #define SOUND_PLAUNCH 0 |
Pokitto | 5:56c4f2f12ec0 | 140 | #define SOUND_ELAUNCH 1 |
Pokitto | 5:56c4f2f12ec0 | 141 | #define SOUND_DETONATE 2 |
Pokitto | 5:56c4f2f12ec0 | 142 | #define SOUND_SCORE 3 |
Pokitto | 5:56c4f2f12ec0 | 143 | #define SOUND_DEAD 4 |
Pokitto | 5:56c4f2f12ec0 | 144 | #define SOUND_LOSE 5 |
Pokitto | 5:56c4f2f12ec0 | 145 | |
Pokitto | 5:56c4f2f12ec0 | 146 | #define MODE_PREGAME 0 |
Pokitto | 5:56c4f2f12ec0 | 147 | #define MODE_GAME 1 |
Pokitto | 5:56c4f2f12ec0 | 148 | #define MODE_LULL 2 |
Pokitto | 5:56c4f2f12ec0 | 149 | #define MODE_DEAD 3 |
Pokitto | 5:56c4f2f12ec0 | 150 | #define MODE_POSTDEAD 4 |
Pokitto | 5:56c4f2f12ec0 | 151 | |
Pokitto | 5:56c4f2f12ec0 | 152 | #define TARGET_SPEED 3 |
Pokitto | 5:56c4f2f12ec0 | 153 | |
Pokitto | 5:56c4f2f12ec0 | 154 | #define LAUNCHER_ONE 1 |
Pokitto | 5:56c4f2f12ec0 | 155 | #define LAUNCHER_TWO 2 |
Pokitto | 5:56c4f2f12ec0 | 156 | #define MAX_PMISSILES 10 |
Pokitto | 5:56c4f2f12ec0 | 157 | #define PSPEED 4 |
Pokitto | 5:56c4f2f12ec0 | 158 | #define PRADIUS 7 |
Pokitto | 5:56c4f2f12ec0 | 159 | #define EXPAND 0 |
Pokitto | 5:56c4f2f12ec0 | 160 | #define SHRINK 1 |
Pokitto | 5:56c4f2f12ec0 | 161 | |
Pokitto | 5:56c4f2f12ec0 | 162 | #define MAX_EMISSILES 10 |
Pokitto | 5:56c4f2f12ec0 | 163 | #define MAX_CHANCE 50 |
Pokitto | 5:56c4f2f12ec0 | 164 | |
Pokitto | 5:56c4f2f12ec0 | 165 | // State variables |
Pokitto | 5:56c4f2f12ec0 | 166 | uint8_t mode = 0; |
Pokitto | 5:56c4f2f12ec0 | 167 | uint8_t counter = 0; |
Pokitto | 5:56c4f2f12ec0 | 168 | uint8_t flash = 0; |
Pokitto | 5:56c4f2f12ec0 | 169 | uint8_t stage = 0; //Maximum of 255 stages |
Pokitto | 5:56c4f2f12ec0 | 170 | uint32_t score = 0; //Score needs more space than other vars |
Pokitto | 5:56c4f2f12ec0 | 171 | |
Pokitto | 5:56c4f2f12ec0 | 172 | uint8_t lullMissiles = 0; |
Pokitto | 5:56c4f2f12ec0 | 173 | uint8_t lullCities[8] = {0,0,0,0,0,0,0,0}; |
Pokitto | 5:56c4f2f12ec0 | 174 | |
Pokitto | 5:56c4f2f12ec0 | 175 | uint8_t cities[8] = {1,1,1,1,1,1,1,1}; //Whether the cities or launchers are alive |
Pokitto | 5:56c4f2f12ec0 | 176 | |
Pokitto | 5:56c4f2f12ec0 | 177 | uint8_t targetX = 84/2; |
Pokitto | 5:56c4f2f12ec0 | 178 | uint8_t targetY = 48/2; |
Pokitto | 5:56c4f2f12ec0 | 179 | uint8_t pammo[2] = {10,10}; |
Pokitto | 5:56c4f2f12ec0 | 180 | uint8_t pDests[MAX_PMISSILES][2] = {{100,100},{100,100},{100,100},{100,100},{100,100},{100,100},{100,100},{100,100},{100,100},{100,100}}; |
Pokitto | 5:56c4f2f12ec0 | 181 | float pMissiles[MAX_PMISSILES][3] = {{100,100,0},{100,100,0},{100,100,0},{100,100,0},{100,100,0},{100,100,0},{100,100,0},{100,100,0},{100,100,0},{100,100,0}}; |
Pokitto | 5:56c4f2f12ec0 | 182 | uint8_t pDetonations[MAX_PMISSILES][4] = {{100,100,0,0},{100,100,0,0},{100,100,0,0},{100,100,0,0},{100,100,0,0},{100,100,0,0},{100,100,0,0},{100,100,0,0},{100,100,0,0},{100,100,0,0}}; |
Pokitto | 5:56c4f2f12ec0 | 183 | |
Pokitto | 5:56c4f2f12ec0 | 184 | uint8_t etotal = 5; |
Pokitto | 5:56c4f2f12ec0 | 185 | uint8_t echance = 1; |
Pokitto | 5:56c4f2f12ec0 | 186 | float espeed = 0.2; |
Pokitto | 5:56c4f2f12ec0 | 187 | uint8_t eDests[MAX_EMISSILES] = {100,100,100,100,100,100,100,100,100,100}; |
Pokitto | 5:56c4f2f12ec0 | 188 | float eMissiles[MAX_EMISSILES][4] = {{100,100,100,100},{100,100,100,100},{100,100,100,100},{100,100,100,100},{100,100,100,100},{100,100,100,100},{100,100,100,100},{100,100,100,100},{100,100,100,100},{100,100,100,100}}; |
Pokitto | 5:56c4f2f12ec0 | 189 | |
Pokitto | 5:56c4f2f12ec0 | 190 | void setup() { |
Pokitto | 5:56c4f2f12ec0 | 191 | gb.begin(); |
Pokitto | 5:56c4f2f12ec0 | 192 | loadHighscores(); |
Pokitto | 5:56c4f2f12ec0 | 193 | gb.titleScreen(armageddon); |
Pokitto | 5:56c4f2f12ec0 | 194 | gb.battery.show = false; |
Pokitto | 5:56c4f2f12ec0 | 195 | gb.pickRandomSeed(); |
Pokitto | 5:56c4f2f12ec0 | 196 | } |
Pokitto | 5:56c4f2f12ec0 | 197 | |
Pokitto | 5:56c4f2f12ec0 | 198 | void nextStage(){ |
Pokitto | 5:56c4f2f12ec0 | 199 | stage++; |
Pokitto | 5:56c4f2f12ec0 | 200 | //Reset cities (since we cleared them for the visual effect |
Pokitto | 5:56c4f2f12ec0 | 201 | for( uint8_t i = 0; i < 8; i++ ){ |
Pokitto | 5:56c4f2f12ec0 | 202 | cities[i] = lullCities[i]; |
Pokitto | 5:56c4f2f12ec0 | 203 | } |
Pokitto | 5:56c4f2f12ec0 | 204 | //Reset launchers |
Pokitto | 5:56c4f2f12ec0 | 205 | cities[2] = 1; |
Pokitto | 5:56c4f2f12ec0 | 206 | cities[5] = 1; |
Pokitto | 5:56c4f2f12ec0 | 207 | //Reset missiles |
Pokitto | 5:56c4f2f12ec0 | 208 | pammo[0] = 10; |
Pokitto | 5:56c4f2f12ec0 | 209 | pammo[1] = 10; |
Pokitto | 5:56c4f2f12ec0 | 210 | //Reset in-flight missiles |
Pokitto | 5:56c4f2f12ec0 | 211 | for( uint8_t i = 0; i < 10; i++ ){ |
Pokitto | 5:56c4f2f12ec0 | 212 | pDests[i][0] = 100; |
Pokitto | 5:56c4f2f12ec0 | 213 | pDetonations[i][0] = 100; |
Pokitto | 5:56c4f2f12ec0 | 214 | eDests[i] = 100; |
Pokitto | 5:56c4f2f12ec0 | 215 | } |
Pokitto | 5:56c4f2f12ec0 | 216 | |
Pokitto | 5:56c4f2f12ec0 | 217 | etotal = stage > 10 ? 20 : 10+stage; //Max of 20 missiles per stage, start at 10 |
Pokitto | 5:56c4f2f12ec0 | 218 | //echance = stage > 5 ? 5 : stage; //Max of 5/100 chance per frame |
Pokitto | 5:56c4f2f12ec0 | 219 | espeed = stage > 18 ? 2 : 0.2+(stage*0.1); //Max speed of 2, up 0.1 per stage, starts at 0.2 |
Pokitto | 5:56c4f2f12ec0 | 220 | } |
Pokitto | 5:56c4f2f12ec0 | 221 | |
Pokitto | 5:56c4f2f12ec0 | 222 | void nextLull(){ |
Pokitto | 5:56c4f2f12ec0 | 223 | //Reset lullMissiles |
Pokitto | 5:56c4f2f12ec0 | 224 | lullMissiles = 0; |
Pokitto | 5:56c4f2f12ec0 | 225 | //Reset lullCities |
Pokitto | 5:56c4f2f12ec0 | 226 | for( uint8_t i = 0; i < 8; i++ ){ |
Pokitto | 5:56c4f2f12ec0 | 227 | lullCities[i] = 0; |
Pokitto | 5:56c4f2f12ec0 | 228 | } |
Pokitto | 5:56c4f2f12ec0 | 229 | } |
Pokitto | 5:56c4f2f12ec0 | 230 | |
Pokitto | 5:56c4f2f12ec0 | 231 | void drawScore(){ |
Pokitto | 5:56c4f2f12ec0 | 232 | gb.display.cursorX = 84/2 - 4*3; |
Pokitto | 5:56c4f2f12ec0 | 233 | gb.display.cursorY = 0; |
Pokitto | 5:56c4f2f12ec0 | 234 | |
Pokitto | 5:56c4f2f12ec0 | 235 | if( score < 100000 ){ |
Pokitto | 5:56c4f2f12ec0 | 236 | gb.display.print(0); |
Pokitto | 5:56c4f2f12ec0 | 237 | } |
Pokitto | 5:56c4f2f12ec0 | 238 | if( score < 10000 ){ |
Pokitto | 5:56c4f2f12ec0 | 239 | gb.display.print(0); |
Pokitto | 5:56c4f2f12ec0 | 240 | } |
Pokitto | 5:56c4f2f12ec0 | 241 | if( score < 1000 ){ |
Pokitto | 5:56c4f2f12ec0 | 242 | gb.display.print(0); |
Pokitto | 5:56c4f2f12ec0 | 243 | } |
Pokitto | 5:56c4f2f12ec0 | 244 | if( score < 100 ){ |
Pokitto | 5:56c4f2f12ec0 | 245 | gb.display.print(0); |
Pokitto | 5:56c4f2f12ec0 | 246 | } |
Pokitto | 5:56c4f2f12ec0 | 247 | if( score < 10 ){ |
Pokitto | 5:56c4f2f12ec0 | 248 | gb.display.print(0); |
Pokitto | 5:56c4f2f12ec0 | 249 | } |
Pokitto | 5:56c4f2f12ec0 | 250 | gb.display.print(score); |
Pokitto | 5:56c4f2f12ec0 | 251 | } |
Pokitto | 5:56c4f2f12ec0 | 252 | |
Pokitto | 5:56c4f2f12ec0 | 253 | void drawTargets(){ |
Pokitto | 5:56c4f2f12ec0 | 254 | gb.display.drawFastHLine(targetX-1,targetY,3); |
Pokitto | 5:56c4f2f12ec0 | 255 | gb.display.drawFastVLine(targetX,targetY-1,3); |
Pokitto | 5:56c4f2f12ec0 | 256 | |
Pokitto | 5:56c4f2f12ec0 | 257 | for(uint8_t i = 0; i < MAX_PMISSILES; i++){ |
Pokitto | 5:56c4f2f12ec0 | 258 | //Check for a valid destination without a current detonation |
Pokitto | 5:56c4f2f12ec0 | 259 | if( pDests[i][0] <= 84 && pDetonations[i][0] > 84 ){ |
Pokitto | 5:56c4f2f12ec0 | 260 | gb.display.drawPixel(pDests[i][0], pDests[i][1]); |
Pokitto | 5:56c4f2f12ec0 | 261 | } |
Pokitto | 5:56c4f2f12ec0 | 262 | } |
Pokitto | 5:56c4f2f12ec0 | 263 | } |
Pokitto | 5:56c4f2f12ec0 | 264 | |
Pokitto | 5:56c4f2f12ec0 | 265 | void drawCities(){ |
Pokitto | 5:56c4f2f12ec0 | 266 | //uint8_t alldead = 1; |
Pokitto | 5:56c4f2f12ec0 | 267 | for(uint8_t i = 0; i < 8; i++){ |
Pokitto | 5:56c4f2f12ec0 | 268 | if( i == 2 || i == 5 ){ |
Pokitto | 5:56c4f2f12ec0 | 269 | if( cities[i] ){ |
Pokitto | 5:56c4f2f12ec0 | 270 | gb.display.drawBitmap(i*10+2,40,launcher); |
Pokitto | 5:56c4f2f12ec0 | 271 | }else{ |
Pokitto | 5:56c4f2f12ec0 | 272 | gb.display.drawBitmap(i*10+2,40,deadlauncher); |
Pokitto | 5:56c4f2f12ec0 | 273 | } |
Pokitto | 5:56c4f2f12ec0 | 274 | }else{ |
Pokitto | 5:56c4f2f12ec0 | 275 | if( cities[i] ){ |
Pokitto | 5:56c4f2f12ec0 | 276 | //alldead = 0; |
Pokitto | 5:56c4f2f12ec0 | 277 | gb.display.drawBitmap(i*10+2,40,city); |
Pokitto | 5:56c4f2f12ec0 | 278 | }else{ |
Pokitto | 5:56c4f2f12ec0 | 279 | gb.display.drawBitmap(i*10+2,40,deadcity); |
Pokitto | 5:56c4f2f12ec0 | 280 | } |
Pokitto | 5:56c4f2f12ec0 | 281 | } |
Pokitto | 5:56c4f2f12ec0 | 282 | } |
Pokitto | 5:56c4f2f12ec0 | 283 | |
Pokitto | 5:56c4f2f12ec0 | 284 | /* |
Pokitto | 5:56c4f2f12ec0 | 285 | if( alldead ){ |
Pokitto | 5:56c4f2f12ec0 | 286 | gb.display.cursorX = 84/2 - 5*3; |
Pokitto | 5:56c4f2f12ec0 | 287 | gb.display.cursorY = 48/2 - 5; |
Pokitto | 5:56c4f2f12ec0 | 288 | gb.display.print("THE END"); |
Pokitto | 5:56c4f2f12ec0 | 289 | } |
Pokitto | 5:56c4f2f12ec0 | 290 | */ |
Pokitto | 5:56c4f2f12ec0 | 291 | } |
Pokitto | 5:56c4f2f12ec0 | 292 | |
Pokitto | 5:56c4f2f12ec0 | 293 | void drawAmmo(){ |
HomineLudens | 6:22d706e5dd6e | 294 | gb.display.setColor(2); |
Pokitto | 5:56c4f2f12ec0 | 295 | for( uint8_t i = 0; i < 2; i++ ){ |
Pokitto | 5:56c4f2f12ec0 | 296 | uint8_t xcoord = i == 0 ? 25 : 55; |
Pokitto | 5:56c4f2f12ec0 | 297 | uint8_t ycoord = 47; |
Pokitto | 5:56c4f2f12ec0 | 298 | if( cities[i*3+2] ){ //Is launcher alive? |
Pokitto | 5:56c4f2f12ec0 | 299 | for( uint8_t j = 0; j < pammo[i]; j++ ){ |
Pokitto | 5:56c4f2f12ec0 | 300 | gb.display.drawPixel(xcoord,ycoord); |
Pokitto | 5:56c4f2f12ec0 | 301 | if( xcoord % 2 == 0 ){ |
Pokitto | 5:56c4f2f12ec0 | 302 | xcoord--; |
Pokitto | 5:56c4f2f12ec0 | 303 | ycoord--; |
Pokitto | 5:56c4f2f12ec0 | 304 | }else{ |
Pokitto | 5:56c4f2f12ec0 | 305 | xcoord++; |
Pokitto | 5:56c4f2f12ec0 | 306 | } |
Pokitto | 5:56c4f2f12ec0 | 307 | } |
Pokitto | 5:56c4f2f12ec0 | 308 | } |
Pokitto | 5:56c4f2f12ec0 | 309 | } |
HomineLudens | 6:22d706e5dd6e | 310 | gb.display.setColor(1); |
Pokitto | 5:56c4f2f12ec0 | 311 | } |
Pokitto | 5:56c4f2f12ec0 | 312 | |
Pokitto | 5:56c4f2f12ec0 | 313 | void drawMissiles(){ |
Pokitto | 5:56c4f2f12ec0 | 314 | //Player Missiles |
Pokitto | 5:56c4f2f12ec0 | 315 | gb.display.setColor(2); |
Pokitto | 5:56c4f2f12ec0 | 316 | for(uint8_t i = 0; i < MAX_PMISSILES; i++){ |
Pokitto | 5:56c4f2f12ec0 | 317 | //Check for a valid destination without a current detonation |
Pokitto | 5:56c4f2f12ec0 | 318 | if( pDests[i][0] <= 84 && pDetonations[i][0] > 84 ){ |
Pokitto | 5:56c4f2f12ec0 | 319 | if(pMissiles[i][2] == LAUNCHER_ONE){ |
Pokitto | 5:56c4f2f12ec0 | 320 | gb.display.drawLine(25,40,pMissiles[i][0], pMissiles[i][1]); |
Pokitto | 5:56c4f2f12ec0 | 321 | }else{ |
Pokitto | 5:56c4f2f12ec0 | 322 | gb.display.drawLine(56,40,pMissiles[i][0], pMissiles[i][1]); |
Pokitto | 5:56c4f2f12ec0 | 323 | } |
Pokitto | 5:56c4f2f12ec0 | 324 | } |
Pokitto | 5:56c4f2f12ec0 | 325 | } |
Pokitto | 5:56c4f2f12ec0 | 326 | |
Pokitto | 5:56c4f2f12ec0 | 327 | //Enemy Missiles |
Pokitto | 5:56c4f2f12ec0 | 328 | gb.display.setColor(3); |
Pokitto | 5:56c4f2f12ec0 | 329 | for(uint8_t i = 0; i < MAX_EMISSILES; i++){ |
Pokitto | 5:56c4f2f12ec0 | 330 | //Check for a valid destination |
Pokitto | 5:56c4f2f12ec0 | 331 | if( eDests[i] <= 84 ){ |
Pokitto | 5:56c4f2f12ec0 | 332 | gb.display.drawLine(eMissiles[i][0],eMissiles[i][1],eMissiles[i][2], eMissiles[i][3]); |
Pokitto | 5:56c4f2f12ec0 | 333 | } |
Pokitto | 5:56c4f2f12ec0 | 334 | } |
Pokitto | 5:56c4f2f12ec0 | 335 | gb.display.setColor(1); |
Pokitto | 5:56c4f2f12ec0 | 336 | } |
Pokitto | 5:56c4f2f12ec0 | 337 | |
Pokitto | 5:56c4f2f12ec0 | 338 | void drawDetonations(){ |
Pokitto | 5:56c4f2f12ec0 | 339 | for(uint8_t i = 0; i < MAX_PMISSILES; i++){ |
Pokitto | 5:56c4f2f12ec0 | 340 | if( pDetonations[i][0] <= 84 ){ |
Pokitto | 5:56c4f2f12ec0 | 341 | gb.display.drawCircle(pDetonations[i][0],pDetonations[i][1],pDetonations[i][2]); |
Pokitto | 5:56c4f2f12ec0 | 342 | } |
Pokitto | 5:56c4f2f12ec0 | 343 | } |
Pokitto | 5:56c4f2f12ec0 | 344 | } |
Pokitto | 5:56c4f2f12ec0 | 345 | |
Pokitto | 5:56c4f2f12ec0 | 346 | void launchMissile(uint8_t launcher){ |
Pokitto | 5:56c4f2f12ec0 | 347 | //If there is no free slot in pDests, do not launch |
Pokitto | 5:56c4f2f12ec0 | 348 | for(uint8_t i = 0; i < MAX_PMISSILES; i++){ |
Pokitto | 5:56c4f2f12ec0 | 349 | if( pDests[i][0] > 84 ){ |
Pokitto | 5:56c4f2f12ec0 | 350 | // Which launcher? Alive? Has ammo? |
Pokitto | 5:56c4f2f12ec0 | 351 | if(launcher == LAUNCHER_ONE && cities[2] && pammo[0]){ |
Pokitto | 5:56c4f2f12ec0 | 352 | pDests[i][0] = targetX; |
Pokitto | 5:56c4f2f12ec0 | 353 | pDests[i][1] = targetY; |
Pokitto | 5:56c4f2f12ec0 | 354 | pMissiles[i][0] = 25; //X-coord of left launcher |
Pokitto | 5:56c4f2f12ec0 | 355 | pMissiles[i][2] = LAUNCHER_ONE; //Launched from launcher one |
Pokitto | 5:56c4f2f12ec0 | 356 | pammo[0]--; |
Pokitto | 5:56c4f2f12ec0 | 357 | playSound(SOUND_PLAUNCH); |
Pokitto | 5:56c4f2f12ec0 | 358 | }else if(launcher == LAUNCHER_TWO && cities[5] && pammo[1]){ |
Pokitto | 5:56c4f2f12ec0 | 359 | pDests[i][0] = targetX; |
Pokitto | 5:56c4f2f12ec0 | 360 | pDests[i][1] = targetY; |
Pokitto | 5:56c4f2f12ec0 | 361 | pMissiles[i][0] = 56; //X-coord of right launcher |
Pokitto | 5:56c4f2f12ec0 | 362 | pMissiles[i][2] = LAUNCHER_TWO; //Launched from launcher two |
Pokitto | 5:56c4f2f12ec0 | 363 | pammo[1]--; |
Pokitto | 5:56c4f2f12ec0 | 364 | playSound(SOUND_PLAUNCH); |
Pokitto | 5:56c4f2f12ec0 | 365 | } |
Pokitto | 5:56c4f2f12ec0 | 366 | pMissiles[i][1] = 40; //Y-coord of both launchers |
Pokitto | 5:56c4f2f12ec0 | 367 | break; |
Pokitto | 5:56c4f2f12ec0 | 368 | } |
Pokitto | 5:56c4f2f12ec0 | 369 | } |
Pokitto | 5:56c4f2f12ec0 | 370 | } |
Pokitto | 5:56c4f2f12ec0 | 371 | |
Pokitto | 5:56c4f2f12ec0 | 372 | void tryLaunchEnemy(){ |
Pokitto | 5:56c4f2f12ec0 | 373 | uint8_t someActive = 0; |
Pokitto | 5:56c4f2f12ec0 | 374 | |
Pokitto | 5:56c4f2f12ec0 | 375 | if( etotal > 0 ){ |
Pokitto | 5:56c4f2f12ec0 | 376 | |
Pokitto | 5:56c4f2f12ec0 | 377 | // Check whether there are any active missiles |
Pokitto | 5:56c4f2f12ec0 | 378 | // If none are active, always spawn one to avoid |
Pokitto | 5:56c4f2f12ec0 | 379 | // long pauses without any enemy missiles |
Pokitto | 5:56c4f2f12ec0 | 380 | for(uint8_t i = 0; i < MAX_EMISSILES; i++){ |
Pokitto | 5:56c4f2f12ec0 | 381 | if( eDests[i] <= 84 ){ |
Pokitto | 5:56c4f2f12ec0 | 382 | someActive = 1; |
Pokitto | 5:56c4f2f12ec0 | 383 | break; |
Pokitto | 5:56c4f2f12ec0 | 384 | } |
Pokitto | 5:56c4f2f12ec0 | 385 | } |
Pokitto | 5:56c4f2f12ec0 | 386 | |
Pokitto | 5:56c4f2f12ec0 | 387 | if( (!someActive || echance >= random(100)) ){ //echance of 100 |
Pokitto | 5:56c4f2f12ec0 | 388 | for(uint8_t i = 0; i < MAX_EMISSILES; i++){ |
Pokitto | 5:56c4f2f12ec0 | 389 | if( eDests[i] > 84 ){ |
Pokitto | 5:56c4f2f12ec0 | 390 | etotal--; |
Pokitto | 5:56c4f2f12ec0 | 391 | eDests[i] = random(8); //Target one of the 6 cities or 2 launch sites |
Pokitto | 5:56c4f2f12ec0 | 392 | eMissiles[i][0] = random(84); //Screen width |
Pokitto | 5:56c4f2f12ec0 | 393 | eMissiles[i][1] = 0; //Top of screen |
Pokitto | 5:56c4f2f12ec0 | 394 | eMissiles[i][2] = eMissiles[i][0]; //Start and end are same |
Pokitto | 5:56c4f2f12ec0 | 395 | eMissiles[i][3] = 0; //Top of screen |
Pokitto | 5:56c4f2f12ec0 | 396 | playSound(SOUND_ELAUNCH); |
Pokitto | 5:56c4f2f12ec0 | 397 | break; //Only spawn one |
Pokitto | 5:56c4f2f12ec0 | 398 | } |
Pokitto | 5:56c4f2f12ec0 | 399 | } |
Pokitto | 5:56c4f2f12ec0 | 400 | } |
Pokitto | 5:56c4f2f12ec0 | 401 | |
Pokitto | 5:56c4f2f12ec0 | 402 | } |
Pokitto | 5:56c4f2f12ec0 | 403 | } |
Pokitto | 5:56c4f2f12ec0 | 404 | |
Pokitto | 5:56c4f2f12ec0 | 405 | void stepMissiles(){ |
Pokitto | 5:56c4f2f12ec0 | 406 | //Player Missiles |
Pokitto | 5:56c4f2f12ec0 | 407 | for(uint8_t i = 0; i < MAX_PMISSILES; i++){ |
Pokitto | 5:56c4f2f12ec0 | 408 | //Check for a valid destination without a current detonation |
Pokitto | 5:56c4f2f12ec0 | 409 | if( pDests[i][0] <= 84 && pDetonations[i][0] > 84 ){ |
Pokitto | 5:56c4f2f12ec0 | 410 | //If the missile is close enough to the destination, detonate |
Pokitto | 5:56c4f2f12ec0 | 411 | if( abs( pDests[i][0] - pMissiles[i][0] ) < PSPEED && abs( pDests[i][1] - pMissiles[i][1] ) < PSPEED ){ |
Pokitto | 5:56c4f2f12ec0 | 412 | pDetonations[i][0] = pDests[i][0]; |
Pokitto | 5:56c4f2f12ec0 | 413 | pDetonations[i][1] = pDests[i][1]; |
Pokitto | 5:56c4f2f12ec0 | 414 | pDetonations[i][2] = 0; //Start detonation at radius of 0 |
Pokitto | 5:56c4f2f12ec0 | 415 | pDetonations[i][3] = EXPAND; //Detonation is increasing in size |
Pokitto | 5:56c4f2f12ec0 | 416 | //Otherwise, keep moving towards destination |
Pokitto | 5:56c4f2f12ec0 | 417 | }else{ |
Pokitto | 5:56c4f2f12ec0 | 418 | float dir = atan2(pDests[i][1]-pMissiles[i][1], pDests[i][0]-pMissiles[i][0]); |
Pokitto | 5:56c4f2f12ec0 | 419 | pMissiles[i][0] += PSPEED * cos(dir); |
Pokitto | 5:56c4f2f12ec0 | 420 | pMissiles[i][1] += PSPEED * sin(dir); |
Pokitto | 5:56c4f2f12ec0 | 421 | } |
Pokitto | 5:56c4f2f12ec0 | 422 | } |
Pokitto | 5:56c4f2f12ec0 | 423 | } |
Pokitto | 5:56c4f2f12ec0 | 424 | |
Pokitto | 5:56c4f2f12ec0 | 425 | //Enemy Missiles |
Pokitto | 5:56c4f2f12ec0 | 426 | for(uint8_t i = 0; i < MAX_EMISSILES; i++){ |
Pokitto | 5:56c4f2f12ec0 | 427 | //Check for a valid destination |
Pokitto | 5:56c4f2f12ec0 | 428 | if( eDests[i] <= 84 ){ |
Pokitto | 5:56c4f2f12ec0 | 429 | //If enemy missile is close enough to the destination, detonate |
Pokitto | 5:56c4f2f12ec0 | 430 | if( abs( (eDests[i]*10+6) - eMissiles[i][2] ) < PSPEED && abs( 44 - eMissiles[i][3] ) < PSPEED ){ |
Pokitto | 5:56c4f2f12ec0 | 431 | cities[eDests[i]] = 0; //Destroy city/launcher |
Pokitto | 5:56c4f2f12ec0 | 432 | |
Pokitto | 5:56c4f2f12ec0 | 433 | //If launcher, remove its ammo |
Pokitto | 5:56c4f2f12ec0 | 434 | if( eDests[i] == 2 ){ |
Pokitto | 5:56c4f2f12ec0 | 435 | pammo[0] = 0; |
Pokitto | 5:56c4f2f12ec0 | 436 | } |
Pokitto | 5:56c4f2f12ec0 | 437 | if( eDests[i] == 5 ){ |
Pokitto | 5:56c4f2f12ec0 | 438 | pammo[1] = 0; |
Pokitto | 5:56c4f2f12ec0 | 439 | } |
Pokitto | 5:56c4f2f12ec0 | 440 | |
Pokitto | 5:56c4f2f12ec0 | 441 | eDests[i] = 100; //Reset enemy missile |
Pokitto | 5:56c4f2f12ec0 | 442 | playSound(SOUND_DEAD); |
Pokitto | 5:56c4f2f12ec0 | 443 | //Otherwise, keep moving towards destination |
Pokitto | 5:56c4f2f12ec0 | 444 | }else{ |
Pokitto | 5:56c4f2f12ec0 | 445 | float dir = atan2( 44-eMissiles[i][3], (eDests[i]*10+6)-eMissiles[i][2] ); |
Pokitto | 5:56c4f2f12ec0 | 446 | eMissiles[i][2] += espeed * cos(dir); |
Pokitto | 5:56c4f2f12ec0 | 447 | eMissiles[i][3] += espeed * sin(dir); |
Pokitto | 5:56c4f2f12ec0 | 448 | } |
Pokitto | 5:56c4f2f12ec0 | 449 | } |
Pokitto | 5:56c4f2f12ec0 | 450 | } |
Pokitto | 5:56c4f2f12ec0 | 451 | } |
Pokitto | 5:56c4f2f12ec0 | 452 | |
Pokitto | 5:56c4f2f12ec0 | 453 | void stepDetonations(){ |
Pokitto | 5:56c4f2f12ec0 | 454 | if( counter%2 == 0 ){ |
Pokitto | 5:56c4f2f12ec0 | 455 | for(uint8_t i = 0; i < MAX_PMISSILES; i++){ |
Pokitto | 5:56c4f2f12ec0 | 456 | if( pDetonations[i][0] <= 84 ){ |
Pokitto | 5:56c4f2f12ec0 | 457 | if( pDetonations[i][3] == EXPAND ){ //If detonation is expanding |
Pokitto | 5:56c4f2f12ec0 | 458 | if( pDetonations[i][2] < PRADIUS ){ |
Pokitto | 5:56c4f2f12ec0 | 459 | pDetonations[i][2]++; |
Pokitto | 5:56c4f2f12ec0 | 460 | }else{ |
Pokitto | 5:56c4f2f12ec0 | 461 | pDetonations[i][3] = SHRINK; //Start shrinking |
Pokitto | 5:56c4f2f12ec0 | 462 | } |
Pokitto | 5:56c4f2f12ec0 | 463 | } |
Pokitto | 5:56c4f2f12ec0 | 464 | //Check this now instead of using else because it may have just |
Pokitto | 5:56c4f2f12ec0 | 465 | //set to SHRINK; immediately checking will remove a delay at full |
Pokitto | 5:56c4f2f12ec0 | 466 | //size. If a delay is desired, this if can be switched to an else. |
Pokitto | 5:56c4f2f12ec0 | 467 | if( pDetonations[i][3] == SHRINK ){ //If detonation is shrinking |
Pokitto | 5:56c4f2f12ec0 | 468 | if( pDetonations[i][2] > 0 ){ |
Pokitto | 5:56c4f2f12ec0 | 469 | pDetonations[i][2]--; |
Pokitto | 5:56c4f2f12ec0 | 470 | }else{ |
Pokitto | 5:56c4f2f12ec0 | 471 | pDetonations[i][0] = 100; //Detonation is complete, remove it |
Pokitto | 5:56c4f2f12ec0 | 472 | pDests[i][0] = 100; //Remove this destination |
Pokitto | 5:56c4f2f12ec0 | 473 | } |
Pokitto | 5:56c4f2f12ec0 | 474 | } |
Pokitto | 5:56c4f2f12ec0 | 475 | } |
Pokitto | 5:56c4f2f12ec0 | 476 | } |
Pokitto | 5:56c4f2f12ec0 | 477 | } |
Pokitto | 5:56c4f2f12ec0 | 478 | } |
Pokitto | 5:56c4f2f12ec0 | 479 | |
Pokitto | 5:56c4f2f12ec0 | 480 | void stepCollision(){ |
Pokitto | 5:56c4f2f12ec0 | 481 | //Player Detonations with Enemy Missiles |
Pokitto | 5:56c4f2f12ec0 | 482 | for(uint8_t i = 0; i < MAX_PMISSILES; i++){ |
Pokitto | 5:56c4f2f12ec0 | 483 | if( pDetonations[i][0] <= 84 ){ |
Pokitto | 5:56c4f2f12ec0 | 484 | for(uint8_t j = 0; j < MAX_EMISSILES; j++){ |
Pokitto | 5:56c4f2f12ec0 | 485 | if( eDests[j] <= 84 && pDetonations[i][2] >= sqrt( (eMissiles[j][2]-pDetonations[i][0])*(eMissiles[j][2]-pDetonations[i][0]) + (eMissiles[j][3]-pDetonations[i][1])*(eMissiles[j][3]-pDetonations[i][1]) ) ){ |
Pokitto | 5:56c4f2f12ec0 | 486 | eDests[j] = 100; //Remove enemy missile |
Pokitto | 5:56c4f2f12ec0 | 487 | score+=25; |
Pokitto | 5:56c4f2f12ec0 | 488 | playSound(SOUND_DETONATE); |
Pokitto | 5:56c4f2f12ec0 | 489 | } |
Pokitto | 5:56c4f2f12ec0 | 490 | } |
Pokitto | 5:56c4f2f12ec0 | 491 | } |
Pokitto | 5:56c4f2f12ec0 | 492 | } |
Pokitto | 5:56c4f2f12ec0 | 493 | } |
Pokitto | 5:56c4f2f12ec0 | 494 | |
Pokitto | 5:56c4f2f12ec0 | 495 | |
Pokitto | 5:56c4f2f12ec0 | 496 | void checkMenu(){ |
Pokitto | 5:56c4f2f12ec0 | 497 | if( gb.buttons.pressed(BTN_C) ){ |
Pokitto | 5:56c4f2f12ec0 | 498 | gb.titleScreen(armageddon); |
Pokitto | 5:56c4f2f12ec0 | 499 | gb.battery.show = false; |
Pokitto | 5:56c4f2f12ec0 | 500 | } |
Pokitto | 5:56c4f2f12ec0 | 501 | } |
Pokitto | 5:56c4f2f12ec0 | 502 | |
Pokitto | 5:56c4f2f12ec0 | 503 | void checkWin(){ |
Pokitto | 5:56c4f2f12ec0 | 504 | if( etotal == 0 ){ |
Pokitto | 5:56c4f2f12ec0 | 505 | for(uint8_t i = 0; i < MAX_EMISSILES; i++){ |
Pokitto | 5:56c4f2f12ec0 | 506 | //Check for a valid destination |
Pokitto | 5:56c4f2f12ec0 | 507 | if( eDests[i] <= 84 ){ |
Pokitto | 5:56c4f2f12ec0 | 508 | return; |
Pokitto | 5:56c4f2f12ec0 | 509 | } |
Pokitto | 5:56c4f2f12ec0 | 510 | } |
Pokitto | 5:56c4f2f12ec0 | 511 | //If we get here, all enemy missiles are destroyed and they have no more |
Pokitto | 5:56c4f2f12ec0 | 512 | nextLull(); |
Pokitto | 5:56c4f2f12ec0 | 513 | mode = MODE_LULL; |
Pokitto | 5:56c4f2f12ec0 | 514 | } |
Pokitto | 5:56c4f2f12ec0 | 515 | } |
Pokitto | 5:56c4f2f12ec0 | 516 | |
Pokitto | 5:56c4f2f12ec0 | 517 | void checkLose(){ |
Pokitto | 5:56c4f2f12ec0 | 518 | for(uint8_t i = 0; i < 8; i++){ |
Pokitto | 5:56c4f2f12ec0 | 519 | if( i != 2 && i != 5 ){ |
Pokitto | 5:56c4f2f12ec0 | 520 | if( cities[i] ){ |
Pokitto | 5:56c4f2f12ec0 | 521 | return; // A city remains alive |
Pokitto | 5:56c4f2f12ec0 | 522 | } |
Pokitto | 5:56c4f2f12ec0 | 523 | } |
Pokitto | 5:56c4f2f12ec0 | 524 | } |
Pokitto | 5:56c4f2f12ec0 | 525 | //If we get here, all cities are dead. It is the end of days. |
Pokitto | 5:56c4f2f12ec0 | 526 | counter = 0; |
Pokitto | 5:56c4f2f12ec0 | 527 | mode = MODE_DEAD; |
Pokitto | 5:56c4f2f12ec0 | 528 | playSound(SOUND_LOSE); |
Pokitto | 5:56c4f2f12ec0 | 529 | } |
Pokitto | 5:56c4f2f12ec0 | 530 | |
Pokitto | 5:56c4f2f12ec0 | 531 | void stepGame(){ |
Pokitto | 5:56c4f2f12ec0 | 532 | //Player input |
Pokitto | 5:56c4f2f12ec0 | 533 | if( gb.buttons.pressed(BTN_A) ){ |
HomineLudens | 6:22d706e5dd6e | 534 | launchMissile(LAUNCHER_TWO); |
Pokitto | 5:56c4f2f12ec0 | 535 | } |
Pokitto | 5:56c4f2f12ec0 | 536 | if( gb.buttons.pressed(BTN_B) ){ |
HomineLudens | 6:22d706e5dd6e | 537 | launchMissile(LAUNCHER_ONE); |
Pokitto | 5:56c4f2f12ec0 | 538 | } |
Pokitto | 5:56c4f2f12ec0 | 539 | |
Pokitto | 5:56c4f2f12ec0 | 540 | if( gb.buttons.repeat(BTN_LEFT,1) ){ |
Pokitto | 5:56c4f2f12ec0 | 541 | targetX = targetX-TARGET_SPEED > 0 ? targetX-TARGET_SPEED : 0; |
Pokitto | 5:56c4f2f12ec0 | 542 | } |
Pokitto | 5:56c4f2f12ec0 | 543 | if( gb.buttons.repeat(BTN_RIGHT,1) ){ |
Pokitto | 5:56c4f2f12ec0 | 544 | targetX = targetX+TARGET_SPEED < 84 ? targetX+TARGET_SPEED : 84; |
Pokitto | 5:56c4f2f12ec0 | 545 | } |
Pokitto | 5:56c4f2f12ec0 | 546 | if( gb.buttons.repeat(BTN_UP,1) ){ |
Pokitto | 5:56c4f2f12ec0 | 547 | targetY = targetY-TARGET_SPEED > 0 ? targetY-TARGET_SPEED : 0; |
Pokitto | 5:56c4f2f12ec0 | 548 | } |
Pokitto | 5:56c4f2f12ec0 | 549 | if( gb.buttons.repeat(BTN_DOWN,1) ){ |
Pokitto | 5:56c4f2f12ec0 | 550 | targetY = targetY+TARGET_SPEED < 48 ? targetY+TARGET_SPEED : 48; |
Pokitto | 5:56c4f2f12ec0 | 551 | } |
Pokitto | 5:56c4f2f12ec0 | 552 | |
Pokitto | 5:56c4f2f12ec0 | 553 | //Game logic |
Pokitto | 5:56c4f2f12ec0 | 554 | tryLaunchEnemy(); |
Pokitto | 5:56c4f2f12ec0 | 555 | stepMissiles(); |
Pokitto | 5:56c4f2f12ec0 | 556 | stepDetonations(); |
Pokitto | 5:56c4f2f12ec0 | 557 | stepCollision(); |
Pokitto | 5:56c4f2f12ec0 | 558 | |
Pokitto | 5:56c4f2f12ec0 | 559 | //Drawing |
Pokitto | 5:56c4f2f12ec0 | 560 | drawScore(); |
Pokitto | 5:56c4f2f12ec0 | 561 | drawTargets(); |
Pokitto | 5:56c4f2f12ec0 | 562 | drawCities(); |
Pokitto | 5:56c4f2f12ec0 | 563 | drawAmmo(); |
Pokitto | 5:56c4f2f12ec0 | 564 | drawMissiles(); |
Pokitto | 5:56c4f2f12ec0 | 565 | drawDetonations(); |
Pokitto | 5:56c4f2f12ec0 | 566 | |
Pokitto | 5:56c4f2f12ec0 | 567 | checkWin(); |
Pokitto | 5:56c4f2f12ec0 | 568 | checkLose(); |
Pokitto | 5:56c4f2f12ec0 | 569 | } |
Pokitto | 5:56c4f2f12ec0 | 570 | |
Pokitto | 5:56c4f2f12ec0 | 571 | void drawLull(){ |
Pokitto | 5:56c4f2f12ec0 | 572 | uint8_t cityCount = 0; |
Pokitto | 5:56c4f2f12ec0 | 573 | gb.display.cursorX = 84/2 - 4*6; |
Pokitto | 5:56c4f2f12ec0 | 574 | gb.display.cursorY = 48/2 - 5*3; |
Pokitto | 5:56c4f2f12ec0 | 575 | gb.display.print(("BONUS POINTS")); |
Pokitto | 5:56c4f2f12ec0 | 576 | |
Pokitto | 5:56c4f2f12ec0 | 577 | gb.display.cursorX = 84/2 - 4*8; |
Pokitto | 5:56c4f2f12ec0 | 578 | gb.display.cursorY += 5*2; |
Pokitto | 5:56c4f2f12ec0 | 579 | gb.display.print(lullMissiles); |
Pokitto | 5:56c4f2f12ec0 | 580 | |
Pokitto | 5:56c4f2f12ec0 | 581 | for(uint8_t i = 0; i < lullMissiles; i++){ |
Pokitto | 5:56c4f2f12ec0 | 582 | gb.display.drawPixel(84/2 - 4*6 + i*2,48/2 - 3); |
Pokitto | 5:56c4f2f12ec0 | 583 | } |
Pokitto | 5:56c4f2f12ec0 | 584 | |
Pokitto | 5:56c4f2f12ec0 | 585 | gb.display.cursorX = 84/2 - 4*8; |
Pokitto | 5:56c4f2f12ec0 | 586 | gb.display.cursorY += 5*2; |
Pokitto | 5:56c4f2f12ec0 | 587 | for( uint8_t i; i < 8; i++ ){ |
Pokitto | 5:56c4f2f12ec0 | 588 | if( lullCities[i] ) cityCount++; |
Pokitto | 5:56c4f2f12ec0 | 589 | } |
Pokitto | 5:56c4f2f12ec0 | 590 | gb.display.print(cityCount); |
Pokitto | 5:56c4f2f12ec0 | 591 | |
Pokitto | 5:56c4f2f12ec0 | 592 | for(uint8_t i = 0; i < cityCount; i++){ |
Pokitto | 5:56c4f2f12ec0 | 593 | gb.display.drawBitmap(84/2 - 4*6 + i*9,48/2+2, city); |
Pokitto | 5:56c4f2f12ec0 | 594 | } |
Pokitto | 5:56c4f2f12ec0 | 595 | |
Pokitto | 5:56c4f2f12ec0 | 596 | drawScore(); |
Pokitto | 5:56c4f2f12ec0 | 597 | drawCities(); |
Pokitto | 5:56c4f2f12ec0 | 598 | drawAmmo(); |
Pokitto | 5:56c4f2f12ec0 | 599 | } |
Pokitto | 5:56c4f2f12ec0 | 600 | |
Pokitto | 5:56c4f2f12ec0 | 601 | void stepLull(){ |
Pokitto | 5:56c4f2f12ec0 | 602 | |
Pokitto | 5:56c4f2f12ec0 | 603 | if( counter % 4 == 0 && (pammo[0] > 0 || pammo[1] > 0) ){ |
Pokitto | 5:56c4f2f12ec0 | 604 | lullMissiles++; |
Pokitto | 5:56c4f2f12ec0 | 605 | score+=10; |
Pokitto | 5:56c4f2f12ec0 | 606 | if( pammo[0] > 0 ) pammo[0]--; |
Pokitto | 5:56c4f2f12ec0 | 607 | else pammo[1]--; |
Pokitto | 5:56c4f2f12ec0 | 608 | playSound(SOUND_SCORE); |
Pokitto | 5:56c4f2f12ec0 | 609 | } |
Pokitto | 5:56c4f2f12ec0 | 610 | |
Pokitto | 5:56c4f2f12ec0 | 611 | //If we have already iterated through the missiles |
Pokitto | 5:56c4f2f12ec0 | 612 | if( counter % 8 == 0 && pammo[0] == 0 && pammo[1] == 0 ){ |
Pokitto | 5:56c4f2f12ec0 | 613 | for( uint8_t i = 0; i < 9; i++ ){ |
Pokitto | 5:56c4f2f12ec0 | 614 | if( i == 8 ){ //We have iterated through all live cities |
Pokitto | 5:56c4f2f12ec0 | 615 | nextStage(); |
Pokitto | 5:56c4f2f12ec0 | 616 | mode = MODE_GAME; |
Pokitto | 5:56c4f2f12ec0 | 617 | return; |
Pokitto | 5:56c4f2f12ec0 | 618 | } |
Pokitto | 5:56c4f2f12ec0 | 619 | //If not a launcher and the city is alive |
Pokitto | 5:56c4f2f12ec0 | 620 | if( i != 2 && i != 5 && cities[i] != 0 ){ |
Pokitto | 5:56c4f2f12ec0 | 621 | lullCities[i] = 1; |
Pokitto | 5:56c4f2f12ec0 | 622 | score+=100; |
Pokitto | 5:56c4f2f12ec0 | 623 | cities[i] = 0; |
Pokitto | 5:56c4f2f12ec0 | 624 | playSound(SOUND_SCORE); |
Pokitto | 5:56c4f2f12ec0 | 625 | break; |
Pokitto | 5:56c4f2f12ec0 | 626 | } |
Pokitto | 5:56c4f2f12ec0 | 627 | } |
Pokitto | 5:56c4f2f12ec0 | 628 | } |
Pokitto | 5:56c4f2f12ec0 | 629 | |
Pokitto | 5:56c4f2f12ec0 | 630 | drawLull(); |
Pokitto | 5:56c4f2f12ec0 | 631 | } |
Pokitto | 5:56c4f2f12ec0 | 632 | |
Pokitto | 5:56c4f2f12ec0 | 633 | void stepDead(){ |
Pokitto | 5:56c4f2f12ec0 | 634 | gb.display.cursorX = 84/2 - 5*3; |
Pokitto | 5:56c4f2f12ec0 | 635 | gb.display.cursorY = 48/2 - 5; |
Pokitto | 5:56c4f2f12ec0 | 636 | gb.display.print(("THE END")); |
Pokitto | 5:56c4f2f12ec0 | 637 | |
Pokitto | 5:56c4f2f12ec0 | 638 | if( mode == MODE_DEAD && counter%20 == 0 ){ |
Pokitto | 5:56c4f2f12ec0 | 639 | mode = MODE_POSTDEAD; |
Pokitto | 5:56c4f2f12ec0 | 640 | }else if( mode == MODE_POSTDEAD ){ |
Pokitto | 5:56c4f2f12ec0 | 641 | if( counter%8 == 0 ){ |
Pokitto | 5:56c4f2f12ec0 | 642 | flash ^= 255; |
Pokitto | 5:56c4f2f12ec0 | 643 | } |
Pokitto | 5:56c4f2f12ec0 | 644 | if( flash ){ |
Pokitto | 5:56c4f2f12ec0 | 645 | gb.display.cursorX = 84/2 - 5*3; |
Pokitto | 5:56c4f2f12ec0 | 646 | gb.display.cursorY = 48 - 9; |
Pokitto | 5:56c4f2f12ec0 | 647 | gb.display.print(("PRESS \25")); |
Pokitto | 5:56c4f2f12ec0 | 648 | |
Pokitto | 5:56c4f2f12ec0 | 649 | if( isHighscore(score) ){ |
Pokitto | 5:56c4f2f12ec0 | 650 | gb.display.cursorX = 84/2 - 5*5 - 2; |
Pokitto | 5:56c4f2f12ec0 | 651 | gb.display.cursorY = 48 - 15; |
Pokitto | 5:56c4f2f12ec0 | 652 | gb.display.print(("NEW HIGHSCORE")); |
Pokitto | 5:56c4f2f12ec0 | 653 | } |
Pokitto | 5:56c4f2f12ec0 | 654 | } |
Pokitto | 5:56c4f2f12ec0 | 655 | |
Pokitto | 5:56c4f2f12ec0 | 656 | if( gb.buttons.pressed(BTN_A) ){ |
Pokitto | 5:56c4f2f12ec0 | 657 | if( isHighscore(score) ){ |
Pokitto | 5:56c4f2f12ec0 | 658 | char tmp_name[11]; |
Pokitto | 5:56c4f2f12ec0 | 659 | //gb.getDefaultName(tmp_name); |
Pokitto | 5:56c4f2f12ec0 | 660 | gb.keyboard(tmp_name, 11); |
Pokitto | 5:56c4f2f12ec0 | 661 | //saveHighscore(score,tmp_name); |
Pokitto | 5:56c4f2f12ec0 | 662 | } |
Pokitto | 5:56c4f2f12ec0 | 663 | score = 0; |
Pokitto | 5:56c4f2f12ec0 | 664 | mode = MODE_PREGAME; |
Pokitto | 5:56c4f2f12ec0 | 665 | } |
Pokitto | 5:56c4f2f12ec0 | 666 | } |
Pokitto | 5:56c4f2f12ec0 | 667 | } |
Pokitto | 5:56c4f2f12ec0 | 668 | |
Pokitto | 5:56c4f2f12ec0 | 669 | void stepPregame(){ |
Pokitto | 5:56c4f2f12ec0 | 670 | drawHighscores(); |
Pokitto | 5:56c4f2f12ec0 | 671 | |
Pokitto | 5:56c4f2f12ec0 | 672 | if( counter%8 == 0 ){ |
Pokitto | 5:56c4f2f12ec0 | 673 | flash ^= 255; |
Pokitto | 5:56c4f2f12ec0 | 674 | } |
Pokitto | 5:56c4f2f12ec0 | 675 | if( flash ){ |
Pokitto | 5:56c4f2f12ec0 | 676 | gb.display.cursorX = 84/2 - 5*3; |
Pokitto | 5:56c4f2f12ec0 | 677 | gb.display.cursorY = 48 - 9; |
Pokitto | 5:56c4f2f12ec0 | 678 | gb.display.print(("PRESS \25")); |
Pokitto | 5:56c4f2f12ec0 | 679 | } |
Pokitto | 5:56c4f2f12ec0 | 680 | |
Pokitto | 5:56c4f2f12ec0 | 681 | if( gb.buttons.pressed(BTN_A) ){ |
Pokitto | 5:56c4f2f12ec0 | 682 | stage = 255; |
Pokitto | 5:56c4f2f12ec0 | 683 | for( uint8_t i = 0; i < 8; i++ ){ |
Pokitto | 5:56c4f2f12ec0 | 684 | lullCities[i] = 1; |
Pokitto | 5:56c4f2f12ec0 | 685 | } |
Pokitto | 5:56c4f2f12ec0 | 686 | nextStage(); //Reset to stage 0 |
Pokitto | 5:56c4f2f12ec0 | 687 | mode = MODE_GAME; |
Pokitto | 5:56c4f2f12ec0 | 688 | } |
Pokitto | 5:56c4f2f12ec0 | 689 | } |
Pokitto | 5:56c4f2f12ec0 | 690 | |
Pokitto | 5:56c4f2f12ec0 | 691 | void loop() { |
Pokitto | 5:56c4f2f12ec0 | 692 | if(gb.update()){ |
Pokitto | 5:56c4f2f12ec0 | 693 | |
Pokitto | 5:56c4f2f12ec0 | 694 | switch( mode ){ |
Pokitto | 5:56c4f2f12ec0 | 695 | case MODE_GAME: |
Pokitto | 5:56c4f2f12ec0 | 696 | stepGame(); |
Pokitto | 5:56c4f2f12ec0 | 697 | break; |
Pokitto | 5:56c4f2f12ec0 | 698 | |
Pokitto | 5:56c4f2f12ec0 | 699 | case MODE_LULL: |
Pokitto | 5:56c4f2f12ec0 | 700 | stepLull(); |
Pokitto | 5:56c4f2f12ec0 | 701 | break; |
Pokitto | 5:56c4f2f12ec0 | 702 | |
Pokitto | 5:56c4f2f12ec0 | 703 | case MODE_DEAD: |
Pokitto | 5:56c4f2f12ec0 | 704 | case MODE_POSTDEAD: |
Pokitto | 5:56c4f2f12ec0 | 705 | stepDead(); |
Pokitto | 5:56c4f2f12ec0 | 706 | break; |
Pokitto | 5:56c4f2f12ec0 | 707 | |
Pokitto | 5:56c4f2f12ec0 | 708 | case MODE_PREGAME: |
Pokitto | 5:56c4f2f12ec0 | 709 | stepPregame(); |
Pokitto | 5:56c4f2f12ec0 | 710 | break; |
Pokitto | 5:56c4f2f12ec0 | 711 | } |
Pokitto | 5:56c4f2f12ec0 | 712 | |
Pokitto | 5:56c4f2f12ec0 | 713 | checkMenu(); |
Pokitto | 5:56c4f2f12ec0 | 714 | |
Pokitto | 5:56c4f2f12ec0 | 715 | counter++; |
Pokitto | 5:56c4f2f12ec0 | 716 | } |
Pokitto | 5:56c4f2f12ec0 | 717 | } |
Pokitto | 5:56c4f2f12ec0 | 718 | #define NUM_HIGHSCORES 5 |
Pokitto | 5:56c4f2f12ec0 | 719 | #define NAME_SIZE 10 |
Pokitto | 5:56c4f2f12ec0 | 720 | #define ENTRY_SIZE 15 |
Pokitto | 5:56c4f2f12ec0 | 721 | |
Pokitto | 5:56c4f2f12ec0 | 722 | uint32_t highscores[NUM_HIGHSCORES]; |
Pokitto | 5:56c4f2f12ec0 | 723 | char names[NUM_HIGHSCORES][NAME_SIZE+1]; |
Pokitto | 5:56c4f2f12ec0 | 724 | |
Pokitto | 5:56c4f2f12ec0 | 725 | void loadHighscores(){ |
Pokitto | 5:56c4f2f12ec0 | 726 | for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){ |
Pokitto | 5:56c4f2f12ec0 | 727 | for( uint8_t offset = 0; offset < ENTRY_SIZE; offset++ ){ |
Pokitto | 5:56c4f2f12ec0 | 728 | if( offset < NAME_SIZE ){ |
Pokitto | 5:56c4f2f12ec0 | 729 | //names[entry][offset] = EEPROM.read( ENTRY_SIZE * entry + offset ); |
Pokitto | 5:56c4f2f12ec0 | 730 | }else{ |
Pokitto | 5:56c4f2f12ec0 | 731 | uint8_t* addr = (uint8_t*) &highscores[entry]; |
Pokitto | 5:56c4f2f12ec0 | 732 | addr+=offset-NAME_SIZE; |
Pokitto | 5:56c4f2f12ec0 | 733 | //*addr = EEPROM.read( ENTRY_SIZE * entry + offset ); |
Pokitto | 5:56c4f2f12ec0 | 734 | } |
Pokitto | 5:56c4f2f12ec0 | 735 | } |
Pokitto | 5:56c4f2f12ec0 | 736 | } |
Pokitto | 5:56c4f2f12ec0 | 737 | } |
Pokitto | 5:56c4f2f12ec0 | 738 | |
Pokitto | 5:56c4f2f12ec0 | 739 | uint8_t isHighscore(uint32_t score){ |
Pokitto | 5:56c4f2f12ec0 | 740 | if( score > highscores[NUM_HIGHSCORES-1] ){ |
Pokitto | 5:56c4f2f12ec0 | 741 | return 1; |
Pokitto | 5:56c4f2f12ec0 | 742 | } |
Pokitto | 5:56c4f2f12ec0 | 743 | return 0; |
Pokitto | 5:56c4f2f12ec0 | 744 | } |
Pokitto | 5:56c4f2f12ec0 | 745 | |
Pokitto | 5:56c4f2f12ec0 | 746 | void saveHighscore(uint32_t score, char* who){ |
Pokitto | 5:56c4f2f12ec0 | 747 | uint8_t found = 0; |
Pokitto | 5:56c4f2f12ec0 | 748 | uint32_t tmp_score = 0; |
Pokitto | 5:56c4f2f12ec0 | 749 | char tmp_name[10]; |
Pokitto | 5:56c4f2f12ec0 | 750 | for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){ |
Pokitto | 5:56c4f2f12ec0 | 751 | if( score > highscores[entry] ){ |
Pokitto | 5:56c4f2f12ec0 | 752 | found = 1; |
Pokitto | 5:56c4f2f12ec0 | 753 | } |
Pokitto | 5:56c4f2f12ec0 | 754 | if( found ){ |
Pokitto | 5:56c4f2f12ec0 | 755 | tmp_score = highscores[entry]; |
Pokitto | 5:56c4f2f12ec0 | 756 | strcpy(tmp_name,names[entry]); |
Pokitto | 5:56c4f2f12ec0 | 757 | |
Pokitto | 5:56c4f2f12ec0 | 758 | highscores[entry] = score; |
Pokitto | 5:56c4f2f12ec0 | 759 | strcpy(names[entry], who); |
Pokitto | 5:56c4f2f12ec0 | 760 | |
Pokitto | 5:56c4f2f12ec0 | 761 | score = tmp_score; |
Pokitto | 5:56c4f2f12ec0 | 762 | strcpy(who, tmp_name); |
Pokitto | 5:56c4f2f12ec0 | 763 | } |
Pokitto | 5:56c4f2f12ec0 | 764 | } |
Pokitto | 5:56c4f2f12ec0 | 765 | for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){ |
Pokitto | 5:56c4f2f12ec0 | 766 | for( uint8_t offset = 0; offset < ENTRY_SIZE; offset++ ){ |
Pokitto | 5:56c4f2f12ec0 | 767 | if( offset < NAME_SIZE ){ |
Pokitto | 5:56c4f2f12ec0 | 768 | //EEPROM.write( ENTRY_SIZE * entry + offset, names[entry][offset] ); |
Pokitto | 5:56c4f2f12ec0 | 769 | }else{ |
Pokitto | 5:56c4f2f12ec0 | 770 | uint8_t* addr = (uint8_t*) &highscores[entry]; |
Pokitto | 5:56c4f2f12ec0 | 771 | addr+=offset-NAME_SIZE; |
Pokitto | 5:56c4f2f12ec0 | 772 | //EEPROM.write( ENTRY_SIZE * entry + offset, *addr ); |
Pokitto | 5:56c4f2f12ec0 | 773 | } |
Pokitto | 5:56c4f2f12ec0 | 774 | } |
Pokitto | 5:56c4f2f12ec0 | 775 | } |
Pokitto | 5:56c4f2f12ec0 | 776 | } |
Pokitto | 5:56c4f2f12ec0 | 777 | |
Pokitto | 5:56c4f2f12ec0 | 778 | void drawHighscores(){ |
Pokitto | 5:56c4f2f12ec0 | 779 | gb.display.cursorX = 84/2 - 5*4; |
Pokitto | 5:56c4f2f12ec0 | 780 | gb.display.cursorY = 5; |
Pokitto | 5:56c4f2f12ec0 | 781 | gb.display.print(("HIGHSCORES")); |
Pokitto | 5:56c4f2f12ec0 | 782 | |
Pokitto | 5:56c4f2f12ec0 | 783 | for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){ |
Pokitto | 5:56c4f2f12ec0 | 784 | gb.display.cursorX = 5; |
Pokitto | 5:56c4f2f12ec0 | 785 | gb.display.cursorY = 12 + 5*entry; |
Pokitto | 5:56c4f2f12ec0 | 786 | gb.display.print(names[entry]); |
Pokitto | 5:56c4f2f12ec0 | 787 | gb.display.print((" ")); |
Pokitto | 5:56c4f2f12ec0 | 788 | gb.display.cursorX = 84 - 5*6; |
Pokitto | 5:56c4f2f12ec0 | 789 | if( highscores[entry] < 100000 ){ |
Pokitto | 5:56c4f2f12ec0 | 790 | gb.display.print(0); |
Pokitto | 5:56c4f2f12ec0 | 791 | } |
Pokitto | 5:56c4f2f12ec0 | 792 | if( highscores[entry] < 10000 ){ |
Pokitto | 5:56c4f2f12ec0 | 793 | gb.display.print(0); |
Pokitto | 5:56c4f2f12ec0 | 794 | } |
Pokitto | 5:56c4f2f12ec0 | 795 | if( highscores[entry] < 1000 ){ |
Pokitto | 5:56c4f2f12ec0 | 796 | gb.display.print(0); |
Pokitto | 5:56c4f2f12ec0 | 797 | } |
Pokitto | 5:56c4f2f12ec0 | 798 | if( highscores[entry] < 100 ){ |
Pokitto | 5:56c4f2f12ec0 | 799 | gb.display.print(0); |
Pokitto | 5:56c4f2f12ec0 | 800 | } |
Pokitto | 5:56c4f2f12ec0 | 801 | if( highscores[entry] < 10 ){ |
Pokitto | 5:56c4f2f12ec0 | 802 | gb.display.print(0); |
Pokitto | 5:56c4f2f12ec0 | 803 | } |
Pokitto | 5:56c4f2f12ec0 | 804 | gb.display.print(highscores[entry]); |
Pokitto | 5:56c4f2f12ec0 | 805 | } |
Pokitto | 5:56c4f2f12ec0 | 806 | } |
Pokitto | 5:56c4f2f12ec0 | 807 | |
Pokitto | 5:56c4f2f12ec0 | 808 | // Wave, pitch, duration, arpeggio step duration, arpeggio step size |
Pokitto | 5:56c4f2f12ec0 | 809 | const int8_t sounds[][5] = { |
Pokitto | 5:56c4f2f12ec0 | 810 | { 0, 20, 5, 1, 1 }, //Player launch |
Pokitto | 5:56c4f2f12ec0 | 811 | { 0, 25, 5, 1, -1 }, //Enemy launch |
Pokitto | 5:56c4f2f12ec0 | 812 | { 1, 10, 5, 1, -1 }, //Detonating enemy missile |
Pokitto | 5:56c4f2f12ec0 | 813 | { 1, 10, 2, 0, 0 }, //Score pips |
Pokitto | 5:56c4f2f12ec0 | 814 | { 1, 2, 10, 1, -1 }, //A city dies |
Pokitto | 5:56c4f2f12ec0 | 815 | { 0, 20, 14, 3, -1 }, //Lose |
Pokitto | 5:56c4f2f12ec0 | 816 | }; |
Pokitto | 5:56c4f2f12ec0 | 817 | |
Pokitto | 5:56c4f2f12ec0 | 818 | void initSound(){ |
Pokitto | 5:56c4f2f12ec0 | 819 | gb.sound.command(CMD_VOLUME, 5, 0, 0); |
Pokitto | 5:56c4f2f12ec0 | 820 | gb.sound.command(CMD_SLIDE, 0, 0, 0); |
Pokitto | 5:56c4f2f12ec0 | 821 | } |
Pokitto | 5:56c4f2f12ec0 | 822 | |
Pokitto | 5:56c4f2f12ec0 | 823 | void playSound(uint8_t i){ |
Pokitto | 5:56c4f2f12ec0 | 824 | gb.sound.command(CMD_VOLUME, 5, 0, 0); |
Pokitto | 5:56c4f2f12ec0 | 825 | gb.sound.command(CMD_SLIDE, 0, 0, 0); |
Pokitto | 5:56c4f2f12ec0 | 826 | gb.sound.command(CMD_ARPEGGIO, sounds[i][3], sounds[i][4], 0); |
Pokitto | 5:56c4f2f12ec0 | 827 | gb.sound.command(CMD_INSTRUMENT, sounds[i][0], 0, 0); |
Pokitto | 5:56c4f2f12ec0 | 828 | gb.sound.playNote(sounds[i][1], sounds[i][2], 0); |
Pokitto | 5:56c4f2f12ec0 | 829 | |
Pokitto | 5:56c4f2f12ec0 | 830 | //gb.sound.playNote(20, 5, 0); |
Pokitto | 5:56c4f2f12ec0 | 831 | } |
Pokitto | 5:56c4f2f12ec0 | 832 | |
Pokitto | 5:56c4f2f12ec0 | 833 |