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

Dependencies:   PokittoLib

Fork of Asterocks by Pokitto Community Team

Committer:
wuuff
Date:
Mon Oct 30 07:27:43 2017 +0000
Revision:
14:41173f26c0ef
Parent:
13:b133c46dbda7
Child:
15:933ac6bcd8b8
Expanded game area to fit 110x88 resolution, added new title screen, added default highscores, fixed not being able to add highscore

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);
wuuff 14:41173f26c0ef 32 void saveHighscore(uint32_t,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();
wuuff 13:b133c46dbda7 40 gb.display.setDefaultPalette();
Pokitto 5:56c4f2f12ec0 41 while (gb.isRunning()) {
Pokitto 5:56c4f2f12ec0 42 loop();
Pokitto 5:56c4f2f12ec0 43 }
Pokitto 5:56c4f2f12ec0 44 }
Pokitto 5:56c4f2f12ec0 45
wuuff 14:41173f26c0ef 46 #define WIDTH 110
wuuff 14:41173f26c0ef 47 #define HEIGHT 88
wuuff 14:41173f26c0ef 48 #define TEXT_WIDTH 6
wuuff 14:41173f26c0ef 49 #define TEXT_HEIGHT 8
wuuff 14:41173f26c0ef 50
wuuff 14:41173f26c0ef 51 const byte armageddon[] PROGMEM = {112,88,
wuuff 14:41173f26c0ef 52 B11111111,B11111111,B11111000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 53 B11111111,B11111111,B11111000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 54 B11111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001111,B11111100,
wuuff 14:41173f26c0ef 55 B11111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001111,B11111100,
wuuff 14:41173f26c0ef 56 B11111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001111,B11111100,
wuuff 14:41173f26c0ef 57 B11111000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01111100,
wuuff 14:41173f26c0ef 58 B11111000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01111100,
wuuff 14:41173f26c0ef 59 B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100,
wuuff 14:41173f26c0ef 60 B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100,
wuuff 14:41173f26c0ef 61 B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100,
wuuff 14:41173f26c0ef 62 B00000001,B10000001,B11100000,B00110000,B11000000,B11000000,B00111000,B00111111,B10011110,B00000111,B10000000,B00011000,B00011000,B01100000,
wuuff 14:41173f26c0ef 63 B00000001,B10000001,B11100000,B00110000,B11000000,B11000000,B00111000,B00111111,B10011110,B00000111,B10000000,B00011000,B00011000,B01100000,
wuuff 14:41173f26c0ef 64 B00000001,B10000001,B10011000,B00111001,B11000000,B11000000,B11000110,B00110000,B00011001,B10000110,B01100000,B01100110,B00011100,B01100000,
wuuff 14:41173f26c0ef 65 B00000001,B10000001,B10011000,B00111001,B11000000,B11000000,B11000110,B00110000,B00011001,B10000110,B01100000,B01100110,B00011100,B01100000,
wuuff 14:41173f26c0ef 66 B00000001,B10000001,B10011000,B00111001,B11000000,B11000000,B11000110,B00110000,B00011001,B10000110,B01100000,B01100110,B00011100,B01100000,
wuuff 14:41173f26c0ef 67 B00000110,B01100001,B11111000,B00111001,B11000011,B00110000,B11000000,B00111111,B00011000,B01100110,B00011001,B10000001,B10011011,B01100000,
wuuff 14:41173f26c0ef 68 B00000110,B01100001,B11111000,B00111001,B11000011,B00110000,B11000000,B00111111,B00011000,B01100110,B00011001,B10000001,B10011011,B01100000,
wuuff 14:41173f26c0ef 69 B00000111,B11100001,B10011000,B00110110,B11000011,B11110000,B11001110,B00110000,B00011000,B01100110,B00011001,B10000001,B10011000,B11100000,
wuuff 14:41173f26c0ef 70 B00000111,B11100001,B10011000,B00110110,B11000011,B11110000,B11001110,B00110000,B00011000,B01100110,B00011001,B10000001,B10011000,B11100000,
wuuff 14:41173f26c0ef 71 B00000111,B11100001,B10011000,B00110110,B11000011,B11110000,B11001110,B00110000,B00011000,B01100110,B00011001,B10000001,B10011000,B11100000,
wuuff 14:41173f26c0ef 72 B00000110,B01100001,B10011100,B00110000,B11000011,B00110000,B11000110,B00110000,B00011001,B10000110,B01100000,B01100110,B00011000,B01100000,
wuuff 14:41173f26c0ef 73 B00000110,B01100001,B10001110,B00110000,B11000011,B00110000,B11000110,B00110000,B00011001,B10000110,B01100000,B01100110,B00011000,B01100000,
wuuff 14:41173f26c0ef 74 B00011110,B01111001,B10000110,B00110000,B11001111,B00111100,B00111000,B00111111,B10011110,B00000111,B10000000,B00011000,B00011000,B01100000,
wuuff 14:41173f26c0ef 75 B00011110,B01111001,B10000110,B00110000,B11001111,B00111100,B00111000,B00111111,B10011110,B00000111,B10000000,B00011000,B00011000,B01100000,
wuuff 14:41173f26c0ef 76 B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100,
wuuff 14:41173f26c0ef 77 B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100,
wuuff 14:41173f26c0ef 78 B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100,
wuuff 14:41173f26c0ef 79 B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00011100,
wuuff 14:41173f26c0ef 80 B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00011100,
wuuff 14:41173f26c0ef 81 B11111000,B00000000,B00000000,B00000000,B01111111,B10000000,B00000000,B00000000,B00000111,B11111000,B00000000,B00000000,B00000000,B01111100,
wuuff 14:41173f26c0ef 82 B11111000,B00000000,B00000000,B00000000,B01111111,B10000000,B00000000,B00000000,B00000111,B11111000,B00000000,B00000000,B00000000,B01111100,
wuuff 14:41173f26c0ef 83 B11111000,B00000000,B00000000,B00000000,B01111111,B10000000,B00000000,B00000000,B00000111,B11111000,B00000000,B00000000,B00000000,B01111100,
wuuff 14:41173f26c0ef 84 B11111111,B10000000,B00000000,B00111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11110000,B00000000,B00000111,B11111100,
wuuff 14:41173f26c0ef 85 B11111111,B10000000,B00000000,B00111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11110000,B00000000,B00000111,B11111100,
wuuff 14:41173f26c0ef 86 B11111111,B11110000,B00000111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B10000000,B00111111,B11111100,
wuuff 14:41173f26c0ef 87 B11111111,B11110000,B00000111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B10000000,B00111111,B11111100,
wuuff 14:41173f26c0ef 88 B11111111,B11110000,B00000111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B10000000,B00111111,B11111100,
wuuff 14:41173f26c0ef 89 B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 90 B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 91 B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11000000,B00001111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 92 B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11000000,B00001111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 93 B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11000000,B00001111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 94 B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11000000,B00001111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 95 B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11000000,B00001111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 96 B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000000,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 97 B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000000,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 98 B11111111,B11111111,B11111111,B11111111,B10000000,B11111111,B11000000,B00001111,B11111100,B00000111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 99 B11111111,B11111111,B11111111,B11111111,B10000000,B11111111,B11000000,B00001111,B11111100,B00000111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 100 B11111111,B11111111,B11111111,B11111111,B10000000,B11111111,B11000000,B00001111,B11111100,B00000111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 101 B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 102 B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 103 B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 104 B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 105 B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 106 B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 107 B11111111,B11111111,B11111111,B11111110,B01111111,B11111111,B00000000,B00000011,B11111111,B11111001,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 108 B11111111,B11111111,B11111111,B11111111,B10000000,B11111111,B00000000,B00000011,B11111100,B00000111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 109 B11111111,B11111111,B11111111,B11111111,B10000000,B11111111,B00000000,B00000011,B11111100,B00000111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 110 B11111111,B11111111,B11111111,B11111111,B10000000,B11111111,B00000000,B00000011,B11111100,B00000111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 111 B11111111,B11111111,B11111111,B11111111,B11111111,B00000011,B00000000,B00000011,B00000011,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 112 B11111111,B11111111,B11111111,B11111111,B11111111,B00000011,B00000000,B00000011,B00000011,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 113 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 114 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 115 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 116 B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 117 B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 118 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 119 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 120 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 121 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 122 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 123 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 124 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 125 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 126 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 127 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 128 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 129 B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 130 B11111111,B11111111,B11111111,B11111111,B11111111,B11111000,B00000000,B00000000,B01111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 131 B11111111,B11111111,B11111111,B11111111,B11111111,B11111000,B00000000,B00000000,B01111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 132 B11111111,B11111111,B11111111,B11111111,B11111111,B11111000,B00000000,B00000000,B01111111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 133 B11111111,B11111111,B11111111,B11111111,B11111111,B11100000,B00000000,B00000000,B00011111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 134 B11111111,B11111111,B11111111,B11111111,B11111111,B11100000,B00000000,B00000000,B00011111,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 135 B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000000,B00000000,B00000011,B11111111,B11111111,B11111111,B11111111,B11111100,
wuuff 14:41173f26c0ef 136 B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000000,B00000000,B00000011,B11010101,B01010100,B01000111,B00010001,B01000100,
wuuff 14:41173f26c0ef 137 B11111111,B11111111,B11111111,B11111111,B11111111,B00000000,B00000000,B00000000,B00000011,B11010101,B01010101,B11011111,B11010101,B01110100,
wuuff 14:41173f26c0ef 138 B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B00000000,B00000000,B11000101,B01010100,B11001111,B00110101,B01101100,
wuuff 14:41173f26c0ef 139 B11111111,B11111111,B11111111,B11111111,B11111100,B00000000,B00000000,B00000000,B00000000,B11010100,B01000101,B11011111,B00010001,B01011100,
Pokitto 5:56c4f2f12ec0 140 };
Pokitto 5:56c4f2f12ec0 141
Pokitto 5:56c4f2f12ec0 142 /*const byte city[] PROGMEM = {8,8,
Pokitto 5:56c4f2f12ec0 143 B00000000,
Pokitto 5:56c4f2f12ec0 144 B00000000,
Pokitto 5:56c4f2f12ec0 145 B00000000,
Pokitto 5:56c4f2f12ec0 146 B00000000,
Pokitto 5:56c4f2f12ec0 147 B00100010,
Pokitto 5:56c4f2f12ec0 148 B01110110,
Pokitto 5:56c4f2f12ec0 149 B01111110,
Pokitto 5:56c4f2f12ec0 150 B11111111,
Pokitto 5:56c4f2f12ec0 151 };*/
Pokitto 5:56c4f2f12ec0 152
Pokitto 5:56c4f2f12ec0 153 const byte city[] PROGMEM = {8,8,
Pokitto 5:56c4f2f12ec0 154 B00000000,
Pokitto 5:56c4f2f12ec0 155 B00000000,
Pokitto 5:56c4f2f12ec0 156 B00000000,
Pokitto 5:56c4f2f12ec0 157 B00000000,
Pokitto 5:56c4f2f12ec0 158 B01100100,
Pokitto 5:56c4f2f12ec0 159 B01101110,
Pokitto 5:56c4f2f12ec0 160 B01111111,
Pokitto 5:56c4f2f12ec0 161 B11111111,
Pokitto 5:56c4f2f12ec0 162 };
Pokitto 5:56c4f2f12ec0 163
Pokitto 5:56c4f2f12ec0 164 const byte deadcity[] PROGMEM = {8,8,
Pokitto 5:56c4f2f12ec0 165 B00000000,
Pokitto 5:56c4f2f12ec0 166 B00000000,
Pokitto 5:56c4f2f12ec0 167 B00000000,
Pokitto 5:56c4f2f12ec0 168 B00000000,
Pokitto 5:56c4f2f12ec0 169 B00000000,
Pokitto 5:56c4f2f12ec0 170 B00000000,
Pokitto 5:56c4f2f12ec0 171 B00100000,
Pokitto 5:56c4f2f12ec0 172 B01100010,
Pokitto 5:56c4f2f12ec0 173 };
Pokitto 5:56c4f2f12ec0 174
Pokitto 5:56c4f2f12ec0 175 const byte launcher[] PROGMEM = {8,8,
Pokitto 5:56c4f2f12ec0 176 B00011000,
Pokitto 5:56c4f2f12ec0 177 B00011000,
Pokitto 5:56c4f2f12ec0 178 B00011000,
Pokitto 5:56c4f2f12ec0 179 B00100100,
Pokitto 5:56c4f2f12ec0 180 B00100100,
Pokitto 5:56c4f2f12ec0 181 B01000010,
Pokitto 5:56c4f2f12ec0 182 B01000010,
Pokitto 5:56c4f2f12ec0 183 B10000001,
Pokitto 5:56c4f2f12ec0 184 };
Pokitto 5:56c4f2f12ec0 185
Pokitto 5:56c4f2f12ec0 186 const byte deadlauncher[] PROGMEM = {8,8,
Pokitto 5:56c4f2f12ec0 187 B00000000,
Pokitto 5:56c4f2f12ec0 188 B00000000,
Pokitto 5:56c4f2f12ec0 189 B00000000,
Pokitto 5:56c4f2f12ec0 190 B00000000,
Pokitto 5:56c4f2f12ec0 191 B00000000,
Pokitto 5:56c4f2f12ec0 192 B01100110,
Pokitto 5:56c4f2f12ec0 193 B01011010,
Pokitto 5:56c4f2f12ec0 194 B10000001,
Pokitto 5:56c4f2f12ec0 195 };
Pokitto 5:56c4f2f12ec0 196
Pokitto 5:56c4f2f12ec0 197 #define SOUND_PLAUNCH 0
Pokitto 5:56c4f2f12ec0 198 #define SOUND_ELAUNCH 1
Pokitto 5:56c4f2f12ec0 199 #define SOUND_DETONATE 2
Pokitto 5:56c4f2f12ec0 200 #define SOUND_SCORE 3
Pokitto 5:56c4f2f12ec0 201 #define SOUND_DEAD 4
Pokitto 5:56c4f2f12ec0 202 #define SOUND_LOSE 5
Pokitto 5:56c4f2f12ec0 203
Pokitto 5:56c4f2f12ec0 204 #define MODE_PREGAME 0
Pokitto 5:56c4f2f12ec0 205 #define MODE_GAME 1
Pokitto 5:56c4f2f12ec0 206 #define MODE_LULL 2
Pokitto 5:56c4f2f12ec0 207 #define MODE_DEAD 3
Pokitto 5:56c4f2f12ec0 208 #define MODE_POSTDEAD 4
Pokitto 5:56c4f2f12ec0 209
Pokitto 5:56c4f2f12ec0 210 #define TARGET_SPEED 3
Pokitto 5:56c4f2f12ec0 211
Pokitto 5:56c4f2f12ec0 212 #define LAUNCHER_ONE 1
Pokitto 5:56c4f2f12ec0 213 #define LAUNCHER_TWO 2
Pokitto 5:56c4f2f12ec0 214 #define MAX_PMISSILES 10
Pokitto 5:56c4f2f12ec0 215 #define PSPEED 4
Pokitto 5:56c4f2f12ec0 216 #define PRADIUS 7
Pokitto 5:56c4f2f12ec0 217 #define EXPAND 0
Pokitto 5:56c4f2f12ec0 218 #define SHRINK 1
Pokitto 5:56c4f2f12ec0 219
Pokitto 5:56c4f2f12ec0 220 #define MAX_EMISSILES 10
Pokitto 5:56c4f2f12ec0 221 #define MAX_CHANCE 50
Pokitto 5:56c4f2f12ec0 222
Pokitto 5:56c4f2f12ec0 223 // State variables
Pokitto 5:56c4f2f12ec0 224 uint8_t mode = 0;
Pokitto 5:56c4f2f12ec0 225 uint8_t counter = 0;
Pokitto 5:56c4f2f12ec0 226 uint8_t flash = 0;
Pokitto 5:56c4f2f12ec0 227 uint8_t stage = 0; //Maximum of 255 stages
Pokitto 5:56c4f2f12ec0 228 uint32_t score = 0; //Score needs more space than other vars
Pokitto 5:56c4f2f12ec0 229
wuuff 13:b133c46dbda7 230 uint32_t lullMissiles = 0;
Pokitto 5:56c4f2f12ec0 231 uint8_t lullCities[8] = {0,0,0,0,0,0,0,0};
Pokitto 5:56c4f2f12ec0 232
Pokitto 5:56c4f2f12ec0 233 uint8_t cities[8] = {1,1,1,1,1,1,1,1}; //Whether the cities or launchers are alive
Pokitto 5:56c4f2f12ec0 234
wuuff 14:41173f26c0ef 235 uint8_t targetX = WIDTH/2;
wuuff 14:41173f26c0ef 236 uint8_t targetY = HEIGHT/2;
Pokitto 5:56c4f2f12ec0 237 uint8_t pammo[2] = {10,10};
Pokitto 5:56c4f2f12ec0 238 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 239 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 240 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 241
Pokitto 5:56c4f2f12ec0 242 uint8_t etotal = 5;
Pokitto 5:56c4f2f12ec0 243 uint8_t echance = 1;
Pokitto 5:56c4f2f12ec0 244 float espeed = 0.2;
Pokitto 5:56c4f2f12ec0 245 uint8_t eDests[MAX_EMISSILES] = {100,100,100,100,100,100,100,100,100,100};
Pokitto 5:56c4f2f12ec0 246 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 247
wuuff 14:41173f26c0ef 248 void doTitle(uint8_t is_pause){
wuuff 14:41173f26c0ef 249 while (gb.isRunning()) {
wuuff 14:41173f26c0ef 250 if( gb.update() ){
wuuff 14:41173f26c0ef 251 gb.display.setColor(7);
wuuff 14:41173f26c0ef 252 gb.display.drawBitmap(0,0,armageddon);
wuuff 14:41173f26c0ef 253 if( counter%8 == 0 ){
wuuff 14:41173f26c0ef 254 flash ^= 255;
wuuff 14:41173f26c0ef 255 }
wuuff 14:41173f26c0ef 256
wuuff 14:41173f26c0ef 257 if( flash ){
wuuff 14:41173f26c0ef 258 gb.display.setColor(4);
wuuff 14:41173f26c0ef 259 gb.display.cursorY = HEIGHT - TEXT_HEIGHT*2;
wuuff 14:41173f26c0ef 260 if( is_pause ){
wuuff 14:41173f26c0ef 261 gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*3;
wuuff 14:41173f26c0ef 262 gb.display.print(("PAUSED"));
wuuff 14:41173f26c0ef 263 }else{
wuuff 14:41173f26c0ef 264 gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*3;
wuuff 14:41173f26c0ef 265 gb.display.print(("PRESS \25"));
wuuff 14:41173f26c0ef 266 }
wuuff 14:41173f26c0ef 267 }
wuuff 14:41173f26c0ef 268 counter++;
wuuff 14:41173f26c0ef 269 if( gb.buttons.pressed(BTN_A) ){
wuuff 14:41173f26c0ef 270 gb.display.setColor(WHITE);
wuuff 14:41173f26c0ef 271 break;
wuuff 14:41173f26c0ef 272 }
wuuff 14:41173f26c0ef 273 }
wuuff 14:41173f26c0ef 274 }
wuuff 14:41173f26c0ef 275 }
wuuff 14:41173f26c0ef 276
Pokitto 5:56c4f2f12ec0 277 void setup() {
Pokitto 5:56c4f2f12ec0 278 gb.begin();
Pokitto 5:56c4f2f12ec0 279 loadHighscores();
wuuff 14:41173f26c0ef 280
wuuff 14:41173f26c0ef 281 //We need to do extra Gamebuino-formatting-specific initialization if we don't use the title screen
wuuff 14:41173f26c0ef 282 gb.display.setFont(font5x7);
wuuff 14:41173f26c0ef 283 gb.display.fontSize = 1;
wuuff 14:41173f26c0ef 284 gb.display.textWrap = false;
wuuff 14:41173f26c0ef 285 gb.display.persistence = false;
Pokitto 5:56c4f2f12ec0 286 gb.battery.show = false;
wuuff 14:41173f26c0ef 287 gb.display.setColor(BLACK);
wuuff 14:41173f26c0ef 288 gb.display.setColorDepth(1);
wuuff 14:41173f26c0ef 289
wuuff 14:41173f26c0ef 290 doTitle(0);
Pokitto 5:56c4f2f12ec0 291 gb.pickRandomSeed();
Pokitto 5:56c4f2f12ec0 292 }
Pokitto 5:56c4f2f12ec0 293
Pokitto 5:56c4f2f12ec0 294 void nextStage(){
Pokitto 5:56c4f2f12ec0 295 stage++;
Pokitto 5:56c4f2f12ec0 296 //Reset cities (since we cleared them for the visual effect
Pokitto 5:56c4f2f12ec0 297 for( uint8_t i = 0; i < 8; i++ ){
Pokitto 5:56c4f2f12ec0 298 cities[i] = lullCities[i];
Pokitto 5:56c4f2f12ec0 299 }
Pokitto 5:56c4f2f12ec0 300 //Reset launchers
Pokitto 5:56c4f2f12ec0 301 cities[2] = 1;
Pokitto 5:56c4f2f12ec0 302 cities[5] = 1;
Pokitto 5:56c4f2f12ec0 303 //Reset missiles
Pokitto 5:56c4f2f12ec0 304 pammo[0] = 10;
Pokitto 5:56c4f2f12ec0 305 pammo[1] = 10;
Pokitto 5:56c4f2f12ec0 306 //Reset in-flight missiles
Pokitto 5:56c4f2f12ec0 307 for( uint8_t i = 0; i < 10; i++ ){
wuuff 14:41173f26c0ef 308 pDests[i][0] = 127;
wuuff 14:41173f26c0ef 309 pDetonations[i][0] = 127;
wuuff 14:41173f26c0ef 310 eDests[i] = 127;
Pokitto 5:56c4f2f12ec0 311 }
Pokitto 5:56c4f2f12ec0 312
Pokitto 5:56c4f2f12ec0 313 etotal = stage > 10 ? 20 : 10+stage; //Max of 20 missiles per stage, start at 10
Pokitto 5:56c4f2f12ec0 314 //echance = stage > 5 ? 5 : stage; //Max of 5/100 chance per frame
Pokitto 5:56c4f2f12ec0 315 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 316 }
Pokitto 5:56c4f2f12ec0 317
Pokitto 5:56c4f2f12ec0 318 void nextLull(){
Pokitto 5:56c4f2f12ec0 319 //Reset lullMissiles
Pokitto 5:56c4f2f12ec0 320 lullMissiles = 0;
Pokitto 5:56c4f2f12ec0 321 //Reset lullCities
Pokitto 5:56c4f2f12ec0 322 for( uint8_t i = 0; i < 8; i++ ){
Pokitto 5:56c4f2f12ec0 323 lullCities[i] = 0;
Pokitto 5:56c4f2f12ec0 324 }
Pokitto 5:56c4f2f12ec0 325 }
Pokitto 5:56c4f2f12ec0 326
Pokitto 5:56c4f2f12ec0 327 void drawScore(){
wuuff 14:41173f26c0ef 328 gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*3;
Pokitto 5:56c4f2f12ec0 329 gb.display.cursorY = 0;
Pokitto 5:56c4f2f12ec0 330
Pokitto 5:56c4f2f12ec0 331 if( score < 100000 ){
Pokitto 5:56c4f2f12ec0 332 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 333 }
Pokitto 5:56c4f2f12ec0 334 if( score < 10000 ){
Pokitto 5:56c4f2f12ec0 335 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 336 }
Pokitto 5:56c4f2f12ec0 337 if( score < 1000 ){
Pokitto 5:56c4f2f12ec0 338 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 339 }
Pokitto 5:56c4f2f12ec0 340 if( score < 100 ){
Pokitto 5:56c4f2f12ec0 341 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 342 }
Pokitto 5:56c4f2f12ec0 343 if( score < 10 ){
Pokitto 5:56c4f2f12ec0 344 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 345 }
Pokitto 5:56c4f2f12ec0 346 gb.display.print(score);
Pokitto 5:56c4f2f12ec0 347 }
Pokitto 5:56c4f2f12ec0 348
Pokitto 5:56c4f2f12ec0 349 void drawTargets(){
Pokitto 5:56c4f2f12ec0 350 gb.display.drawFastHLine(targetX-1,targetY,3);
wuuff 13:b133c46dbda7 351 gb.display.drawFastVLine(targetX,targetY-1,2);
Pokitto 5:56c4f2f12ec0 352
Pokitto 5:56c4f2f12ec0 353 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
Pokitto 5:56c4f2f12ec0 354 //Check for a valid destination without a current detonation
wuuff 14:41173f26c0ef 355 if( pDests[i][0] <= WIDTH && pDetonations[i][0] > WIDTH ){
Pokitto 5:56c4f2f12ec0 356 gb.display.drawPixel(pDests[i][0], pDests[i][1]);
Pokitto 5:56c4f2f12ec0 357 }
Pokitto 5:56c4f2f12ec0 358 }
Pokitto 5:56c4f2f12ec0 359 }
Pokitto 5:56c4f2f12ec0 360
Pokitto 5:56c4f2f12ec0 361 void drawCities(){
wuuff 13:b133c46dbda7 362 gb.display.setColor(4);
Pokitto 5:56c4f2f12ec0 363 //uint8_t alldead = 1;
Pokitto 5:56c4f2f12ec0 364 for(uint8_t i = 0; i < 8; i++){
Pokitto 5:56c4f2f12ec0 365 if( i == 2 || i == 5 ){
Pokitto 5:56c4f2f12ec0 366 if( cities[i] ){
wuuff 14:41173f26c0ef 367 gb.display.drawBitmap(i*14+2,HEIGHT-8,launcher);
Pokitto 5:56c4f2f12ec0 368 }else{
wuuff 14:41173f26c0ef 369 gb.display.drawBitmap(i*14+2,HEIGHT-8,deadlauncher);
Pokitto 5:56c4f2f12ec0 370 }
Pokitto 5:56c4f2f12ec0 371 }else{
Pokitto 5:56c4f2f12ec0 372 if( cities[i] ){
Pokitto 5:56c4f2f12ec0 373 //alldead = 0;
wuuff 14:41173f26c0ef 374 gb.display.drawBitmap(i*14+2,HEIGHT-8,city);
Pokitto 5:56c4f2f12ec0 375 }else{
wuuff 14:41173f26c0ef 376 gb.display.drawBitmap(i*14+2,HEIGHT-8,deadcity);
Pokitto 5:56c4f2f12ec0 377 }
Pokitto 5:56c4f2f12ec0 378 }
Pokitto 5:56c4f2f12ec0 379 }
Pokitto 5:56c4f2f12ec0 380
wuuff 13:b133c46dbda7 381 gb.display.setColor(1);
Pokitto 5:56c4f2f12ec0 382 /*
Pokitto 5:56c4f2f12ec0 383 if( alldead ){
Pokitto 5:56c4f2f12ec0 384 gb.display.cursorX = 84/2 - 5*3;
Pokitto 5:56c4f2f12ec0 385 gb.display.cursorY = 48/2 - 5;
Pokitto 5:56c4f2f12ec0 386 gb.display.print("THE END");
Pokitto 5:56c4f2f12ec0 387 }
Pokitto 5:56c4f2f12ec0 388 */
Pokitto 5:56c4f2f12ec0 389 }
Pokitto 5:56c4f2f12ec0 390
Pokitto 5:56c4f2f12ec0 391 void drawAmmo(){
wuuff 13:b133c46dbda7 392 gb.display.setColor(3);
Pokitto 5:56c4f2f12ec0 393 for( uint8_t i = 0; i < 2; i++ ){
wuuff 14:41173f26c0ef 394 uint8_t xcoord = i == 0 ? 2*14 + 5 : 5*14 + 5;
wuuff 14:41173f26c0ef 395 uint8_t ycoord = HEIGHT-1;
Pokitto 5:56c4f2f12ec0 396 if( cities[i*3+2] ){ //Is launcher alive?
Pokitto 5:56c4f2f12ec0 397 for( uint8_t j = 0; j < pammo[i]; j++ ){
Pokitto 5:56c4f2f12ec0 398 gb.display.drawPixel(xcoord,ycoord);
Pokitto 5:56c4f2f12ec0 399 if( xcoord % 2 == 0 ){
Pokitto 5:56c4f2f12ec0 400 xcoord--;
Pokitto 5:56c4f2f12ec0 401 ycoord--;
Pokitto 5:56c4f2f12ec0 402 }else{
Pokitto 5:56c4f2f12ec0 403 xcoord++;
Pokitto 5:56c4f2f12ec0 404 }
Pokitto 5:56c4f2f12ec0 405 }
Pokitto 5:56c4f2f12ec0 406 }
Pokitto 5:56c4f2f12ec0 407 }
HomineLudens 6:22d706e5dd6e 408 gb.display.setColor(1);
Pokitto 5:56c4f2f12ec0 409 }
Pokitto 5:56c4f2f12ec0 410
Pokitto 5:56c4f2f12ec0 411 void drawMissiles(){
Pokitto 5:56c4f2f12ec0 412 //Player Missiles
wuuff 13:b133c46dbda7 413 gb.display.setColor(3);
Pokitto 5:56c4f2f12ec0 414 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
Pokitto 5:56c4f2f12ec0 415 //Check for a valid destination without a current detonation
wuuff 14:41173f26c0ef 416 if( pDests[i][0] <= WIDTH && pDetonations[i][0] > WIDTH ){
Pokitto 5:56c4f2f12ec0 417 if(pMissiles[i][2] == LAUNCHER_ONE){
wuuff 14:41173f26c0ef 418 gb.display.drawLine(2*14 + 5,HEIGHT-8,pMissiles[i][0], pMissiles[i][1]);
Pokitto 5:56c4f2f12ec0 419 }else{
wuuff 14:41173f26c0ef 420 gb.display.drawLine(5*14 + 6,HEIGHT-8,pMissiles[i][0], pMissiles[i][1]);
Pokitto 5:56c4f2f12ec0 421 }
Pokitto 5:56c4f2f12ec0 422 }
Pokitto 5:56c4f2f12ec0 423 }
Pokitto 5:56c4f2f12ec0 424
Pokitto 5:56c4f2f12ec0 425 //Enemy Missiles
wuuff 13:b133c46dbda7 426 gb.display.setColor(7);
Pokitto 5:56c4f2f12ec0 427 for(uint8_t i = 0; i < MAX_EMISSILES; i++){
Pokitto 5:56c4f2f12ec0 428 //Check for a valid destination
wuuff 14:41173f26c0ef 429 if( eDests[i] <= WIDTH ){
Pokitto 5:56c4f2f12ec0 430 gb.display.drawLine(eMissiles[i][0],eMissiles[i][1],eMissiles[i][2], eMissiles[i][3]);
Pokitto 5:56c4f2f12ec0 431 }
Pokitto 5:56c4f2f12ec0 432 }
Pokitto 5:56c4f2f12ec0 433 gb.display.setColor(1);
Pokitto 5:56c4f2f12ec0 434 }
Pokitto 5:56c4f2f12ec0 435
wuuff 13:b133c46dbda7 436 uint8_t explosionColor = 0;
Pokitto 5:56c4f2f12ec0 437 void drawDetonations(){
wuuff 13:b133c46dbda7 438 gb.display.setColor(explosionColor+1);
wuuff 13:b133c46dbda7 439 if(counter%2 == 0){
wuuff 13:b133c46dbda7 440 explosionColor++;
wuuff 13:b133c46dbda7 441 explosionColor%=7;
wuuff 13:b133c46dbda7 442 }
Pokitto 5:56c4f2f12ec0 443 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
wuuff 14:41173f26c0ef 444 if( pDetonations[i][0] <= WIDTH ){
wuuff 13:b133c46dbda7 445 gb.display.fillCircle(pDetonations[i][0],pDetonations[i][1],pDetonations[i][2]);
Pokitto 5:56c4f2f12ec0 446 }
Pokitto 5:56c4f2f12ec0 447 }
wuuff 13:b133c46dbda7 448 gb.display.setColor(1);
Pokitto 5:56c4f2f12ec0 449 }
Pokitto 5:56c4f2f12ec0 450
Pokitto 5:56c4f2f12ec0 451 void launchMissile(uint8_t launcher){
Pokitto 5:56c4f2f12ec0 452 //If there is no free slot in pDests, do not launch
Pokitto 5:56c4f2f12ec0 453 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
wuuff 14:41173f26c0ef 454 if( pDests[i][0] > WIDTH ){
Pokitto 5:56c4f2f12ec0 455 // Which launcher? Alive? Has ammo?
Pokitto 5:56c4f2f12ec0 456 if(launcher == LAUNCHER_ONE && cities[2] && pammo[0]){
Pokitto 5:56c4f2f12ec0 457 pDests[i][0] = targetX;
Pokitto 5:56c4f2f12ec0 458 pDests[i][1] = targetY;
wuuff 14:41173f26c0ef 459 pMissiles[i][0] = 2*14 + 5; //X-coord of left launcher
Pokitto 5:56c4f2f12ec0 460 pMissiles[i][2] = LAUNCHER_ONE; //Launched from launcher one
Pokitto 5:56c4f2f12ec0 461 pammo[0]--;
Pokitto 5:56c4f2f12ec0 462 playSound(SOUND_PLAUNCH);
Pokitto 5:56c4f2f12ec0 463 }else if(launcher == LAUNCHER_TWO && cities[5] && pammo[1]){
Pokitto 5:56c4f2f12ec0 464 pDests[i][0] = targetX;
Pokitto 5:56c4f2f12ec0 465 pDests[i][1] = targetY;
wuuff 14:41173f26c0ef 466 pMissiles[i][0] = 5*14 + 6; //X-coord of right launcher
Pokitto 5:56c4f2f12ec0 467 pMissiles[i][2] = LAUNCHER_TWO; //Launched from launcher two
Pokitto 5:56c4f2f12ec0 468 pammo[1]--;
Pokitto 5:56c4f2f12ec0 469 playSound(SOUND_PLAUNCH);
Pokitto 5:56c4f2f12ec0 470 }
wuuff 14:41173f26c0ef 471 pMissiles[i][1] = HEIGHT-8; //Y-coord of both launchers
Pokitto 5:56c4f2f12ec0 472 break;
Pokitto 5:56c4f2f12ec0 473 }
Pokitto 5:56c4f2f12ec0 474 }
Pokitto 5:56c4f2f12ec0 475 }
Pokitto 5:56c4f2f12ec0 476
Pokitto 5:56c4f2f12ec0 477 void tryLaunchEnemy(){
Pokitto 5:56c4f2f12ec0 478 uint8_t someActive = 0;
Pokitto 5:56c4f2f12ec0 479
Pokitto 5:56c4f2f12ec0 480 if( etotal > 0 ){
Pokitto 5:56c4f2f12ec0 481
Pokitto 5:56c4f2f12ec0 482 // Check whether there are any active missiles
Pokitto 5:56c4f2f12ec0 483 // If none are active, always spawn one to avoid
Pokitto 5:56c4f2f12ec0 484 // long pauses without any enemy missiles
Pokitto 5:56c4f2f12ec0 485 for(uint8_t i = 0; i < MAX_EMISSILES; i++){
wuuff 14:41173f26c0ef 486 if( eDests[i] <= WIDTH ){
Pokitto 5:56c4f2f12ec0 487 someActive = 1;
Pokitto 5:56c4f2f12ec0 488 break;
Pokitto 5:56c4f2f12ec0 489 }
Pokitto 5:56c4f2f12ec0 490 }
Pokitto 5:56c4f2f12ec0 491
Pokitto 5:56c4f2f12ec0 492 if( (!someActive || echance >= random(100)) ){ //echance of 100
Pokitto 5:56c4f2f12ec0 493 for(uint8_t i = 0; i < MAX_EMISSILES; i++){
wuuff 14:41173f26c0ef 494 if( eDests[i] > WIDTH ){
Pokitto 5:56c4f2f12ec0 495 etotal--;
wuuff 13:b133c46dbda7 496 eDests[i] = random(7); //Target one of the 6 cities or 2 launch sites TODO: Come back later if random's behavior changes
wuuff 14:41173f26c0ef 497 eMissiles[i][0] = random(WIDTH); //Screen width //TODO: if random is supposed to be inclusive, add a -1
Pokitto 5:56c4f2f12ec0 498 eMissiles[i][1] = 0; //Top of screen
Pokitto 5:56c4f2f12ec0 499 eMissiles[i][2] = eMissiles[i][0]; //Start and end are same
Pokitto 5:56c4f2f12ec0 500 eMissiles[i][3] = 0; //Top of screen
Pokitto 5:56c4f2f12ec0 501 playSound(SOUND_ELAUNCH);
Pokitto 5:56c4f2f12ec0 502 break; //Only spawn one
Pokitto 5:56c4f2f12ec0 503 }
Pokitto 5:56c4f2f12ec0 504 }
Pokitto 5:56c4f2f12ec0 505 }
Pokitto 5:56c4f2f12ec0 506
Pokitto 5:56c4f2f12ec0 507 }
Pokitto 5:56c4f2f12ec0 508 }
Pokitto 5:56c4f2f12ec0 509
Pokitto 5:56c4f2f12ec0 510 void stepMissiles(){
Pokitto 5:56c4f2f12ec0 511 //Player Missiles
Pokitto 5:56c4f2f12ec0 512 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
Pokitto 5:56c4f2f12ec0 513 //Check for a valid destination without a current detonation
wuuff 14:41173f26c0ef 514 if( pDests[i][0] <= WIDTH && pDetonations[i][0] > WIDTH ){
Pokitto 5:56c4f2f12ec0 515 //If the missile is close enough to the destination, detonate
Pokitto 5:56c4f2f12ec0 516 if( abs( pDests[i][0] - pMissiles[i][0] ) < PSPEED && abs( pDests[i][1] - pMissiles[i][1] ) < PSPEED ){
Pokitto 5:56c4f2f12ec0 517 pDetonations[i][0] = pDests[i][0];
Pokitto 5:56c4f2f12ec0 518 pDetonations[i][1] = pDests[i][1];
Pokitto 5:56c4f2f12ec0 519 pDetonations[i][2] = 0; //Start detonation at radius of 0
Pokitto 5:56c4f2f12ec0 520 pDetonations[i][3] = EXPAND; //Detonation is increasing in size
Pokitto 5:56c4f2f12ec0 521 //Otherwise, keep moving towards destination
Pokitto 5:56c4f2f12ec0 522 }else{
Pokitto 5:56c4f2f12ec0 523 float dir = atan2(pDests[i][1]-pMissiles[i][1], pDests[i][0]-pMissiles[i][0]);
Pokitto 5:56c4f2f12ec0 524 pMissiles[i][0] += PSPEED * cos(dir);
Pokitto 5:56c4f2f12ec0 525 pMissiles[i][1] += PSPEED * sin(dir);
Pokitto 5:56c4f2f12ec0 526 }
Pokitto 5:56c4f2f12ec0 527 }
Pokitto 5:56c4f2f12ec0 528 }
Pokitto 5:56c4f2f12ec0 529
Pokitto 5:56c4f2f12ec0 530 //Enemy Missiles
Pokitto 5:56c4f2f12ec0 531 for(uint8_t i = 0; i < MAX_EMISSILES; i++){
Pokitto 5:56c4f2f12ec0 532 //Check for a valid destination
wuuff 14:41173f26c0ef 533 if( eDests[i] <= WIDTH ){
Pokitto 5:56c4f2f12ec0 534 //If enemy missile is close enough to the destination, detonate
wuuff 14:41173f26c0ef 535 if( abs( (eDests[i]*14+6) - eMissiles[i][2] ) < PSPEED && abs( HEIGHT-4 - eMissiles[i][3] ) < PSPEED ){
Pokitto 5:56c4f2f12ec0 536 cities[eDests[i]] = 0; //Destroy city/launcher
Pokitto 5:56c4f2f12ec0 537
Pokitto 5:56c4f2f12ec0 538 //If launcher, remove its ammo
Pokitto 5:56c4f2f12ec0 539 if( eDests[i] == 2 ){
Pokitto 5:56c4f2f12ec0 540 pammo[0] = 0;
Pokitto 5:56c4f2f12ec0 541 }
Pokitto 5:56c4f2f12ec0 542 if( eDests[i] == 5 ){
Pokitto 5:56c4f2f12ec0 543 pammo[1] = 0;
Pokitto 5:56c4f2f12ec0 544 }
Pokitto 5:56c4f2f12ec0 545
wuuff 14:41173f26c0ef 546 eDests[i] = 127; //Reset enemy missile
Pokitto 5:56c4f2f12ec0 547 playSound(SOUND_DEAD);
Pokitto 5:56c4f2f12ec0 548 //Otherwise, keep moving towards destination
Pokitto 5:56c4f2f12ec0 549 }else{
wuuff 14:41173f26c0ef 550 float dir = atan2( HEIGHT-4 - eMissiles[i][3], (eDests[i]*14+6)-eMissiles[i][2] );
Pokitto 5:56c4f2f12ec0 551 eMissiles[i][2] += espeed * cos(dir);
Pokitto 5:56c4f2f12ec0 552 eMissiles[i][3] += espeed * sin(dir);
Pokitto 5:56c4f2f12ec0 553 }
Pokitto 5:56c4f2f12ec0 554 }
Pokitto 5:56c4f2f12ec0 555 }
Pokitto 5:56c4f2f12ec0 556 }
Pokitto 5:56c4f2f12ec0 557
Pokitto 5:56c4f2f12ec0 558 void stepDetonations(){
Pokitto 5:56c4f2f12ec0 559 if( counter%2 == 0 ){
Pokitto 5:56c4f2f12ec0 560 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
wuuff 14:41173f26c0ef 561 if( pDetonations[i][0] <= WIDTH ){
Pokitto 5:56c4f2f12ec0 562 if( pDetonations[i][3] == EXPAND ){ //If detonation is expanding
Pokitto 5:56c4f2f12ec0 563 if( pDetonations[i][2] < PRADIUS ){
Pokitto 5:56c4f2f12ec0 564 pDetonations[i][2]++;
Pokitto 5:56c4f2f12ec0 565 }else{
Pokitto 5:56c4f2f12ec0 566 pDetonations[i][3] = SHRINK; //Start shrinking
Pokitto 5:56c4f2f12ec0 567 }
Pokitto 5:56c4f2f12ec0 568 }
Pokitto 5:56c4f2f12ec0 569 //Check this now instead of using else because it may have just
Pokitto 5:56c4f2f12ec0 570 //set to SHRINK; immediately checking will remove a delay at full
Pokitto 5:56c4f2f12ec0 571 //size. If a delay is desired, this if can be switched to an else.
Pokitto 5:56c4f2f12ec0 572 if( pDetonations[i][3] == SHRINK ){ //If detonation is shrinking
Pokitto 5:56c4f2f12ec0 573 if( pDetonations[i][2] > 0 ){
Pokitto 5:56c4f2f12ec0 574 pDetonations[i][2]--;
Pokitto 5:56c4f2f12ec0 575 }else{
wuuff 14:41173f26c0ef 576 pDetonations[i][0] = 127; //Detonation is complete, remove it
wuuff 14:41173f26c0ef 577 pDests[i][0] = 127; //Remove this destination
Pokitto 5:56c4f2f12ec0 578 }
Pokitto 5:56c4f2f12ec0 579 }
Pokitto 5:56c4f2f12ec0 580 }
Pokitto 5:56c4f2f12ec0 581 }
Pokitto 5:56c4f2f12ec0 582 }
Pokitto 5:56c4f2f12ec0 583 }
Pokitto 5:56c4f2f12ec0 584
Pokitto 5:56c4f2f12ec0 585 void stepCollision(){
Pokitto 5:56c4f2f12ec0 586 //Player Detonations with Enemy Missiles
Pokitto 5:56c4f2f12ec0 587 for(uint8_t i = 0; i < MAX_PMISSILES; i++){
wuuff 14:41173f26c0ef 588 if( pDetonations[i][0] <= WIDTH ){
Pokitto 5:56c4f2f12ec0 589 for(uint8_t j = 0; j < MAX_EMISSILES; j++){
wuuff 14:41173f26c0ef 590 //Add extra +1 to explosion radius so that collisions are more generous
wuuff 14:41173f26c0ef 591 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]) ) ){
wuuff 14:41173f26c0ef 592 eDests[j] = 127; //Remove enemy missile
Pokitto 5:56c4f2f12ec0 593 score+=25;
Pokitto 5:56c4f2f12ec0 594 playSound(SOUND_DETONATE);
Pokitto 5:56c4f2f12ec0 595 }
Pokitto 5:56c4f2f12ec0 596 }
Pokitto 5:56c4f2f12ec0 597 }
Pokitto 5:56c4f2f12ec0 598 }
Pokitto 5:56c4f2f12ec0 599 }
Pokitto 5:56c4f2f12ec0 600
Pokitto 5:56c4f2f12ec0 601
Pokitto 5:56c4f2f12ec0 602 void checkMenu(){
Pokitto 5:56c4f2f12ec0 603 if( gb.buttons.pressed(BTN_C) ){
wuuff 14:41173f26c0ef 604 doTitle(1);
Pokitto 5:56c4f2f12ec0 605 }
Pokitto 5:56c4f2f12ec0 606 }
Pokitto 5:56c4f2f12ec0 607
Pokitto 5:56c4f2f12ec0 608 void checkWin(){
Pokitto 5:56c4f2f12ec0 609 if( etotal == 0 ){
Pokitto 5:56c4f2f12ec0 610 for(uint8_t i = 0; i < MAX_EMISSILES; i++){
Pokitto 5:56c4f2f12ec0 611 //Check for a valid destination
wuuff 14:41173f26c0ef 612 if( eDests[i] <= WIDTH ){
Pokitto 5:56c4f2f12ec0 613 return;
Pokitto 5:56c4f2f12ec0 614 }
Pokitto 5:56c4f2f12ec0 615 }
Pokitto 5:56c4f2f12ec0 616 //If we get here, all enemy missiles are destroyed and they have no more
Pokitto 5:56c4f2f12ec0 617 nextLull();
Pokitto 5:56c4f2f12ec0 618 mode = MODE_LULL;
Pokitto 5:56c4f2f12ec0 619 }
Pokitto 5:56c4f2f12ec0 620 }
Pokitto 5:56c4f2f12ec0 621
Pokitto 5:56c4f2f12ec0 622 void checkLose(){
Pokitto 5:56c4f2f12ec0 623 for(uint8_t i = 0; i < 8; i++){
Pokitto 5:56c4f2f12ec0 624 if( i != 2 && i != 5 ){
Pokitto 5:56c4f2f12ec0 625 if( cities[i] ){
Pokitto 5:56c4f2f12ec0 626 return; // A city remains alive
Pokitto 5:56c4f2f12ec0 627 }
Pokitto 5:56c4f2f12ec0 628 }
Pokitto 5:56c4f2f12ec0 629 }
Pokitto 5:56c4f2f12ec0 630 //If we get here, all cities are dead. It is the end of days.
Pokitto 5:56c4f2f12ec0 631 counter = 0;
Pokitto 5:56c4f2f12ec0 632 mode = MODE_DEAD;
Pokitto 5:56c4f2f12ec0 633 playSound(SOUND_LOSE);
Pokitto 5:56c4f2f12ec0 634 }
Pokitto 5:56c4f2f12ec0 635
Pokitto 5:56c4f2f12ec0 636 void stepGame(){
Pokitto 5:56c4f2f12ec0 637 //Player input
Pokitto 5:56c4f2f12ec0 638 if( gb.buttons.pressed(BTN_A) ){
HomineLudens 6:22d706e5dd6e 639 launchMissile(LAUNCHER_TWO);
Pokitto 5:56c4f2f12ec0 640 }
Pokitto 5:56c4f2f12ec0 641 if( gb.buttons.pressed(BTN_B) ){
HomineLudens 6:22d706e5dd6e 642 launchMissile(LAUNCHER_ONE);
Pokitto 5:56c4f2f12ec0 643 }
Pokitto 5:56c4f2f12ec0 644
Pokitto 5:56c4f2f12ec0 645 if( gb.buttons.repeat(BTN_LEFT,1) ){
Pokitto 5:56c4f2f12ec0 646 targetX = targetX-TARGET_SPEED > 0 ? targetX-TARGET_SPEED : 0;
Pokitto 5:56c4f2f12ec0 647 }
Pokitto 5:56c4f2f12ec0 648 if( gb.buttons.repeat(BTN_RIGHT,1) ){
wuuff 14:41173f26c0ef 649 targetX = targetX+TARGET_SPEED < WIDTH ? targetX+TARGET_SPEED : WIDTH;
Pokitto 5:56c4f2f12ec0 650 }
Pokitto 5:56c4f2f12ec0 651 if( gb.buttons.repeat(BTN_UP,1) ){
Pokitto 5:56c4f2f12ec0 652 targetY = targetY-TARGET_SPEED > 0 ? targetY-TARGET_SPEED : 0;
Pokitto 5:56c4f2f12ec0 653 }
Pokitto 5:56c4f2f12ec0 654 if( gb.buttons.repeat(BTN_DOWN,1) ){
wuuff 14:41173f26c0ef 655 targetY = targetY+TARGET_SPEED < HEIGHT ? targetY+TARGET_SPEED : HEIGHT;
Pokitto 5:56c4f2f12ec0 656 }
Pokitto 5:56c4f2f12ec0 657
Pokitto 5:56c4f2f12ec0 658 //Game logic
Pokitto 5:56c4f2f12ec0 659 tryLaunchEnemy();
Pokitto 5:56c4f2f12ec0 660 stepMissiles();
Pokitto 5:56c4f2f12ec0 661 stepDetonations();
Pokitto 5:56c4f2f12ec0 662 stepCollision();
Pokitto 5:56c4f2f12ec0 663
Pokitto 5:56c4f2f12ec0 664 //Drawing
Pokitto 5:56c4f2f12ec0 665 drawScore();
Pokitto 5:56c4f2f12ec0 666 drawTargets();
Pokitto 5:56c4f2f12ec0 667 drawCities();
Pokitto 5:56c4f2f12ec0 668 drawAmmo();
Pokitto 5:56c4f2f12ec0 669 drawMissiles();
Pokitto 5:56c4f2f12ec0 670 drawDetonations();
Pokitto 5:56c4f2f12ec0 671
Pokitto 5:56c4f2f12ec0 672 checkWin();
Pokitto 5:56c4f2f12ec0 673 checkLose();
Pokitto 5:56c4f2f12ec0 674 }
Pokitto 5:56c4f2f12ec0 675
Pokitto 5:56c4f2f12ec0 676 void drawLull(){
wuuff 13:b133c46dbda7 677 uint32_t cityCount = 0;
wuuff 14:41173f26c0ef 678 gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*6;
wuuff 14:41173f26c0ef 679 gb.display.cursorY = HEIGHT/2 - TEXT_HEIGHT*3;
Pokitto 5:56c4f2f12ec0 680 gb.display.print(("BONUS POINTS"));
Pokitto 5:56c4f2f12ec0 681
wuuff 14:41173f26c0ef 682 gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*8;
wuuff 14:41173f26c0ef 683 gb.display.cursorY += TEXT_HEIGHT*2;
Pokitto 5:56c4f2f12ec0 684 gb.display.print(lullMissiles);
Pokitto 5:56c4f2f12ec0 685
wuuff 13:b133c46dbda7 686 gb.display.setColor(3);
Pokitto 5:56c4f2f12ec0 687 for(uint8_t i = 0; i < lullMissiles; i++){
wuuff 14:41173f26c0ef 688 gb.display.drawPixel(WIDTH/2 - TEXT_WIDTH*6 + i*2,HEIGHT/2 - 3);
Pokitto 5:56c4f2f12ec0 689 }
Pokitto 5:56c4f2f12ec0 690
wuuff 13:b133c46dbda7 691 gb.display.setColor(1);
wuuff 14:41173f26c0ef 692 gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*8;
wuuff 14:41173f26c0ef 693 gb.display.cursorY += TEXT_HEIGHT*2;
wuuff 13:b133c46dbda7 694 for( uint8_t i = 0; i < 8; i++ ){
Pokitto 5:56c4f2f12ec0 695 if( lullCities[i] ) cityCount++;
Pokitto 5:56c4f2f12ec0 696 }
Pokitto 5:56c4f2f12ec0 697 gb.display.print(cityCount);
Pokitto 5:56c4f2f12ec0 698
wuuff 13:b133c46dbda7 699 gb.display.setColor(4);
Pokitto 5:56c4f2f12ec0 700 for(uint8_t i = 0; i < cityCount; i++){
wuuff 14:41173f26c0ef 701 gb.display.drawBitmap(WIDTH/2 - TEXT_WIDTH*6 + i*9,HEIGHT/2+2, city);
Pokitto 5:56c4f2f12ec0 702 }
Pokitto 5:56c4f2f12ec0 703
wuuff 13:b133c46dbda7 704 gb.display.setColor(1);
Pokitto 5:56c4f2f12ec0 705 drawScore();
Pokitto 5:56c4f2f12ec0 706 drawCities();
Pokitto 5:56c4f2f12ec0 707 drawAmmo();
Pokitto 5:56c4f2f12ec0 708 }
Pokitto 5:56c4f2f12ec0 709
Pokitto 5:56c4f2f12ec0 710 void stepLull(){
Pokitto 5:56c4f2f12ec0 711
Pokitto 5:56c4f2f12ec0 712 if( counter % 4 == 0 && (pammo[0] > 0 || pammo[1] > 0) ){
Pokitto 5:56c4f2f12ec0 713 lullMissiles++;
Pokitto 5:56c4f2f12ec0 714 score+=10;
Pokitto 5:56c4f2f12ec0 715 if( pammo[0] > 0 ) pammo[0]--;
Pokitto 5:56c4f2f12ec0 716 else pammo[1]--;
Pokitto 5:56c4f2f12ec0 717 playSound(SOUND_SCORE);
Pokitto 5:56c4f2f12ec0 718 }
Pokitto 5:56c4f2f12ec0 719
Pokitto 5:56c4f2f12ec0 720 //If we have already iterated through the missiles
Pokitto 5:56c4f2f12ec0 721 if( counter % 8 == 0 && pammo[0] == 0 && pammo[1] == 0 ){
Pokitto 5:56c4f2f12ec0 722 for( uint8_t i = 0; i < 9; i++ ){
Pokitto 5:56c4f2f12ec0 723 if( i == 8 ){ //We have iterated through all live cities
Pokitto 5:56c4f2f12ec0 724 nextStage();
Pokitto 5:56c4f2f12ec0 725 mode = MODE_GAME;
Pokitto 5:56c4f2f12ec0 726 return;
Pokitto 5:56c4f2f12ec0 727 }
Pokitto 5:56c4f2f12ec0 728 //If not a launcher and the city is alive
Pokitto 5:56c4f2f12ec0 729 if( i != 2 && i != 5 && cities[i] != 0 ){
Pokitto 5:56c4f2f12ec0 730 lullCities[i] = 1;
Pokitto 5:56c4f2f12ec0 731 score+=100;
Pokitto 5:56c4f2f12ec0 732 cities[i] = 0;
Pokitto 5:56c4f2f12ec0 733 playSound(SOUND_SCORE);
Pokitto 5:56c4f2f12ec0 734 break;
Pokitto 5:56c4f2f12ec0 735 }
Pokitto 5:56c4f2f12ec0 736 }
Pokitto 5:56c4f2f12ec0 737 }
Pokitto 5:56c4f2f12ec0 738
Pokitto 5:56c4f2f12ec0 739 drawLull();
Pokitto 5:56c4f2f12ec0 740 }
Pokitto 5:56c4f2f12ec0 741
Pokitto 5:56c4f2f12ec0 742 void stepDead(){
wuuff 14:41173f26c0ef 743 gb.display.setColor(7);
wuuff 14:41173f26c0ef 744 gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*3 - TEXT_WIDTH/2;;
wuuff 14:41173f26c0ef 745 gb.display.cursorY = HEIGHT/2 - TEXT_HEIGHT;
Pokitto 5:56c4f2f12ec0 746 gb.display.print(("THE END"));
wuuff 14:41173f26c0ef 747 gb.display.setColor(1);
Pokitto 5:56c4f2f12ec0 748
Pokitto 5:56c4f2f12ec0 749 if( mode == MODE_DEAD && counter%20 == 0 ){
Pokitto 5:56c4f2f12ec0 750 mode = MODE_POSTDEAD;
Pokitto 5:56c4f2f12ec0 751 }else if( mode == MODE_POSTDEAD ){
Pokitto 5:56c4f2f12ec0 752 if( counter%8 == 0 ){
Pokitto 5:56c4f2f12ec0 753 flash ^= 255;
Pokitto 5:56c4f2f12ec0 754 }
Pokitto 5:56c4f2f12ec0 755 if( flash ){
wuuff 14:41173f26c0ef 756 gb.display.setColor(4);
wuuff 14:41173f26c0ef 757 gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*3 - TEXT_WIDTH/2;
wuuff 14:41173f26c0ef 758 gb.display.cursorY = HEIGHT - TEXT_HEIGHT*2;
Pokitto 5:56c4f2f12ec0 759 gb.display.print(("PRESS \25"));
Pokitto 5:56c4f2f12ec0 760
Pokitto 5:56c4f2f12ec0 761 if( isHighscore(score) ){
wuuff 14:41173f26c0ef 762 gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*6 - TEXT_WIDTH/2;
wuuff 14:41173f26c0ef 763 gb.display.cursorY = HEIGHT - TEXT_HEIGHT*3;
Pokitto 5:56c4f2f12ec0 764 gb.display.print(("NEW HIGHSCORE"));
Pokitto 5:56c4f2f12ec0 765 }
wuuff 14:41173f26c0ef 766 gb.display.setColor(1);
Pokitto 5:56c4f2f12ec0 767 }
Pokitto 5:56c4f2f12ec0 768
Pokitto 5:56c4f2f12ec0 769 if( gb.buttons.pressed(BTN_A) ){
Pokitto 5:56c4f2f12ec0 770 if( isHighscore(score) ){
wuuff 14:41173f26c0ef 771 char tmp_name[11] = "User";
Pokitto 5:56c4f2f12ec0 772 //gb.getDefaultName(tmp_name);
Pokitto 5:56c4f2f12ec0 773 gb.keyboard(tmp_name, 11);
wuuff 14:41173f26c0ef 774 saveHighscore(score,tmp_name);
Pokitto 5:56c4f2f12ec0 775 }
Pokitto 5:56c4f2f12ec0 776 score = 0;
Pokitto 5:56c4f2f12ec0 777 mode = MODE_PREGAME;
Pokitto 5:56c4f2f12ec0 778 }
Pokitto 5:56c4f2f12ec0 779 }
Pokitto 5:56c4f2f12ec0 780 }
Pokitto 5:56c4f2f12ec0 781
Pokitto 5:56c4f2f12ec0 782 void stepPregame(){
Pokitto 5:56c4f2f12ec0 783 drawHighscores();
Pokitto 5:56c4f2f12ec0 784
Pokitto 5:56c4f2f12ec0 785 if( counter%8 == 0 ){
Pokitto 5:56c4f2f12ec0 786 flash ^= 255;
Pokitto 5:56c4f2f12ec0 787 }
Pokitto 5:56c4f2f12ec0 788 if( flash ){
wuuff 14:41173f26c0ef 789 gb.display.setColor(4);
wuuff 14:41173f26c0ef 790 gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*3;
wuuff 14:41173f26c0ef 791 gb.display.cursorY = HEIGHT - TEXT_HEIGHT*2;
Pokitto 5:56c4f2f12ec0 792 gb.display.print(("PRESS \25"));
wuuff 14:41173f26c0ef 793 gb.display.setColor(1);
Pokitto 5:56c4f2f12ec0 794 }
Pokitto 5:56c4f2f12ec0 795
Pokitto 5:56c4f2f12ec0 796 if( gb.buttons.pressed(BTN_A) ){
Pokitto 5:56c4f2f12ec0 797 stage = 255;
Pokitto 5:56c4f2f12ec0 798 for( uint8_t i = 0; i < 8; i++ ){
Pokitto 5:56c4f2f12ec0 799 lullCities[i] = 1;
Pokitto 5:56c4f2f12ec0 800 }
Pokitto 5:56c4f2f12ec0 801 nextStage(); //Reset to stage 0
Pokitto 5:56c4f2f12ec0 802 mode = MODE_GAME;
Pokitto 5:56c4f2f12ec0 803 }
Pokitto 5:56c4f2f12ec0 804 }
Pokitto 5:56c4f2f12ec0 805
Pokitto 5:56c4f2f12ec0 806 void loop() {
Pokitto 5:56c4f2f12ec0 807 if(gb.update()){
Pokitto 5:56c4f2f12ec0 808
Pokitto 5:56c4f2f12ec0 809 switch( mode ){
Pokitto 5:56c4f2f12ec0 810 case MODE_GAME:
Pokitto 5:56c4f2f12ec0 811 stepGame();
Pokitto 5:56c4f2f12ec0 812 break;
Pokitto 5:56c4f2f12ec0 813
Pokitto 5:56c4f2f12ec0 814 case MODE_LULL:
Pokitto 5:56c4f2f12ec0 815 stepLull();
Pokitto 5:56c4f2f12ec0 816 break;
Pokitto 5:56c4f2f12ec0 817
Pokitto 5:56c4f2f12ec0 818 case MODE_DEAD:
Pokitto 5:56c4f2f12ec0 819 case MODE_POSTDEAD:
Pokitto 5:56c4f2f12ec0 820 stepDead();
Pokitto 5:56c4f2f12ec0 821 break;
Pokitto 5:56c4f2f12ec0 822
Pokitto 5:56c4f2f12ec0 823 case MODE_PREGAME:
Pokitto 5:56c4f2f12ec0 824 stepPregame();
Pokitto 5:56c4f2f12ec0 825 break;
Pokitto 5:56c4f2f12ec0 826 }
Pokitto 5:56c4f2f12ec0 827
Pokitto 5:56c4f2f12ec0 828 checkMenu();
Pokitto 5:56c4f2f12ec0 829
Pokitto 5:56c4f2f12ec0 830 counter++;
Pokitto 5:56c4f2f12ec0 831 }
Pokitto 5:56c4f2f12ec0 832 }
Pokitto 5:56c4f2f12ec0 833 #define NUM_HIGHSCORES 5
Pokitto 5:56c4f2f12ec0 834 #define NAME_SIZE 10
Pokitto 5:56c4f2f12ec0 835 #define ENTRY_SIZE 15
Pokitto 5:56c4f2f12ec0 836
wuuff 14:41173f26c0ef 837 uint32_t highscores[NUM_HIGHSCORES] = {10000,7000,5000,4000,2000};
wuuff 14:41173f26c0ef 838 char names[NUM_HIGHSCORES][NAME_SIZE+1] = {"Crack Shot", "Defender", "Gunner", "We Tried", "No Hope"};
Pokitto 5:56c4f2f12ec0 839
Pokitto 5:56c4f2f12ec0 840 void loadHighscores(){
Pokitto 5:56c4f2f12ec0 841 for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){
Pokitto 5:56c4f2f12ec0 842 for( uint8_t offset = 0; offset < ENTRY_SIZE; offset++ ){
Pokitto 5:56c4f2f12ec0 843 if( offset < NAME_SIZE ){
Pokitto 5:56c4f2f12ec0 844 //names[entry][offset] = EEPROM.read( ENTRY_SIZE * entry + offset );
Pokitto 5:56c4f2f12ec0 845 }else{
Pokitto 5:56c4f2f12ec0 846 uint8_t* addr = (uint8_t*) &highscores[entry];
Pokitto 5:56c4f2f12ec0 847 addr+=offset-NAME_SIZE;
Pokitto 5:56c4f2f12ec0 848 //*addr = EEPROM.read( ENTRY_SIZE * entry + offset );
Pokitto 5:56c4f2f12ec0 849 }
Pokitto 5:56c4f2f12ec0 850 }
Pokitto 5:56c4f2f12ec0 851 }
Pokitto 5:56c4f2f12ec0 852 }
Pokitto 5:56c4f2f12ec0 853
Pokitto 5:56c4f2f12ec0 854 uint8_t isHighscore(uint32_t score){
Pokitto 5:56c4f2f12ec0 855 if( score > highscores[NUM_HIGHSCORES-1] ){
Pokitto 5:56c4f2f12ec0 856 return 1;
Pokitto 5:56c4f2f12ec0 857 }
Pokitto 5:56c4f2f12ec0 858 return 0;
Pokitto 5:56c4f2f12ec0 859 }
Pokitto 5:56c4f2f12ec0 860
Pokitto 5:56c4f2f12ec0 861 void saveHighscore(uint32_t score, char* who){
Pokitto 5:56c4f2f12ec0 862 uint8_t found = 0;
Pokitto 5:56c4f2f12ec0 863 uint32_t tmp_score = 0;
Pokitto 5:56c4f2f12ec0 864 char tmp_name[10];
Pokitto 5:56c4f2f12ec0 865 for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){
Pokitto 5:56c4f2f12ec0 866 if( score > highscores[entry] ){
Pokitto 5:56c4f2f12ec0 867 found = 1;
Pokitto 5:56c4f2f12ec0 868 }
Pokitto 5:56c4f2f12ec0 869 if( found ){
Pokitto 5:56c4f2f12ec0 870 tmp_score = highscores[entry];
Pokitto 5:56c4f2f12ec0 871 strcpy(tmp_name,names[entry]);
Pokitto 5:56c4f2f12ec0 872
Pokitto 5:56c4f2f12ec0 873 highscores[entry] = score;
Pokitto 5:56c4f2f12ec0 874 strcpy(names[entry], who);
Pokitto 5:56c4f2f12ec0 875
Pokitto 5:56c4f2f12ec0 876 score = tmp_score;
Pokitto 5:56c4f2f12ec0 877 strcpy(who, tmp_name);
Pokitto 5:56c4f2f12ec0 878 }
Pokitto 5:56c4f2f12ec0 879 }
Pokitto 5:56c4f2f12ec0 880 for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){
Pokitto 5:56c4f2f12ec0 881 for( uint8_t offset = 0; offset < ENTRY_SIZE; offset++ ){
Pokitto 5:56c4f2f12ec0 882 if( offset < NAME_SIZE ){
Pokitto 5:56c4f2f12ec0 883 //EEPROM.write( ENTRY_SIZE * entry + offset, names[entry][offset] );
Pokitto 5:56c4f2f12ec0 884 }else{
Pokitto 5:56c4f2f12ec0 885 uint8_t* addr = (uint8_t*) &highscores[entry];
Pokitto 5:56c4f2f12ec0 886 addr+=offset-NAME_SIZE;
Pokitto 5:56c4f2f12ec0 887 //EEPROM.write( ENTRY_SIZE * entry + offset, *addr );
Pokitto 5:56c4f2f12ec0 888 }
Pokitto 5:56c4f2f12ec0 889 }
Pokitto 5:56c4f2f12ec0 890 }
Pokitto 5:56c4f2f12ec0 891 }
Pokitto 5:56c4f2f12ec0 892
Pokitto 5:56c4f2f12ec0 893 void drawHighscores(){
wuuff 14:41173f26c0ef 894 gb.display.setColor(4);
wuuff 14:41173f26c0ef 895 gb.display.cursorX = WIDTH/2 - TEXT_WIDTH*5;
wuuff 14:41173f26c0ef 896 gb.display.cursorY = TEXT_HEIGHT;
Pokitto 5:56c4f2f12ec0 897 gb.display.print(("HIGHSCORES"));
wuuff 14:41173f26c0ef 898 gb.display.setColor(1);
Pokitto 5:56c4f2f12ec0 899
Pokitto 5:56c4f2f12ec0 900 for( uint8_t entry = 0; entry < NUM_HIGHSCORES; entry++ ){
wuuff 14:41173f26c0ef 901 gb.display.cursorX = 0;
wuuff 14:41173f26c0ef 902 gb.display.cursorY = TEXT_HEIGHT*3 + TEXT_HEIGHT*entry;
Pokitto 5:56c4f2f12ec0 903 gb.display.print(names[entry]);
wuuff 14:41173f26c0ef 904 gb.display.cursorX = WIDTH - TEXT_WIDTH*6;
Pokitto 5:56c4f2f12ec0 905 if( highscores[entry] < 100000 ){
Pokitto 5:56c4f2f12ec0 906 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 907 }
Pokitto 5:56c4f2f12ec0 908 if( highscores[entry] < 10000 ){
Pokitto 5:56c4f2f12ec0 909 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 910 }
Pokitto 5:56c4f2f12ec0 911 if( highscores[entry] < 1000 ){
Pokitto 5:56c4f2f12ec0 912 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 913 }
Pokitto 5:56c4f2f12ec0 914 if( highscores[entry] < 100 ){
Pokitto 5:56c4f2f12ec0 915 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 916 }
Pokitto 5:56c4f2f12ec0 917 if( highscores[entry] < 10 ){
Pokitto 5:56c4f2f12ec0 918 gb.display.print(0);
Pokitto 5:56c4f2f12ec0 919 }
Pokitto 5:56c4f2f12ec0 920 gb.display.print(highscores[entry]);
Pokitto 5:56c4f2f12ec0 921 }
Pokitto 5:56c4f2f12ec0 922 }
Pokitto 5:56c4f2f12ec0 923
Pokitto 5:56c4f2f12ec0 924 // Wave, pitch, duration, arpeggio step duration, arpeggio step size
Pokitto 5:56c4f2f12ec0 925 const int8_t sounds[][5] = {
Pokitto 5:56c4f2f12ec0 926 { 0, 20, 5, 1, 1 }, //Player launch
Pokitto 5:56c4f2f12ec0 927 { 0, 25, 5, 1, -1 }, //Enemy launch
Pokitto 5:56c4f2f12ec0 928 { 1, 10, 5, 1, -1 }, //Detonating enemy missile
Pokitto 5:56c4f2f12ec0 929 { 1, 10, 2, 0, 0 }, //Score pips
Pokitto 5:56c4f2f12ec0 930 { 1, 2, 10, 1, -1 }, //A city dies
Pokitto 5:56c4f2f12ec0 931 { 0, 20, 14, 3, -1 }, //Lose
Pokitto 5:56c4f2f12ec0 932 };
Pokitto 5:56c4f2f12ec0 933
Pokitto 5:56c4f2f12ec0 934 void initSound(){
Pokitto 5:56c4f2f12ec0 935 gb.sound.command(CMD_VOLUME, 5, 0, 0);
Pokitto 5:56c4f2f12ec0 936 gb.sound.command(CMD_SLIDE, 0, 0, 0);
Pokitto 5:56c4f2f12ec0 937 }
Pokitto 5:56c4f2f12ec0 938
Pokitto 5:56c4f2f12ec0 939 void playSound(uint8_t i){
Pokitto 5:56c4f2f12ec0 940 gb.sound.command(CMD_VOLUME, 5, 0, 0);
Pokitto 5:56c4f2f12ec0 941 gb.sound.command(CMD_SLIDE, 0, 0, 0);
Pokitto 5:56c4f2f12ec0 942 gb.sound.command(CMD_ARPEGGIO, sounds[i][3], sounds[i][4], 0);
Pokitto 5:56c4f2f12ec0 943 gb.sound.command(CMD_INSTRUMENT, sounds[i][0], 0, 0);
Pokitto 5:56c4f2f12ec0 944 gb.sound.playNote(sounds[i][1], sounds[i][2], 0);
Pokitto 5:56c4f2f12ec0 945
Pokitto 5:56c4f2f12ec0 946 //gb.sound.playNote(20, 5, 0);
Pokitto 5:56c4f2f12ec0 947 }
Pokitto 5:56c4f2f12ec0 948
Pokitto 5:56c4f2f12ec0 949