Great game by Aurelién Rodot for Gamebuin. Ported by Jonne
Dependencies: PokittoLib
Fork of Asterocks by
Crabator.cpp@13:9bf683c077df, 2018-05-02 (annotated)
- Committer:
- Pokitto
- Date:
- Wed May 02 06:31:17 2018 +0000
- Revision:
- 13:9bf683c077df
- Parent:
- 5:42a7d8c6c8fd
New pokittolib with improved volume controls & better button handling
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pokitto | 5:42a7d8c6c8fd | 1 | //#include <SPI.h> |
Pokitto | 5:42a7d8c6c8fd | 2 | #include <Pokitto.h> |
Pokitto | 5:42a7d8c6c8fd | 3 | #include "Crabator.h" |
Pokitto | 5:42a7d8c6c8fd | 4 | Pokitto::Core gb; |
Pokitto | 5:42a7d8c6c8fd | 5 | //#include <EEPROM.h> |
Pokitto | 5:42a7d8c6c8fd | 6 | //#include <avr/pgmspace.h> |
Pokitto | 5:42a7d8c6c8fd | 7 | |
Pokitto | 5:42a7d8c6c8fd | 8 | uint16_t hazepalette[16]; |
Pokitto | 5:42a7d8c6c8fd | 9 | |
Pokitto | 5:42a7d8c6c8fd | 10 | extern const byte font3x5[]; |
Pokitto | 5:42a7d8c6c8fd | 11 | extern const byte font5x7[]; |
Pokitto | 5:42a7d8c6c8fd | 12 | |
Pokitto | 5:42a7d8c6c8fd | 13 | #define WORLD_W 16 |
Pokitto | 5:42a7d8c6c8fd | 14 | #define WORLD_H 12 |
Pokitto | 5:42a7d8c6c8fd | 15 | uint8_t byteWidth = (WORLD_H + 7) / 8; |
Pokitto | 5:42a7d8c6c8fd | 16 | |
Pokitto | 5:42a7d8c6c8fd | 17 | //declare all the sprites which are in the "sprites" tab |
Pokitto | 5:42a7d8c6c8fd | 18 | extern const byte PROGMEM logo[]; |
Pokitto | 5:42a7d8c6c8fd | 19 | extern const byte PROGMEM world[]; |
Pokitto | 5:42a7d8c6c8fd | 20 | extern const byte PROGMEM tiles[]; |
Pokitto | 5:42a7d8c6c8fd | 21 | extern const byte PROGMEM mobSprite[]; |
Pokitto | 5:42a7d8c6c8fd | 22 | extern const byte PROGMEM bossSprite[]; |
Pokitto | 5:42a7d8c6c8fd | 23 | extern const byte PROGMEM playerSprite[]; |
Pokitto | 5:42a7d8c6c8fd | 24 | extern const byte PROGMEM splashSprite[]; |
Pokitto | 5:42a7d8c6c8fd | 25 | extern const byte PROGMEM crateSprite[]; |
Pokitto | 5:42a7d8c6c8fd | 26 | extern const byte PROGMEM fullHeart[]; |
Pokitto | 5:42a7d8c6c8fd | 27 | extern const byte PROGMEM halfHeart[]; |
Pokitto | 5:42a7d8c6c8fd | 28 | extern const byte PROGMEM emptyHeart[]; |
Pokitto | 5:42a7d8c6c8fd | 29 | |
Pokitto | 5:42a7d8c6c8fd | 30 | #define playerW 6 |
Pokitto | 5:42a7d8c6c8fd | 31 | #define playerH 6 |
Pokitto | 5:42a7d8c6c8fd | 32 | byte playerSpeed; |
Pokitto | 5:42a7d8c6c8fd | 33 | int playerX; |
Pokitto | 5:42a7d8c6c8fd | 34 | int playerY; |
Pokitto | 5:42a7d8c6c8fd | 35 | int playerLife; |
Pokitto | 5:42a7d8c6c8fd | 36 | #define playerLifeMax 6 |
Pokitto | 5:42a7d8c6c8fd | 37 | byte playerDir; |
Pokitto | 5:42a7d8c6c8fd | 38 | int cameraX; |
Pokitto | 5:42a7d8c6c8fd | 39 | int cameraY; |
Pokitto | 5:42a7d8c6c8fd | 40 | byte shake_magnitude; |
Pokitto | 5:42a7d8c6c8fd | 41 | byte shake_timeLeft; |
Pokitto | 5:42a7d8c6c8fd | 42 | const PROGMEM uint16_t player_damage_sound[] = {0x0045,0x564,0x0000}; |
Pokitto | 5:42a7d8c6c8fd | 43 | |
Pokitto | 5:42a7d8c6c8fd | 44 | ///////////////////////////////////// MOBS |
Pokitto | 5:42a7d8c6c8fd | 45 | #define NUMMOBS 16 |
Pokitto | 5:42a7d8c6c8fd | 46 | #define INITNUMMOBS 4 |
Pokitto | 5:42a7d8c6c8fd | 47 | #define MOBSRATE 6 //how often is the mob number increased (every X kills) |
Pokitto | 5:42a7d8c6c8fd | 48 | #define BOSSFREQ 16//one boss every X kills (initially) |
Pokitto | 5:42a7d8c6c8fd | 49 | #define BOSSRATE 1 //every boss killed, the next one will spawn X kills earlier |
Pokitto | 5:42a7d8c6c8fd | 50 | byte boss_nextSpawn; |
Pokitto | 5:42a7d8c6c8fd | 51 | byte boss_freq; |
Pokitto | 5:42a7d8c6c8fd | 52 | byte activeMobs; |
Pokitto | 5:42a7d8c6c8fd | 53 | int mobs_x[NUMMOBS]; |
Pokitto | 5:42a7d8c6c8fd | 54 | int mobs_y[NUMMOBS]; |
Pokitto | 5:42a7d8c6c8fd | 55 | byte mobs_dir[NUMMOBS]; |
Pokitto | 5:42a7d8c6c8fd | 56 | int8_t mobs_life[NUMMOBS]; // was char - Jonne |
Pokitto | 5:42a7d8c6c8fd | 57 | byte mobs_size[NUMMOBS]; |
Pokitto | 5:42a7d8c6c8fd | 58 | byte mob_maxLife = 10; |
Pokitto | 5:42a7d8c6c8fd | 59 | byte boss_maxLife = 100; |
Pokitto | 5:42a7d8c6c8fd | 60 | #define boss_size 6 |
Pokitto | 5:42a7d8c6c8fd | 61 | #define mob_size 4 |
Pokitto | 5:42a7d8c6c8fd | 62 | //const PROGMEM uint16_t mob_damage_sound[] = {0x5C1F, 0x0000}; |
Pokitto | 5:42a7d8c6c8fd | 63 | const PROGMEM uint16_t mob_death_sound[] = {0x0045,0x184,0x0000}; |
Pokitto | 5:42a7d8c6c8fd | 64 | |
Pokitto | 5:42a7d8c6c8fd | 65 | #define NUMSPLASH 16 |
Pokitto | 5:42a7d8c6c8fd | 66 | boolean splash_active[NUMSPLASH]; |
Pokitto | 5:42a7d8c6c8fd | 67 | int splash_x[NUMSPLASH]; |
Pokitto | 5:42a7d8c6c8fd | 68 | int splash_y[NUMSPLASH]; |
Pokitto | 5:42a7d8c6c8fd | 69 | int splash_dir[NUMSPLASH]; |
Pokitto | 5:42a7d8c6c8fd | 70 | |
Pokitto | 5:42a7d8c6c8fd | 71 | ///////////////////////////////////// WEAPONS |
Pokitto | 5:42a7d8c6c8fd | 72 | #define NUMBULLETS 10 |
Pokitto | 5:42a7d8c6c8fd | 73 | int bullets_x[NUMBULLETS]; |
Pokitto | 5:42a7d8c6c8fd | 74 | int bullets_y[NUMBULLETS]; |
Pokitto | 5:42a7d8c6c8fd | 75 | byte bullets_dir[NUMBULLETS]; |
Pokitto | 5:42a7d8c6c8fd | 76 | boolean bullets_active[NUMBULLETS]; |
Pokitto | 5:42a7d8c6c8fd | 77 | byte bullets_weapon[NUMBULLETS]; |
Pokitto | 5:42a7d8c6c8fd | 78 | |
Pokitto | 5:42a7d8c6c8fd | 79 | int blast_x; |
Pokitto | 5:42a7d8c6c8fd | 80 | int blast_y; |
Pokitto | 5:42a7d8c6c8fd | 81 | byte blast_lifespan; |
Pokitto | 5:42a7d8c6c8fd | 82 | byte blast_bullet; |
Pokitto | 5:42a7d8c6c8fd | 83 | |
Pokitto | 5:42a7d8c6c8fd | 84 | #define NUMWEAPONS 5 |
Pokitto | 5:42a7d8c6c8fd | 85 | byte currentWeapon; |
Pokitto | 5:42a7d8c6c8fd | 86 | byte nextShot; |
Pokitto | 5:42a7d8c6c8fd | 87 | |
Pokitto | 5:42a7d8c6c8fd | 88 | const char str357[] PROGMEM = ".357"; |
Pokitto | 5:42a7d8c6c8fd | 89 | const char strP90[] PROGMEM = "P90"; |
Pokitto | 5:42a7d8c6c8fd | 90 | const char strAK47[] PROGMEM = "AK47"; |
Pokitto | 5:42a7d8c6c8fd | 91 | const char strRPG[] PROGMEM = "RPG"; |
Pokitto | 5:42a7d8c6c8fd | 92 | const char strMG42[] PROGMEM = "MG42"; |
Pokitto | 5:42a7d8c6c8fd | 93 | const char* const weapon_name[NUMWEAPONS] PROGMEM = { |
Pokitto | 5:42a7d8c6c8fd | 94 | str357,strP90, strAK47, strRPG, strMG42}; |
Pokitto | 5:42a7d8c6c8fd | 95 | const byte weapon_size[NUMWEAPONS] = { |
Pokitto | 5:42a7d8c6c8fd | 96 | 2, 1, 2, 3, 2}; |
Pokitto | 5:42a7d8c6c8fd | 97 | const byte weapon_damage[NUMWEAPONS] = { |
Pokitto | 5:42a7d8c6c8fd | 98 | 10, 2, 3, 5, 4}; |
Pokitto | 5:42a7d8c6c8fd | 99 | const byte weapon_rate[NUMWEAPONS] = { |
Pokitto | 5:42a7d8c6c8fd | 100 | 30, 1, 2, 30, 1}; |
Pokitto | 5:42a7d8c6c8fd | 101 | const byte weapon_speed[NUMWEAPONS] = { |
Pokitto | 5:42a7d8c6c8fd | 102 | 4, 5, 3, 2, 5}; |
Pokitto | 5:42a7d8c6c8fd | 103 | const byte weapon_spread[NUMWEAPONS] = { |
Pokitto | 5:42a7d8c6c8fd | 104 | 1, 2, 1, 0, 2}; |
Pokitto | 5:42a7d8c6c8fd | 105 | const byte weapon_ennemyRecoil[NUMWEAPONS] = { |
Pokitto | 5:42a7d8c6c8fd | 106 | 3, 2, 3, 0, 3}; |
Pokitto | 5:42a7d8c6c8fd | 107 | const byte weapon_playerRecoil[NUMWEAPONS] = { |
Pokitto | 5:42a7d8c6c8fd | 108 | 0, 0, 1, 3, 3}; |
Pokitto | 5:42a7d8c6c8fd | 109 | const unsigned int weapon_ammo[NUMWEAPONS] = { |
Pokitto | 5:42a7d8c6c8fd | 110 | 9999, 500, 300, 20, 150}; |
Pokitto | 5:42a7d8c6c8fd | 111 | unsigned int ammo; |
Pokitto | 5:42a7d8c6c8fd | 112 | |
Pokitto | 5:42a7d8c6c8fd | 113 | const uint16_t magnum_sound[] PROGMEM = {0x0045,0x7049,0x17C,0x784D,0x42C,0x0000}; |
Pokitto | 5:42a7d8c6c8fd | 114 | const uint16_t p90_sound[] PROGMEM = {0x0045, 0x0154, 0x0000}; |
Pokitto | 5:42a7d8c6c8fd | 115 | const uint16_t p90_alternative_sound[] PROGMEM = {0x0045, 0x014C, 0x0000}; |
Pokitto | 5:42a7d8c6c8fd | 116 | const uint16_t ak47_sound[] PROGMEM = {0x0045, 0x012C, 0x0000}; |
Pokitto | 5:42a7d8c6c8fd | 117 | const uint16_t mg42_sound[] PROGMEM = {0x0045,0x140,0x8141,0x7849,0x788D,0x52C,0x0000}; |
Pokitto | 5:42a7d8c6c8fd | 118 | const uint16_t rpg_sound[] PROGMEM = {0x0045,0x8101,0x7F30,0x0000}; |
Pokitto | 5:42a7d8c6c8fd | 119 | |
Pokitto | 5:42a7d8c6c8fd | 120 | const uint16_t* const weapons_sounds[NUMWEAPONS] PROGMEM= { |
Pokitto | 5:42a7d8c6c8fd | 121 | magnum_sound, p90_sound, ak47_sound, rpg_sound, mg42_sound}; |
Pokitto | 5:42a7d8c6c8fd | 122 | const uint16_t blast_sound[] PROGMEM = {0x0045,0x7849,0x784D,0xA28,0x0000}; |
Pokitto | 5:42a7d8c6c8fd | 123 | int crate_x, crate_y; |
Pokitto | 5:42a7d8c6c8fd | 124 | const uint16_t power_up[] PROGMEM = {0x0005,0x140,0x150,0x15C,0x170,0x180,0x16C,0x154,0x160,0x174,0x184,0x14C,0x15C,0x168,0x17C,0x18C,0x0000}; |
Pokitto | 5:42a7d8c6c8fd | 125 | |
Pokitto | 5:42a7d8c6c8fd | 126 | ///////////////////////////////////// SCORE |
Pokitto | 5:42a7d8c6c8fd | 127 | #define RANKMAX 5 //number of high scores to save |
Pokitto | 5:42a7d8c6c8fd | 128 | int score = 0; |
Pokitto | 5:42a7d8c6c8fd | 129 | //int lastScore = 0; |
Pokitto | 5:42a7d8c6c8fd | 130 | int kills = 0; |
Pokitto | 5:42a7d8c6c8fd | 131 | int highscore[RANKMAX]; |
Pokitto | 5:42a7d8c6c8fd | 132 | //byte scoreDisplayTimeLeft; |
Pokitto | 5:42a7d8c6c8fd | 133 | #define NAMELENGTH 10 |
Pokitto | 5:42a7d8c6c8fd | 134 | char name[RANKMAX][NAMELENGTH+1]; |
Pokitto | 5:42a7d8c6c8fd | 135 | |
Pokitto | 5:42a7d8c6c8fd | 136 | // predefinitions |
Pokitto | 5:42a7d8c6c8fd | 137 | |
Pokitto | 5:42a7d8c6c8fd | 138 | void loadHighscore(); |
Pokitto | 5:42a7d8c6c8fd | 139 | void initGame(); |
Pokitto | 5:42a7d8c6c8fd | 140 | boolean collideWorld(int16_t, int16_t, uint8_t, uint8_t); |
Pokitto | 5:42a7d8c6c8fd | 141 | void damageMob(byte,byte); |
Pokitto | 5:42a7d8c6c8fd | 142 | boolean checkMobCollisions(byte); |
Pokitto | 5:42a7d8c6c8fd | 143 | boolean collideOtherMobs(byte); |
Pokitto | 5:42a7d8c6c8fd | 144 | void pausem(); |
Pokitto | 5:42a7d8c6c8fd | 145 | void play(); |
Pokitto | 5:42a7d8c6c8fd | 146 | void displayHighScores(); |
Pokitto | 5:42a7d8c6c8fd | 147 | void saveHighscore(); |
Pokitto | 5:42a7d8c6c8fd | 148 | void shakeScreen(); |
Pokitto | 5:42a7d8c6c8fd | 149 | void drawWorld(int16_t, int16_t); |
Pokitto | 5:42a7d8c6c8fd | 150 | void displayScore(); |
Pokitto | 5:42a7d8c6c8fd | 151 | |
Pokitto | 5:42a7d8c6c8fd | 152 | /*int16_t random (int lo,int hi) { |
Pokitto | 5:42a7d8c6c8fd | 153 | return rand() % hi + lo; |
Pokitto | 5:42a7d8c6c8fd | 154 | }*/ |
Pokitto | 5:42a7d8c6c8fd | 155 | |
Pokitto | 5:42a7d8c6c8fd | 156 | ///////////////////////////////////// SETUP |
Pokitto | 5:42a7d8c6c8fd | 157 | void setup() { |
Pokitto | 5:42a7d8c6c8fd | 158 | |
Pokitto | 5:42a7d8c6c8fd | 159 | /** Set colors for this game **/ |
Pokitto | 5:42a7d8c6c8fd | 160 | |
Pokitto | 5:42a7d8c6c8fd | 161 | /** TO ADD COLORS TO YOUR GAMEBUINO GAME, SIMPLY USE VALUES ABOVE 1 !!!! */ |
Pokitto | 5:42a7d8c6c8fd | 162 | |
Pokitto | 5:42a7d8c6c8fd | 163 | gb.display.palette[1] = COLOR_WHITE; |
Pokitto | 5:42a7d8c6c8fd | 164 | gb.display.palette[2] = COLOR_CYAN; |
Pokitto | 5:42a7d8c6c8fd | 165 | gb.display.palette[3] = COLOR_MAGENTA; |
Pokitto | 5:42a7d8c6c8fd | 166 | gb.display.palette[4] = COLOR_RED; |
Pokitto | 5:42a7d8c6c8fd | 167 | gb.display.palette[8] = gb.display.RGBto565(0xff,0xfc,0); // small mob |
Pokitto | 5:42a7d8c6c8fd | 168 | gb.display.palette[7] = gb.display.RGBto565(0x18,0x9a,0x61); // shrub shadow |
Pokitto | 5:42a7d8c6c8fd | 169 | gb.display.palette[5] = gb.display.RGBto565(0x2c,0xff,0x0b); //world (shrubs) |
Pokitto | 5:42a7d8c6c8fd | 170 | gb.display.palette[6] = gb.display.RGBto565(0xf7,0xb2,0);// crate |
Pokitto | 5:42a7d8c6c8fd | 171 | gb.display.palette[9] = gb.display.RGBto565(0xfc,0x14,4);// big mob fc1404 |
Pokitto | 5:42a7d8c6c8fd | 172 | gb.display.palette[10] = gb.display.RGBto565(0,0x53,0xae); // blue shadow |
Pokitto | 5:42a7d8c6c8fd | 173 | gb.display.palette[15] = gb.display.RGBto565(0xff,0xfd,0xbf); // bright sunlight |
Pokitto | 5:42a7d8c6c8fd | 174 | |
Pokitto | 5:42a7d8c6c8fd | 175 | /** YOU HAVE 16 COLORS FREELY SELECTABLE FROM 256000 COLORS !!! **/ |
Pokitto | 5:42a7d8c6c8fd | 176 | |
Pokitto | 5:42a7d8c6c8fd | 177 | /** NOW LETS REBUILD! **/ |
Pokitto | 5:42a7d8c6c8fd | 178 | |
Pokitto | 5:42a7d8c6c8fd | 179 | |
Pokitto | 5:42a7d8c6c8fd | 180 | |
Pokitto | 5:42a7d8c6c8fd | 181 | for (uint16_t k =0 ; k<16; k++) hazepalette[k] = gb.display.interpolateColor(gb.display.palette[k],gb.display.palette[15],0); |
Pokitto | 5:42a7d8c6c8fd | 182 | gb.display.paletteptr = hazepalette; |
Pokitto | 5:42a7d8c6c8fd | 183 | gb.begin(); |
Pokitto | 5:42a7d8c6c8fd | 184 | //while(1) gb.update(); |
Pokitto | 5:42a7d8c6c8fd | 185 | gb.display.setFont(font5x7); |
Pokitto | 5:42a7d8c6c8fd | 186 | gb.titleScreen(logo); |
Pokitto | 5:42a7d8c6c8fd | 187 | |
Pokitto | 5:42a7d8c6c8fd | 188 | gb.pickRandomSeed(); |
Pokitto | 5:42a7d8c6c8fd | 189 | loadHighscore(); |
Pokitto | 5:42a7d8c6c8fd | 190 | initGame(); |
Pokitto | 5:42a7d8c6c8fd | 191 | } |
Pokitto | 5:42a7d8c6c8fd | 192 | |
Pokitto | 5:42a7d8c6c8fd | 193 | ///////////////////////////////////// LOOP |
Pokitto | 5:42a7d8c6c8fd | 194 | void loop() { |
Pokitto | 5:42a7d8c6c8fd | 195 | play(); |
Pokitto | 5:42a7d8c6c8fd | 196 | if (!gb.isRunning()) return; |
Pokitto | 5:42a7d8c6c8fd | 197 | pausem(); |
Pokitto | 5:42a7d8c6c8fd | 198 | if (!gb.isRunning()) return; |
Pokitto | 5:42a7d8c6c8fd | 199 | gb.titleScreen(logo); |
Pokitto | 5:42a7d8c6c8fd | 200 | } |
Pokitto | 5:42a7d8c6c8fd | 201 | |
Pokitto | 5:42a7d8c6c8fd | 202 | ///////////////////////////////////// SCREEN COORD |
Pokitto | 5:42a7d8c6c8fd | 203 | boolean screenCoord(int absoluteX, int absoluteY, int &x, int &y){ |
Pokitto | 5:42a7d8c6c8fd | 204 | x = absoluteX - cameraX + 8; |
Pokitto | 5:42a7d8c6c8fd | 205 | x = (x >= 0) ? x%(WORLD_W*8) : WORLD_W*8 + x%(WORLD_W*8); |
Pokitto | 5:42a7d8c6c8fd | 206 | x -= 8; |
Pokitto | 5:42a7d8c6c8fd | 207 | y = absoluteY - cameraY + 8; |
Pokitto | 5:42a7d8c6c8fd | 208 | y = (y >= 0) ? y%(WORLD_H*8) : WORLD_H*8 + y%(WORLD_H*8); |
Pokitto | 5:42a7d8c6c8fd | 209 | y -= 8; |
Pokitto | 5:42a7d8c6c8fd | 210 | if((x > LCDWIDTH) || (y > LCDHEIGHT)) |
Pokitto | 5:42a7d8c6c8fd | 211 | return false; |
Pokitto | 5:42a7d8c6c8fd | 212 | return true; |
Pokitto | 5:42a7d8c6c8fd | 213 | } |
Pokitto | 5:42a7d8c6c8fd | 214 | |
Pokitto | 5:42a7d8c6c8fd | 215 | #define wrap(i, imax) ((imax+i)%(imax)) |
Pokitto | 5:42a7d8c6c8fd | 216 | |
Pokitto | 5:42a7d8c6c8fd | 217 | ///////////////////////////////////// MOVE XYDS |
Pokitto | 5:42a7d8c6c8fd | 218 | void moveXYDS(int &x, int &y, byte &dir, int8_t speed){ |
Pokitto | 5:42a7d8c6c8fd | 219 | switch(dir){ //switch case depending on the mob's movement direction |
Pokitto | 5:42a7d8c6c8fd | 220 | case 0: //going upward |
Pokitto | 5:42a7d8c6c8fd | 221 | y -= speed; |
Pokitto | 5:42a7d8c6c8fd | 222 | break; |
Pokitto | 5:42a7d8c6c8fd | 223 | case 1: //left |
Pokitto | 5:42a7d8c6c8fd | 224 | x -= speed; |
Pokitto | 5:42a7d8c6c8fd | 225 | break; |
Pokitto | 5:42a7d8c6c8fd | 226 | case 2: //downward |
Pokitto | 5:42a7d8c6c8fd | 227 | y += speed; |
Pokitto | 5:42a7d8c6c8fd | 228 | break; |
Pokitto | 5:42a7d8c6c8fd | 229 | case 3: //right |
Pokitto | 5:42a7d8c6c8fd | 230 | x += speed; |
Pokitto | 5:42a7d8c6c8fd | 231 | break; |
Pokitto | 5:42a7d8c6c8fd | 232 | } |
Pokitto | 5:42a7d8c6c8fd | 233 | x = wrap(x, WORLD_W*8); |
Pokitto | 5:42a7d8c6c8fd | 234 | y = wrap(y, WORLD_H*8); |
Pokitto | 5:42a7d8c6c8fd | 235 | } |
Pokitto | 5:42a7d8c6c8fd | 236 | |
Pokitto | 5:42a7d8c6c8fd | 237 | ///////////////////////////////////// DISTANCE BETWEEN |
Pokitto | 5:42a7d8c6c8fd | 238 | byte distanceBetween(int pos1, int pos2, int worldSize){ |
Pokitto | 5:42a7d8c6c8fd | 239 | byte dist = abs(pos1 - pos2); |
Pokitto | 5:42a7d8c6c8fd | 240 | dist = (dist < worldSize/2) ? dist : worldSize - dist; |
Pokitto | 5:42a7d8c6c8fd | 241 | return dist; |
Pokitto | 5:42a7d8c6c8fd | 242 | } |
Pokitto | 5:42a7d8c6c8fd | 243 | |
Pokitto | 5:42a7d8c6c8fd | 244 | ///////////////////////////////////// ASSIGN ARRAY |
Pokitto | 5:42a7d8c6c8fd | 245 | void assignArray(char *array1, char *array2, byte length){ |
Pokitto | 5:42a7d8c6c8fd | 246 | for(byte i=0; i<length; i++) |
Pokitto | 5:42a7d8c6c8fd | 247 | array1[i] = array2[i]; |
Pokitto | 5:42a7d8c6c8fd | 248 | } |
Pokitto | 5:42a7d8c6c8fd | 249 | |
Pokitto | 5:42a7d8c6c8fd | 250 | ///////////////////////////////////// SHOOT |
Pokitto | 5:42a7d8c6c8fd | 251 | #define min(a,b) (((a)<(b))?(a):(b)) |
Pokitto | 5:42a7d8c6c8fd | 252 | #define max(a,b) (((a)>(b))?(a):(b)) |
Pokitto | 5:42a7d8c6c8fd | 253 | |
Pokitto | 5:42a7d8c6c8fd | 254 | |
Pokitto | 5:42a7d8c6c8fd | 255 | void shoot(){ |
Pokitto | 5:42a7d8c6c8fd | 256 | if(ammo){ |
Pokitto | 5:42a7d8c6c8fd | 257 | if(nextShot == 0){ |
Pokitto | 5:42a7d8c6c8fd | 258 | for(byte thisBullet = 0; thisBullet < NUMBULLETS; thisBullet++){ |
Pokitto | 5:42a7d8c6c8fd | 259 | if(!bullets_active[thisBullet]){ //look for the first inactive bullet |
Pokitto | 5:42a7d8c6c8fd | 260 | bullets_active[thisBullet] = true; //set it to active as it's fired |
Pokitto | 5:42a7d8c6c8fd | 261 | bullets_weapon[thisBullet] = currentWeapon; |
Pokitto | 5:42a7d8c6c8fd | 262 | |
Pokitto | 5:42a7d8c6c8fd | 263 | nextShot = weapon_rate[currentWeapon]; |
Pokitto | 5:42a7d8c6c8fd | 264 | ammo--; |
Pokitto | 5:42a7d8c6c8fd | 265 | //spawn a bullet with some spreading |
Pokitto | 5:42a7d8c6c8fd | 266 | int8_t spreadMax = weapon_spread[currentWeapon]; // this was char, jonne |
Pokitto | 5:42a7d8c6c8fd | 267 | int8_t spreadMin = (weapon_size[currentWeapon]%2==0) ? -spreadMax : -spreadMax-1; |
Pokitto | 5:42a7d8c6c8fd | 268 | bullets_x[thisBullet] = playerX + playerW/2 + random(spreadMin,spreadMax+1) - weapon_size[currentWeapon]/2; |
Pokitto | 5:42a7d8c6c8fd | 269 | bullets_y[thisBullet] = playerY + playerH/2 + random(spreadMin,spreadMax+1) - weapon_size[currentWeapon]/2; |
Pokitto | 5:42a7d8c6c8fd | 270 | |
Pokitto | 5:42a7d8c6c8fd | 271 | bullets_dir[thisBullet] = playerDir; |
Pokitto | 5:42a7d8c6c8fd | 272 | blast_bullet = thisBullet; |
Pokitto | 5:42a7d8c6c8fd | 273 | if(((currentWeapon == 1)||(currentWeapon==4))&&(gb.frameCount%2)) |
Pokitto | 5:42a7d8c6c8fd | 274 | { |
Pokitto | 5:42a7d8c6c8fd | 275 | } |
Pokitto | 5:42a7d8c6c8fd | 276 | else{ |
Pokitto | 5:42a7d8c6c8fd | 277 | gb.sound.playPattern((uint16_t*)pgm_read_word(&(weapons_sounds[currentWeapon])), 0); |
Pokitto | 5:42a7d8c6c8fd | 278 | } |
Pokitto | 5:42a7d8c6c8fd | 279 | if(currentWeapon == 1){//with P90 cancel every two sounds to avoid continuous beep |
Pokitto | 5:42a7d8c6c8fd | 280 | if(rand()%2) |
Pokitto | 5:42a7d8c6c8fd | 281 | gb.sound.playPattern(p90_alternative_sound, 0); |
Pokitto | 5:42a7d8c6c8fd | 282 | } |
Pokitto | 5:42a7d8c6c8fd | 283 | //player recoil |
Pokitto | 5:42a7d8c6c8fd | 284 | byte recoil = weapon_playerRecoil[currentWeapon]; |
Pokitto | 5:42a7d8c6c8fd | 285 | moveXYDS(playerX, playerY, playerDir, -recoil); |
Pokitto | 5:42a7d8c6c8fd | 286 | for(byte i = 0; i<recoil; i++){ |
Pokitto | 5:42a7d8c6c8fd | 287 | if(collideWorld(playerX, playerY, playerW, playerH)) |
Pokitto | 5:42a7d8c6c8fd | 288 | moveXYDS(playerX, playerY, playerDir, 1); |
Pokitto | 5:42a7d8c6c8fd | 289 | else |
Pokitto | 5:42a7d8c6c8fd | 290 | break; |
Pokitto | 5:42a7d8c6c8fd | 291 | } |
Pokitto | 5:42a7d8c6c8fd | 292 | if(currentWeapon == 4){ //MG42 |
Pokitto | 5:42a7d8c6c8fd | 293 | shake_magnitude = 1; |
Pokitto | 5:42a7d8c6c8fd | 294 | shake_timeLeft = 2; |
Pokitto | 5:42a7d8c6c8fd | 295 | } |
Pokitto | 5:42a7d8c6c8fd | 296 | break; |
Pokitto | 5:42a7d8c6c8fd | 297 | } |
Pokitto | 5:42a7d8c6c8fd | 298 | } |
Pokitto | 5:42a7d8c6c8fd | 299 | } |
Pokitto | 5:42a7d8c6c8fd | 300 | } |
Pokitto | 5:42a7d8c6c8fd | 301 | else{ |
Pokitto | 5:42a7d8c6c8fd | 302 | currentWeapon = max(0, currentWeapon-1); //cut... no, magnum finally |
Pokitto | 5:42a7d8c6c8fd | 303 | ammo = weapon_ammo[currentWeapon]; |
Pokitto | 5:42a7d8c6c8fd | 304 | nextShot = 20; |
Pokitto | 5:42a7d8c6c8fd | 305 | gb.popup(("Out of ammo!"), 30); |
Pokitto | 5:42a7d8c6c8fd | 306 | } |
Pokitto | 5:42a7d8c6c8fd | 307 | } |
Pokitto | 5:42a7d8c6c8fd | 308 | |
Pokitto | 5:42a7d8c6c8fd | 309 | ///////////////////////////////////// MOVE BULLETS |
Pokitto | 5:42a7d8c6c8fd | 310 | void moveBullets(){ |
Pokitto | 5:42a7d8c6c8fd | 311 | for(byte thisBullet = 0; thisBullet < NUMBULLETS; thisBullet++){ |
Pokitto | 5:42a7d8c6c8fd | 312 | if(bullets_active[thisBullet]){ |
Pokitto | 5:42a7d8c6c8fd | 313 | byte s = weapon_size[bullets_weapon[thisBullet]]; |
Pokitto | 5:42a7d8c6c8fd | 314 | moveXYDS(bullets_x[thisBullet], bullets_y[thisBullet], bullets_dir[thisBullet], weapon_speed[bullets_weapon[thisBullet]]); |
Pokitto | 5:42a7d8c6c8fd | 315 | |
Pokitto | 5:42a7d8c6c8fd | 316 | //collide world |
Pokitto | 5:42a7d8c6c8fd | 317 | if(collideWorld(bullets_x[thisBullet], bullets_y[thisBullet], s, s)){ |
Pokitto | 5:42a7d8c6c8fd | 318 | bullets_active[thisBullet] = false; |
Pokitto | 5:42a7d8c6c8fd | 319 | if(bullets_weapon[thisBullet] == 3){ //RPG |
Pokitto | 5:42a7d8c6c8fd | 320 | blast_x = bullets_x[thisBullet]; |
Pokitto | 5:42a7d8c6c8fd | 321 | blast_y = bullets_y[thisBullet]; |
Pokitto | 5:42a7d8c6c8fd | 322 | blast_lifespan = 8; |
Pokitto | 5:42a7d8c6c8fd | 323 | gb.sound.playPattern(blast_sound, 0); |
Pokitto | 5:42a7d8c6c8fd | 324 | } |
Pokitto | 5:42a7d8c6c8fd | 325 | else{ |
Pokitto | 5:42a7d8c6c8fd | 326 | } |
Pokitto | 5:42a7d8c6c8fd | 327 | continue; |
Pokitto | 5:42a7d8c6c8fd | 328 | } |
Pokitto | 5:42a7d8c6c8fd | 329 | |
Pokitto | 5:42a7d8c6c8fd | 330 | for(byte thisMob=0; thisMob<activeMobs; thisMob++){ //for each mob |
Pokitto | 5:42a7d8c6c8fd | 331 | |
Pokitto | 5:42a7d8c6c8fd | 332 | if(gb.collideRectRect(bullets_x[thisBullet], bullets_y[thisBullet], s, s, |
Pokitto | 5:42a7d8c6c8fd | 333 | mobs_x[thisMob], mobs_y[thisMob], mobs_size[thisMob], mobs_size[thisMob])){ |
Pokitto | 5:42a7d8c6c8fd | 334 | |
Pokitto | 5:42a7d8c6c8fd | 335 | if(bullets_weapon[thisBullet] == 3){ //RPG |
Pokitto | 5:42a7d8c6c8fd | 336 | blast_x = bullets_x[thisBullet]; |
Pokitto | 5:42a7d8c6c8fd | 337 | blast_y = bullets_y[thisBullet]; |
Pokitto | 5:42a7d8c6c8fd | 338 | blast_lifespan = 8; |
Pokitto | 5:42a7d8c6c8fd | 339 | gb.sound.playPattern(blast_sound, 0); |
Pokitto | 5:42a7d8c6c8fd | 340 | } |
Pokitto | 5:42a7d8c6c8fd | 341 | else { |
Pokitto | 5:42a7d8c6c8fd | 342 | damageMob(thisMob, thisBullet); |
Pokitto | 5:42a7d8c6c8fd | 343 | } |
Pokitto | 5:42a7d8c6c8fd | 344 | bullets_active[thisBullet] = false; |
Pokitto | 5:42a7d8c6c8fd | 345 | break; |
Pokitto | 5:42a7d8c6c8fd | 346 | } |
Pokitto | 5:42a7d8c6c8fd | 347 | } |
Pokitto | 5:42a7d8c6c8fd | 348 | |
Pokitto | 5:42a7d8c6c8fd | 349 | } |
Pokitto | 5:42a7d8c6c8fd | 350 | } |
Pokitto | 5:42a7d8c6c8fd | 351 | } |
Pokitto | 5:42a7d8c6c8fd | 352 | |
Pokitto | 5:42a7d8c6c8fd | 353 | ///////////////////////////////////// EXPLODE |
Pokitto | 5:42a7d8c6c8fd | 354 | void explode(){ |
Pokitto | 5:42a7d8c6c8fd | 355 | if(blast_lifespan){ |
Pokitto | 5:42a7d8c6c8fd | 356 | blast_lifespan--; |
Pokitto | 5:42a7d8c6c8fd | 357 | //gb.buzz(50+random(0,100),40); |
Pokitto | 5:42a7d8c6c8fd | 358 | shake_magnitude = 4; |
Pokitto | 5:42a7d8c6c8fd | 359 | shake_timeLeft = 2; |
Pokitto | 5:42a7d8c6c8fd | 360 | //pick a random blast |
Pokitto | 5:42a7d8c6c8fd | 361 | byte s = 10 + random (0,6); |
Pokitto | 5:42a7d8c6c8fd | 362 | int x = blast_x + random(-4,4) -s/2; |
Pokitto | 5:42a7d8c6c8fd | 363 | int y = blast_y + random(-4,4) -s/2; |
Pokitto | 5:42a7d8c6c8fd | 364 | //damages |
Pokitto | 5:42a7d8c6c8fd | 365 | for(byte thisMob=0; thisMob<activeMobs; thisMob++){ |
Pokitto | 5:42a7d8c6c8fd | 366 | if(gb.collideRectRect(mobs_x[thisMob], mobs_y[thisMob], mobs_size[thisMob], mobs_size[thisMob], |
Pokitto | 5:42a7d8c6c8fd | 367 | x,y,s,s)) |
Pokitto | 5:42a7d8c6c8fd | 368 | damageMob(thisMob,blast_bullet); |
Pokitto | 5:42a7d8c6c8fd | 369 | } |
Pokitto | 5:42a7d8c6c8fd | 370 | //display |
Pokitto | 5:42a7d8c6c8fd | 371 | int x_screen, y_screen; |
Pokitto | 5:42a7d8c6c8fd | 372 | if(screenCoord(x, y, x_screen, y_screen)) |
Pokitto | 5:42a7d8c6c8fd | 373 | gb.display.fillRect(x_screen, y_screen, s, s); |
Pokitto | 5:42a7d8c6c8fd | 374 | } |
Pokitto | 5:42a7d8c6c8fd | 375 | } |
Pokitto | 5:42a7d8c6c8fd | 376 | |
Pokitto | 5:42a7d8c6c8fd | 377 | ///////////////////////////////////// DRAW BULLETS |
Pokitto | 5:42a7d8c6c8fd | 378 | void drawBullets(){ |
Pokitto | 5:42a7d8c6c8fd | 379 | gb.display.setColor(1); |
Pokitto | 5:42a7d8c6c8fd | 380 | for(byte thisBullet = 0; thisBullet < NUMBULLETS; thisBullet++){ |
Pokitto | 5:42a7d8c6c8fd | 381 | if(bullets_active[thisBullet]){ |
Pokitto | 5:42a7d8c6c8fd | 382 | int x, y; |
Pokitto | 5:42a7d8c6c8fd | 383 | if(screenCoord(bullets_x[thisBullet], bullets_y[thisBullet], x, y)){ |
Pokitto | 5:42a7d8c6c8fd | 384 | byte s = weapon_size[bullets_weapon[thisBullet]]; |
Pokitto | 5:42a7d8c6c8fd | 385 | if(s==1) |
Pokitto | 5:42a7d8c6c8fd | 386 | gb.display.drawPixel(x, y); |
Pokitto | 5:42a7d8c6c8fd | 387 | else |
Pokitto | 5:42a7d8c6c8fd | 388 | gb.display.fillRect(x, y, s, s); |
Pokitto | 5:42a7d8c6c8fd | 389 | } |
Pokitto | 5:42a7d8c6c8fd | 390 | } |
Pokitto | 5:42a7d8c6c8fd | 391 | } |
Pokitto | 5:42a7d8c6c8fd | 392 | } |
Pokitto | 5:42a7d8c6c8fd | 393 | |
Pokitto | 5:42a7d8c6c8fd | 394 | ///////////////////////////////////// DRAW AMMO OVERLAY |
Pokitto | 5:42a7d8c6c8fd | 395 | void drawAmmoOverlay(){ |
Pokitto | 5:42a7d8c6c8fd | 396 | if(ammo){ |
Pokitto | 5:42a7d8c6c8fd | 397 | // text shadow |
Pokitto | 5:42a7d8c6c8fd | 398 | /* |
Pokitto | 5:42a7d8c6c8fd | 399 | gb.display.setColor(10); |
Pokitto | 5:42a7d8c6c8fd | 400 | gb.display.cursorX = -1; |
Pokitto | 5:42a7d8c6c8fd | 401 | gb.display.cursorY = LCDHEIGHT-gb.display.fontHeight-1; |
Pokitto | 5:42a7d8c6c8fd | 402 | gb.display.print((const __FlashStringHelper*)pgm_read_word(weapon_name+currentWeapon)); //some crazy casts |
Pokitto | 5:42a7d8c6c8fd | 403 | gb.display.cursorX = -1; |
Pokitto | 5:42a7d8c6c8fd | 404 | gb.display.cursorY = LCDHEIGHT-gb.display.fontHeight+1; |
Pokitto | 5:42a7d8c6c8fd | 405 | gb.display.print((const __FlashStringHelper*)pgm_read_word(weapon_name+currentWeapon)); //some crazy casts |
Pokitto | 5:42a7d8c6c8fd | 406 | gb.display.cursorX = 1; |
Pokitto | 5:42a7d8c6c8fd | 407 | gb.display.cursorY = LCDHEIGHT-gb.display.fontHeight-1; |
Pokitto | 5:42a7d8c6c8fd | 408 | gb.display.print((const __FlashStringHelper*)pgm_read_word(weapon_name+currentWeapon)); //some crazy casts |
Pokitto | 5:42a7d8c6c8fd | 409 | gb.display.cursorX = +1; |
Pokitto | 5:42a7d8c6c8fd | 410 | gb.display.cursorY = LCDHEIGHT-gb.display.fontHeight+1; |
Pokitto | 5:42a7d8c6c8fd | 411 | gb.display.print((const __FlashStringHelper*)pgm_read_word(weapon_name+currentWeapon)); //some crazy casts |
Pokitto | 5:42a7d8c6c8fd | 412 | */ |
Pokitto | 5:42a7d8c6c8fd | 413 | // white on top |
Pokitto | 5:42a7d8c6c8fd | 414 | gb.display.setColor(2); |
Pokitto | 5:42a7d8c6c8fd | 415 | gb.display.cursorX = 0; |
Pokitto | 5:42a7d8c6c8fd | 416 | gb.display.cursorY = LCDHEIGHT-gb.display.fontHeight; |
Pokitto | 5:42a7d8c6c8fd | 417 | gb.display.print((char*)(weapon_name[currentWeapon])); //some crazy casts |
Pokitto | 5:42a7d8c6c8fd | 418 | |
Pokitto | 5:42a7d8c6c8fd | 419 | if(nextShot>2) |
Pokitto | 5:42a7d8c6c8fd | 420 | gb.display.fillRect(-2,LCDHEIGHT-2,nextShot,2); |
Pokitto | 5:42a7d8c6c8fd | 421 | if(currentWeapon > 0){ //don't display the ammo of the cut |
Pokitto | 5:42a7d8c6c8fd | 422 | byte xOffset = 0; |
Pokitto | 5:42a7d8c6c8fd | 423 | if (ammo < 100) |
Pokitto | 5:42a7d8c6c8fd | 424 | xOffset += gb.display.fontWidth; |
Pokitto | 5:42a7d8c6c8fd | 425 | if (ammo < 10) |
Pokitto | 5:42a7d8c6c8fd | 426 | xOffset += gb.display.fontWidth; |
Pokitto | 5:42a7d8c6c8fd | 427 | gb.display.cursorX = LCDWIDTH-3*gb.display.fontWidth+xOffset; |
Pokitto | 5:42a7d8c6c8fd | 428 | gb.display.cursorY = LCDHEIGHT-gb.display.fontHeight; |
Pokitto | 5:42a7d8c6c8fd | 429 | gb.display.print(ammo); |
Pokitto | 5:42a7d8c6c8fd | 430 | } |
Pokitto | 5:42a7d8c6c8fd | 431 | else { |
Pokitto | 5:42a7d8c6c8fd | 432 | gb.display.cursorX = LCDWIDTH-3*gb.display.fontWidth; |
Pokitto | 5:42a7d8c6c8fd | 433 | gb.display.cursorY = LCDHEIGHT-gb.display.fontHeight; |
Pokitto | 5:42a7d8c6c8fd | 434 | gb.display.print(("inf")); |
Pokitto | 5:42a7d8c6c8fd | 435 | } |
Pokitto | 5:42a7d8c6c8fd | 436 | } |
Pokitto | 5:42a7d8c6c8fd | 437 | } |
Pokitto | 5:42a7d8c6c8fd | 438 | |
Pokitto | 5:42a7d8c6c8fd | 439 | ///////////////////////////////////// SET SPLASH |
Pokitto | 5:42a7d8c6c8fd | 440 | void setSplash(int x, int y){ |
Pokitto | 5:42a7d8c6c8fd | 441 | for(byte thisSplash = 0; thisSplash < NUMSPLASH; thisSplash++){ |
Pokitto | 5:42a7d8c6c8fd | 442 | if(!splash_active[thisSplash]){ //look for the first inactive splash |
Pokitto | 5:42a7d8c6c8fd | 443 | splash_active[thisSplash] = true; //set it to active |
Pokitto | 5:42a7d8c6c8fd | 444 | splash_x[thisSplash] = x; |
Pokitto | 5:42a7d8c6c8fd | 445 | splash_y[thisSplash] = y; |
Pokitto | 5:42a7d8c6c8fd | 446 | splash_dir[thisSplash] = random(0,5); |
Pokitto | 5:42a7d8c6c8fd | 447 | break; |
Pokitto | 5:42a7d8c6c8fd | 448 | } |
Pokitto | 5:42a7d8c6c8fd | 449 | } |
Pokitto | 5:42a7d8c6c8fd | 450 | } |
Pokitto | 5:42a7d8c6c8fd | 451 | |
Pokitto | 5:42a7d8c6c8fd | 452 | ///////////////////////////////////// DRAW SPLASHES |
Pokitto | 5:42a7d8c6c8fd | 453 | void drawSplashes(){ |
Pokitto | 5:42a7d8c6c8fd | 454 | for(byte thisSplash = 0; thisSplash < NUMSPLASH; thisSplash++){ |
Pokitto | 5:42a7d8c6c8fd | 455 | if(splash_active[thisSplash]){ |
Pokitto | 5:42a7d8c6c8fd | 456 | int x, y; |
Pokitto | 5:42a7d8c6c8fd | 457 | if(screenCoord(splash_x[thisSplash], splash_y[thisSplash], x, y)){ //if the splash is in the screen |
Pokitto | 5:42a7d8c6c8fd | 458 | //draw it |
Pokitto | 5:42a7d8c6c8fd | 459 | gb.display.drawBitmap(x-2, y-2, splashSprite, splash_dir[thisSplash], NOFLIP); |
Pokitto | 5:42a7d8c6c8fd | 460 | } |
Pokitto | 5:42a7d8c6c8fd | 461 | else{ //erase it if it is out of the screen |
Pokitto | 5:42a7d8c6c8fd | 462 | splash_active[thisSplash] = false; |
Pokitto | 5:42a7d8c6c8fd | 463 | } |
Pokitto | 5:42a7d8c6c8fd | 464 | } |
Pokitto | 5:42a7d8c6c8fd | 465 | } |
Pokitto | 5:42a7d8c6c8fd | 466 | } |
Pokitto | 5:42a7d8c6c8fd | 467 | |
Pokitto | 5:42a7d8c6c8fd | 468 | |
Pokitto | 5:42a7d8c6c8fd | 469 | ///////////////////////////////////// SPAWN CRATE |
Pokitto | 5:42a7d8c6c8fd | 470 | void spawnCrate(){ |
Pokitto | 5:42a7d8c6c8fd | 471 | boolean okay = false; |
Pokitto | 5:42a7d8c6c8fd | 472 | while (okay == false){ |
Pokitto | 5:42a7d8c6c8fd | 473 | //pick a random location |
Pokitto | 5:42a7d8c6c8fd | 474 | crate_x = random(0, WORLD_W) * 8; |
Pokitto | 5:42a7d8c6c8fd | 475 | crate_y = random(0, WORLD_H) * 8; |
Pokitto | 5:42a7d8c6c8fd | 476 | okay = true; |
Pokitto | 5:42a7d8c6c8fd | 477 | //is that in a wall ? |
Pokitto | 5:42a7d8c6c8fd | 478 | if(collideWorld(crate_x, crate_y, 8, 8)){ |
Pokitto | 5:42a7d8c6c8fd | 479 | okay = false; |
Pokitto | 5:42a7d8c6c8fd | 480 | } |
Pokitto | 5:42a7d8c6c8fd | 481 | //is that in the screen ? |
Pokitto | 5:42a7d8c6c8fd | 482 | int x, y; |
Pokitto | 5:42a7d8c6c8fd | 483 | if(screenCoord(crate_x, crate_y, x, y)){ |
Pokitto | 5:42a7d8c6c8fd | 484 | okay = false; |
Pokitto | 5:42a7d8c6c8fd | 485 | } |
Pokitto | 5:42a7d8c6c8fd | 486 | } |
Pokitto | 5:42a7d8c6c8fd | 487 | } |
Pokitto | 5:42a7d8c6c8fd | 488 | |
Pokitto | 5:42a7d8c6c8fd | 489 | ///////////////////////////////////// COLLIDE CRATE |
Pokitto | 5:42a7d8c6c8fd | 490 | void collideCrate(){ |
Pokitto | 5:42a7d8c6c8fd | 491 | if(gb.collideRectRect(crate_x+2, crate_y+2, 4, 4, playerX, playerY, playerW, playerH)){ |
Pokitto | 5:42a7d8c6c8fd | 492 | if (score <5){ |
Pokitto | 5:42a7d8c6c8fd | 493 | gb.popup(("Earn $5 first"), 30); |
Pokitto | 5:42a7d8c6c8fd | 494 | return; |
Pokitto | 5:42a7d8c6c8fd | 495 | } |
Pokitto | 5:42a7d8c6c8fd | 496 | if(currentWeapon<(NUMWEAPONS-1)){ |
Pokitto | 5:42a7d8c6c8fd | 497 | gb.popup(("Upgraded !"), 30); |
Pokitto | 5:42a7d8c6c8fd | 498 | gb.sound.playPattern(power_up,0); |
Pokitto | 5:42a7d8c6c8fd | 499 | } |
Pokitto | 5:42a7d8c6c8fd | 500 | else{ |
Pokitto | 5:42a7d8c6c8fd | 501 | gb.popup(("Refilled !"), 30); |
Pokitto | 5:42a7d8c6c8fd | 502 | } |
Pokitto | 5:42a7d8c6c8fd | 503 | score -= 5; |
Pokitto | 5:42a7d8c6c8fd | 504 | spawnCrate(); |
Pokitto | 5:42a7d8c6c8fd | 505 | currentWeapon = min(NUMWEAPONS-1, currentWeapon+1); //upgrade to the next weapon |
Pokitto | 5:42a7d8c6c8fd | 506 | ammo = weapon_ammo[currentWeapon]; |
Pokitto | 5:42a7d8c6c8fd | 507 | //gb.popup(weapon_name[currentWeapon], 30); |
Pokitto | 5:42a7d8c6c8fd | 508 | //if(random(0,score/10)==0) //the higher is your score, the less life you will find in crates |
Pokitto | 5:42a7d8c6c8fd | 509 | playerLife = min(playerLife+1, playerLifeMax); |
Pokitto | 5:42a7d8c6c8fd | 510 | int hazefactor = (255-42*playerLife)*2/3; |
Pokitto | 5:42a7d8c6c8fd | 511 | for (uint16_t k =0 ; k<16; k++) hazepalette[k] = gb.display.interpolateColor(gb.display.palette[k],gb.display.palette[4],hazefactor); |
Pokitto | 5:42a7d8c6c8fd | 512 | //gb.buzz(2000,40); |
Pokitto | 5:42a7d8c6c8fd | 513 | } |
Pokitto | 5:42a7d8c6c8fd | 514 | } |
Pokitto | 5:42a7d8c6c8fd | 515 | |
Pokitto | 5:42a7d8c6c8fd | 516 | ///////////////////////////////////// DRAW CRATE |
Pokitto | 5:42a7d8c6c8fd | 517 | void drawCrate(){ |
Pokitto | 5:42a7d8c6c8fd | 518 | int x, y; |
Pokitto | 5:42a7d8c6c8fd | 519 | if(screenCoord(crate_x, crate_y, x, y)){ |
Pokitto | 5:42a7d8c6c8fd | 520 | gb.display.setColor(8); |
Pokitto | 5:42a7d8c6c8fd | 521 | gb.display.drawBitmap(x, y, crateSprite); |
Pokitto | 5:42a7d8c6c8fd | 522 | //gb.display.setColor(6); |
Pokitto | 5:42a7d8c6c8fd | 523 | //gb.display.drawBitmap(x-1, y, crateSprite); |
Pokitto | 5:42a7d8c6c8fd | 524 | } |
Pokitto | 5:42a7d8c6c8fd | 525 | } |
Pokitto | 5:42a7d8c6c8fd | 526 | |
Pokitto | 5:42a7d8c6c8fd | 527 | |
Pokitto | 5:42a7d8c6c8fd | 528 | |
Pokitto | 5:42a7d8c6c8fd | 529 | ///////////////////////////////////// SPAWN ONE MOB |
Pokitto | 5:42a7d8c6c8fd | 530 | boolean spawnMob(byte thisMob){ |
Pokitto | 5:42a7d8c6c8fd | 531 | boolean okay = false; |
Pokitto | 5:42a7d8c6c8fd | 532 | byte timout = 0; |
Pokitto | 5:42a7d8c6c8fd | 533 | mobs_size[thisMob] = mob_size; |
Pokitto | 5:42a7d8c6c8fd | 534 | mobs_life[thisMob] = mob_maxLife; |
Pokitto | 5:42a7d8c6c8fd | 535 | if(!boss_nextSpawn){ //spawn big mobs every 20 kills starting from 15 |
Pokitto | 5:42a7d8c6c8fd | 536 | boss_freq = max(boss_freq - BOSSRATE, 1); |
Pokitto | 5:42a7d8c6c8fd | 537 | boss_nextSpawn = boss_freq; |
Pokitto | 5:42a7d8c6c8fd | 538 | mobs_size[thisMob] = boss_size; |
Pokitto | 5:42a7d8c6c8fd | 539 | mobs_life[thisMob] = boss_maxLife; |
Pokitto | 5:42a7d8c6c8fd | 540 | //gb.popup("Boss spawned !", 30); |
Pokitto | 5:42a7d8c6c8fd | 541 | } |
Pokitto | 5:42a7d8c6c8fd | 542 | while(okay == false){ //do the following until it's okay |
Pokitto | 5:42a7d8c6c8fd | 543 | //pick a random location |
Pokitto | 5:42a7d8c6c8fd | 544 | mobs_x[thisMob] = random(0, WORLD_W*2) * 4; |
Pokitto | 5:42a7d8c6c8fd | 545 | mobs_y[thisMob] = random(0, WORLD_H*2) * 4; |
Pokitto | 5:42a7d8c6c8fd | 546 | //and check if that position is okay |
Pokitto | 5:42a7d8c6c8fd | 547 | okay = true; |
Pokitto | 5:42a7d8c6c8fd | 548 | |
Pokitto | 5:42a7d8c6c8fd | 549 | if(checkMobCollisions(thisMob)){ |
Pokitto | 5:42a7d8c6c8fd | 550 | okay = false; |
Pokitto | 5:42a7d8c6c8fd | 551 | continue; |
Pokitto | 5:42a7d8c6c8fd | 552 | } |
Pokitto | 5:42a7d8c6c8fd | 553 | //spawn the mobs out of the player's view |
Pokitto | 5:42a7d8c6c8fd | 554 | if(wrap(mobs_x[thisMob] - cameraX, WORLD_W*8) < LCDWIDTH){ |
Pokitto | 5:42a7d8c6c8fd | 555 | okay = false; |
Pokitto | 5:42a7d8c6c8fd | 556 | continue; |
Pokitto | 5:42a7d8c6c8fd | 557 | } |
Pokitto | 5:42a7d8c6c8fd | 558 | if(wrap(mobs_y[thisMob] - cameraY, WORLD_H*8) < LCDHEIGHT){ |
Pokitto | 5:42a7d8c6c8fd | 559 | okay = false; |
Pokitto | 5:42a7d8c6c8fd | 560 | continue; |
Pokitto | 5:42a7d8c6c8fd | 561 | } |
Pokitto | 5:42a7d8c6c8fd | 562 | } |
Pokitto | 5:42a7d8c6c8fd | 563 | mobs_dir[thisMob] = rand() % 4; //then pick a random direction |
Pokitto | 5:42a7d8c6c8fd | 564 | return true; |
Pokitto | 5:42a7d8c6c8fd | 565 | } |
Pokitto | 5:42a7d8c6c8fd | 566 | |
Pokitto | 5:42a7d8c6c8fd | 567 | ///////////////////////////////////// SPAWN ALL MOBS |
Pokitto | 5:42a7d8c6c8fd | 568 | boolean spawnMobs(){ |
Pokitto | 5:42a7d8c6c8fd | 569 | for(byte thisMob=0; thisMob<activeMobs; thisMob++){ //put mobs far away |
Pokitto | 5:42a7d8c6c8fd | 570 | mobs_x[thisMob] = 9999; |
Pokitto | 5:42a7d8c6c8fd | 571 | mobs_y[thisMob] = 9999; |
Pokitto | 5:42a7d8c6c8fd | 572 | } |
Pokitto | 5:42a7d8c6c8fd | 573 | for(byte thisMob=0; thisMob<activeMobs; thisMob++){ |
Pokitto | 5:42a7d8c6c8fd | 574 | if(!spawnMob(thisMob)) //try to spawn a mob |
Pokitto | 5:42a7d8c6c8fd | 575 | return false; //return false if an error occur |
Pokitto | 5:42a7d8c6c8fd | 576 | } |
Pokitto | 5:42a7d8c6c8fd | 577 | return true; |
Pokitto | 5:42a7d8c6c8fd | 578 | } |
Pokitto | 5:42a7d8c6c8fd | 579 | |
Pokitto | 5:42a7d8c6c8fd | 580 | ///////////////////////////////////// MOVE MOBS |
Pokitto | 5:42a7d8c6c8fd | 581 | void moveMobs(){ |
Pokitto | 5:42a7d8c6c8fd | 582 | for(byte thisMob=0; thisMob<activeMobs; thisMob++){ //for each mob |
Pokitto | 5:42a7d8c6c8fd | 583 | int x = wrap(mobs_x[thisMob] - cameraX, WORLD_W*8); |
Pokitto | 5:42a7d8c6c8fd | 584 | int y = wrap(mobs_y[thisMob] - cameraY, WORLD_H*8); |
Pokitto | 5:42a7d8c6c8fd | 585 | //if the mob is close to the screen |
Pokitto | 5:42a7d8c6c8fd | 586 | if( (distanceBetween(mobs_x[thisMob], playerX, WORLD_W*8) < (LCDWIDTH+32)) && (distanceBetween(mobs_y[thisMob], playerY, WORLD_H*8) < (LCDHEIGHT+32))){ |
Pokitto | 5:42a7d8c6c8fd | 587 | moveXYDS(mobs_x[thisMob], mobs_y[thisMob], mobs_dir[thisMob], 1); //go forward |
Pokitto | 5:42a7d8c6c8fd | 588 | |
Pokitto | 5:42a7d8c6c8fd | 589 | //if there is a collision, move a step backward and pick a new random direction |
Pokitto | 5:42a7d8c6c8fd | 590 | if(checkMobCollisions(thisMob)){ |
Pokitto | 5:42a7d8c6c8fd | 591 | moveXYDS(mobs_x[thisMob], mobs_y[thisMob], mobs_dir[thisMob], -1); |
Pokitto | 5:42a7d8c6c8fd | 592 | mobs_dir[thisMob] = rand()%4; |
Pokitto | 5:42a7d8c6c8fd | 593 | continue; |
Pokitto | 5:42a7d8c6c8fd | 594 | } |
Pokitto | 5:42a7d8c6c8fd | 595 | |
Pokitto | 5:42a7d8c6c8fd | 596 | //go in a random direction |
Pokitto | 5:42a7d8c6c8fd | 597 | if(random(0,32)==0){ |
Pokitto | 5:42a7d8c6c8fd | 598 | mobs_dir[thisMob] = rand()%4; |
Pokitto | 5:42a7d8c6c8fd | 599 | continue; |
Pokitto | 5:42a7d8c6c8fd | 600 | } |
Pokitto | 5:42a7d8c6c8fd | 601 | |
Pokitto | 5:42a7d8c6c8fd | 602 | //go in the direction on the player (randomly choose between X and Y axis) |
Pokitto | 5:42a7d8c6c8fd | 603 | if(random(0,16)==0){ |
Pokitto | 5:42a7d8c6c8fd | 604 | if(random(0,2)){ |
Pokitto | 5:42a7d8c6c8fd | 605 | //get closer to the player on the X axis |
Pokitto | 5:42a7d8c6c8fd | 606 | if((LCDWIDTH/2 - x) > 0){ //go to the left if the player is on the left |
Pokitto | 5:42a7d8c6c8fd | 607 | mobs_dir[thisMob] = 3; |
Pokitto | 5:42a7d8c6c8fd | 608 | } |
Pokitto | 5:42a7d8c6c8fd | 609 | else{ // or go to the right if the player is on the right |
Pokitto | 5:42a7d8c6c8fd | 610 | mobs_dir[thisMob] = 1; |
Pokitto | 5:42a7d8c6c8fd | 611 | } |
Pokitto | 5:42a7d8c6c8fd | 612 | } |
Pokitto | 5:42a7d8c6c8fd | 613 | //if the distance between the player and the mob is larger on the Y axis |
Pokitto | 5:42a7d8c6c8fd | 614 | else { |
Pokitto | 5:42a7d8c6c8fd | 615 | //get closer to the player on the Y axis |
Pokitto | 5:42a7d8c6c8fd | 616 | if((LCDHEIGHT/2 - y) > 0){ //go downward |
Pokitto | 5:42a7d8c6c8fd | 617 | mobs_dir[thisMob] = 2; |
Pokitto | 5:42a7d8c6c8fd | 618 | } |
Pokitto | 5:42a7d8c6c8fd | 619 | else{ //go upward |
Pokitto | 5:42a7d8c6c8fd | 620 | mobs_dir[thisMob] = 0; |
Pokitto | 5:42a7d8c6c8fd | 621 | } |
Pokitto | 5:42a7d8c6c8fd | 622 | } |
Pokitto | 5:42a7d8c6c8fd | 623 | } |
Pokitto | 5:42a7d8c6c8fd | 624 | } |
Pokitto | 5:42a7d8c6c8fd | 625 | } |
Pokitto | 5:42a7d8c6c8fd | 626 | } |
Pokitto | 5:42a7d8c6c8fd | 627 | |
Pokitto | 5:42a7d8c6c8fd | 628 | ///////////////////////////////////// CHECK MOB COLLISIONS |
Pokitto | 5:42a7d8c6c8fd | 629 | boolean checkMobCollisions(byte thisMob){ |
Pokitto | 5:42a7d8c6c8fd | 630 | //check collision with the world |
Pokitto | 5:42a7d8c6c8fd | 631 | if(collideWorld(mobs_x[thisMob], mobs_y[thisMob], mobs_size[thisMob], mobs_size[thisMob])) |
Pokitto | 5:42a7d8c6c8fd | 632 | return true; |
Pokitto | 5:42a7d8c6c8fd | 633 | //check collision with other mobs |
Pokitto | 5:42a7d8c6c8fd | 634 | if(collideOtherMobs(thisMob)) |
Pokitto | 5:42a7d8c6c8fd | 635 | return true; |
Pokitto | 5:42a7d8c6c8fd | 636 | return false; |
Pokitto | 5:42a7d8c6c8fd | 637 | } |
Pokitto | 5:42a7d8c6c8fd | 638 | |
Pokitto | 5:42a7d8c6c8fd | 639 | |
Pokitto | 5:42a7d8c6c8fd | 640 | ///////////////////////////////////// CHECK IF A MOB COLLIDE ANOTHER ONE |
Pokitto | 5:42a7d8c6c8fd | 641 | boolean collideOtherMobs(byte thisMob){ |
Pokitto | 5:42a7d8c6c8fd | 642 | for(byte otherMob=0; otherMob<activeMobs; otherMob++){ |
Pokitto | 5:42a7d8c6c8fd | 643 | if(thisMob == otherMob) //don't check collision with iself >_<' |
Pokitto | 5:42a7d8c6c8fd | 644 | continue; |
Pokitto | 5:42a7d8c6c8fd | 645 | if(gb.collideRectRect(mobs_x[thisMob], mobs_y[thisMob], mobs_size[thisMob], mobs_size[thisMob], |
Pokitto | 5:42a7d8c6c8fd | 646 | mobs_x[otherMob], mobs_y[otherMob], mobs_size[otherMob], mobs_size[otherMob])){ |
Pokitto | 5:42a7d8c6c8fd | 647 | return true; |
Pokitto | 5:42a7d8c6c8fd | 648 | } |
Pokitto | 5:42a7d8c6c8fd | 649 | } |
Pokitto | 5:42a7d8c6c8fd | 650 | return false; |
Pokitto | 5:42a7d8c6c8fd | 651 | } |
Pokitto | 5:42a7d8c6c8fd | 652 | |
Pokitto | 5:42a7d8c6c8fd | 653 | ///////////////////////////////////// DRAW MOBS |
Pokitto | 5:42a7d8c6c8fd | 654 | void drawMobs(){ |
Pokitto | 5:42a7d8c6c8fd | 655 | gb.display.setColor(1); //8 |
Pokitto | 5:42a7d8c6c8fd | 656 | for(byte thisMob=0; thisMob<activeMobs; thisMob++){ |
Pokitto | 5:42a7d8c6c8fd | 657 | //int x = wrap(mobs_x[thisMob] - cameraX + playerW/2, WORLD_W*8); |
Pokitto | 5:42a7d8c6c8fd | 658 | //int y = wrap(mobs_y[thisMob] - cameraY + playerH/2, WORLD_H*8); |
Pokitto | 5:42a7d8c6c8fd | 659 | int x, y; |
Pokitto | 5:42a7d8c6c8fd | 660 | if(screenCoord(mobs_x[thisMob], mobs_y[thisMob], x, y)){ |
Pokitto | 5:42a7d8c6c8fd | 661 | if(mobs_size[thisMob] != boss_size) |
Pokitto | 5:42a7d8c6c8fd | 662 | { |
Pokitto | 5:42a7d8c6c8fd | 663 | gb.display.setColor(8); |
Pokitto | 5:42a7d8c6c8fd | 664 | gb.display.drawBitmap(x-2, y-2, mobSprite, mobs_dir[thisMob], NOFLIP); |
Pokitto | 5:42a7d8c6c8fd | 665 | } else |
Pokitto | 5:42a7d8c6c8fd | 666 | { gb.display.setColor(9); |
Pokitto | 5:42a7d8c6c8fd | 667 | gb.display.drawBitmap(x-1, y-1, bossSprite, mobs_dir[thisMob], NOFLIP); |
Pokitto | 5:42a7d8c6c8fd | 668 | } |
Pokitto | 5:42a7d8c6c8fd | 669 | //gb.fillRect(x, y, mobs_size[thisMob], mobs_size[thisMob], BLACK); |
Pokitto | 5:42a7d8c6c8fd | 670 | } |
Pokitto | 5:42a7d8c6c8fd | 671 | } |
Pokitto | 5:42a7d8c6c8fd | 672 | } |
Pokitto | 5:42a7d8c6c8fd | 673 | |
Pokitto | 5:42a7d8c6c8fd | 674 | ///////////////////////////////////// DAMAGE MOB |
Pokitto | 5:42a7d8c6c8fd | 675 | void damageMob(byte thisMob, byte thisBullet){ |
Pokitto | 5:42a7d8c6c8fd | 676 | mobs_life[thisMob] -= weapon_damage[bullets_weapon[thisBullet]]; |
Pokitto | 5:42a7d8c6c8fd | 677 | //recoil |
Pokitto | 5:42a7d8c6c8fd | 678 | byte recoil = weapon_ennemyRecoil[bullets_weapon[thisBullet]]; |
Pokitto | 5:42a7d8c6c8fd | 679 | if(mobs_size[thisMob] == boss_size) |
Pokitto | 5:42a7d8c6c8fd | 680 | recoil /= 4; |
Pokitto | 5:42a7d8c6c8fd | 681 | moveXYDS(mobs_x[thisMob], mobs_y[thisMob], bullets_dir[thisBullet], recoil); |
Pokitto | 5:42a7d8c6c8fd | 682 | if(checkMobCollisions(thisMob)) |
Pokitto | 5:42a7d8c6c8fd | 683 | moveXYDS(mobs_x[thisMob], mobs_y[thisMob], bullets_dir[thisBullet], -recoil); |
Pokitto | 5:42a7d8c6c8fd | 684 | mobs_dir[thisMob] = (bullets_dir[thisBullet] + 2) % 4; |
Pokitto | 5:42a7d8c6c8fd | 685 | //gb.buzz(1200,10); |
Pokitto | 5:42a7d8c6c8fd | 686 | if(mobs_life[thisMob] <= 0){ //the mob dies |
Pokitto | 5:42a7d8c6c8fd | 687 | score++; |
Pokitto | 5:42a7d8c6c8fd | 688 | kills++; |
Pokitto | 5:42a7d8c6c8fd | 689 | boss_nextSpawn--; |
Pokitto | 5:42a7d8c6c8fd | 690 | if(bullets_weapon[thisBullet]!=3){ //if it's no the RPG |
Pokitto | 5:42a7d8c6c8fd | 691 | gb.sound.playPattern(mob_death_sound,0); |
Pokitto | 5:42a7d8c6c8fd | 692 | } |
Pokitto | 5:42a7d8c6c8fd | 693 | if(mobs_size[thisMob] == boss_size) |
Pokitto | 5:42a7d8c6c8fd | 694 | score += 4; |
Pokitto | 5:42a7d8c6c8fd | 695 | setSplash(mobs_x[thisMob], mobs_y[thisMob]); |
Pokitto | 5:42a7d8c6c8fd | 696 | int x, y; |
Pokitto | 5:42a7d8c6c8fd | 697 | if(screenCoord(mobs_x[thisMob], mobs_y[thisMob], x, y)){ |
Pokitto | 5:42a7d8c6c8fd | 698 | gb.display.fillRect(x-1, y-1, mobs_size[thisMob]+1, mobs_size[thisMob]+1); |
Pokitto | 5:42a7d8c6c8fd | 699 | } |
Pokitto | 5:42a7d8c6c8fd | 700 | //gb.buzz(1400,20); |
Pokitto | 5:42a7d8c6c8fd | 701 | spawnMob(thisMob); |
Pokitto | 5:42a7d8c6c8fd | 702 | if(activeMobs < NUMMOBS){ //if the max isn't reached |
Pokitto | 5:42a7d8c6c8fd | 703 | if(activeMobs < (kills/MOBSRATE)+INITNUMMOBS){ //every 8 mobs killed |
Pokitto | 5:42a7d8c6c8fd | 704 | activeMobs++; //add a mob |
Pokitto | 5:42a7d8c6c8fd | 705 | spawnMob(activeMobs-1); //spawn the mob added |
Pokitto | 5:42a7d8c6c8fd | 706 | } |
Pokitto | 5:42a7d8c6c8fd | 707 | } |
Pokitto | 5:42a7d8c6c8fd | 708 | } |
Pokitto | 5:42a7d8c6c8fd | 709 | else { //the mob survives |
Pokitto | 5:42a7d8c6c8fd | 710 | } |
Pokitto | 5:42a7d8c6c8fd | 711 | } |
Pokitto | 5:42a7d8c6c8fd | 712 | |
Pokitto | 5:42a7d8c6c8fd | 713 | |
Pokitto | 5:42a7d8c6c8fd | 714 | |
Pokitto | 5:42a7d8c6c8fd | 715 | #define PAUSEMENULENGTH 5 |
Pokitto | 5:42a7d8c6c8fd | 716 | const char strPlay[] PROGMEM = "Play"; |
Pokitto | 5:42a7d8c6c8fd | 717 | const char strRestart[] PROGMEM = "Restart"; |
Pokitto | 5:42a7d8c6c8fd | 718 | const char strHighScores[] PROGMEM = "High scores"; |
Pokitto | 5:42a7d8c6c8fd | 719 | const char strSystemInfo[] PROGMEM = "System Info"; |
Pokitto | 5:42a7d8c6c8fd | 720 | const char strMainMenu[] PROGMEM = "Main Menu"; |
Pokitto | 5:42a7d8c6c8fd | 721 | |
Pokitto | 5:42a7d8c6c8fd | 722 | |
Pokitto | 5:42a7d8c6c8fd | 723 | const char* const pauseMenu[PAUSEMENULENGTH] PROGMEM = { |
Pokitto | 5:42a7d8c6c8fd | 724 | strPlay, |
Pokitto | 5:42a7d8c6c8fd | 725 | strRestart, |
Pokitto | 5:42a7d8c6c8fd | 726 | strHighScores, |
Pokitto | 5:42a7d8c6c8fd | 727 | strSystemInfo, |
Pokitto | 5:42a7d8c6c8fd | 728 | strMainMenu |
Pokitto | 5:42a7d8c6c8fd | 729 | }; |
Pokitto | 5:42a7d8c6c8fd | 730 | |
Pokitto | 5:42a7d8c6c8fd | 731 | ///////////////////////////////////// PAUSE |
Pokitto | 5:42a7d8c6c8fd | 732 | void pausem(){ |
Pokitto | 5:42a7d8c6c8fd | 733 | while(gb.isRunning()){ |
Pokitto | 5:42a7d8c6c8fd | 734 | if(gb.update()){ |
Pokitto | 5:42a7d8c6c8fd | 735 | switch(gb.menu(pauseMenu, PAUSEMENULENGTH)){ |
Pokitto | 5:42a7d8c6c8fd | 736 | case 0: //resume |
Pokitto | 5:42a7d8c6c8fd | 737 | gb.wait(100); |
Pokitto | 5:42a7d8c6c8fd | 738 | gb.display.setFont(font3x5); |
Pokitto | 5:42a7d8c6c8fd | 739 | play(); |
Pokitto | 5:42a7d8c6c8fd | 740 | gb.display.setFont(font5x7); |
Pokitto | 5:42a7d8c6c8fd | 741 | gb.battery.show = true; |
Pokitto | 5:42a7d8c6c8fd | 742 | break; |
Pokitto | 5:42a7d8c6c8fd | 743 | case 1: //restart |
Pokitto | 5:42a7d8c6c8fd | 744 | initGame(); |
Pokitto | 5:42a7d8c6c8fd | 745 | gb.display.setFont(font3x5); |
Pokitto | 5:42a7d8c6c8fd | 746 | play(); |
Pokitto | 5:42a7d8c6c8fd | 747 | gb.display.setFont(font5x7); |
Pokitto | 5:42a7d8c6c8fd | 748 | gb.battery.show = true; |
Pokitto | 5:42a7d8c6c8fd | 749 | return; |
Pokitto | 5:42a7d8c6c8fd | 750 | case 2: //high scores |
Pokitto | 5:42a7d8c6c8fd | 751 | displayHighScores(); |
Pokitto | 5:42a7d8c6c8fd | 752 | break; |
Pokitto | 5:42a7d8c6c8fd | 753 | case 3: //System info |
Pokitto | 5:42a7d8c6c8fd | 754 | gb.display.setFont(font3x5); |
Pokitto | 5:42a7d8c6c8fd | 755 | while (1) { |
Pokitto | 5:42a7d8c6c8fd | 756 | if (gb.update()) { |
Pokitto | 5:42a7d8c6c8fd | 757 | if (gb.buttons.pressed(BTN_C)) { |
Pokitto | 5:42a7d8c6c8fd | 758 | gb.display.setFont(font5x7); |
Pokitto | 5:42a7d8c6c8fd | 759 | gb.sound.playCancel(); |
Pokitto | 5:42a7d8c6c8fd | 760 | break; |
Pokitto | 5:42a7d8c6c8fd | 761 | } |
Pokitto | 5:42a7d8c6c8fd | 762 | //gb.display.setCursor(0, 0); |
Pokitto | 5:42a7d8c6c8fd | 763 | gb.display.print(("Bat:")); |
Pokitto | 5:42a7d8c6c8fd | 764 | gb.display.print(gb.battery.voltage); |
Pokitto | 5:42a7d8c6c8fd | 765 | gb.display.println(("mV")); |
Pokitto | 5:42a7d8c6c8fd | 766 | |
Pokitto | 5:42a7d8c6c8fd | 767 | gb.display.print(("Bat lvl:")); |
Pokitto | 5:42a7d8c6c8fd | 768 | gb.display.print(gb.battery.level); |
Pokitto | 5:42a7d8c6c8fd | 769 | gb.display.println(("/4")); |
Pokitto | 5:42a7d8c6c8fd | 770 | |
Pokitto | 5:42a7d8c6c8fd | 771 | gb.display.print(("Light:")); |
Pokitto | 5:42a7d8c6c8fd | 772 | gb.display.println(gb.backlight.ambientLight); |
Pokitto | 5:42a7d8c6c8fd | 773 | |
Pokitto | 5:42a7d8c6c8fd | 774 | gb.display.print(("Backlight:")); |
Pokitto | 5:42a7d8c6c8fd | 775 | gb.display.println(gb.backlight.backlightValue); |
Pokitto | 5:42a7d8c6c8fd | 776 | |
Pokitto | 5:42a7d8c6c8fd | 777 | gb.display.print(("Volume:")); |
Pokitto | 5:42a7d8c6c8fd | 778 | gb.display.print(gb.sound.getVolume()); |
Pokitto | 5:42a7d8c6c8fd | 779 | //gb.display.print(F("/")); |
Pokitto | 5:42a7d8c6c8fd | 780 | //gb.display.println(gb.sound.volumeMax); |
Pokitto | 5:42a7d8c6c8fd | 781 | |
Pokitto | 5:42a7d8c6c8fd | 782 | gb.display.print("Mobs:"); |
Pokitto | 5:42a7d8c6c8fd | 783 | gb.display.print(activeMobs); |
Pokitto | 5:42a7d8c6c8fd | 784 | gb.display.print("/"); |
Pokitto | 5:42a7d8c6c8fd | 785 | gb.display.println(NUMMOBS); |
Pokitto | 5:42a7d8c6c8fd | 786 | |
Pokitto | 5:42a7d8c6c8fd | 787 | gb.display.print("Killed:"); |
Pokitto | 5:42a7d8c6c8fd | 788 | gb.display.println(kills); |
Pokitto | 5:42a7d8c6c8fd | 789 | } |
Pokitto | 5:42a7d8c6c8fd | 790 | } |
Pokitto | 5:42a7d8c6c8fd | 791 | break; |
Pokitto | 5:42a7d8c6c8fd | 792 | case 4: //change game |
Pokitto | 5:42a7d8c6c8fd | 793 | //gb.changeGame(); |
Pokitto | 5:42a7d8c6c8fd | 794 | gb.titleScreen(logo); |
Pokitto | 5:42a7d8c6c8fd | 795 | break; |
Pokitto | 5:42a7d8c6c8fd | 796 | default: |
Pokitto | 5:42a7d8c6c8fd | 797 | return; |
Pokitto | 5:42a7d8c6c8fd | 798 | } |
Pokitto | 5:42a7d8c6c8fd | 799 | } |
Pokitto | 5:42a7d8c6c8fd | 800 | } |
Pokitto | 5:42a7d8c6c8fd | 801 | } |
Pokitto | 5:42a7d8c6c8fd | 802 | |
Pokitto | 5:42a7d8c6c8fd | 803 | ///////////////////////////////////// DISPLAY HIGHSCORES |
Pokitto | 5:42a7d8c6c8fd | 804 | void displayHighScores(){ |
Pokitto | 5:42a7d8c6c8fd | 805 | while(true){ |
Pokitto | 5:42a7d8c6c8fd | 806 | if(gb.update()){ |
Pokitto | 5:42a7d8c6c8fd | 807 | gb.display.cursorX = 9+random(0,2); |
Pokitto | 5:42a7d8c6c8fd | 808 | gb.display.cursorY = 0+random(0,2); |
Pokitto | 5:42a7d8c6c8fd | 809 | gb.display.println(("HIGH SCORES")); |
Pokitto | 5:42a7d8c6c8fd | 810 | gb.display.textWrap = false; |
Pokitto | 5:42a7d8c6c8fd | 811 | gb.display.cursorX = 0; |
Pokitto | 5:42a7d8c6c8fd | 812 | gb.display.cursorY = gb.display.fontHeight; |
Pokitto | 5:42a7d8c6c8fd | 813 | for(byte thisScore=0; thisScore<RANKMAX; thisScore++){ |
Pokitto | 5:42a7d8c6c8fd | 814 | if(highscore[thisScore]==0) |
Pokitto | 5:42a7d8c6c8fd | 815 | gb.display.print('-'); |
Pokitto | 5:42a7d8c6c8fd | 816 | else |
Pokitto | 5:42a7d8c6c8fd | 817 | gb.display.print(name[thisScore]); |
Pokitto | 5:42a7d8c6c8fd | 818 | gb.display.cursorX = LCDWIDTH-3*gb.display.fontWidth; |
Pokitto | 5:42a7d8c6c8fd | 819 | gb.display.cursorY = gb.display.fontHeight+gb.display.fontHeight*thisScore; |
Pokitto | 5:42a7d8c6c8fd | 820 | gb.display.println(highscore[thisScore]); |
Pokitto | 5:42a7d8c6c8fd | 821 | } |
Pokitto | 5:42a7d8c6c8fd | 822 | if(gb.buttons.pressed(BTN_A) || gb.buttons.pressed(BTN_B) || gb.buttons.pressed(BTN_C)){ |
Pokitto | 5:42a7d8c6c8fd | 823 | gb.sound.playOK(); |
Pokitto | 5:42a7d8c6c8fd | 824 | break; |
Pokitto | 5:42a7d8c6c8fd | 825 | } |
Pokitto | 5:42a7d8c6c8fd | 826 | } |
Pokitto | 5:42a7d8c6c8fd | 827 | } |
Pokitto | 5:42a7d8c6c8fd | 828 | } |
Pokitto | 5:42a7d8c6c8fd | 829 | |
Pokitto | 5:42a7d8c6c8fd | 830 | |
Pokitto | 5:42a7d8c6c8fd | 831 | |
Pokitto | 5:42a7d8c6c8fd | 832 | |
Pokitto | 5:42a7d8c6c8fd | 833 | ///////////////////////////////////// INIT GAME |
Pokitto | 5:42a7d8c6c8fd | 834 | void initGame(){ |
Pokitto | 5:42a7d8c6c8fd | 835 | //lastScore = score; |
Pokitto | 5:42a7d8c6c8fd | 836 | if(score > highscore[RANKMAX-1]){ //if the score is better than the worse high score |
Pokitto | 5:42a7d8c6c8fd | 837 | saveHighscore(); |
Pokitto | 5:42a7d8c6c8fd | 838 | } |
Pokitto | 5:42a7d8c6c8fd | 839 | //scoreDisplayTimeLeft = 64; |
Pokitto | 5:42a7d8c6c8fd | 840 | score = 0; |
Pokitto | 5:42a7d8c6c8fd | 841 | kills = 0; |
Pokitto | 5:42a7d8c6c8fd | 842 | currentWeapon = 0; //magnum |
Pokitto | 5:42a7d8c6c8fd | 843 | ammo = 9999; |
Pokitto | 5:42a7d8c6c8fd | 844 | nextShot = 0; |
Pokitto | 5:42a7d8c6c8fd | 845 | shake_timeLeft = 0; |
Pokitto | 5:42a7d8c6c8fd | 846 | playerLife = playerLifeMax; |
Pokitto | 5:42a7d8c6c8fd | 847 | boss_freq = BOSSFREQ; |
Pokitto | 5:42a7d8c6c8fd | 848 | boss_nextSpawn = boss_freq; |
Pokitto | 5:42a7d8c6c8fd | 849 | activeMobs = INITNUMMOBS; //6 initial mobs |
Pokitto | 5:42a7d8c6c8fd | 850 | do{ |
Pokitto | 5:42a7d8c6c8fd | 851 | do{ |
Pokitto | 5:42a7d8c6c8fd | 852 | playerX = random(0, WORLD_W) * 8; |
Pokitto | 5:42a7d8c6c8fd | 853 | playerY = random(0, WORLD_H) * 8; |
Pokitto | 5:42a7d8c6c8fd | 854 | } |
Pokitto | 5:42a7d8c6c8fd | 855 | while(collideWorld(playerX, playerY, playerW, playerH)); |
Pokitto | 5:42a7d8c6c8fd | 856 | cameraX = playerX - LCDWIDTH/2 + playerW/2; |
Pokitto | 5:42a7d8c6c8fd | 857 | cameraY = playerY - LCDHEIGHT/2 + playerW/2; |
Pokitto | 5:42a7d8c6c8fd | 858 | } |
Pokitto | 5:42a7d8c6c8fd | 859 | while(!spawnMobs()); //do that until mobs are spawned without error |
Pokitto | 5:42a7d8c6c8fd | 860 | //spawn crate |
Pokitto | 5:42a7d8c6c8fd | 861 | spawnCrate(); |
Pokitto | 5:42a7d8c6c8fd | 862 | //reset bullets |
Pokitto | 5:42a7d8c6c8fd | 863 | for(byte thisBullet = 0; thisBullet < NUMBULLETS; thisBullet++){ |
Pokitto | 5:42a7d8c6c8fd | 864 | bullets_active[thisBullet] = false; |
Pokitto | 5:42a7d8c6c8fd | 865 | } |
Pokitto | 5:42a7d8c6c8fd | 866 | //reset splashes |
Pokitto | 5:42a7d8c6c8fd | 867 | for(byte thisSplash = 0; thisSplash < NUMSPLASH; thisSplash++){ |
Pokitto | 5:42a7d8c6c8fd | 868 | splash_active[thisSplash] = false; |
Pokitto | 5:42a7d8c6c8fd | 869 | } |
Pokitto | 5:42a7d8c6c8fd | 870 | blast_lifespan = 0; //reset explosion |
Pokitto | 5:42a7d8c6c8fd | 871 | } |
Pokitto | 5:42a7d8c6c8fd | 872 | |
Pokitto | 5:42a7d8c6c8fd | 873 | ///////////////////////////////////// PLAY |
Pokitto | 5:42a7d8c6c8fd | 874 | void play(){ |
Pokitto | 5:42a7d8c6c8fd | 875 | gb.battery.show = false; |
Pokitto | 5:42a7d8c6c8fd | 876 | byte i = 0; |
Pokitto | 5:42a7d8c6c8fd | 877 | while(i < 10 && gb.isRunning()){ |
Pokitto | 5:42a7d8c6c8fd | 878 | if(gb.update()){ |
Pokitto | 5:42a7d8c6c8fd | 879 | gb.display.fontSize = 2; |
Pokitto | 5:42a7d8c6c8fd | 880 | gb.display.cursorX = 6; |
Pokitto | 5:42a7d8c6c8fd | 881 | gb.display.cursorY = 16; |
Pokitto | 5:42a7d8c6c8fd | 882 | gb.display.print(("LET'S GO!")); |
Pokitto | 5:42a7d8c6c8fd | 883 | i++; |
Pokitto | 5:42a7d8c6c8fd | 884 | } |
Pokitto | 5:42a7d8c6c8fd | 885 | } |
Pokitto | 5:42a7d8c6c8fd | 886 | gb.display.fontSize = 1; |
Pokitto | 5:42a7d8c6c8fd | 887 | gb.popup(("\x15:shoot \x16:run"), 60); |
Pokitto | 5:42a7d8c6c8fd | 888 | |
Pokitto | 5:42a7d8c6c8fd | 889 | while(gb.isRunning()){ |
Pokitto | 5:42a7d8c6c8fd | 890 | if(gb.update()){ |
Pokitto | 5:42a7d8c6c8fd | 891 | if(gb.buttons.pressed(BTN_C)){ |
Pokitto | 5:42a7d8c6c8fd | 892 | gb.sound.playCancel(); |
Pokitto | 5:42a7d8c6c8fd | 893 | return; |
Pokitto | 5:42a7d8c6c8fd | 894 | //gb.battery.show = true; |
Pokitto | 5:42a7d8c6c8fd | 895 | //pause(); |
Pokitto | 5:42a7d8c6c8fd | 896 | //gb.battery.show = false; |
Pokitto | 5:42a7d8c6c8fd | 897 | } |
Pokitto | 5:42a7d8c6c8fd | 898 | boolean moved = false; |
Pokitto | 5:42a7d8c6c8fd | 899 | if(gb.buttons.repeat(BTN_RIGHT, 1)){ |
Pokitto | 5:42a7d8c6c8fd | 900 | playerDir = 3; |
Pokitto | 5:42a7d8c6c8fd | 901 | moved = true; |
Pokitto | 5:42a7d8c6c8fd | 902 | } |
Pokitto | 5:42a7d8c6c8fd | 903 | else{ |
Pokitto | 5:42a7d8c6c8fd | 904 | if(gb.buttons.repeat(BTN_LEFT, 1)){ |
Pokitto | 5:42a7d8c6c8fd | 905 | playerDir = 1; |
Pokitto | 5:42a7d8c6c8fd | 906 | moved = true; |
Pokitto | 5:42a7d8c6c8fd | 907 | } |
Pokitto | 5:42a7d8c6c8fd | 908 | } |
Pokitto | 5:42a7d8c6c8fd | 909 | if(gb.buttons.repeat(BTN_DOWN, 1)){ |
Pokitto | 5:42a7d8c6c8fd | 910 | playerDir = 2; |
Pokitto | 5:42a7d8c6c8fd | 911 | moved = true; |
Pokitto | 5:42a7d8c6c8fd | 912 | } |
Pokitto | 5:42a7d8c6c8fd | 913 | else{ |
Pokitto | 5:42a7d8c6c8fd | 914 | if(gb.buttons.repeat(BTN_UP, 1)){ |
Pokitto | 5:42a7d8c6c8fd | 915 | playerDir = 0; |
Pokitto | 5:42a7d8c6c8fd | 916 | moved = true; |
Pokitto | 5:42a7d8c6c8fd | 917 | } |
Pokitto | 5:42a7d8c6c8fd | 918 | } |
Pokitto | 5:42a7d8c6c8fd | 919 | if(moved){ |
Pokitto | 5:42a7d8c6c8fd | 920 | moveXYDS(playerX, playerY, playerDir, playerSpeed); |
Pokitto | 5:42a7d8c6c8fd | 921 | if(collideWorld(playerX, playerY, playerW, playerH)) |
Pokitto | 5:42a7d8c6c8fd | 922 | moveXYDS(playerX, playerY, playerDir, -playerSpeed); |
Pokitto | 5:42a7d8c6c8fd | 923 | } |
Pokitto | 5:42a7d8c6c8fd | 924 | cameraX = playerX + playerW/2 - LCDWIDTH/2; |
Pokitto | 5:42a7d8c6c8fd | 925 | cameraY = playerY + playerH/2 - LCDHEIGHT/2; |
Pokitto | 5:42a7d8c6c8fd | 926 | shakeScreen(); |
Pokitto | 5:42a7d8c6c8fd | 927 | /* |
Pokitto | 5:42a7d8c6c8fd | 928 | gb.display.setColor(7); // shrub shadow |
Pokitto | 5:42a7d8c6c8fd | 929 | drawWorld(cameraX-3, cameraY-3); |
Pokitto | 5:42a7d8c6c8fd | 930 | gb.display.setColor(5); // shrubs |
Pokitto | 5:42a7d8c6c8fd | 931 | drawWorld(cameraX, cameraY); |
Pokitto | 5:42a7d8c6c8fd | 932 | */ |
Pokitto | 5:42a7d8c6c8fd | 933 | int x, y; |
Pokitto | 5:42a7d8c6c8fd | 934 | screenCoord(playerX, playerY, x, y); |
Pokitto | 5:42a7d8c6c8fd | 935 | //gb.display.setColor(10); //shadow |
Pokitto | 5:42a7d8c6c8fd | 936 | int8_t ox=0,oy=0; |
Pokitto | 5:42a7d8c6c8fd | 937 | ox--; |
Pokitto | 5:42a7d8c6c8fd | 938 | //gb.display.drawBitmap(x+ox, y+oy, playerSprite, playerDir, NOFLIP); |
Pokitto | 5:42a7d8c6c8fd | 939 | gb.display.setColor(3); //magenta |
Pokitto | 5:42a7d8c6c8fd | 940 | gb.display.drawBitmap(x, y, playerSprite, playerDir, NOFLIP); |
Pokitto | 5:42a7d8c6c8fd | 941 | byte thisSprite = 0; |
Pokitto | 5:42a7d8c6c8fd | 942 | moveMobs(); |
Pokitto | 5:42a7d8c6c8fd | 943 | drawMobs(); |
Pokitto | 5:42a7d8c6c8fd | 944 | if(nextShot) |
Pokitto | 5:42a7d8c6c8fd | 945 | nextShot--; |
Pokitto | 5:42a7d8c6c8fd | 946 | if(gb.buttons.repeat(BTN_A, 1) && !gb.buttons.repeat(BTN_B, 1)){ |
Pokitto | 5:42a7d8c6c8fd | 947 | shoot(); |
Pokitto | 5:42a7d8c6c8fd | 948 | } |
Pokitto | 5:42a7d8c6c8fd | 949 | if (gb.buttons.repeat(BTN_B, 1)){ |
Pokitto | 5:42a7d8c6c8fd | 950 | playerSpeed = 2; |
Pokitto | 5:42a7d8c6c8fd | 951 | } |
Pokitto | 5:42a7d8c6c8fd | 952 | else { |
Pokitto | 5:42a7d8c6c8fd | 953 | playerSpeed = 1; |
Pokitto | 5:42a7d8c6c8fd | 954 | } |
Pokitto | 5:42a7d8c6c8fd | 955 | moveBullets(); |
Pokitto | 5:42a7d8c6c8fd | 956 | drawBullets(); |
Pokitto | 5:42a7d8c6c8fd | 957 | explode(); |
Pokitto | 5:42a7d8c6c8fd | 958 | gb.display.setColor(4); |
Pokitto | 5:42a7d8c6c8fd | 959 | drawSplashes(); |
Pokitto | 5:42a7d8c6c8fd | 960 | collideCrate(); |
Pokitto | 5:42a7d8c6c8fd | 961 | drawCrate(); |
Pokitto | 5:42a7d8c6c8fd | 962 | /** DRAW WORLD**/ |
Pokitto | 5:42a7d8c6c8fd | 963 | //gb.display.setColor(7); // shrub shadow |
Pokitto | 5:42a7d8c6c8fd | 964 | //drawWorld(cameraX-2, cameraY-2); |
Pokitto | 5:42a7d8c6c8fd | 965 | gb.display.setColor(5); // shrubs |
Pokitto | 5:42a7d8c6c8fd | 966 | drawWorld(cameraX, cameraY); |
Pokitto | 5:42a7d8c6c8fd | 967 | //life remaining |
Pokitto | 5:42a7d8c6c8fd | 968 | for(byte i=0; i<=playerLifeMax/2; i+=1){ |
Pokitto | 5:42a7d8c6c8fd | 969 | if((i*2)<=playerLife){ |
Pokitto | 5:42a7d8c6c8fd | 970 | gb.display.setColor(4); |
Pokitto | 5:42a7d8c6c8fd | 971 | gb.display.drawBitmap(LCDWIDTH-i*9+2, 0, fullHeart); |
Pokitto | 5:42a7d8c6c8fd | 972 | } |
Pokitto | 5:42a7d8c6c8fd | 973 | else{ |
Pokitto | 5:42a7d8c6c8fd | 974 | gb.display.setColor(0,0); |
Pokitto | 5:42a7d8c6c8fd | 975 | gb.display.drawBitmap(LCDWIDTH-i*9+2, 0, fullHeart); |
Pokitto | 5:42a7d8c6c8fd | 976 | gb.display.setColor(4,0); |
Pokitto | 5:42a7d8c6c8fd | 977 | gb.display.drawBitmap(LCDWIDTH-i*9+2, 0, emptyHeart); |
Pokitto | 5:42a7d8c6c8fd | 978 | } |
Pokitto | 5:42a7d8c6c8fd | 979 | } |
Pokitto | 5:42a7d8c6c8fd | 980 | if(!playerLife){ |
Pokitto | 5:42a7d8c6c8fd | 981 | if((gb.frameCount%2)==0){ |
Pokitto | 5:42a7d8c6c8fd | 982 | shake_magnitude = 2; |
Pokitto | 5:42a7d8c6c8fd | 983 | shake_timeLeft = 1; |
Pokitto | 5:42a7d8c6c8fd | 984 | } |
Pokitto | 5:42a7d8c6c8fd | 985 | } |
Pokitto | 5:42a7d8c6c8fd | 986 | else{ |
Pokitto | 5:42a7d8c6c8fd | 987 | if(playerLife == 1){ |
Pokitto | 5:42a7d8c6c8fd | 988 | shake_magnitude = 1; |
Pokitto | 5:42a7d8c6c8fd | 989 | shake_timeLeft = 1; |
Pokitto | 5:42a7d8c6c8fd | 990 | } |
Pokitto | 5:42a7d8c6c8fd | 991 | } |
Pokitto | 5:42a7d8c6c8fd | 992 | |
Pokitto | 5:42a7d8c6c8fd | 993 | if(playerLife%2){ //odd number |
Pokitto | 5:42a7d8c6c8fd | 994 | gb.display.setColor(4,0); |
Pokitto | 5:42a7d8c6c8fd | 995 | gb.display.drawBitmap(LCDWIDTH-(playerLife/2+1)*9+2, 0, halfHeart); |
Pokitto | 5:42a7d8c6c8fd | 996 | } |
Pokitto | 5:42a7d8c6c8fd | 997 | |
Pokitto | 5:42a7d8c6c8fd | 998 | drawAmmoOverlay(); |
Pokitto | 5:42a7d8c6c8fd | 999 | |
Pokitto | 5:42a7d8c6c8fd | 1000 | displayScore(); |
Pokitto | 5:42a7d8c6c8fd | 1001 | for(byte thisMob=0; thisMob<activeMobs; thisMob++){ |
Pokitto | 5:42a7d8c6c8fd | 1002 | if(gb.collideRectRect(mobs_x[thisMob],mobs_y[thisMob], mobs_size[thisMob], mobs_size[thisMob], |
Pokitto | 5:42a7d8c6c8fd | 1003 | playerX, playerY, playerW, playerH)){ |
Pokitto | 5:42a7d8c6c8fd | 1004 | playerLife--; |
Pokitto | 5:42a7d8c6c8fd | 1005 | //pokConsoleAddMessage(MSG_PRINT,V_INT16,playerLife); |
Pokitto | 5:42a7d8c6c8fd | 1006 | shake_magnitude = 2; |
Pokitto | 5:42a7d8c6c8fd | 1007 | shake_timeLeft = 4; |
Pokitto | 5:42a7d8c6c8fd | 1008 | if(mobs_size[thisMob] == boss_size){ |
Pokitto | 5:42a7d8c6c8fd | 1009 | playerLife--; |
Pokitto | 5:42a7d8c6c8fd | 1010 | shake_magnitude = 3; |
Pokitto | 5:42a7d8c6c8fd | 1011 | shake_timeLeft = 4; |
Pokitto | 5:42a7d8c6c8fd | 1012 | } |
Pokitto | 5:42a7d8c6c8fd | 1013 | //int hazefactor = (255-42*playerLife)*2/3; |
Pokitto | 5:42a7d8c6c8fd | 1014 | //for (uint16_t k =0 ; k<16; k++) hazepalette[k] = pokInterpolateColor(palette[k],palette[4],hazefactor); |
Pokitto | 5:42a7d8c6c8fd | 1015 | gb.sound.playPattern(player_damage_sound, 0); |
Pokitto | 5:42a7d8c6c8fd | 1016 | spawnMob(thisMob); |
Pokitto | 5:42a7d8c6c8fd | 1017 | if(playerLife < 0){ |
Pokitto | 5:42a7d8c6c8fd | 1018 | byte timer=0; |
Pokitto | 5:42a7d8c6c8fd | 1019 | while(1){ |
Pokitto | 5:42a7d8c6c8fd | 1020 | if(gb.update()){ |
Pokitto | 5:42a7d8c6c8fd | 1021 | //gb.display.setColor(1); |
Pokitto | 5:42a7d8c6c8fd | 1022 | drawMobs(); |
Pokitto | 5:42a7d8c6c8fd | 1023 | drawBullets(); |
Pokitto | 5:42a7d8c6c8fd | 1024 | drawSplashes(); |
Pokitto | 5:42a7d8c6c8fd | 1025 | drawCrate(); |
Pokitto | 5:42a7d8c6c8fd | 1026 | drawAmmoOverlay(); |
Pokitto | 5:42a7d8c6c8fd | 1027 | displayScore(); |
Pokitto | 5:42a7d8c6c8fd | 1028 | drawWorld(cameraX, cameraY); |
Pokitto | 5:42a7d8c6c8fd | 1029 | gb.display.drawBitmap(x-1, y-1, playerSprite, playerDir, NOFLIP); |
Pokitto | 5:42a7d8c6c8fd | 1030 | gb.display.setColor(WHITE); |
Pokitto | 5:42a7d8c6c8fd | 1031 | gb.display.fillRect(0,0,timer*2,LCDHEIGHT); |
Pokitto | 5:42a7d8c6c8fd | 1032 | gb.display.fillRect(LCDWIDTH-timer*2,0,timer*2,LCDHEIGHT); |
Pokitto | 5:42a7d8c6c8fd | 1033 | gb.display.setColor(BLACK, WHITE); |
Pokitto | 5:42a7d8c6c8fd | 1034 | gb.display.cursorX = 12; |
Pokitto | 5:42a7d8c6c8fd | 1035 | gb.display.cursorY = 1; |
Pokitto | 5:42a7d8c6c8fd | 1036 | gb.display.print(("GAME OVER!")); |
Pokitto | 5:42a7d8c6c8fd | 1037 | timer++; |
Pokitto | 5:42a7d8c6c8fd | 1038 | if(timer==((LCDWIDTH/4)+10)) |
Pokitto | 5:42a7d8c6c8fd | 1039 | break; |
Pokitto | 5:42a7d8c6c8fd | 1040 | } |
Pokitto | 5:42a7d8c6c8fd | 1041 | //int hazefactor = 0; |
Pokitto | 5:42a7d8c6c8fd | 1042 | //for (uint16_t k =0 ; k<16; k++) hazepalette[k] = pokInterpolateColor(palette[k],palette[4],hazefactor); |
Pokitto | 5:42a7d8c6c8fd | 1043 | } |
Pokitto | 5:42a7d8c6c8fd | 1044 | while(1){ |
Pokitto | 5:42a7d8c6c8fd | 1045 | if(gb.update()){ |
Pokitto | 5:42a7d8c6c8fd | 1046 | if(score > highscore[RANKMAX-1]){ //if the score is better than the worse high score |
Pokitto | 5:42a7d8c6c8fd | 1047 | gb.display.cursorX = 2+rand()%2; |
Pokitto | 5:42a7d8c6c8fd | 1048 | gb.display.cursorY = 0+rand()%2; |
Pokitto | 5:42a7d8c6c8fd | 1049 | gb.display.print(("NEW HIGHSCORE")); |
Pokitto | 5:42a7d8c6c8fd | 1050 | } |
Pokitto | 5:42a7d8c6c8fd | 1051 | else{ |
Pokitto | 5:42a7d8c6c8fd | 1052 | gb.display.cursorX = 12; |
Pokitto | 5:42a7d8c6c8fd | 1053 | gb.display.cursorY = 1; |
Pokitto | 5:42a7d8c6c8fd | 1054 | gb.display.print(("GAME OVER!")); |
Pokitto | 5:42a7d8c6c8fd | 1055 | } |
Pokitto | 5:42a7d8c6c8fd | 1056 | gb.display.cursorX = 0; |
Pokitto | 5:42a7d8c6c8fd | 1057 | gb.display.cursorY = 12; |
Pokitto | 5:42a7d8c6c8fd | 1058 | gb.display.print(("You made $")); |
Pokitto | 5:42a7d8c6c8fd | 1059 | gb.display.print(score); |
Pokitto | 5:42a7d8c6c8fd | 1060 | gb.display.print(("\nby killing\n")); |
Pokitto | 5:42a7d8c6c8fd | 1061 | gb.display.print(kills); |
Pokitto | 5:42a7d8c6c8fd | 1062 | gb.display.print((" crabs.")); |
Pokitto | 5:42a7d8c6c8fd | 1063 | gb.display.cursorX = 0; |
Pokitto | 5:42a7d8c6c8fd | 1064 | gb.display.cursorY = 40; |
Pokitto | 5:42a7d8c6c8fd | 1065 | gb.display.print(("\x15:accept")); |
Pokitto | 5:42a7d8c6c8fd | 1066 | if(gb.buttons.pressed(BTN_A)){ |
Pokitto | 5:42a7d8c6c8fd | 1067 | gb.sound.playOK(); |
Pokitto | 5:42a7d8c6c8fd | 1068 | break; |
Pokitto | 5:42a7d8c6c8fd | 1069 | } |
Pokitto | 5:42a7d8c6c8fd | 1070 | } |
Pokitto | 5:42a7d8c6c8fd | 1071 | } |
Pokitto | 5:42a7d8c6c8fd | 1072 | initGame(); |
Pokitto | 5:42a7d8c6c8fd | 1073 | break; |
Pokitto | 5:42a7d8c6c8fd | 1074 | } |
Pokitto | 5:42a7d8c6c8fd | 1075 | } |
Pokitto | 5:42a7d8c6c8fd | 1076 | } |
Pokitto | 5:42a7d8c6c8fd | 1077 | |
Pokitto | 5:42a7d8c6c8fd | 1078 | } |
Pokitto | 5:42a7d8c6c8fd | 1079 | } |
Pokitto | 5:42a7d8c6c8fd | 1080 | } |
Pokitto | 5:42a7d8c6c8fd | 1081 | |
Pokitto | 5:42a7d8c6c8fd | 1082 | ///////////////////////////////////// DISPLAY SCORE |
Pokitto | 5:42a7d8c6c8fd | 1083 | void displayScore(){ |
Pokitto | 5:42a7d8c6c8fd | 1084 | // blue on bottom |
Pokitto | 5:42a7d8c6c8fd | 1085 | /* gb.display.setColor(10); |
Pokitto | 5:42a7d8c6c8fd | 1086 | gb.display.cursorX = -1; |
Pokitto | 5:42a7d8c6c8fd | 1087 | gb.display.cursorY = -1; |
Pokitto | 5:42a7d8c6c8fd | 1088 | gb.display.print('$'); |
Pokitto | 5:42a7d8c6c8fd | 1089 | gb.display.println(score); |
Pokitto | 5:42a7d8c6c8fd | 1090 | gb.display.cursorX = 0; |
Pokitto | 5:42a7d8c6c8fd | 1091 | gb.display.cursorY = -1; |
Pokitto | 5:42a7d8c6c8fd | 1092 | gb.display.print('$'); |
Pokitto | 5:42a7d8c6c8fd | 1093 | gb.display.println(score); |
Pokitto | 5:42a7d8c6c8fd | 1094 | gb.display.cursorX = 1; |
Pokitto | 5:42a7d8c6c8fd | 1095 | gb.display.cursorY = -1; |
Pokitto | 5:42a7d8c6c8fd | 1096 | gb.display.print('$'); |
Pokitto | 5:42a7d8c6c8fd | 1097 | gb.display.println(score); |
Pokitto | 5:42a7d8c6c8fd | 1098 | gb.display.cursorX = -1; |
Pokitto | 5:42a7d8c6c8fd | 1099 | gb.display.cursorY = 0; |
Pokitto | 5:42a7d8c6c8fd | 1100 | gb.display.print('$'); |
Pokitto | 5:42a7d8c6c8fd | 1101 | gb.display.println(score); |
Pokitto | 5:42a7d8c6c8fd | 1102 | gb.display.cursorX = 0; |
Pokitto | 5:42a7d8c6c8fd | 1103 | gb.display.cursorY = 1; |
Pokitto | 5:42a7d8c6c8fd | 1104 | gb.display.print('$'); |
Pokitto | 5:42a7d8c6c8fd | 1105 | gb.display.println(score); |
Pokitto | 5:42a7d8c6c8fd | 1106 | gb.display.cursorX = -1; |
Pokitto | 5:42a7d8c6c8fd | 1107 | gb.display.cursorY = 1; |
Pokitto | 5:42a7d8c6c8fd | 1108 | gb.display.print('$'); |
Pokitto | 5:42a7d8c6c8fd | 1109 | gb.display.println(score); |
Pokitto | 5:42a7d8c6c8fd | 1110 | gb.display.cursorX = 0; |
Pokitto | 5:42a7d8c6c8fd | 1111 | gb.display.cursorY = 1; |
Pokitto | 5:42a7d8c6c8fd | 1112 | gb.display.print('$'); |
Pokitto | 5:42a7d8c6c8fd | 1113 | gb.display.println(score); |
Pokitto | 5:42a7d8c6c8fd | 1114 | gb.display.cursorX = 1; |
Pokitto | 5:42a7d8c6c8fd | 1115 | gb.display.cursorY = 1; |
Pokitto | 5:42a7d8c6c8fd | 1116 | gb.display.print('$'); |
Pokitto | 5:42a7d8c6c8fd | 1117 | gb.display.println(score); |
Pokitto | 5:42a7d8c6c8fd | 1118 | gb.display.cursorX = 1; |
Pokitto | 5:42a7d8c6c8fd | 1119 | gb.display.cursorY = 0; |
Pokitto | 5:42a7d8c6c8fd | 1120 | gb.display.print('$'); |
Pokitto | 5:42a7d8c6c8fd | 1121 | gb.display.println(score);*/ |
Pokitto | 5:42a7d8c6c8fd | 1122 | // white on top |
Pokitto | 5:42a7d8c6c8fd | 1123 | gb.display.setColor(8); |
Pokitto | 5:42a7d8c6c8fd | 1124 | gb.display.cursorX = 0; |
Pokitto | 5:42a7d8c6c8fd | 1125 | gb.display.cursorY = 0; |
Pokitto | 5:42a7d8c6c8fd | 1126 | gb.display.print('$'); |
Pokitto | 5:42a7d8c6c8fd | 1127 | gb.display.println(score); |
Pokitto | 5:42a7d8c6c8fd | 1128 | } |
Pokitto | 5:42a7d8c6c8fd | 1129 | |
Pokitto | 5:42a7d8c6c8fd | 1130 | ///////////////////////////////////// SHAKE SCREEN |
Pokitto | 5:42a7d8c6c8fd | 1131 | void shakeScreen(){ |
Pokitto | 5:42a7d8c6c8fd | 1132 | if(shake_timeLeft){ |
Pokitto | 5:42a7d8c6c8fd | 1133 | shake_timeLeft--; |
Pokitto | 5:42a7d8c6c8fd | 1134 | cameraX += random(-shake_magnitude,shake_magnitude+1); |
Pokitto | 5:42a7d8c6c8fd | 1135 | cameraY += random(-shake_magnitude,shake_magnitude+1); |
Pokitto | 5:42a7d8c6c8fd | 1136 | byte backlightStep = gb.backlight.backlightMax / 4; |
Pokitto | 5:42a7d8c6c8fd | 1137 | gb.backlight.set(gb.backlight.backlightValue-random(0,backlightStep*shake_magnitude)); |
Pokitto | 5:42a7d8c6c8fd | 1138 | } |
Pokitto | 5:42a7d8c6c8fd | 1139 | } |
Pokitto | 5:42a7d8c6c8fd | 1140 | |
Pokitto | 5:42a7d8c6c8fd | 1141 | ///////////////////////////////////// LOAD HIGHSCORE |
Pokitto | 5:42a7d8c6c8fd | 1142 | void loadHighscore(){ |
Pokitto | 5:42a7d8c6c8fd | 1143 | /* |
Pokitto | 5:42a7d8c6c8fd | 1144 | for(byte thisScore = 0; thisScore < RANKMAX; thisScore++){ |
Pokitto | 5:42a7d8c6c8fd | 1145 | for(byte i=0; i<NAMELENGTH; i++){ |
Pokitto | 5:42a7d8c6c8fd | 1146 | name[thisScore][i] = EEPROM.read(i + thisScore*(NAMELENGTH+2)); |
Pokitto | 5:42a7d8c6c8fd | 1147 | } |
Pokitto | 5:42a7d8c6c8fd | 1148 | highscore[thisScore] = EEPROM.read(NAMELENGTH + thisScore*(NAMELENGTH+2)) & 0x00FF; //LSB |
Pokitto | 5:42a7d8c6c8fd | 1149 | highscore[thisScore] += (EEPROM.read(NAMELENGTH+1 + thisScore*(NAMELENGTH+2)) << 8) & 0xFF00; //MSB |
Pokitto | 5:42a7d8c6c8fd | 1150 | highscore[thisScore] = (highscore[thisScore]==0xFFFF) ? 0 : highscore[thisScore]; |
Pokitto | 5:42a7d8c6c8fd | 1151 | }*/ //jonnehw |
Pokitto | 5:42a7d8c6c8fd | 1152 | } |
Pokitto | 5:42a7d8c6c8fd | 1153 | |
Pokitto | 5:42a7d8c6c8fd | 1154 | ///////////////////////////////////// SAVE HIGHSCORE |
Pokitto | 5:42a7d8c6c8fd | 1155 | void saveHighscore(){ |
Pokitto | 5:42a7d8c6c8fd | 1156 | //gb.getDefaultName(name[RANKMAX-1]); |
Pokitto | 5:42a7d8c6c8fd | 1157 | gb.display.setFont(font5x7); |
Pokitto | 5:42a7d8c6c8fd | 1158 | gb.keyboard(name[RANKMAX-1], NAMELENGTH+1); |
Pokitto | 5:42a7d8c6c8fd | 1159 | highscore[RANKMAX-1] = score; |
Pokitto | 5:42a7d8c6c8fd | 1160 | for(byte i=RANKMAX-1; i>0; i--){ //bubble sorting FTW |
Pokitto | 5:42a7d8c6c8fd | 1161 | if(highscore[i-1] < highscore[i]){ |
Pokitto | 5:42a7d8c6c8fd | 1162 | char tempName[NAMELENGTH]; |
Pokitto | 5:42a7d8c6c8fd | 1163 | strcpy(tempName, name[i-1]); |
Pokitto | 5:42a7d8c6c8fd | 1164 | strcpy(name[i-1], name[i]); |
Pokitto | 5:42a7d8c6c8fd | 1165 | strcpy(name[i], tempName); |
Pokitto | 5:42a7d8c6c8fd | 1166 | unsigned int tempScore; |
Pokitto | 5:42a7d8c6c8fd | 1167 | tempScore = highscore[i-1]; |
Pokitto | 5:42a7d8c6c8fd | 1168 | highscore[i-1] = highscore[i]; |
Pokitto | 5:42a7d8c6c8fd | 1169 | highscore[i] = tempScore; |
Pokitto | 5:42a7d8c6c8fd | 1170 | } |
Pokitto | 5:42a7d8c6c8fd | 1171 | else{ |
Pokitto | 5:42a7d8c6c8fd | 1172 | break; |
Pokitto | 5:42a7d8c6c8fd | 1173 | } |
Pokitto | 5:42a7d8c6c8fd | 1174 | } |
Pokitto | 5:42a7d8c6c8fd | 1175 | /* |
Pokitto | 5:42a7d8c6c8fd | 1176 | for(byte thisScore = 0; thisScore < RANKMAX; thisScore++){ |
Pokitto | 5:42a7d8c6c8fd | 1177 | for(byte i=0; i<NAMELENGTH; i++){ |
Pokitto | 5:42a7d8c6c8fd | 1178 | EEPROM.write(i + thisScore*(NAMELENGTH+2), name[thisScore][i]); |
Pokitto | 5:42a7d8c6c8fd | 1179 | } |
Pokitto | 5:42a7d8c6c8fd | 1180 | EEPROM.write(NAMELENGTH + thisScore*(NAMELENGTH+2), highscore[thisScore] & 0x00FF); //LSB |
Pokitto | 5:42a7d8c6c8fd | 1181 | EEPROM.write(NAMELENGTH+1 + thisScore*(NAMELENGTH+2), (highscore[thisScore] >> 8) & 0x00FF); //MSB |
Pokitto | 5:42a7d8c6c8fd | 1182 | }*/// jonnehw |
Pokitto | 5:42a7d8c6c8fd | 1183 | displayHighScores(); |
Pokitto | 5:42a7d8c6c8fd | 1184 | } |
Pokitto | 5:42a7d8c6c8fd | 1185 | |
Pokitto | 5:42a7d8c6c8fd | 1186 | |
Pokitto | 5:42a7d8c6c8fd | 1187 | |
Pokitto | 5:42a7d8c6c8fd | 1188 | const byte PROGMEM logo[] = |
Pokitto | 5:42a7d8c6c8fd | 1189 | { |
Pokitto | 5:42a7d8c6c8fd | 1190 | 64,36, //width and height |
Pokitto | 5:42a7d8c6c8fd | 1191 | B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, |
Pokitto | 5:42a7d8c6c8fd | 1192 | B10000000, B00000000, B00000000, B00000000, B00000000, B00000001, B01000001, B01000001, |
Pokitto | 5:42a7d8c6c8fd | 1193 | B10000000, B00000000, B00000001, B10000000, B00000110, B00000100, B00010100, B00010001, |
Pokitto | 5:42a7d8c6c8fd | 1194 | B10000000, B00000000, B00000001, B10000000, B00000110, B00000000, B10000000, B10000001, |
Pokitto | 5:42a7d8c6c8fd | 1195 | B10000000, B00000000, B00000001, B10000000, B00000110, B00000000, B00000000, B01000001, |
Pokitto | 5:42a7d8c6c8fd | 1196 | B10001111, B00111111, B01111001, B10111001, B11101111, B10011110, B01111110, B00010001, |
Pokitto | 5:42a7d8c6c8fd | 1197 | B10011001, B10111011, B11001101, B11111011, B00110110, B00110011, B01110110, B00100001, |
Pokitto | 5:42a7d8c6c8fd | 1198 | B10011001, B10110011, B00001101, B10011000, B00110110, B00110011, B01100110, B01000101, |
Pokitto | 5:42a7d8c6c8fd | 1199 | |
Pokitto | 5:42a7d8c6c8fd | 1200 | B10011000, B00110000, B01111101, B10011001, B11110110, B00110011, B01100000, B00000011, |
Pokitto | 5:42a7d8c6c8fd | 1201 | B10011000, B00110000, B11001101, B10011011, B00110110, B00110011, B01100001, B01000001, |
Pokitto | 5:42a7d8c6c8fd | 1202 | B10011000, B00110000, B11001101, B10011011, B00110110, B00110011, B01100100, B00010101, |
Pokitto | 5:42a7d8c6c8fd | 1203 | B10011001, B10110000, B11011101, B10011011, B01110110, B00110011, B01100000, B10001001, |
Pokitto | 5:42a7d8c6c8fd | 1204 | B11001111, B00110000, B11111101, B11110011, B11110011, B10011110, B01100000, B01000001, |
Pokitto | 5:42a7d8c6c8fd | 1205 | B10000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000101, B00010101, |
Pokitto | 5:42a7d8c6c8fd | 1206 | B10100000, B00000000, B00000000, B00000000, B00000000, B00100000, B10000000, B10100001, |
Pokitto | 5:42a7d8c6c8fd | 1207 | B11000000, B00000000, B00011000, B00001100, B00000000, B00000000, B00001111, B11110101, |
Pokitto | 5:42a7d8c6c8fd | 1208 | |
Pokitto | 5:42a7d8c6c8fd | 1209 | B10010000, B00000000, B00100100, B01010010, B10000000, B11110000, B00001000, B00010011, |
Pokitto | 5:42a7d8c6c8fd | 1210 | B11010000, B00000010, B10101100, B01010110, B10000001, B11111000, B00001111, B11110001, |
Pokitto | 5:42a7d8c6c8fd | 1211 | B10011001, B01000011, B00110100, B11011010, B11100001, B11111000, B00001010, B00110101, |
Pokitto | 5:42a7d8c6c8fd | 1212 | B10010101, B01000010, B00100101, B01010010, B10000001, B11111000, B00001100, B01011001, |
Pokitto | 5:42a7d8c6c8fd | 1213 | B11011101, B11000010, B00011001, B11001100, B01100001, B01101000, B00001111, B11110001, |
Pokitto | 5:42a7d8c6c8fd | 1214 | B10000000, B01000000, B00000000, B00000000, B00000000, B11110000, B00001000, B00010101, |
Pokitto | 5:42a7d8c6c8fd | 1215 | B10000000, B10000000, B00000000, B00000000, B00000000, B00000000, B00001111, B11110001, |
Pokitto | 5:42a7d8c6c8fd | 1216 | B11000000, B00000000, B00000000, B00000000, B00000110, B00000000, B00000000, B00000101, |
Pokitto | 5:42a7d8c6c8fd | 1217 | |
Pokitto | 5:42a7d8c6c8fd | 1218 | B10000000, B00000000, B00000000, B00000000, B00001111, B00000000, B00000000, B00000011, |
Pokitto | 5:42a7d8c6c8fd | 1219 | B11000000, B00000000, B00000000, B00000000, B00000110, B00000000, B00000000, B00000001, |
Pokitto | 5:42a7d8c6c8fd | 1220 | B10010000, B00000000, B00000000, B00000000, B00001001, B00000000, B00000000, B00000101, |
Pokitto | 5:42a7d8c6c8fd | 1221 | B10000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00001001, |
Pokitto | 5:42a7d8c6c8fd | 1222 | B11000001, B01000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000001, |
Pokitto | 5:42a7d8c6c8fd | 1223 | B10010011, B11010000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000101, |
Pokitto | 5:42a7d8c6c8fd | 1224 | B10100011, B11100000, B00000000, B00000000, B00000000, B00000110, B00000000, B00000001, |
Pokitto | 5:42a7d8c6c8fd | 1225 | B10000011, B11100000, B00000101, B01000101, B01000000, B00001111, B00000101, B01000101, |
Pokitto | 5:42a7d8c6c8fd | 1226 | |
Pokitto | 5:42a7d8c6c8fd | 1227 | B10000011, B11010000, B00000010, B00000010, B00000000, B00000110, B00000010, B00000011, |
Pokitto | 5:42a7d8c6c8fd | 1228 | B10000001, B01000000, B00000001, B01000001, B01000000, B00001001, B00000001, B01000001, |
Pokitto | 5:42a7d8c6c8fd | 1229 | B10000000, B00000000, B00000100, B00010100, B00010000, B00000000, B00000100, B00010101, |
Pokitto | 5:42a7d8c6c8fd | 1230 | B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, |
Pokitto | 5:42a7d8c6c8fd | 1231 | }; |
Pokitto | 5:42a7d8c6c8fd | 1232 | |
Pokitto | 5:42a7d8c6c8fd | 1233 | const byte PROGMEM world[]= |
Pokitto | 5:42a7d8c6c8fd | 1234 | { |
Pokitto | 5:42a7d8c6c8fd | 1235 | B11001111,B11001111, |
Pokitto | 5:42a7d8c6c8fd | 1236 | B10000000,B01000000, |
Pokitto | 5:42a7d8c6c8fd | 1237 | B00000001,B11111100, |
Pokitto | 5:42a7d8c6c8fd | 1238 | B00111001,B11100000, |
Pokitto | 5:42a7d8c6c8fd | 1239 | B00001100,B00000110, |
Pokitto | 5:42a7d8c6c8fd | 1240 | B10000111,B00011111, |
Pokitto | 5:42a7d8c6c8fd | 1241 | B11000011,B11000001, |
Pokitto | 5:42a7d8c6c8fd | 1242 | B10000001,B00000001, |
Pokitto | 5:42a7d8c6c8fd | 1243 | B00111100,B00110011, |
Pokitto | 5:42a7d8c6c8fd | 1244 | B00000111,B11100000, |
Pokitto | 5:42a7d8c6c8fd | 1245 | B10000100,B00001001, |
Pokitto | 5:42a7d8c6c8fd | 1246 | B11000001,B11001111, |
Pokitto | 5:42a7d8c6c8fd | 1247 | }; |
Pokitto | 5:42a7d8c6c8fd | 1248 | const byte PROGMEM tiles[]= |
Pokitto | 5:42a7d8c6c8fd | 1249 | { |
Pokitto | 5:42a7d8c6c8fd | 1250 | 8,8, |
Pokitto | 5:42a7d8c6c8fd | 1251 | B01010100, |
Pokitto | 5:42a7d8c6c8fd | 1252 | B00100000, |
Pokitto | 5:42a7d8c6c8fd | 1253 | B00010100, |
Pokitto | 5:42a7d8c6c8fd | 1254 | B01000001, |
Pokitto | 5:42a7d8c6c8fd | 1255 | B10001000, |
Pokitto | 5:42a7d8c6c8fd | 1256 | B00000100, |
Pokitto | 5:42a7d8c6c8fd | 1257 | B01010001, |
Pokitto | 5:42a7d8c6c8fd | 1258 | B00001010, |
Pokitto | 5:42a7d8c6c8fd | 1259 | }; |
Pokitto | 5:42a7d8c6c8fd | 1260 | const byte PROGMEM mobSprite[]= |
Pokitto | 5:42a7d8c6c8fd | 1261 | { |
Pokitto | 5:42a7d8c6c8fd | 1262 | 8,8, |
Pokitto | 5:42a7d8c6c8fd | 1263 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1264 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1265 | B00011000, |
Pokitto | 5:42a7d8c6c8fd | 1266 | B00111100, |
Pokitto | 5:42a7d8c6c8fd | 1267 | B00011000, |
Pokitto | 5:42a7d8c6c8fd | 1268 | B00100100, |
Pokitto | 5:42a7d8c6c8fd | 1269 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1270 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1271 | }; |
Pokitto | 5:42a7d8c6c8fd | 1272 | const byte PROGMEM bossSprite[]= |
Pokitto | 5:42a7d8c6c8fd | 1273 | { |
Pokitto | 5:42a7d8c6c8fd | 1274 | 8,8, |
Pokitto | 5:42a7d8c6c8fd | 1275 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1276 | B00100100, |
Pokitto | 5:42a7d8c6c8fd | 1277 | B00011000, |
Pokitto | 5:42a7d8c6c8fd | 1278 | B01111110, |
Pokitto | 5:42a7d8c6c8fd | 1279 | B00111100, |
Pokitto | 5:42a7d8c6c8fd | 1280 | B01111110, |
Pokitto | 5:42a7d8c6c8fd | 1281 | B00111100, |
Pokitto | 5:42a7d8c6c8fd | 1282 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1283 | }; |
Pokitto | 5:42a7d8c6c8fd | 1284 | const byte PROGMEM playerSprite[]= |
Pokitto | 5:42a7d8c6c8fd | 1285 | { |
Pokitto | 5:42a7d8c6c8fd | 1286 | 8,8, |
Pokitto | 5:42a7d8c6c8fd | 1287 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1288 | B00111100, |
Pokitto | 5:42a7d8c6c8fd | 1289 | B01011010, |
Pokitto | 5:42a7d8c6c8fd | 1290 | B01111110, |
Pokitto | 5:42a7d8c6c8fd | 1291 | B01111110, |
Pokitto | 5:42a7d8c6c8fd | 1292 | B01111110, |
Pokitto | 5:42a7d8c6c8fd | 1293 | B00111100, |
Pokitto | 5:42a7d8c6c8fd | 1294 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1295 | }; |
Pokitto | 5:42a7d8c6c8fd | 1296 | const byte PROGMEM splashSprite[]= |
Pokitto | 5:42a7d8c6c8fd | 1297 | { |
Pokitto | 5:42a7d8c6c8fd | 1298 | 8,8, |
Pokitto | 5:42a7d8c6c8fd | 1299 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1300 | B00001000, |
Pokitto | 5:42a7d8c6c8fd | 1301 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1302 | B00011000, |
Pokitto | 5:42a7d8c6c8fd | 1303 | B00111000, |
Pokitto | 5:42a7d8c6c8fd | 1304 | B10110100, |
Pokitto | 5:42a7d8c6c8fd | 1305 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1306 | B00010000, |
Pokitto | 5:42a7d8c6c8fd | 1307 | }; |
Pokitto | 5:42a7d8c6c8fd | 1308 | const byte PROGMEM crateSprite[]= |
Pokitto | 5:42a7d8c6c8fd | 1309 | { |
Pokitto | 5:42a7d8c6c8fd | 1310 | 8,8, |
Pokitto | 5:42a7d8c6c8fd | 1311 | B11111111, |
Pokitto | 5:42a7d8c6c8fd | 1312 | B10000001, |
Pokitto | 5:42a7d8c6c8fd | 1313 | B11111111, |
Pokitto | 5:42a7d8c6c8fd | 1314 | B10100011, |
Pokitto | 5:42a7d8c6c8fd | 1315 | B11000101, |
Pokitto | 5:42a7d8c6c8fd | 1316 | B11111111, |
Pokitto | 5:42a7d8c6c8fd | 1317 | B10000001, |
Pokitto | 5:42a7d8c6c8fd | 1318 | B11111111, |
Pokitto | 5:42a7d8c6c8fd | 1319 | }; |
Pokitto | 5:42a7d8c6c8fd | 1320 | const byte PROGMEM fullHeart[]= |
Pokitto | 5:42a7d8c6c8fd | 1321 | { |
Pokitto | 5:42a7d8c6c8fd | 1322 | 8,8, |
Pokitto | 5:42a7d8c6c8fd | 1323 | B01101100, |
Pokitto | 5:42a7d8c6c8fd | 1324 | B11111110, |
Pokitto | 5:42a7d8c6c8fd | 1325 | B11111110, |
Pokitto | 5:42a7d8c6c8fd | 1326 | B01111100, |
Pokitto | 5:42a7d8c6c8fd | 1327 | B00111000, |
Pokitto | 5:42a7d8c6c8fd | 1328 | B00010000, |
Pokitto | 5:42a7d8c6c8fd | 1329 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1330 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1331 | }; |
Pokitto | 5:42a7d8c6c8fd | 1332 | const byte PROGMEM halfHeart[]= |
Pokitto | 5:42a7d8c6c8fd | 1333 | { |
Pokitto | 5:42a7d8c6c8fd | 1334 | 8,8, |
Pokitto | 5:42a7d8c6c8fd | 1335 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1336 | B00001100, |
Pokitto | 5:42a7d8c6c8fd | 1337 | B00011100, |
Pokitto | 5:42a7d8c6c8fd | 1338 | B00011000, |
Pokitto | 5:42a7d8c6c8fd | 1339 | B00010000, |
Pokitto | 5:42a7d8c6c8fd | 1340 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1341 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1342 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1343 | }; |
Pokitto | 5:42a7d8c6c8fd | 1344 | const byte PROGMEM emptyHeart[]= |
Pokitto | 5:42a7d8c6c8fd | 1345 | { |
Pokitto | 5:42a7d8c6c8fd | 1346 | 8,8, |
Pokitto | 5:42a7d8c6c8fd | 1347 | B01101100, |
Pokitto | 5:42a7d8c6c8fd | 1348 | B10010010, |
Pokitto | 5:42a7d8c6c8fd | 1349 | B10000010, |
Pokitto | 5:42a7d8c6c8fd | 1350 | B01000100, |
Pokitto | 5:42a7d8c6c8fd | 1351 | B00101000, |
Pokitto | 5:42a7d8c6c8fd | 1352 | B00010000, |
Pokitto | 5:42a7d8c6c8fd | 1353 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1354 | B00000000, |
Pokitto | 5:42a7d8c6c8fd | 1355 | }; |
Pokitto | 5:42a7d8c6c8fd | 1356 | |
Pokitto | 5:42a7d8c6c8fd | 1357 | |
Pokitto | 5:42a7d8c6c8fd | 1358 | |
Pokitto | 5:42a7d8c6c8fd | 1359 | ///////////////////////////////////// GET TILE |
Pokitto | 5:42a7d8c6c8fd | 1360 | boolean getTile(uint8_t i, uint8_t j){ |
Pokitto | 5:42a7d8c6c8fd | 1361 | |
Pokitto | 5:42a7d8c6c8fd | 1362 | uint8_t test; |
Pokitto | 5:42a7d8c6c8fd | 1363 | test = (pgm_read_byte(world + (j%WORLD_H)*byteWidth + (i%WORLD_W)/8) & (B10000000 >> (i % 8))); |
Pokitto | 5:42a7d8c6c8fd | 1364 | if(test) |
Pokitto | 5:42a7d8c6c8fd | 1365 | return true; |
Pokitto | 5:42a7d8c6c8fd | 1366 | else |
Pokitto | 5:42a7d8c6c8fd | 1367 | return false; |
Pokitto | 5:42a7d8c6c8fd | 1368 | } |
Pokitto | 5:42a7d8c6c8fd | 1369 | |
Pokitto | 5:42a7d8c6c8fd | 1370 | ///////////////////////////////////// DRAW WORLD |
Pokitto | 5:42a7d8c6c8fd | 1371 | void drawWorld(int16_t x, int16_t y){ |
Pokitto | 5:42a7d8c6c8fd | 1372 | int8_t i, j, |
Pokitto | 5:42a7d8c6c8fd | 1373 | w = WORLD_W, |
Pokitto | 5:42a7d8c6c8fd | 1374 | h = WORLD_H; |
Pokitto | 5:42a7d8c6c8fd | 1375 | x = wrap(x,w*8); |
Pokitto | 5:42a7d8c6c8fd | 1376 | y = wrap(y,h*8); |
Pokitto | 5:42a7d8c6c8fd | 1377 | for(j=y/8; j < (LCDHEIGHT/8 + y/8 + 1); j++) { |
Pokitto | 5:42a7d8c6c8fd | 1378 | for(i=x/8; i < (LCDWIDTH/8 + x/8 + 1); i++ ) { |
Pokitto | 5:42a7d8c6c8fd | 1379 | if(getTile(i, j)) { |
Pokitto | 5:42a7d8c6c8fd | 1380 | gb.display.drawBitmap(i*8 - x, j*8 - y, tiles); |
Pokitto | 5:42a7d8c6c8fd | 1381 | } |
Pokitto | 5:42a7d8c6c8fd | 1382 | } |
Pokitto | 5:42a7d8c6c8fd | 1383 | } |
Pokitto | 5:42a7d8c6c8fd | 1384 | } |
Pokitto | 5:42a7d8c6c8fd | 1385 | |
Pokitto | 5:42a7d8c6c8fd | 1386 | ///////////////////////////////////// COLLIDE WORLD |
Pokitto | 5:42a7d8c6c8fd | 1387 | boolean collideWorld(int16_t x, int16_t y, uint8_t w, uint8_t h){ |
Pokitto | 5:42a7d8c6c8fd | 1388 | if(getTile(x/8, y/8)) |
Pokitto | 5:42a7d8c6c8fd | 1389 | return true; |
Pokitto | 5:42a7d8c6c8fd | 1390 | if(getTile((x+w-1)/8, y/8)) |
Pokitto | 5:42a7d8c6c8fd | 1391 | return true; |
Pokitto | 5:42a7d8c6c8fd | 1392 | if(getTile((x+w-1)/8, (y+h-1)/8)) |
Pokitto | 5:42a7d8c6c8fd | 1393 | return true; |
Pokitto | 5:42a7d8c6c8fd | 1394 | if(getTile(x/8, (y+h-1)/8)) |
Pokitto | 5:42a7d8c6c8fd | 1395 | return true; |
Pokitto | 5:42a7d8c6c8fd | 1396 | return false; |
Pokitto | 5:42a7d8c6c8fd | 1397 | } |
Pokitto | 5:42a7d8c6c8fd | 1398 |