Armageddon - a missile commad clone by Wuuff, originally for Gamebuino. Conversion by Jonne
Dependencies: PokittoLib
Fork of Asterocks by
Diff: ageddon.cpp
- Revision:
- 14:41173f26c0ef
- Parent:
- 13:b133c46dbda7
- Child:
- 15:933ac6bcd8b8
--- a/ageddon.cpp Mon Oct 30 02:45:32 2017 +0000 +++ b/ageddon.cpp Mon Oct 30 07:27:43 2017 +0000 @@ -29,7 +29,7 @@ void loop(); void loadHighscores(); uint8_t isHighscore(uint32_t); -void saveHighscore(char); +void saveHighscore(uint32_t,char*); void drawHighscores(); void initSound(); void playSound(uint8_t); @@ -43,43 +43,100 @@ } } -const byte armageddon[] PROGMEM = {64,36, -B11111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00001111,B11111111, -B11111100,B00001111,B11111111,B11111111,B11111111,B11111111,B11110000,B00111111, -B11100011,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11000111, -B10011111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111001, -B01110111,B10011110,B11101110,B11111001,B11000010,B01111001,B11110111,B10111010, -B01110111,B10101110,B01001110,B11110110,B11011110,B10111010,B11101011,B10011010, -B01101011,B10001110,B01001101,B01110111,B11000110,B11011011,B01011101,B10101010, -B01100011,B10101110,B10101100,B01110100,B11011110,B11011011,B01011101,B10110010, -B01101011,B10100110,B11101101,B01110110,B11011110,B10111010,B11101011,B10111010, -B01001001,B10110110,B11101001,B00111001,B11000010,B01111001,B11110111,B10111010, -B10111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111101, -B11011111,B11111111,B11100000,B11111111,B11111111,B00000111,B11111111,B11111011, -B11100011,B11111110,B00011111,B00011111,B11111000,B11111000,B01111111,B11000111, -B11111000,B11100001,B11111111,B11101111,B11110111,B11111111,B10000111,B00011111, -B11111110,B00001111,B11111111,B11110111,B11101111,B11111111,B11110000,B01111111, -B11111111,B11111111,B11111111,B11110111,B11101111,B11111111,B11111111,B11111111, -B11111111,B11111111,B11111111,B11111011,B11011111,B11111111,B11111111,B11111111, -B11111111,B11111111,B11111111,B11111011,B11011111,B11111111,B11111111,B11111111, -B11111111,B11111111,B11111110,B00000011,B11000000,B01111111,B11111111,B11111111, -B11111111,B11111111,B11100001,B11111011,B11011111,B10000111,B11111111,B11111111, -B11111111,B11111111,B11011111,B11110011,B11001111,B11111011,B11111111,B11111111, -B11111111,B11111111,B11011111,B11110011,B11001111,B11111011,B11111111,B11111111, -B11111111,B11111111,B11011111,B11110011,B11001111,B11111011,B11111111,B11111111, -B11111111,B11111111,B11100001,B11110011,B11001111,B10000111,B11111111,B11111111, -B11111111,B11111111,B11111110,B00010111,B11101000,B01111111,B11111111,B11111111, -B11111111,B11111111,B11111111,B11100000,B00000111,B11111111,B11111111,B11111111, -B11111111,B11111111,B11111111,B11110111,B11101111,B11111111,B11111111,B11111111, -B11111111,B11111111,B11111111,B11100111,B11100111,B11111111,B11111111,B11111111, -B11111111,B11111111,B11111111,B11100111,B11100111,B11111111,B11111111,B11111111, -B11111111,B11111111,B11111111,B11101111,B11110111,B11111111,B11111111,B11111111, -B11111111,B11111111,B11111111,B11101111,B11110111,B11111111,B11111111,B11111111, -B11111111,B11111111,B11111111,B11101111,B11110111,B11111111,B11111111,B11111111, -B11111111,B11111111,B11111111,B11011111,B11111011,B11111111,B11111111,B11111111, -B11111111,B11111111,B11111111,B10111111,B11111101,B11111111,B11111111,B11111111, -B11111111,B11111111,B11111110,B01111111,B11111110,B01111111,B11111111,B11111111, -B11111111,B11111111,B11111101,B11111111,B11111111,B10111111,B11111111,B11111111, +#define WIDTH 110 +#define HEIGHT 88 +#define TEXT_WIDTH 6 +#define TEXT_HEIGHT 8 + +const byte armageddon[] PROGMEM = {112,88, +B11111111,B11111111,B11111000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01111111,B11111111,B11111100, +B11111111,B11111111,B11111000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01111111,B11111111,B11111100, +B11111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001111,B11111100, +B11111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001111,B11111100, +B11111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001111,B11111100, +B11111000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01111100, +B11111000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01111100, +B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100, +B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100, +B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100, +B00000001,B10000001,B11100000,B00110000,B11000000,B11000000,B00111000,B00111111,B10011110,B00000111,B10000000,B00011000,B00011000,B01100000, +B00000001,B10000001,B11100000,B00110000,B11000000,B11000000,B00111000,B00111111,B10011110,B00000111,B10000000,B00011000,B00011000,B01100000, +B00000001,B10000001,B10011000,B00111001,B11000000,B11000000,B11000110,B00110000,B00011001,B10000110,B01100000,B01100110,B00011100,B01100000, +B00000001,B10000001,B10011000,B00111001,B11000000,B11000000,B11000110,B00110000,B00011001,B10000110,B01100000,B01100110,B00011100,B01100000, +B00000001,B10000001,B10011000,B00111001,B11000000,B11000000,B11000110,B00110000,B00011001,B10000110,B01100000,B01100110,B00011100,B01100000, +B00000110,B01100001,B11111000,B00111001,B11000011,B00110000,B11000000,B00111111,B00011000,B01100110,B00011001,B10000001,B10011011,B01100000, +B00000110,B01100001,B11111000,B00111001,B11000011,B00110000,B11000000,B00111111,B00011000,B01100110,B00011001,B10000001,B10011011,B01100000, +B00000111,B11100001,B10011000,B00110110,B11000011,B11110000,B11001110,B00110000,B00011000,B01100110,B00011001,B10000001,B10011000,B11100000, +B00000111,B11100001,B10011000,B00110110,B11000011,B11110000,B11001110,B00110000,B00011000,B01100110,B00011001,B10000001,B10011000,B11100000, +B00000111,B11100001,B10011000,B00110110,B11000011,B11110000,B11001110,B00110000,B00011000,B01100110,B00011001,B10000001,B10011000,B11100000, +B00000110,B01100001,B10011100,B00110000,B11000011,B00110000,B11000110,B00110000,B00011001,B10000110,B01100000,B01100110,B00011000,B01100000, +B00000110,B01100001,B10001110,B00110000,B11000011,B00110000,B11000110,B00110000,B00011001,B10000110,B01100000,B01100110,B00011000,B01100000, +B00011110,B01111001,B10000110,B00110000,B11001111,B00111100,B00111000,B00111111,B10011110,B00000111,B10000000,B00011000,B00011000,B01100000, +B00011110,B01111001,B10000110,B00110000,B11001111,B00111100,B00111000,B00111111,B10011110,B00000111,B10000000,B00011000,B00011000,B01100000, +B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100, +B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100, +B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100, +B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00011100, +B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00011100, +B11111000,B00000000,B00000000,B00000000,B01111111,B10000000,B00000000,B00000000,B00000111,B11111000,B00000000,B00000000,B00000000,B01111100, +B11111000,B00000000,B00000000,B00000000,B01111111,B10000000,B00000000,B00000000,B00000111,B11111000,B00000000,B00000000,B00000000,B01111100, +B11111000,B00000000,B00000000,B00000000,B01111111,B10000000,B00000000,B00000000,B00000111,B11111000,B00000000,B00000000,B00000000,B01111100, +B11111111,B10000000,B00000000,B00111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11110000,B00000000,B00000111,B11111100, +B11111111,B10000000,B00000000,B00111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11110000,B00000000,B00000111,B11111100, +B11111111,B11110000,B00000111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B10000000,B00111111,B11111100, +B11111111,B11110000,B00000111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B10000000,B00111111,B11111100, +B11111111,B11110000,B00000111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B10000000,B00111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11000000,B00001111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11000000,B00001111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11000000,B00001111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11000000,B00001111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11000000,B00001111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000000,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000000,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B10000000,B11111111,B11000000,B00001111,B11111100,B00000111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B10000000,B11111111,B11000000,B00001111,B11111100,B00000111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B10000000,B11111111,B11000000,B00001111,B11111100,B00000111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B10000000,B11111111,B00000000,B00000011,B11111100,B00000111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B10000000,B11111111,B00000000,B00000011,B11111100,B00000111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B10000000,B11111111,B00000000,B00000011,B11111100,B00000111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B00000011,B00000000,B00000011,B00000011,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B00000011,B00000000,B00000011,B00000011,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111000,B00000000,B00000000,B01111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111000,B00000000,B00000000,B01111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11111000,B00000000,B00000000,B01111111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11100000,B00000000,B00000000,B00011111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B11100000,B00000000,B00000000,B00011111,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000000,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111100, +B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000000,B00000000,B00000011,B11010101,B01010100,B01000111,B00010001,B01000100, +B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000000,B00000000,B00000011,B11010101,B01010101,B11011111,B11010101,B01110100, +B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B00000000,B00000000,B11000101,B01010100,B11001111,B00110101,B01101100, +B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B00000000,B00000000,B11010100,B01000101,B11011111,B00010001,B01011100, }; /*const byte city[] PROGMEM = {8,8, @@ -175,8 +232,8 @@ uint8_t cities[8] = {1,1,1,1,1,1,1,1}; //Whether the cities or launchers are alive -uint8_t targetX = 84/2; -uint8_t targetY = 48/2; +uint8_t targetX = WIDTH/2; +uint8_t targetY = HEIGHT/2; uint8_t pammo[2] = {10,10}; 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}}; 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}}; @@ -188,11 +245,49 @@ uint8_t eDests[MAX_EMISSILES] = {100,100,100,100,100,100,100,100,100,100}; 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}}; +void doTitle(uint8_t is_pause){ + while (gb.isRunning()) { + if( gb.update() ){ + gb.display.setColor(7); + gb.display.drawBitmap(0,0,armageddon); + if( counter%8 == 0 ){ + flash ^= 255; + } + + if( flash ){ + gb.display.setColor(4); + gb.display.cursorY = HEIGHT - TEXT_HEIGHT*2; + if( is_pause ){ + gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*3; + gb.display.print(("PAUSED")); + }else{ + gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*3; + gb.display.print(("PRESS \25")); + } + } + counter++; + if( gb.buttons.pressed(BTN_A) ){ + gb.display.setColor(WHITE); + break; + } + } + } +} + void setup() { gb.begin(); loadHighscores(); - gb.titleScreen(armageddon); + + //We need to do extra Gamebuino-formatting-specific initialization if we don't use the title screen + gb.display.setFont(font5x7); + gb.display.fontSize = 1; + gb.display.textWrap = false; + gb.display.persistence = false; gb.battery.show = false; + gb.display.setColor(BLACK); + gb.display.setColorDepth(1); + + doTitle(0); gb.pickRandomSeed(); } @@ -210,9 +305,9 @@ pammo[1] = 10; //Reset in-flight missiles for( uint8_t i = 0; i < 10; i++ ){ - pDests[i][0] = 100; - pDetonations[i][0] = 100; - eDests[i] = 100; + pDests[i][0] = 127; + pDetonations[i][0] = 127; + eDests[i] = 127; } etotal = stage > 10 ? 20 : 10+stage; //Max of 20 missiles per stage, start at 10 @@ -230,7 +325,7 @@ } void drawScore(){ - gb.display.cursorX = 84/2 - 4*3; + gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*3; gb.display.cursorY = 0; if( score < 100000 ){ @@ -257,7 +352,7 @@ for(uint8_t i = 0; i < MAX_PMISSILES; i++){ //Check for a valid destination without a current detonation - if( pDests[i][0] <= 84 && pDetonations[i][0] > 84 ){ + if( pDests[i][0] <= WIDTH && pDetonations[i][0] > WIDTH ){ gb.display.drawPixel(pDests[i][0], pDests[i][1]); } } @@ -269,16 +364,16 @@ for(uint8_t i = 0; i < 8; i++){ if( i == 2 || i == 5 ){ if( cities[i] ){ - gb.display.drawBitmap(i*10+2,40,launcher); + gb.display.drawBitmap(i*14+2,HEIGHT-8,launcher); }else{ - gb.display.drawBitmap(i*10+2,40,deadlauncher); + gb.display.drawBitmap(i*14+2,HEIGHT-8,deadlauncher); } }else{ if( cities[i] ){ //alldead = 0; - gb.display.drawBitmap(i*10+2,40,city); + gb.display.drawBitmap(i*14+2,HEIGHT-8,city); }else{ - gb.display.drawBitmap(i*10+2,40,deadcity); + gb.display.drawBitmap(i*14+2,HEIGHT-8,deadcity); } } } @@ -296,8 +391,8 @@ void drawAmmo(){ gb.display.setColor(3); for( uint8_t i = 0; i < 2; i++ ){ - uint8_t xcoord = i == 0 ? 25 : 55; - uint8_t ycoord = 47; + uint8_t xcoord = i == 0 ? 2*14 + 5 : 5*14 + 5; + uint8_t ycoord = HEIGHT-1; if( cities[i*3+2] ){ //Is launcher alive? for( uint8_t j = 0; j < pammo[i]; j++ ){ gb.display.drawPixel(xcoord,ycoord); @@ -318,11 +413,11 @@ gb.display.setColor(3); for(uint8_t i = 0; i < MAX_PMISSILES; i++){ //Check for a valid destination without a current detonation - if( pDests[i][0] <= 84 && pDetonations[i][0] > 84 ){ + if( pDests[i][0] <= WIDTH && pDetonations[i][0] > WIDTH ){ if(pMissiles[i][2] == LAUNCHER_ONE){ - gb.display.drawLine(25,40,pMissiles[i][0], pMissiles[i][1]); + gb.display.drawLine(2*14 + 5,HEIGHT-8,pMissiles[i][0], pMissiles[i][1]); }else{ - gb.display.drawLine(56,40,pMissiles[i][0], pMissiles[i][1]); + gb.display.drawLine(5*14 + 6,HEIGHT-8,pMissiles[i][0], pMissiles[i][1]); } } } @@ -331,7 +426,7 @@ gb.display.setColor(7); for(uint8_t i = 0; i < MAX_EMISSILES; i++){ //Check for a valid destination - if( eDests[i] <= 84 ){ + if( eDests[i] <= WIDTH ){ gb.display.drawLine(eMissiles[i][0],eMissiles[i][1],eMissiles[i][2], eMissiles[i][3]); } } @@ -346,7 +441,7 @@ explosionColor%=7; } for(uint8_t i = 0; i < MAX_PMISSILES; i++){ - if( pDetonations[i][0] <= 84 ){ + if( pDetonations[i][0] <= WIDTH ){ gb.display.fillCircle(pDetonations[i][0],pDetonations[i][1],pDetonations[i][2]); } } @@ -356,24 +451,24 @@ void launchMissile(uint8_t launcher){ //If there is no free slot in pDests, do not launch for(uint8_t i = 0; i < MAX_PMISSILES; i++){ - if( pDests[i][0] > 84 ){ + if( pDests[i][0] > WIDTH ){ // Which launcher? Alive? Has ammo? if(launcher == LAUNCHER_ONE && cities[2] && pammo[0]){ pDests[i][0] = targetX; pDests[i][1] = targetY; - pMissiles[i][0] = 25; //X-coord of left launcher + pMissiles[i][0] = 2*14 + 5; //X-coord of left launcher pMissiles[i][2] = LAUNCHER_ONE; //Launched from launcher one pammo[0]--; playSound(SOUND_PLAUNCH); }else if(launcher == LAUNCHER_TWO && cities[5] && pammo[1]){ pDests[i][0] = targetX; pDests[i][1] = targetY; - pMissiles[i][0] = 56; //X-coord of right launcher + pMissiles[i][0] = 5*14 + 6; //X-coord of right launcher pMissiles[i][2] = LAUNCHER_TWO; //Launched from launcher two pammo[1]--; playSound(SOUND_PLAUNCH); } - pMissiles[i][1] = 40; //Y-coord of both launchers + pMissiles[i][1] = HEIGHT-8; //Y-coord of both launchers break; } } @@ -388,7 +483,7 @@ // If none are active, always spawn one to avoid // long pauses without any enemy missiles for(uint8_t i = 0; i < MAX_EMISSILES; i++){ - if( eDests[i] <= 84 ){ + if( eDests[i] <= WIDTH ){ someActive = 1; break; } @@ -396,10 +491,10 @@ if( (!someActive || echance >= random(100)) ){ //echance of 100 for(uint8_t i = 0; i < MAX_EMISSILES; i++){ - if( eDests[i] > 84 ){ + if( eDests[i] > WIDTH ){ etotal--; eDests[i] = random(7); //Target one of the 6 cities or 2 launch sites TODO: Come back later if random's behavior changes - eMissiles[i][0] = random(84); //Screen width + eMissiles[i][0] = random(WIDTH); //Screen width //TODO: if random is supposed to be inclusive, add a -1 eMissiles[i][1] = 0; //Top of screen eMissiles[i][2] = eMissiles[i][0]; //Start and end are same eMissiles[i][3] = 0; //Top of screen @@ -416,7 +511,7 @@ //Player Missiles for(uint8_t i = 0; i < MAX_PMISSILES; i++){ //Check for a valid destination without a current detonation - if( pDests[i][0] <= 84 && pDetonations[i][0] > 84 ){ + if( pDests[i][0] <= WIDTH && pDetonations[i][0] > WIDTH ){ //If the missile is close enough to the destination, detonate if( abs( pDests[i][0] - pMissiles[i][0] ) < PSPEED && abs( pDests[i][1] - pMissiles[i][1] ) < PSPEED ){ pDetonations[i][0] = pDests[i][0]; @@ -435,9 +530,9 @@ //Enemy Missiles for(uint8_t i = 0; i < MAX_EMISSILES; i++){ //Check for a valid destination - if( eDests[i] <= 84 ){ + if( eDests[i] <= WIDTH ){ //If enemy missile is close enough to the destination, detonate - if( abs( (eDests[i]*10+6) - eMissiles[i][2] ) < PSPEED && abs( 44 - eMissiles[i][3] ) < PSPEED ){ + if( abs( (eDests[i]*14+6) - eMissiles[i][2] ) < PSPEED && abs( HEIGHT-4 - eMissiles[i][3] ) < PSPEED ){ cities[eDests[i]] = 0; //Destroy city/launcher //If launcher, remove its ammo @@ -448,11 +543,11 @@ pammo[1] = 0; } - eDests[i] = 100; //Reset enemy missile + eDests[i] = 127; //Reset enemy missile playSound(SOUND_DEAD); //Otherwise, keep moving towards destination }else{ - float dir = atan2( 44-eMissiles[i][3], (eDests[i]*10+6)-eMissiles[i][2] ); + float dir = atan2( HEIGHT-4 - eMissiles[i][3], (eDests[i]*14+6)-eMissiles[i][2] ); eMissiles[i][2] += espeed * cos(dir); eMissiles[i][3] += espeed * sin(dir); } @@ -463,7 +558,7 @@ void stepDetonations(){ if( counter%2 == 0 ){ for(uint8_t i = 0; i < MAX_PMISSILES; i++){ - if( pDetonations[i][0] <= 84 ){ + if( pDetonations[i][0] <= WIDTH ){ if( pDetonations[i][3] == EXPAND ){ //If detonation is expanding if( pDetonations[i][2] < PRADIUS ){ pDetonations[i][2]++; @@ -478,8 +573,8 @@ if( pDetonations[i][2] > 0 ){ pDetonations[i][2]--; }else{ - pDetonations[i][0] = 100; //Detonation is complete, remove it - pDests[i][0] = 100; //Remove this destination + pDetonations[i][0] = 127; //Detonation is complete, remove it + pDests[i][0] = 127; //Remove this destination } } } @@ -490,10 +585,11 @@ void stepCollision(){ //Player Detonations with Enemy Missiles for(uint8_t i = 0; i < MAX_PMISSILES; i++){ - if( pDetonations[i][0] <= 84 ){ + if( pDetonations[i][0] <= WIDTH ){ for(uint8_t j = 0; j < MAX_EMISSILES; j++){ - 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]) ) ){ - eDests[j] = 100; //Remove enemy missile + //Add extra +1 to explosion radius so that collisions are more generous + if( eDests[j] <= WIDTH && pDetonations[i][2] + 1 >= 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]) ) ){ + eDests[j] = 127; //Remove enemy missile score+=25; playSound(SOUND_DETONATE); } @@ -505,8 +601,7 @@ void checkMenu(){ if( gb.buttons.pressed(BTN_C) ){ - gb.titleScreen(armageddon); - gb.battery.show = false; + doTitle(1); } } @@ -514,7 +609,7 @@ if( etotal == 0 ){ for(uint8_t i = 0; i < MAX_EMISSILES; i++){ //Check for a valid destination - if( eDests[i] <= 84 ){ + if( eDests[i] <= WIDTH ){ return; } } @@ -551,13 +646,13 @@ targetX = targetX-TARGET_SPEED > 0 ? targetX-TARGET_SPEED : 0; } if( gb.buttons.repeat(BTN_RIGHT,1) ){ - targetX = targetX+TARGET_SPEED < 84 ? targetX+TARGET_SPEED : 84; + targetX = targetX+TARGET_SPEED < WIDTH ? targetX+TARGET_SPEED : WIDTH; } if( gb.buttons.repeat(BTN_UP,1) ){ targetY = targetY-TARGET_SPEED > 0 ? targetY-TARGET_SPEED : 0; } if( gb.buttons.repeat(BTN_DOWN,1) ){ - targetY = targetY+TARGET_SPEED < 48 ? targetY+TARGET_SPEED : 48; + targetY = targetY+TARGET_SPEED < HEIGHT ? targetY+TARGET_SPEED : HEIGHT; } //Game logic @@ -580,22 +675,22 @@ void drawLull(){ uint32_t cityCount = 0; - gb.display.cursorX = 84/2 - 4*6; - gb.display.cursorY = 48/2 - 5*3; + gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*6; + gb.display.cursorY = HEIGHT/2 - TEXT_HEIGHT*3; gb.display.print(("BONUS POINTS")); - gb.display.cursorX = 84/2 - 4*8; - gb.display.cursorY += 5*2; + gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*8; + gb.display.cursorY += TEXT_HEIGHT*2; gb.display.print(lullMissiles); gb.display.setColor(3); for(uint8_t i = 0; i < lullMissiles; i++){ - gb.display.drawPixel(84/2 - 4*6 + i*2,48/2 - 3); + gb.display.drawPixel(WIDTH/2 - TEXT_WIDTH*6 + i*2,HEIGHT/2 - 3); } gb.display.setColor(1); - gb.display.cursorX = 84/2 - 4*8; - gb.display.cursorY += 5*2; + gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*8; + gb.display.cursorY += TEXT_HEIGHT*2; for( uint8_t i = 0; i < 8; i++ ){ if( lullCities[i] ) cityCount++; } @@ -603,7 +698,7 @@ gb.display.setColor(4); for(uint8_t i = 0; i < cityCount; i++){ - gb.display.drawBitmap(84/2 - 4*6 + i*9,48/2+2, city); + gb.display.drawBitmap(WIDTH/2 - TEXT_WIDTH*6 + i*9,HEIGHT/2+2, city); } gb.display.setColor(1); @@ -645,9 +740,11 @@ } void stepDead(){ - gb.display.cursorX = 84/2 - 5*3; - gb.display.cursorY = 48/2 - 5; + gb.display.setColor(7); + gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*3 - TEXT_WIDTH/2;; + gb.display.cursorY = HEIGHT/2 - TEXT_HEIGHT; gb.display.print(("THE END")); + gb.display.setColor(1); if( mode == MODE_DEAD && counter%20 == 0 ){ mode = MODE_POSTDEAD; @@ -656,23 +753,25 @@ flash ^= 255; } if( flash ){ - gb.display.cursorX = 84/2 - 5*3; - gb.display.cursorY = 48 - 9; + gb.display.setColor(4); + gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*3 - TEXT_WIDTH/2; + gb.display.cursorY = HEIGHT - TEXT_HEIGHT*2; gb.display.print(("PRESS \25")); if( isHighscore(score) ){ - gb.display.cursorX = 84/2 - 5*5 - 2; - gb.display.cursorY = 48 - 15; + gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*6 - TEXT_WIDTH/2; + gb.display.cursorY = HEIGHT - TEXT_HEIGHT*3; gb.display.print(("NEW HIGHSCORE")); } + gb.display.setColor(1); } if( gb.buttons.pressed(BTN_A) ){ if( isHighscore(score) ){ - char tmp_name[11]; + char tmp_name[11] = "User"; //gb.getDefaultName(tmp_name); gb.keyboard(tmp_name, 11); - //saveHighscore(score,tmp_name); + saveHighscore(score,tmp_name); } score = 0; mode = MODE_PREGAME; @@ -687,9 +786,11 @@ flash ^= 255; } if( flash ){ - gb.display.cursorX = 84/2 - 5*3; - gb.display.cursorY = 48 - 9; + gb.display.setColor(4); + gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*3; + gb.display.cursorY = HEIGHT - TEXT_HEIGHT*2; gb.display.print(("PRESS \25")); + gb.display.setColor(1); } if( gb.buttons.pressed(BTN_A) ){ @@ -733,8 +834,8 @@ #define NAME_SIZE 10 #define ENTRY_SIZE 15 -uint32_t highscores[NUM_HIGHSCORES]; -char names[NUM_HIGHSCORES][NAME_SIZE+1]; +uint32_t highscores[NUM_HIGHSCORES] = {10000,7000,5000,4000,2000}; +char names[NUM_HIGHSCORES][NAME_SIZE+1] = {"Crack Shot", "Defender", "Gunner", "We Tried", "No Hope"}; void loadHighscores(){ for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){ @@ -790,16 +891,17 @@ } void drawHighscores(){ - gb.display.cursorX = 84/2 - 5*4; - gb.display.cursorY = 5; + gb.display.setColor(4); + gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*5; + gb.display.cursorY = TEXT_HEIGHT; gb.display.print(("HIGHSCORES")); + gb.display.setColor(1); for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){ - gb.display.cursorX = 5; - gb.display.cursorY = 12 + 5*entry; + gb.display.cursorX = 0; + gb.display.cursorY = TEXT_HEIGHT*3 + TEXT_HEIGHT*entry; gb.display.print(names[entry]); - gb.display.print((" ")); - gb.display.cursorX = 84 - 5*6; + gb.display.cursorX = WIDTH - TEXT_WIDTH*6; if( highscores[entry] < 100000 ){ gb.display.print(0); }