Armageddon - a missile commad clone by Wuuff, originally for Gamebuino. Conversion by Jonne

Dependencies:   PokittoLib

Fork of Asterocks by Pokitto Community Team

Committer:
Pokitto
Date:
Fri Oct 13 21:53:07 2017 +0000
Revision:
5:56c4f2f12ec0
Child:
6:22d706e5dd6e
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew 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(){
Pokitto 5:56c4f2f12ec0 294 for( uint8_t i = 0; i < 2; i++ ){
Pokitto 5:56c4f2f12ec0 295 uint8_t xcoord = i == 0 ? 25 : 55;
Pokitto 5:56c4f2f12ec0 296 uint8_t ycoord = 47;
Pokitto 5:56c4f2f12ec0 297 if( cities[i*3+2] ){ //Is launcher alive?
Pokitto 5:56c4f2f12ec0 298 for( uint8_t j = 0; j < pammo[i]; j++ ){
Pokitto 5:56c4f2f12ec0 299 gb.display.drawPixel(xcoord,ycoord);
Pokitto 5:56c4f2f12ec0 300 if( xcoord % 2 == 0 ){
Pokitto 5:56c4f2f12ec0 301 xcoord--;
Pokitto 5:56c4f2f12ec0 302 ycoord--;
Pokitto 5:56c4f2f12ec0 303 }else{
Pokitto 5:56c4f2f12ec0 304 xcoord++;
Pokitto 5:56c4f2f12ec0 305 }
Pokitto 5:56c4f2f12ec0 306 }
Pokitto 5:56c4f2f12ec0 307 }
Pokitto 5:56c4f2f12ec0 308 }
Pokitto 5:56c4f2f12ec0 309 }
Pokitto 5:56c4f2f12ec0 310
Pokitto 5:56c4f2f12ec0 311 void drawMissiles(){
Pokitto 5:56c4f2f12ec0 312 //Player Missiles
Pokitto 5:56c4f2f12ec0 313 gb.display.setColor(2);
Pokitto 5:56c4f2f12ec0 314 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
Pokitto 5:56c4f2f12ec0 315 //Check for a valid destination without a current detonation
Pokitto 5:56c4f2f12ec0 316 if( pDests[i][0] <= 84 && pDetonations[i][0] > 84 ){
Pokitto 5:56c4f2f12ec0 317 if(pMissiles[i][2] == LAUNCHER_ONE){
Pokitto 5:56c4f2f12ec0 318 gb.display.drawLine(25,40,pMissiles[i][0], pMissiles[i][1]);
Pokitto 5:56c4f2f12ec0 319 }else{
Pokitto 5:56c4f2f12ec0 320 gb.display.drawLine(56,40,pMissiles[i][0], pMissiles[i][1]);
Pokitto 5:56c4f2f12ec0 321 }
Pokitto 5:56c4f2f12ec0 322 }
Pokitto 5:56c4f2f12ec0 323 }
Pokitto 5:56c4f2f12ec0 324
Pokitto 5:56c4f2f12ec0 325 //Enemy Missiles
Pokitto 5:56c4f2f12ec0 326 gb.display.setColor(3);
Pokitto 5:56c4f2f12ec0 327 for(uint8_t i = 0; i < MAX_EMISSILES; i++){
Pokitto 5:56c4f2f12ec0 328 //Check for a valid destination
Pokitto 5:56c4f2f12ec0 329 if( eDests[i] <= 84 ){
Pokitto 5:56c4f2f12ec0 330 gb.display.drawLine(eMissiles[i][0],eMissiles[i][1],eMissiles[i][2], eMissiles[i][3]);
Pokitto 5:56c4f2f12ec0 331 }
Pokitto 5:56c4f2f12ec0 332 }
Pokitto 5:56c4f2f12ec0 333 gb.display.setColor(1);
Pokitto 5:56c4f2f12ec0 334 }
Pokitto 5:56c4f2f12ec0 335
Pokitto 5:56c4f2f12ec0 336 void drawDetonations(){
Pokitto 5:56c4f2f12ec0 337 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
Pokitto 5:56c4f2f12ec0 338 if( pDetonations[i][0] <= 84 ){
Pokitto 5:56c4f2f12ec0 339 gb.display.drawCircle(pDetonations[i][0],pDetonations[i][1],pDetonations[i][2]);
Pokitto 5:56c4f2f12ec0 340 }
Pokitto 5:56c4f2f12ec0 341 }
Pokitto 5:56c4f2f12ec0 342 }
Pokitto 5:56c4f2f12ec0 343
Pokitto 5:56c4f2f12ec0 344 void launchMissile(uint8_t launcher){
Pokitto 5:56c4f2f12ec0 345 //If there is no free slot in pDests, do not launch
Pokitto 5:56c4f2f12ec0 346 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
Pokitto 5:56c4f2f12ec0 347 if( pDests[i][0] > 84 ){
Pokitto 5:56c4f2f12ec0 348 // Which launcher? Alive? Has ammo?
Pokitto 5:56c4f2f12ec0 349 if(launcher == LAUNCHER_ONE && cities[2] && pammo[0]){
Pokitto 5:56c4f2f12ec0 350 pDests[i][0] = targetX;
Pokitto 5:56c4f2f12ec0 351 pDests[i][1] = targetY;
Pokitto 5:56c4f2f12ec0 352 pMissiles[i][0] = 25; //X-coord of left launcher
Pokitto 5:56c4f2f12ec0 353 pMissiles[i][2] = LAUNCHER_ONE; //Launched from launcher one
Pokitto 5:56c4f2f12ec0 354 pammo[0]--;
Pokitto 5:56c4f2f12ec0 355 playSound(SOUND_PLAUNCH);
Pokitto 5:56c4f2f12ec0 356 }else if(launcher == LAUNCHER_TWO && cities[5] && pammo[1]){
Pokitto 5:56c4f2f12ec0 357 pDests[i][0] = targetX;
Pokitto 5:56c4f2f12ec0 358 pDests[i][1] = targetY;
Pokitto 5:56c4f2f12ec0 359 pMissiles[i][0] = 56; //X-coord of right launcher
Pokitto 5:56c4f2f12ec0 360 pMissiles[i][2] = LAUNCHER_TWO; //Launched from launcher two
Pokitto 5:56c4f2f12ec0 361 pammo[1]--;
Pokitto 5:56c4f2f12ec0 362 playSound(SOUND_PLAUNCH);
Pokitto 5:56c4f2f12ec0 363 }
Pokitto 5:56c4f2f12ec0 364 pMissiles[i][1] = 40; //Y-coord of both launchers
Pokitto 5:56c4f2f12ec0 365 break;
Pokitto 5:56c4f2f12ec0 366 }
Pokitto 5:56c4f2f12ec0 367 }
Pokitto 5:56c4f2f12ec0 368 }
Pokitto 5:56c4f2f12ec0 369
Pokitto 5:56c4f2f12ec0 370 void tryLaunchEnemy(){
Pokitto 5:56c4f2f12ec0 371 uint8_t someActive = 0;
Pokitto 5:56c4f2f12ec0 372
Pokitto 5:56c4f2f12ec0 373 if( etotal > 0 ){
Pokitto 5:56c4f2f12ec0 374
Pokitto 5:56c4f2f12ec0 375 // Check whether there are any active missiles
Pokitto 5:56c4f2f12ec0 376 // If none are active, always spawn one to avoid
Pokitto 5:56c4f2f12ec0 377 // long pauses without any enemy missiles
Pokitto 5:56c4f2f12ec0 378 for(uint8_t i = 0; i < MAX_EMISSILES; i++){
Pokitto 5:56c4f2f12ec0 379 if( eDests[i] <= 84 ){
Pokitto 5:56c4f2f12ec0 380 someActive = 1;
Pokitto 5:56c4f2f12ec0 381 break;
Pokitto 5:56c4f2f12ec0 382 }
Pokitto 5:56c4f2f12ec0 383 }
Pokitto 5:56c4f2f12ec0 384
Pokitto 5:56c4f2f12ec0 385 if( (!someActive || echance >= random(100)) ){ //echance of 100
Pokitto 5:56c4f2f12ec0 386 for(uint8_t i = 0; i < MAX_EMISSILES; i++){
Pokitto 5:56c4f2f12ec0 387 if( eDests[i] > 84 ){
Pokitto 5:56c4f2f12ec0 388 etotal--;
Pokitto 5:56c4f2f12ec0 389 eDests[i] = random(8); //Target one of the 6 cities or 2 launch sites
Pokitto 5:56c4f2f12ec0 390 eMissiles[i][0] = random(84); //Screen width
Pokitto 5:56c4f2f12ec0 391 eMissiles[i][1] = 0; //Top of screen
Pokitto 5:56c4f2f12ec0 392 eMissiles[i][2] = eMissiles[i][0]; //Start and end are same
Pokitto 5:56c4f2f12ec0 393 eMissiles[i][3] = 0; //Top of screen
Pokitto 5:56c4f2f12ec0 394 playSound(SOUND_ELAUNCH);
Pokitto 5:56c4f2f12ec0 395 break; //Only spawn one
Pokitto 5:56c4f2f12ec0 396 }
Pokitto 5:56c4f2f12ec0 397 }
Pokitto 5:56c4f2f12ec0 398 }
Pokitto 5:56c4f2f12ec0 399
Pokitto 5:56c4f2f12ec0 400 }
Pokitto 5:56c4f2f12ec0 401 }
Pokitto 5:56c4f2f12ec0 402
Pokitto 5:56c4f2f12ec0 403 void stepMissiles(){
Pokitto 5:56c4f2f12ec0 404 //Player Missiles
Pokitto 5:56c4f2f12ec0 405 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
Pokitto 5:56c4f2f12ec0 406 //Check for a valid destination without a current detonation
Pokitto 5:56c4f2f12ec0 407 if( pDests[i][0] <= 84 && pDetonations[i][0] > 84 ){
Pokitto 5:56c4f2f12ec0 408 //If the missile is close enough to the destination, detonate
Pokitto 5:56c4f2f12ec0 409 if( abs( pDests[i][0] - pMissiles[i][0] ) < PSPEED && abs( pDests[i][1] - pMissiles[i][1] ) < PSPEED ){
Pokitto 5:56c4f2f12ec0 410 pDetonations[i][0] = pDests[i][0];
Pokitto 5:56c4f2f12ec0 411 pDetonations[i][1] = pDests[i][1];
Pokitto 5:56c4f2f12ec0 412 pDetonations[i][2] = 0; //Start detonation at radius of 0
Pokitto 5:56c4f2f12ec0 413 pDetonations[i][3] = EXPAND; //Detonation is increasing in size
Pokitto 5:56c4f2f12ec0 414 //Otherwise, keep moving towards destination
Pokitto 5:56c4f2f12ec0 415 }else{
Pokitto 5:56c4f2f12ec0 416 float dir = atan2(pDests[i][1]-pMissiles[i][1], pDests[i][0]-pMissiles[i][0]);
Pokitto 5:56c4f2f12ec0 417 pMissiles[i][0] += PSPEED * cos(dir);
Pokitto 5:56c4f2f12ec0 418 pMissiles[i][1] += PSPEED * sin(dir);
Pokitto 5:56c4f2f12ec0 419 }
Pokitto 5:56c4f2f12ec0 420 }
Pokitto 5:56c4f2f12ec0 421 }
Pokitto 5:56c4f2f12ec0 422
Pokitto 5:56c4f2f12ec0 423 //Enemy Missiles
Pokitto 5:56c4f2f12ec0 424 for(uint8_t i = 0; i < MAX_EMISSILES; i++){
Pokitto 5:56c4f2f12ec0 425 //Check for a valid destination
Pokitto 5:56c4f2f12ec0 426 if( eDests[i] <= 84 ){
Pokitto 5:56c4f2f12ec0 427 //If enemy missile is close enough to the destination, detonate
Pokitto 5:56c4f2f12ec0 428 if( abs( (eDests[i]*10+6) - eMissiles[i][2] ) < PSPEED && abs( 44 - eMissiles[i][3] ) < PSPEED ){
Pokitto 5:56c4f2f12ec0 429 cities[eDests[i]] = 0; //Destroy city/launcher
Pokitto 5:56c4f2f12ec0 430
Pokitto 5:56c4f2f12ec0 431 //If launcher, remove its ammo
Pokitto 5:56c4f2f12ec0 432 if( eDests[i] == 2 ){
Pokitto 5:56c4f2f12ec0 433 pammo[0] = 0;
Pokitto 5:56c4f2f12ec0 434 }
Pokitto 5:56c4f2f12ec0 435 if( eDests[i] == 5 ){
Pokitto 5:56c4f2f12ec0 436 pammo[1] = 0;
Pokitto 5:56c4f2f12ec0 437 }
Pokitto 5:56c4f2f12ec0 438
Pokitto 5:56c4f2f12ec0 439 eDests[i] = 100; //Reset enemy missile
Pokitto 5:56c4f2f12ec0 440 playSound(SOUND_DEAD);
Pokitto 5:56c4f2f12ec0 441 //Otherwise, keep moving towards destination
Pokitto 5:56c4f2f12ec0 442 }else{
Pokitto 5:56c4f2f12ec0 443 float dir = atan2( 44-eMissiles[i][3], (eDests[i]*10+6)-eMissiles[i][2] );
Pokitto 5:56c4f2f12ec0 444 eMissiles[i][2] += espeed * cos(dir);
Pokitto 5:56c4f2f12ec0 445 eMissiles[i][3] += espeed * sin(dir);
Pokitto 5:56c4f2f12ec0 446 }
Pokitto 5:56c4f2f12ec0 447 }
Pokitto 5:56c4f2f12ec0 448 }
Pokitto 5:56c4f2f12ec0 449 }
Pokitto 5:56c4f2f12ec0 450
Pokitto 5:56c4f2f12ec0 451 void stepDetonations(){
Pokitto 5:56c4f2f12ec0 452 if( counter%2 == 0 ){
Pokitto 5:56c4f2f12ec0 453 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
Pokitto 5:56c4f2f12ec0 454 if( pDetonations[i][0] <= 84 ){
Pokitto 5:56c4f2f12ec0 455 if( pDetonations[i][3] == EXPAND ){ //If detonation is expanding
Pokitto 5:56c4f2f12ec0 456 if( pDetonations[i][2] < PRADIUS ){
Pokitto 5:56c4f2f12ec0 457 pDetonations[i][2]++;
Pokitto 5:56c4f2f12ec0 458 }else{
Pokitto 5:56c4f2f12ec0 459 pDetonations[i][3] = SHRINK; //Start shrinking
Pokitto 5:56c4f2f12ec0 460 }
Pokitto 5:56c4f2f12ec0 461 }
Pokitto 5:56c4f2f12ec0 462 //Check this now instead of using else because it may have just
Pokitto 5:56c4f2f12ec0 463 //set to SHRINK; immediately checking will remove a delay at full
Pokitto 5:56c4f2f12ec0 464 //size. If a delay is desired, this if can be switched to an else.
Pokitto 5:56c4f2f12ec0 465 if( pDetonations[i][3] == SHRINK ){ //If detonation is shrinking
Pokitto 5:56c4f2f12ec0 466 if( pDetonations[i][2] > 0 ){
Pokitto 5:56c4f2f12ec0 467 pDetonations[i][2]--;
Pokitto 5:56c4f2f12ec0 468 }else{
Pokitto 5:56c4f2f12ec0 469 pDetonations[i][0] = 100; //Detonation is complete, remove it
Pokitto 5:56c4f2f12ec0 470 pDests[i][0] = 100; //Remove this destination
Pokitto 5:56c4f2f12ec0 471 }
Pokitto 5:56c4f2f12ec0 472 }
Pokitto 5:56c4f2f12ec0 473 }
Pokitto 5:56c4f2f12ec0 474 }
Pokitto 5:56c4f2f12ec0 475 }
Pokitto 5:56c4f2f12ec0 476 }
Pokitto 5:56c4f2f12ec0 477
Pokitto 5:56c4f2f12ec0 478 void stepCollision(){
Pokitto 5:56c4f2f12ec0 479 //Player Detonations with Enemy Missiles
Pokitto 5:56c4f2f12ec0 480 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
Pokitto 5:56c4f2f12ec0 481 if( pDetonations[i][0] <= 84 ){
Pokitto 5:56c4f2f12ec0 482 for(uint8_t j = 0; j < MAX_EMISSILES; j++){
Pokitto 5:56c4f2f12ec0 483 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 484 eDests[j] = 100; //Remove enemy missile
Pokitto 5:56c4f2f12ec0 485 score+=25;
Pokitto 5:56c4f2f12ec0 486 playSound(SOUND_DETONATE);
Pokitto 5:56c4f2f12ec0 487 }
Pokitto 5:56c4f2f12ec0 488 }
Pokitto 5:56c4f2f12ec0 489 }
Pokitto 5:56c4f2f12ec0 490 }
Pokitto 5:56c4f2f12ec0 491 }
Pokitto 5:56c4f2f12ec0 492
Pokitto 5:56c4f2f12ec0 493
Pokitto 5:56c4f2f12ec0 494 void checkMenu(){
Pokitto 5:56c4f2f12ec0 495 if( gb.buttons.pressed(BTN_C) ){
Pokitto 5:56c4f2f12ec0 496 gb.titleScreen(armageddon);
Pokitto 5:56c4f2f12ec0 497 gb.battery.show = false;
Pokitto 5:56c4f2f12ec0 498 }
Pokitto 5:56c4f2f12ec0 499 }
Pokitto 5:56c4f2f12ec0 500
Pokitto 5:56c4f2f12ec0 501 void checkWin(){
Pokitto 5:56c4f2f12ec0 502 if( etotal == 0 ){
Pokitto 5:56c4f2f12ec0 503 for(uint8_t i = 0; i < MAX_EMISSILES; i++){
Pokitto 5:56c4f2f12ec0 504 //Check for a valid destination
Pokitto 5:56c4f2f12ec0 505 if( eDests[i] <= 84 ){
Pokitto 5:56c4f2f12ec0 506 return;
Pokitto 5:56c4f2f12ec0 507 }
Pokitto 5:56c4f2f12ec0 508 }
Pokitto 5:56c4f2f12ec0 509 //If we get here, all enemy missiles are destroyed and they have no more
Pokitto 5:56c4f2f12ec0 510 nextLull();
Pokitto 5:56c4f2f12ec0 511 mode = MODE_LULL;
Pokitto 5:56c4f2f12ec0 512 }
Pokitto 5:56c4f2f12ec0 513 }
Pokitto 5:56c4f2f12ec0 514
Pokitto 5:56c4f2f12ec0 515 void checkLose(){
Pokitto 5:56c4f2f12ec0 516 for(uint8_t i = 0; i < 8; i++){
Pokitto 5:56c4f2f12ec0 517 if( i != 2 && i != 5 ){
Pokitto 5:56c4f2f12ec0 518 if( cities[i] ){
Pokitto 5:56c4f2f12ec0 519 return; // A city remains alive
Pokitto 5:56c4f2f12ec0 520 }
Pokitto 5:56c4f2f12ec0 521 }
Pokitto 5:56c4f2f12ec0 522 }
Pokitto 5:56c4f2f12ec0 523 //If we get here, all cities are dead. It is the end of days.
Pokitto 5:56c4f2f12ec0 524 counter = 0;
Pokitto 5:56c4f2f12ec0 525 mode = MODE_DEAD;
Pokitto 5:56c4f2f12ec0 526 playSound(SOUND_LOSE);
Pokitto 5:56c4f2f12ec0 527 }
Pokitto 5:56c4f2f12ec0 528
Pokitto 5:56c4f2f12ec0 529 void stepGame(){
Pokitto 5:56c4f2f12ec0 530 //Player input
Pokitto 5:56c4f2f12ec0 531 if( gb.buttons.pressed(BTN_A) ){
Pokitto 5:56c4f2f12ec0 532 launchMissile(LAUNCHER_ONE);
Pokitto 5:56c4f2f12ec0 533 }
Pokitto 5:56c4f2f12ec0 534 if( gb.buttons.pressed(BTN_B) ){
Pokitto 5:56c4f2f12ec0 535 launchMissile(LAUNCHER_TWO);
Pokitto 5:56c4f2f12ec0 536 }
Pokitto 5:56c4f2f12ec0 537
Pokitto 5:56c4f2f12ec0 538 if( gb.buttons.repeat(BTN_LEFT,1) ){
Pokitto 5:56c4f2f12ec0 539 targetX = targetX-TARGET_SPEED > 0 ? targetX-TARGET_SPEED : 0;
Pokitto 5:56c4f2f12ec0 540 }
Pokitto 5:56c4f2f12ec0 541 if( gb.buttons.repeat(BTN_RIGHT,1) ){
Pokitto 5:56c4f2f12ec0 542 targetX = targetX+TARGET_SPEED < 84 ? targetX+TARGET_SPEED : 84;
Pokitto 5:56c4f2f12ec0 543 }
Pokitto 5:56c4f2f12ec0 544 if( gb.buttons.repeat(BTN_UP,1) ){
Pokitto 5:56c4f2f12ec0 545 targetY = targetY-TARGET_SPEED > 0 ? targetY-TARGET_SPEED : 0;
Pokitto 5:56c4f2f12ec0 546 }
Pokitto 5:56c4f2f12ec0 547 if( gb.buttons.repeat(BTN_DOWN,1) ){
Pokitto 5:56c4f2f12ec0 548 targetY = targetY+TARGET_SPEED < 48 ? targetY+TARGET_SPEED : 48;
Pokitto 5:56c4f2f12ec0 549 }
Pokitto 5:56c4f2f12ec0 550
Pokitto 5:56c4f2f12ec0 551 //Game logic
Pokitto 5:56c4f2f12ec0 552 tryLaunchEnemy();
Pokitto 5:56c4f2f12ec0 553 stepMissiles();
Pokitto 5:56c4f2f12ec0 554 stepDetonations();
Pokitto 5:56c4f2f12ec0 555 stepCollision();
Pokitto 5:56c4f2f12ec0 556
Pokitto 5:56c4f2f12ec0 557 //Drawing
Pokitto 5:56c4f2f12ec0 558 drawScore();
Pokitto 5:56c4f2f12ec0 559 drawTargets();
Pokitto 5:56c4f2f12ec0 560 drawCities();
Pokitto 5:56c4f2f12ec0 561 drawAmmo();
Pokitto 5:56c4f2f12ec0 562 drawMissiles();
Pokitto 5:56c4f2f12ec0 563 drawDetonations();
Pokitto 5:56c4f2f12ec0 564
Pokitto 5:56c4f2f12ec0 565 checkWin();
Pokitto 5:56c4f2f12ec0 566 checkLose();
Pokitto 5:56c4f2f12ec0 567 }
Pokitto 5:56c4f2f12ec0 568
Pokitto 5:56c4f2f12ec0 569 void drawLull(){
Pokitto 5:56c4f2f12ec0 570 uint8_t cityCount = 0;
Pokitto 5:56c4f2f12ec0 571 gb.display.cursorX = 84/2 - 4*6;
Pokitto 5:56c4f2f12ec0 572 gb.display.cursorY = 48/2 - 5*3;
Pokitto 5:56c4f2f12ec0 573 gb.display.print(("BONUS POINTS"));
Pokitto 5:56c4f2f12ec0 574
Pokitto 5:56c4f2f12ec0 575 gb.display.cursorX = 84/2 - 4*8;
Pokitto 5:56c4f2f12ec0 576 gb.display.cursorY += 5*2;
Pokitto 5:56c4f2f12ec0 577 gb.display.print(lullMissiles);
Pokitto 5:56c4f2f12ec0 578
Pokitto 5:56c4f2f12ec0 579 for(uint8_t i = 0; i < lullMissiles; i++){
Pokitto 5:56c4f2f12ec0 580 gb.display.drawPixel(84/2 - 4*6 + i*2,48/2 - 3);
Pokitto 5:56c4f2f12ec0 581 }
Pokitto 5:56c4f2f12ec0 582
Pokitto 5:56c4f2f12ec0 583 gb.display.cursorX = 84/2 - 4*8;
Pokitto 5:56c4f2f12ec0 584 gb.display.cursorY += 5*2;
Pokitto 5:56c4f2f12ec0 585 for( uint8_t i; i < 8; i++ ){
Pokitto 5:56c4f2f12ec0 586 if( lullCities[i] ) cityCount++;
Pokitto 5:56c4f2f12ec0 587 }
Pokitto 5:56c4f2f12ec0 588 gb.display.print(cityCount);
Pokitto 5:56c4f2f12ec0 589
Pokitto 5:56c4f2f12ec0 590 for(uint8_t i = 0; i < cityCount; i++){
Pokitto 5:56c4f2f12ec0 591 gb.display.drawBitmap(84/2 - 4*6 + i*9,48/2+2, city);
Pokitto 5:56c4f2f12ec0 592 }
Pokitto 5:56c4f2f12ec0 593
Pokitto 5:56c4f2f12ec0 594 drawScore();
Pokitto 5:56c4f2f12ec0 595 drawCities();
Pokitto 5:56c4f2f12ec0 596 drawAmmo();
Pokitto 5:56c4f2f12ec0 597 }
Pokitto 5:56c4f2f12ec0 598
Pokitto 5:56c4f2f12ec0 599 void stepLull(){
Pokitto 5:56c4f2f12ec0 600
Pokitto 5:56c4f2f12ec0 601 if( counter % 4 == 0 && (pammo[0] > 0 || pammo[1] > 0) ){
Pokitto 5:56c4f2f12ec0 602 lullMissiles++;
Pokitto 5:56c4f2f12ec0 603 score+=10;
Pokitto 5:56c4f2f12ec0 604 if( pammo[0] > 0 ) pammo[0]--;
Pokitto 5:56c4f2f12ec0 605 else pammo[1]--;
Pokitto 5:56c4f2f12ec0 606 playSound(SOUND_SCORE);
Pokitto 5:56c4f2f12ec0 607 }
Pokitto 5:56c4f2f12ec0 608
Pokitto 5:56c4f2f12ec0 609 //If we have already iterated through the missiles
Pokitto 5:56c4f2f12ec0 610 if( counter % 8 == 0 && pammo[0] == 0 && pammo[1] == 0 ){
Pokitto 5:56c4f2f12ec0 611 for( uint8_t i = 0; i < 9; i++ ){
Pokitto 5:56c4f2f12ec0 612 if( i == 8 ){ //We have iterated through all live cities
Pokitto 5:56c4f2f12ec0 613 nextStage();
Pokitto 5:56c4f2f12ec0 614 mode = MODE_GAME;
Pokitto 5:56c4f2f12ec0 615 return;
Pokitto 5:56c4f2f12ec0 616 }
Pokitto 5:56c4f2f12ec0 617 //If not a launcher and the city is alive
Pokitto 5:56c4f2f12ec0 618 if( i != 2 && i != 5 && cities[i] != 0 ){
Pokitto 5:56c4f2f12ec0 619 lullCities[i] = 1;
Pokitto 5:56c4f2f12ec0 620 score+=100;
Pokitto 5:56c4f2f12ec0 621 cities[i] = 0;
Pokitto 5:56c4f2f12ec0 622 playSound(SOUND_SCORE);
Pokitto 5:56c4f2f12ec0 623 break;
Pokitto 5:56c4f2f12ec0 624 }
Pokitto 5:56c4f2f12ec0 625 }
Pokitto 5:56c4f2f12ec0 626 }
Pokitto 5:56c4f2f12ec0 627
Pokitto 5:56c4f2f12ec0 628 drawLull();
Pokitto 5:56c4f2f12ec0 629 }
Pokitto 5:56c4f2f12ec0 630
Pokitto 5:56c4f2f12ec0 631 void stepDead(){
Pokitto 5:56c4f2f12ec0 632 gb.display.cursorX = 84/2 - 5*3;
Pokitto 5:56c4f2f12ec0 633 gb.display.cursorY = 48/2 - 5;
Pokitto 5:56c4f2f12ec0 634 gb.display.print(("THE END"));
Pokitto 5:56c4f2f12ec0 635
Pokitto 5:56c4f2f12ec0 636 if( mode == MODE_DEAD && counter%20 == 0 ){
Pokitto 5:56c4f2f12ec0 637 mode = MODE_POSTDEAD;
Pokitto 5:56c4f2f12ec0 638 }else if( mode == MODE_POSTDEAD ){
Pokitto 5:56c4f2f12ec0 639 if( counter%8 == 0 ){
Pokitto 5:56c4f2f12ec0 640 flash ^= 255;
Pokitto 5:56c4f2f12ec0 641 }
Pokitto 5:56c4f2f12ec0 642 if( flash ){
Pokitto 5:56c4f2f12ec0 643 gb.display.cursorX = 84/2 - 5*3;
Pokitto 5:56c4f2f12ec0 644 gb.display.cursorY = 48 - 9;
Pokitto 5:56c4f2f12ec0 645 gb.display.print(("PRESS \25"));
Pokitto 5:56c4f2f12ec0 646
Pokitto 5:56c4f2f12ec0 647 if( isHighscore(score) ){
Pokitto 5:56c4f2f12ec0 648 gb.display.cursorX = 84/2 - 5*5 - 2;
Pokitto 5:56c4f2f12ec0 649 gb.display.cursorY = 48 - 15;
Pokitto 5:56c4f2f12ec0 650 gb.display.print(("NEW HIGHSCORE"));
Pokitto 5:56c4f2f12ec0 651 }
Pokitto 5:56c4f2f12ec0 652 }
Pokitto 5:56c4f2f12ec0 653
Pokitto 5:56c4f2f12ec0 654 if( gb.buttons.pressed(BTN_A) ){
Pokitto 5:56c4f2f12ec0 655 if( isHighscore(score) ){
Pokitto 5:56c4f2f12ec0 656 char tmp_name[11];
Pokitto 5:56c4f2f12ec0 657 //gb.getDefaultName(tmp_name);
Pokitto 5:56c4f2f12ec0 658 gb.keyboard(tmp_name, 11);
Pokitto 5:56c4f2f12ec0 659 //saveHighscore(score,tmp_name);
Pokitto 5:56c4f2f12ec0 660 }
Pokitto 5:56c4f2f12ec0 661 score = 0;
Pokitto 5:56c4f2f12ec0 662 mode = MODE_PREGAME;
Pokitto 5:56c4f2f12ec0 663 }
Pokitto 5:56c4f2f12ec0 664 }
Pokitto 5:56c4f2f12ec0 665 }
Pokitto 5:56c4f2f12ec0 666
Pokitto 5:56c4f2f12ec0 667 void stepPregame(){
Pokitto 5:56c4f2f12ec0 668 drawHighscores();
Pokitto 5:56c4f2f12ec0 669
Pokitto 5:56c4f2f12ec0 670 if( counter%8 == 0 ){
Pokitto 5:56c4f2f12ec0 671 flash ^= 255;
Pokitto 5:56c4f2f12ec0 672 }
Pokitto 5:56c4f2f12ec0 673 if( flash ){
Pokitto 5:56c4f2f12ec0 674 gb.display.cursorX = 84/2 - 5*3;
Pokitto 5:56c4f2f12ec0 675 gb.display.cursorY = 48 - 9;
Pokitto 5:56c4f2f12ec0 676 gb.display.print(("PRESS \25"));
Pokitto 5:56c4f2f12ec0 677 }
Pokitto 5:56c4f2f12ec0 678
Pokitto 5:56c4f2f12ec0 679 if( gb.buttons.pressed(BTN_A) ){
Pokitto 5:56c4f2f12ec0 680 stage = 255;
Pokitto 5:56c4f2f12ec0 681 for( uint8_t i = 0; i < 8; i++ ){
Pokitto 5:56c4f2f12ec0 682 lullCities[i] = 1;
Pokitto 5:56c4f2f12ec0 683 }
Pokitto 5:56c4f2f12ec0 684 nextStage(); //Reset to stage 0
Pokitto 5:56c4f2f12ec0 685 mode = MODE_GAME;
Pokitto 5:56c4f2f12ec0 686 }
Pokitto 5:56c4f2f12ec0 687 }
Pokitto 5:56c4f2f12ec0 688
Pokitto 5:56c4f2f12ec0 689 void loop() {
Pokitto 5:56c4f2f12ec0 690 if(gb.update()){
Pokitto 5:56c4f2f12ec0 691
Pokitto 5:56c4f2f12ec0 692 switch( mode ){
Pokitto 5:56c4f2f12ec0 693 case MODE_GAME:
Pokitto 5:56c4f2f12ec0 694 stepGame();
Pokitto 5:56c4f2f12ec0 695 break;
Pokitto 5:56c4f2f12ec0 696
Pokitto 5:56c4f2f12ec0 697 case MODE_LULL:
Pokitto 5:56c4f2f12ec0 698 stepLull();
Pokitto 5:56c4f2f12ec0 699 break;
Pokitto 5:56c4f2f12ec0 700
Pokitto 5:56c4f2f12ec0 701 case MODE_DEAD:
Pokitto 5:56c4f2f12ec0 702 case MODE_POSTDEAD:
Pokitto 5:56c4f2f12ec0 703 stepDead();
Pokitto 5:56c4f2f12ec0 704 break;
Pokitto 5:56c4f2f12ec0 705
Pokitto 5:56c4f2f12ec0 706 case MODE_PREGAME:
Pokitto 5:56c4f2f12ec0 707 stepPregame();
Pokitto 5:56c4f2f12ec0 708 break;
Pokitto 5:56c4f2f12ec0 709 }
Pokitto 5:56c4f2f12ec0 710
Pokitto 5:56c4f2f12ec0 711 checkMenu();
Pokitto 5:56c4f2f12ec0 712
Pokitto 5:56c4f2f12ec0 713 counter++;
Pokitto 5:56c4f2f12ec0 714 }
Pokitto 5:56c4f2f12ec0 715 }
Pokitto 5:56c4f2f12ec0 716 #define NUM_HIGHSCORES 5
Pokitto 5:56c4f2f12ec0 717 #define NAME_SIZE 10
Pokitto 5:56c4f2f12ec0 718 #define ENTRY_SIZE 15
Pokitto 5:56c4f2f12ec0 719
Pokitto 5:56c4f2f12ec0 720 uint32_t highscores[NUM_HIGHSCORES];
Pokitto 5:56c4f2f12ec0 721 char names[NUM_HIGHSCORES][NAME_SIZE+1];
Pokitto 5:56c4f2f12ec0 722
Pokitto 5:56c4f2f12ec0 723 void loadHighscores(){
Pokitto 5:56c4f2f12ec0 724 for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){
Pokitto 5:56c4f2f12ec0 725 for( uint8_t offset = 0; offset < ENTRY_SIZE; offset++ ){
Pokitto 5:56c4f2f12ec0 726 if( offset < NAME_SIZE ){
Pokitto 5:56c4f2f12ec0 727 //names[entry][offset] = EEPROM.read( ENTRY_SIZE * entry + offset );
Pokitto 5:56c4f2f12ec0 728 }else{
Pokitto 5:56c4f2f12ec0 729 uint8_t* addr = (uint8_t*) &highscores[entry];
Pokitto 5:56c4f2f12ec0 730 addr+=offset-NAME_SIZE;
Pokitto 5:56c4f2f12ec0 731 //*addr = EEPROM.read( ENTRY_SIZE * entry + offset );
Pokitto 5:56c4f2f12ec0 732 }
Pokitto 5:56c4f2f12ec0 733 }
Pokitto 5:56c4f2f12ec0 734 }
Pokitto 5:56c4f2f12ec0 735 }
Pokitto 5:56c4f2f12ec0 736
Pokitto 5:56c4f2f12ec0 737 uint8_t isHighscore(uint32_t score){
Pokitto 5:56c4f2f12ec0 738 if( score > highscores[NUM_HIGHSCORES-1] ){
Pokitto 5:56c4f2f12ec0 739 return 1;
Pokitto 5:56c4f2f12ec0 740 }
Pokitto 5:56c4f2f12ec0 741 return 0;
Pokitto 5:56c4f2f12ec0 742 }
Pokitto 5:56c4f2f12ec0 743
Pokitto 5:56c4f2f12ec0 744 void saveHighscore(uint32_t score, char* who){
Pokitto 5:56c4f2f12ec0 745 uint8_t found = 0;
Pokitto 5:56c4f2f12ec0 746 uint32_t tmp_score = 0;
Pokitto 5:56c4f2f12ec0 747 char tmp_name[10];
Pokitto 5:56c4f2f12ec0 748 for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){
Pokitto 5:56c4f2f12ec0 749 if( score > highscores[entry] ){
Pokitto 5:56c4f2f12ec0 750 found = 1;
Pokitto 5:56c4f2f12ec0 751 }
Pokitto 5:56c4f2f12ec0 752 if( found ){
Pokitto 5:56c4f2f12ec0 753 tmp_score = highscores[entry];
Pokitto 5:56c4f2f12ec0 754 strcpy(tmp_name,names[entry]);
Pokitto 5:56c4f2f12ec0 755
Pokitto 5:56c4f2f12ec0 756 highscores[entry] = score;
Pokitto 5:56c4f2f12ec0 757 strcpy(names[entry], who);
Pokitto 5:56c4f2f12ec0 758
Pokitto 5:56c4f2f12ec0 759 score = tmp_score;
Pokitto 5:56c4f2f12ec0 760 strcpy(who, tmp_name);
Pokitto 5:56c4f2f12ec0 761 }
Pokitto 5:56c4f2f12ec0 762 }
Pokitto 5:56c4f2f12ec0 763 for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){
Pokitto 5:56c4f2f12ec0 764 for( uint8_t offset = 0; offset < ENTRY_SIZE; offset++ ){
Pokitto 5:56c4f2f12ec0 765 if( offset < NAME_SIZE ){
Pokitto 5:56c4f2f12ec0 766 //EEPROM.write( ENTRY_SIZE * entry + offset, names[entry][offset] );
Pokitto 5:56c4f2f12ec0 767 }else{
Pokitto 5:56c4f2f12ec0 768 uint8_t* addr = (uint8_t*) &highscores[entry];
Pokitto 5:56c4f2f12ec0 769 addr+=offset-NAME_SIZE;
Pokitto 5:56c4f2f12ec0 770 //EEPROM.write( ENTRY_SIZE * entry + offset, *addr );
Pokitto 5:56c4f2f12ec0 771 }
Pokitto 5:56c4f2f12ec0 772 }
Pokitto 5:56c4f2f12ec0 773 }
Pokitto 5:56c4f2f12ec0 774 }
Pokitto 5:56c4f2f12ec0 775
Pokitto 5:56c4f2f12ec0 776 void drawHighscores(){
Pokitto 5:56c4f2f12ec0 777 gb.display.cursorX = 84/2 - 5*4;
Pokitto 5:56c4f2f12ec0 778 gb.display.cursorY = 5;
Pokitto 5:56c4f2f12ec0 779 gb.display.print(("HIGHSCORES"));
Pokitto 5:56c4f2f12ec0 780
Pokitto 5:56c4f2f12ec0 781 for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){
Pokitto 5:56c4f2f12ec0 782 gb.display.cursorX = 5;
Pokitto 5:56c4f2f12ec0 783 gb.display.cursorY = 12 + 5*entry;
Pokitto 5:56c4f2f12ec0 784 gb.display.print(names[entry]);
Pokitto 5:56c4f2f12ec0 785 gb.display.print((" "));
Pokitto 5:56c4f2f12ec0 786 gb.display.cursorX = 84 - 5*6;
Pokitto 5:56c4f2f12ec0 787 if( highscores[entry] < 100000 ){
Pokitto 5:56c4f2f12ec0 788 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 789 }
Pokitto 5:56c4f2f12ec0 790 if( highscores[entry] < 10000 ){
Pokitto 5:56c4f2f12ec0 791 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 792 }
Pokitto 5:56c4f2f12ec0 793 if( highscores[entry] < 1000 ){
Pokitto 5:56c4f2f12ec0 794 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 795 }
Pokitto 5:56c4f2f12ec0 796 if( highscores[entry] < 100 ){
Pokitto 5:56c4f2f12ec0 797 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 798 }
Pokitto 5:56c4f2f12ec0 799 if( highscores[entry] < 10 ){
Pokitto 5:56c4f2f12ec0 800 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 801 }
Pokitto 5:56c4f2f12ec0 802 gb.display.print(highscores[entry]);
Pokitto 5:56c4f2f12ec0 803 }
Pokitto 5:56c4f2f12ec0 804 }
Pokitto 5:56c4f2f12ec0 805
Pokitto 5:56c4f2f12ec0 806 // Wave, pitch, duration, arpeggio step duration, arpeggio step size
Pokitto 5:56c4f2f12ec0 807 const int8_t sounds[][5] = {
Pokitto 5:56c4f2f12ec0 808 { 0, 20, 5, 1, 1 }, //Player launch
Pokitto 5:56c4f2f12ec0 809 { 0, 25, 5, 1, -1 }, //Enemy launch
Pokitto 5:56c4f2f12ec0 810 { 1, 10, 5, 1, -1 }, //Detonating enemy missile
Pokitto 5:56c4f2f12ec0 811 { 1, 10, 2, 0, 0 }, //Score pips
Pokitto 5:56c4f2f12ec0 812 { 1, 2, 10, 1, -1 }, //A city dies
Pokitto 5:56c4f2f12ec0 813 { 0, 20, 14, 3, -1 }, //Lose
Pokitto 5:56c4f2f12ec0 814 };
Pokitto 5:56c4f2f12ec0 815
Pokitto 5:56c4f2f12ec0 816 void initSound(){
Pokitto 5:56c4f2f12ec0 817 gb.sound.command(CMD_VOLUME, 5, 0, 0);
Pokitto 5:56c4f2f12ec0 818 gb.sound.command(CMD_SLIDE, 0, 0, 0);
Pokitto 5:56c4f2f12ec0 819 }
Pokitto 5:56c4f2f12ec0 820
Pokitto 5:56c4f2f12ec0 821 void playSound(uint8_t i){
Pokitto 5:56c4f2f12ec0 822 gb.sound.command(CMD_VOLUME, 5, 0, 0);
Pokitto 5:56c4f2f12ec0 823 gb.sound.command(CMD_SLIDE, 0, 0, 0);
Pokitto 5:56c4f2f12ec0 824 gb.sound.command(CMD_ARPEGGIO, sounds[i][3], sounds[i][4], 0);
Pokitto 5:56c4f2f12ec0 825 gb.sound.command(CMD_INSTRUMENT, sounds[i][0], 0, 0);
Pokitto 5:56c4f2f12ec0 826 gb.sound.playNote(sounds[i][1], sounds[i][2], 0);
Pokitto 5:56c4f2f12ec0 827
Pokitto 5:56c4f2f12ec0 828 //gb.sound.playNote(20, 5, 0);
Pokitto 5:56c4f2f12ec0 829 }
Pokitto 5:56c4f2f12ec0 830
Pokitto 5:56c4f2f12ec0 831