Markus Geiger's Jumping Snake for the Arduboy. Modified and optimised to use the Arduboy2 library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
JUMPING SNAKE | |
Version 1.1 | |
Written by Markus Geiger alias Jayjunx 2018 | |
http://www.chibicom.com | |
Game License: MIT: https://opensource.org/licenses/MIT | |
*/ | |
#include <Arduboy2.h> | |
Arduboy2 arduboy; | |
int8_t i1, i2, i3, i4; | |
int8_t x1, y1, angle1; | |
int8_t deltax, deltay; | |
double d1; | |
double timer=0; | |
int8_t bildwahl = 1; | |
int8_t vorhang; | |
int8_t randomnr; | |
int8_t gamestate = 0; // CHEAT PLACE: standard = 0 | |
int8_t level = 1; // CHEAT PLACE: standard = 1 | |
int8_t lives = 7 ; // CHEAT PLACE: standard = 7 | |
// Snake Data | |
int8_t startx, starty, startangle; // 0 top, 1 right, 2 down, 3 left | |
int8_t snakeheadend; | |
int8_t tail[100]; // Memory elements for path of tail | |
int8_t jumppause; | |
double snakelength; | |
double maxlength; | |
uint8_t food[8][2]; // X, Y | |
bool foodactive[8]; | |
uint8_t foodflash=5; | |
uint8_t foodcrowfactor; | |
bool foodflashdirection; | |
int8_t obstacle[30][5]; | |
int8_t floatingrocks; | |
bool floatingrocksdirection; | |
bool continuegame; // Once allows restart | |
int8_t continuetext; | |
//const PROGMEM bool img1[2000] = {false,true,false,false,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1}; | |
//bool const PROGMEM imgt1[] = { 0,1,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0, }; | |
//bool const imgt2[] = { 0,1,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0, }; | |
// Ancient Rust Logo 128x50 | |
const unsigned char pic1[] PROGMEM = { | |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0x78, 0x3c, 0x9e, 0xcf, 0xe7, 0xe6, 0xee, 0xec, 0xcc, 0xdc, 0xd8, 0x18, 0x38, 0xb0, 0xb0, 0x30, 0x70, 0x60, 0x60, 0xe0, 0xe0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0x60, 0x60, 0x70, 0xb0, 0xb0, 0xb8, 0xb8, 0x98, 0x18, 0x1c, 0xc, 0xe, 0x6e, 0xe6, 0xf7, 0xf3, 0xe7, 0xcf, 0x9e, 0x3c, 0x78, 0xf0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf0, 0xf8, 0x3c, 0x9f, 0xc7, 0xf3, 0xf9, 0xfc, 0x7e, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xf, 0xc3, 0xf1, 0xfc, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf, 0x00, 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0x3d, 0x1d, 0x8d, 0xcd, 0xe5, 0xf1, 0xfb, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0xf3, 0x83, 0xb, 0x3b, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0x3b, 0xb, 0x83, 0xf3, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0xfb, 0xf9, 0xf1, 0xe5, 0xcd, 0x8d, 0x1c, 0x3e, 0xfe, 0xfc, 0xf8, 0xf0, 0xc0, 0x1, 0xf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf8, 0xe0, 0x00, 0x00, 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0xfe, 0xfc, 0xf1, 0xe7, 0xcf, 0x1e, 0x7c, 0xf8, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe0, 0xf8, 0x7e, 0x1f, 0xc7, 0xf3, 0xf8, 0xfe, 0xff, 0xbf, 0xcf, 0xc3, 0xe1, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x3e, 0xff, 0xff, 0xff, 0xff, 0x80, 0xf, 0x7f, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x3e, 0xff, 0xff, 0xff, 0xe3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x9c, 0xff, 0xff, 0xff, 0xff, 0x3e, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xf8, 0xff, 0xff, 0x7f, 0xf, 0x80, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x00, 0x00, 0xc0, 0xf0, 0xfc, 0xfe, 0xff, 0xff, 0x7f, 0x3f, 0x1f, 0x3f, 0xff, 0xfe, 0xf8, 0xe3, 0x8f, 0x3f, 0xfc, 0xf0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xfc, 0xff, 0xf, 0xe3, 0xf8, 0xff, 0xff, 0x7f, 0x3f, 0xf, 0xf, 0x7, 0x3, 0x3, 0x1, 0x1, 0x1, 0xf, 0x3f, 0xff, 0xff, 0xfe, 0xf0, 0xc3, 0x8f, 0x3f, 0x7f, 0xff, 0xfc, 0xf8, 0x60, 0x63, 0x7, 0x7, 0xf, 0x1f, 0x1f, 0xbf, 0xbf, 0xbe, 0xb8, 0x38, 0x33, 0x37, 0x7, 0xcf, 0xcf, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xcf, 0x81, 0x10, 0x1e, 0xf, 0xf, 0xf, 0xf, 0xf, 0x1e, 0x10, 0x1, 0xf, 0x9e, 0x9e, 0xde, 0xde, 0xde, 0xde, 0xdf, 0xcf, 0xcf, 0xc7, 0x37, 0x31, 0xb8, 0xbc, 0xbe, 0xbf, 0xbf, 0x1f, 0x1f, 0xf, 0x7, 0x3, 0x61, 0x70, 0x78, 0xfc, 0xff, 0x7f, 0x3f, 0xf, 0x3, 0xf0, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xf, 0x3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7, 0x1f, 0xff, 0xff, 0xfe, 0xf8, 0x83, 0x1f, 0xff, 0xfc, 0xe0, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xf, 0xe0, 0x7e, 0x7f, 0x3f, 0xbf, 0x83, 0x80, 0xc0, 0xc0, 0xc0, 0xe0, 0xe0, 0x60, 0x70, 0x70, 0x30, 0x38, 0x38, 0x38, 0x19, 0x1d, 0x1d, 0x1c, 0xe, 0x3e, 0x78, 0xf2, 0xc6, 0x9e, 0x3e, 0x7e, 0xff, 0xef, 0xcf, 0x8f, 0x7, 0xc7, 0xff, 0xff, 0xff, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x3, 0x3, 0x3, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7, 0x1, 0x80, 0xf8, 0xfe, 0xfe, 0xfe, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1, 0x7, 0xff, 0xff, 0xff, 0xff, 0xf7, 0x3, 0x3, 0x3, 0x00, 0x00, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x87, 0xcf, 0xef, 0xff, 0xff, 0x3e, 0x9e, 0xc6, 0xf2, 0x78, 0x3e, 0xe, 0xe, 0x1c, 0x1d, 0x1d, 0x19, 0x3b, 0x3b, 0x38, 0x70, 0x70, 0x70, 0x60, 0xe0, 0xe0, 0xc0, 0xc0, 0xc0, 0x80, 0x87, 0xbf, 0x3f, 0x7f, 0x7c, 0x1, 0x1f, 0xff, 0xff, 0xe0, 0x3f, 0x1f, 0x1f, 0x1c, 0xe, 0xe, 0x7, 0x7, 0x3, 0x3, 0x3, 0x1, 0x1, 0x1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3, 0x7, 0xf, 0x1c, 0x39, 0x73, 0x67, 0xef, 0xcf, 0x9f, 0x3f, 0x7b, 0x33, 0xa7, 0x87, 0xcf, 0xde, 0xdc, 0xcc, 0xe8, 0xe0, 0xe7, 0x67, 0x6f, 0x6f, 0x6f, 0x6e, 0x6e, 0x6f, 0x6f, 0x6f, 0x67, 0x67, 0x60, 0x60, 0x6f, 0x6f, 0x6f, 0x6f, 0x6e, 0x6e, 0x6f, 0x6f, 0xef, 0xe7, 0xc7, 0xc0, 0xc0, 0xc0, 0xc0, 0x90, 0xb0, 0x38, 0x7c, 0x3c, 0x9e, 0xcf, 0xef, 0xe7, 0x73, 0x39, 0x1c, 0xe, 0x7, 0x3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1, 0x1, 0x3, 0x3, 0x3, 0x7, 0x7, 0xe, 0xe, 0xc, 0x1f, 0x1f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3, 0x1, 0x1, 0x1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1, 0x1, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3, 0x1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
}; | |
// JUMPING Text 60x13 | |
const unsigned char pic3[] PROGMEM = { | |
0x00, 0x00, 0x00, 0x3, 0x3, 0x3, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x1c, 0x70, 0xc0, 0xf0, 0x3c, 0xff, 0xff, 0x00, 0x3, 0xff, 0xff, 0x83, 0x83, 0xc7, 0xfe, 0x7c, 0x00, 0x3, 0xff, 0xff, 0x3, 0x00, 0xff, 0xff, 0x1e, 0x78, 0xe0, 0x80, 0x00, 0xff, 0xff, 0x00, 0xfe, 0xff, 0x3, 0x3, 0xc3, 0xc3, 0xc7, 0xc6, 0xe, 0x1e, 0x18, 0x18, 0x18, 0x18, 0x1f, 0xf, 0x00, 0xf, 0x1f, 0x18, 0x18, 0x18, 0x1c, 0x1f, 0x1f, 0x00, 0x1f, 0x1f, 0x00, 0x00, 0x1, 0x00, 0x00, 0x1f, 0x1f, 0x00, 0x00, 0x1f, 0x1f, 0x1, 0x1, 0x1, 0x00, 0x00, 0x00, 0x18, 0x1f, 0x1f, 0x18, 0x00, 0x1f, 0x1f, 0x00, 0x00, 0x1, 0x3, 0xf, 0x1f, 0x1f, 0x00, 0xf, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x1f, | |
}; | |
// SNAKE Text 96x27 | |
const unsigned char pic4[] PROGMEM = { | |
0x00, 0xf0, 0xfc, 0xfe, 0xfe, 0x1f, 0x1f, 0xf, 0xf, 0xf, 0xf, 0x1f, 0x1e, 0x7e, 0x7c, 0x78, 0x70, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xf8, 0xf0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xfe, 0xff, 0xff, 0x7f, 0xf, 0x7f, 0xff, 0xff, 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe0, 0xf0, 0xf8, 0x7e, 0x3f, 0x1f, 0x7, 0x3, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x00, 0x00, 0x1, 0x7, 0xf, 0x1f, 0x3f, 0x3e, 0x7c, 0xf8, 0xf8, 0xf0, 0xe0, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x1, 0x7, 0x1f, 0x3f, 0xff, 0xfe, 0xf8, 0xe0, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x80, 0xfc, 0xff, 0xff, 0xff, 0x7, 0x00, 0x00, 0x00, 0x7, 0x7f, 0xff, 0xff, 0xfc, 0x80, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xfc, 0x7e, 0xff, 0xff, 0xf7, 0xc3, 0x1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x78, 0xf8, 0xf8, 0xf8, 0xe0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0x81, 0x83, 0xc7, 0xff, 0xff, 0xff, 0x7c, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3, 0xf, 0x1f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x1f, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1f, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x1, 0x00, 0x00, 0x1, 0x3, 0xf, 0x1f, 0x7f, 0xfc, 0xf8, 0xe0, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x1, 0x3, 0x3, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x3, 0x3, 0x1, 0x00, 0x00, 0x00, 0x00, 0x7, 0x7, 0x7, 0x7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1, 0x7, 0x7, 0x7, 0x7, 0x00, 0x00, 0x7, 0x7, 0x7, 0x7, 0x1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1, 0x7, 0x7, 0x7, 0x7, 0x00, 0x00, 0x7, 0x7, 0x7, 0x7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1, 0x7, 0x7, 0x7, 0x6, 0x00, 0x00, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, | |
}; | |
void setup() { | |
arduboy.begin(); | |
arduboy.clear(); | |
arduboy.setFrameRate(60); | |
arduboy.initRandomSeed(); | |
randomnr = 1 + rand() % 100; // Gen random Nr. | |
//Serial.begin(9600); | |
//Serial.print(F("\n\n Arduboy launched \n\n")); | |
} | |
void loop() | |
{ | |
if (!arduboy.nextFrame()) | |
{ | |
return; | |
} | |
arduboy.clear(); | |
switch (gamestate) | |
{ | |
case 0: | |
// Ancient-Rust-Logo appears and stay for a while or button click | |
arduboy.drawBitmap(0, 4, pic1, 128, 50, WHITE); | |
timer++; | |
d1 = 64 - timer*3; | |
if (d1 < 0) d1 = 0; | |
arduboy.fillCircle(64, 32, d1, BLACK); | |
if ( (timer == 170) || (arduboy.pressed(A_BUTTON)) || (arduboy.pressed(B_BUTTON)) ) | |
{ | |
gamestate = 1; | |
timer = 0; | |
} | |
break; | |
case 1: | |
// Ancien-Rust-Logo "ausgrieseln" | |
arduboy.drawBitmap(0, 4, pic1, 128, 50, WHITE); | |
arduboy.display(); | |
for (d1 = 0; d1 < 40; d1++) | |
{ | |
for (i1 = 0; i1 < 63; i1+=2) | |
{ | |
i2 = d1 / 15+1; | |
arduboy.fillCircle(1 + rand() % 128, i1, i2, BLACK); | |
//arduboy.drawPixel(1 + rand() % 128, i1, BLACK); | |
} | |
arduboy.display(); | |
} | |
arduboy.clear(); // Jetzt ganz schwarz einf�rben | |
arduboy.display(); | |
gamestate = 2; | |
continuegame = 0; | |
timer = 0; | |
i3 = 0; // Used as timer in Gamestate 2 | |
i4 = 0; | |
break; | |
case 2: | |
// Show SNAKE MAIN SCREEN | |
arduboy.digitalWriteRGB(RGB_OFF, RGB_OFF, RGB_ON); | |
arduboy.drawBitmap(64-96/2,32-27/2, pic4, 96, 27, WHITE);// Show "Snake" Text | |
if ( (timer == 0) || (i3==40) )// Define random position for jumping snake text | |
{ | |
i1 = 1 + rand() % 60; | |
i3 = 0; // choose variant | |
if (i1 > 20) i3 = 1; | |
if (i1 > 40) i3 = 2; | |
if (i3 == 0) | |
{ | |
i1 = 0; i2 = 1; // Left top | |
} | |
if (i3 == 1) | |
{ | |
i1 = 64-30; i2 = 1; // Center top | |
} | |
if (i3 == 2) | |
{ | |
i1 = 128 - 60; i2 = 1; // Right top | |
} | |
i3 = rand() % 20; // i3 used as timer now to let jumping text jump | |
} | |
i3++; // i3 used as now | |
arduboy.drawBitmap(i1, i2, pic3, 60, 13, WHITE);// Show "Snake" Text// Paint jumping text | |
// Show any key text | |
arduboy.setCursor(26, 53); | |
arduboy.print(F("PRESS ANY KEY")); | |
// Use snakes as underlines | |
i4++; | |
if (i4 == 255) i4 = 0; | |
//Now paint snakes | |
arduboy.drawLine(0, 16, i4, 16, WHITE); | |
arduboy.drawLine(0, 16, i4-128, 16, BLACK); | |
arduboy.drawLine(127, 48, 128-i4, 48, WHITE); | |
arduboy.drawLine(127, 48, 128-i4+128, 48, BLACK); | |
// Show fadein | |
if (timer < 16) | |
{ | |
arduboy.fillRect(0, 0, 128, 31-timer*2, BLACK); | |
arduboy.fillRect(0, 31+timer*2, 128, 33-timer*2, BLACK); | |
} | |
if (timer == 1200) // If nothing happened back to Ancient Rust Intro | |
{ | |
timer = 0; | |
gamestate = 0; | |
} | |
if (timer>30) | |
if ( (arduboy.pressed(A_BUTTON)) || (arduboy.pressed(B_BUTTON)) ) // Start Game - Show Level | |
{ | |
arduboy.digitalWriteRGB(BLUE_LED, RGB_OFF); | |
timer=0; | |
gamestate = 3; | |
level = 1; | |
lives = 7; | |
i1 = 0; | |
} | |
timer++; | |
break; | |
case 3: | |
// Show Level & Start next Level! | |
// Show any key text | |
arduboy.setCursor(46, 25); | |
arduboy.print(F("LEVEL")); | |
arduboy.setCursor(79, 25); | |
arduboy.print(level); | |
arduboy.setCursor(55, 37); | |
if (lives>1) | |
arduboy.print(F("LIVES")); | |
else | |
arduboy.print(F("LIVE")); | |
arduboy.setCursor(46, 37); | |
arduboy.print(lives); | |
// Show any key text | |
arduboy.setCursor(26, 53); | |
arduboy.print(F("PRESS ANY KEY")); | |
// Show deco line | |
arduboy.drawLine(0, 21, 127, 21, WHITE); | |
arduboy.drawLine(0, 47, 127, 47, WHITE); | |
switch (level) // Show Level Name | |
{ | |
case 1: | |
arduboy.setCursor(20, 9); | |
arduboy.print(F("YOUR FIRST JUMP")); // Show Level Name | |
break; | |
case 2: | |
arduboy.setCursor(30, 9); | |
arduboy.print(F("SUPERSIZE ME")); // Show Level Name | |
break; | |
case 3: | |
arduboy.setCursor(38, 9); | |
arduboy.print(F("FAST FOOD")); // Show Level Name | |
break; | |
case 4: | |
arduboy.setCursor(26, 9); | |
arduboy.print(F("TENNIS LESSON")); // Show Level Name | |
break; | |
case 5: | |
arduboy.setCursor(35, 9); | |
arduboy.print(F("SUPER JUMP")); // Show Level Name | |
break; | |
case 6: | |
arduboy.setCursor(41, 9); | |
arduboy.print(F("THE MAZE")); // Show Level Name | |
break; | |
case 7: | |
arduboy.setCursor(23, 9); | |
arduboy.print(F("FLOATING ROCKS")); // Show Level Name | |
break; | |
case 8: | |
arduboy.setCursor(41, 9); | |
arduboy.print(F("CRUNSHER")); // Show Level Name | |
break; | |
case 9: | |
arduboy.setCursor(23, 9); | |
arduboy.print(F("HUNTING SEASON")); // Show Level Name | |
break; | |
case 10: | |
arduboy.setCursor(4, 9); | |
arduboy.print(F("3 LIVES FOR A FRIEND")); // Show Level Name | |
break; | |
case 11: | |
arduboy.setCursor(26, 9); | |
arduboy.print(F("PERFECT MATCH")); // Show Level Name | |
break; | |
case 12: | |
arduboy.setCursor(23, 9); | |
arduboy.print(F("MINES AND FOOD")); // Show Level Name | |
break; | |
case 13: | |
arduboy.setCursor(37, 9); | |
arduboy.print(F("SURROUNDED")); // Show Level Name | |
break; | |
case 14: | |
arduboy.setCursor(34, 9); | |
arduboy.print(F("THE PASSAGE")); // Show Level Name | |
break; | |
case 15: | |
arduboy.setCursor(38, 9); | |
arduboy.print(F("GODSPEED 1")); // Show Level Name | |
break; | |
case 16: | |
arduboy.setCursor(38, 9); | |
arduboy.print(F("GODSPEED 2")); // Show Level Name | |
break; | |
case 17: | |
arduboy.setCursor(38, 9); | |
arduboy.print(F("GODSPEED 3")); // Show Level Name | |
break; | |
case 18: | |
arduboy.setCursor(44, 9); | |
arduboy.print(F("SLOWMO 1")); // Show Level Name | |
break; | |
case 19: | |
arduboy.setCursor(44, 9); | |
arduboy.print(F("SLOWMO 2")); // Show Level Name | |
break; | |
case 20: | |
arduboy.setCursor(44, 9); | |
arduboy.print(F("SLOWMO 3")); // Show Level Name | |
break; | |
case 21: | |
arduboy.setCursor(47, 9); | |
arduboy.print(F("FLASHED")); // Show Level Name | |
break; | |
case 22: | |
arduboy.setCursor(50, 9); | |
arduboy.print(F("ZIGZAG")); // Show Level Name | |
break; | |
case 23: | |
arduboy.setCursor(52, 9); | |
arduboy.print(F("CROSS")); // Show Level Name | |
break; | |
case 24: | |
arduboy.setCursor(50, 9); | |
arduboy.print(F("REQUIEM")); // Show Level Name | |
break; | |
case 25: | |
arduboy.setCursor(55, 9); | |
arduboy.print(F("RIBS")); // Show Level Name | |
break; | |
case 26: | |
arduboy.setCursor(4, 9); | |
arduboy.print(F("3 LIVES FOR A FRIEND")); // Show Level Name | |
break; | |
case 27: | |
arduboy.setCursor(46, 9); | |
arduboy.print(F("NIRVANA")); // Show Level Name | |
break; | |
//... | |
} | |
// Show fade in | |
if (timer < 16) | |
{ | |
arduboy.fillRect(0, 0, 128, 31 - timer * 2, BLACK); | |
arduboy.fillRect(0, 31 + timer * 2, 128, 33 - timer * 2, BLACK); | |
} | |
if (timer>30) // After a verry little bit, activate buttons | |
if ((arduboy.pressed(A_BUTTON)) || (arduboy.pressed(B_BUTTON))) // Start Game | |
{ | |
// What every level happens: | |
arduboy.setFrameRate(30); | |
timer = 0; | |
gamestate = 4; | |
jumppause = 10; | |
maxlength = 80; | |
foodcrowfactor = 30; | |
startx = 120; | |
starty = 10; | |
startangle =-1; // -1 top, -2 right, -3 down, -4 left, -5 Jump10, -6 ENDE/KOPF | |
tail[0] = 5; | |
tail[1] = -2; | |
tail[2] = 3; | |
tail[3] = -3; | |
tail[4] = 20; | |
tail[5] = -6; | |
foodactive[0] = 1; | |
floatingrocks = 0; floatingrocksdirection = 0; | |
// Delete all old obstacles | |
for (i1 = 0; i1 < 30; i1++) | |
for (i2 = 0; i2 < 5; i2++) | |
{ | |
obstacle[i1][i2] = 0; | |
} | |
i1 = 0; // prepare for food drop nr | |
// Load Level itself | |
if (level == 1) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 1 - YOUR FIRST JUMP | |
{ | |
food[i1][0] = 31; // X, Y, active | |
food[i1][1] = 31; | |
i1++; | |
food[i1][0] = 97; | |
food[i1][1] = 31; // X, Y, active | |
foodactive[i1] = 1; | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
i1 = 0; // Obstacle number | |
obstacle[i1][0] = 1; obstacle[i1][1] = 63; /*obstacle[i1][2] = 0;*/ obstacle[i1][3] = 63; obstacle[i1][4] = 63; | |
} | |
// Load Level itself | |
if (level == 2) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 2 - SUPERSIZE ME | |
{ | |
foodcrowfactor = 120; | |
food[i1][0] = 10; // X, Y, active in extra array | |
food[i1][1] = 10; | |
//foodactive[i1] = 1; i1++; | |
//food[i1][0] = 10; // X, Y, active in extra array | |
//food[i1][1] = 53; | |
i1++; | |
food[i1][0] = 30; // X, Y, active in extra array | |
food[i1][1] = 20; | |
//foodactive[i1] = 1; i1++; | |
//food[i1][0] = 30; // X, Y, active in extra array | |
//food[i1][1] = 43; | |
//foodactive[i1] = 1; i1++; | |
//food[i1][0] = 100; // X, Y, active in extra array | |
//food[i1][1] = 10; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 100; // X, Y, active in extra array | |
food[i1][1] = 53; | |
foodactive[i1] = 1; | |
} | |
// Load Level itself | |
if (level == 3) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 3 - FAST FOOD | |
{ | |
foodcrowfactor = 500; | |
food[i1][0] = 15; // X, Y, active in extra array | |
food[i1][1] = 10; | |
i1++; | |
food[i1][0] = 20; // X, Y, active in extra array | |
food[i1][1] = 10; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 25; // X, Y, active in extra array | |
food[i1][1] = 10; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 30; // X, Y, active in extra array | |
food[i1][1] = 10; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 105; // X, Y, active in extra array | |
food[i1][1] = 57; | |
foodactive[i1] = 1; | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
i1 = 0; // Obstacle number | |
obstacle[i1][0] = 1; /*obstacle[i1][1] = 0;*/ obstacle[i1][2] = 20; obstacle[i1][3] = 80; obstacle[i1][4] = 20; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 80; obstacle[i1][2] = 20; obstacle[i1][3] = 80; obstacle[i1][4] = 35; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 100; /*obstacle[i1][2] = 0*/; obstacle[i1][3] = 100; obstacle[i1][4] = 50; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 100; obstacle[i1][2] = 50; obstacle[i1][3] = 20; obstacle[i1][4] = 50; | |
} | |
// Load Level itself | |
if (level == 4) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 4 - TENNIS LESSON | |
{ | |
food[i1][0] = 50; // X, Y, active in extra array | |
food[i1][1] = 16; | |
i1++; | |
food[i1][0] = 50; // X, Y, active in extra array | |
food[i1][1] = 46; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 76; // X, Y, active in extra array | |
food[i1][1] = 46; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 76; // X, Y, active in extra array | |
food[i1][1] = 16; | |
foodactive[i1] = 1; | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
i1 = 0; // Obstacle number | |
obstacle[i1][0] = 1; obstacle[i1][1] = 20; obstacle[i1][2] = 31; obstacle[i1][3] = 107; obstacle[i1][4] = 31; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 63; /*obstacle[i1][2] = 0;*/ obstacle[i1][3] = 63; obstacle[i1][4] = 63; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 20; /*obstacle[i1][2] = 0;*/ obstacle[i1][3] = 20; obstacle[i1][4] = 63; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 107; /*obstacle[i1][2] = 0;*/ obstacle[i1][3] = 107; obstacle[i1][4] = 63; | |
} | |
// Load Level itself | |
if (level == 5) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 5 - SUPER JUMP | |
{ | |
food[i1][0] = 33; // X, Y, active in extra array | |
food[i1][1] = 10; | |
i1++; | |
food[i1][0] = 93; // X, Y, active in extra array | |
food[i1][1] = 10; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 33; // X, Y, active in extra array | |
food[i1][1] = 53; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 93; // X, Y, active in extra array | |
food[i1][1] = 53; | |
foodactive[i1] = 1; | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
i1 = 0; // Obstacle number | |
obstacle[i1][0] = 2; obstacle[i1][1] = 61; /*obstacle[i1][2] = 0;*/ obstacle[i1][3] = 4; obstacle[i1][4] = 64; i1++; | |
obstacle[i1][0] = 2; /*obstacle[i1][1] = 0;*/ obstacle[i1][2] = 29; obstacle[i1][3] = 61; obstacle[i1][4] = 4; | |
} | |
// Load Level itself | |
if (level == 6) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 6 - THE MAZE | |
{ | |
food[i1][0] = 35; // X, Y, active in extra array | |
food[i1][1] = 35; | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
i1 = 0; // Obstacle number | |
obstacle[i1][0] = 2; obstacle[i1][1] = 105; obstacle[i1][3] = 10; obstacle[i1][4] = 50; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 20; obstacle[i1][2] = 45; obstacle[i1][3] = 95; obstacle[i1][4] = 10; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 20; obstacle[i1][2] = 20; obstacle[i1][3] = 10; obstacle[i1][4] = 35; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 20; obstacle[i1][2] = 15; obstacle[i1][3] = 75; obstacle[i1][4] = 10; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 45; obstacle[i1][2] = 30; obstacle[i1][3] = 10; obstacle[i1][4] = 20; | |
} | |
// Load Level itself | |
if (level == 7) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 7 - FLOATING ROCKS | |
{ | |
food[i1][0] = 5; // X, Y, active in extra array | |
food[i1][1] = 5; | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
i1 = 0; // Obstacle number | |
obstacle[i1][0] = 3; obstacle[i1][1] = 23; obstacle[i1][2] = -50; obstacle[i1][3] = 10; obstacle[i1][4] = 20; i1++; | |
obstacle[i1][0] = 3; obstacle[i1][1] = 43; obstacle[i1][2] = -10; obstacle[i1][3] = 10; obstacle[i1][4] = 20; i1++; | |
obstacle[i1][0] = 3; obstacle[i1][1] = 63; obstacle[i1][2] = 30; obstacle[i1][3] = 10; obstacle[i1][4] = 20; i1++; | |
obstacle[i1][0] = 4; obstacle[i1][2] = 30; obstacle[i1][3] = 50; obstacle[i1][4] = 10; | |
} | |
// Load Level itself | |
if (level == 8) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 8 - CRUNSHER | |
{ | |
food[i1][0] = 5; // X, Y, active in extra array | |
food[i1][1] = 58; | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
i1 = 0; // Obstacle number | |
for (i2 = 0; i2<6; i2++) // Loop | |
{ | |
obstacle[i1][0] = 3; obstacle[i1][1] = 55; obstacle[i1][2] = -40+i2*20; obstacle[i1][3] = 5; obstacle[i1][4] = 5; i1++; | |
obstacle[i1][0] = 5; obstacle[i1][1] = 60; obstacle[i1][2] = 10 + i2 * 20; obstacle[i1][3] = 5; obstacle[i1][4] = 5; i1++; | |
} | |
for (i2 = 0; i2<6; i2++) // Loop | |
{ | |
obstacle[i1][0] = 4; obstacle[i1][1] = -40+i2*30; obstacle[i1][2] = 43; obstacle[i1][3] = 5; obstacle[i1][4] = 5; i1++; | |
} | |
} | |
// Load Level itself | |
if (level == 9) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 9 - HUNTING SEASON | |
{ | |
food[i1][0] = 5; // X, Y, active in extra array | |
food[i1][1] = 58; | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
i1 = 0; // Obstacle number | |
for (i2 = 0; i2<6; i2++) // Loop - Blocks | |
{ | |
obstacle[i1][0] = 2; obstacle[i1][1] = 10+i2*20; obstacle[i1][2] = 21; obstacle[i1][3] = 2; obstacle[i1][4] = 20; i1++; | |
} | |
for (i2 = 0; i2<6; i2++) // Loop - Hunter | |
{ | |
obstacle[i1][0] = 7; obstacle[i1][1] = 8; obstacle[i1][2] = i2*10; i1++; | |
} | |
} | |
// Load Level itself | |
if (level == 10) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 10 - 3 LIVES FOR A FRIEND | |
{ | |
food[i1][0] = 63; // X, Y, active in extra array | |
food[i1][1] = 31; | |
// Nothing, just get one food drop and a free live | |
} | |
// Load Level itself | |
if (level == 11) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 11 - PERFECT MATCH | |
{ | |
food[i1][0] = 5; // X, Y, active in extra array | |
food[i1][1] = 31; | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
i1 = 0; // Obstacle number | |
obstacle[i1][0] = 2; obstacle[i1][1] = 30; obstacle[i1][3] = 20; obstacle[i1][4] = 31; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 30; obstacle[i1][2] = 32; obstacle[i1][3] = 20; obstacle[i1][4] = 32; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 70; obstacle[i1][3] = 10; obstacle[i1][4] = 29; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 70; obstacle[i1][2] = 34; obstacle[i1][3] = 10; obstacle[i1][4] = 32; i1++; | |
} | |
// Load Level itself | |
if (level == 12) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 12 - MINES AND FOOD | |
{ | |
for (i1 = 0; i1 < 8; i1++) // Loop - Food | |
{ | |
food[i1][0] = 5 + rand() % 118; // X, Y, active in extra array | |
food[i1][1] = 5 + rand() % 54; | |
foodactive[i1] = 1; | |
} | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
for (i1 = 0; i1 < 29; i1++) // Loop - Food | |
{ | |
obstacle[i1][0] = 8; obstacle[i1][1] = rand() % 118; obstacle[i1][2] = rand() % 54; obstacle[i1][3] = rand() % 3+1; | |
} | |
} | |
// Load Level itself | |
if (level == 13) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 13 - SURROUNDED | |
{ | |
food[i1][0] = 7; // X, Y, active in extra array | |
food[i1][1] = 7; | |
i1++; | |
food[i1][0] = 7; // X, Y, active in extra array | |
food[i1][1] = 56; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 120; // X, Y, active in extra array | |
food[i1][1] = 7; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 120; // X, Y, active in extra array | |
food[i1][1] = 56; | |
foodactive[i1] = 1; | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
i1 = 0; // Obstacle number | |
for (i2 = 0; i2<6; i2++) // Loop - Blocks | |
{ | |
obstacle[i1][0] = 2; obstacle[i1][1] = 10 + i2 * 20; obstacle[i1][2] = 10; obstacle[i1][3] = 3; obstacle[i1][4] = 10; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 10 + i2 * 20; obstacle[i1][2] = 43; obstacle[i1][3] = 3; obstacle[i1][4] = 10; i1++; | |
} | |
for (i2 = 0; i2<10; i2++) // Loop - Hunter | |
{ | |
obstacle[i1][0] = 7; obstacle[i1][1] = i2 * 12; obstacle[i1][2] = 60; i1++; | |
} | |
} | |
// Load Level itself | |
if (level == 14) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 14 - THE PASSAGE | |
{ | |
maxlength = 800; | |
food[i1][0] = 7; // X, Y, active in extra array | |
food[i1][1] = 7; | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
i1 = 0; // Obstacle number | |
for (i2 = 0; i2<7; i2++) // Loop - Linien - With ofset to get a thicker wall | |
{ | |
obstacle[i1][0] = 1; obstacle[i1][1] = 100+i2; obstacle[i1][3] = 50+i2; obstacle[i1][4] = 50; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 100 + i2; obstacle[i1][2] = 20; obstacle[i1][3] = 50 + i2; obstacle[i1][4] = 70; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 60 + i2; obstacle[i1][2] = 20; obstacle[i1][3] = 10 + i2; obstacle[i1][4] = 70; i1++; | |
} | |
} | |
// Load Level itself | |
if (level == 15) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 15 - GODSPEED 1 | |
{ | |
arduboy.setFrameRate(60); | |
maxlength = 80; | |
foodcrowfactor = 50; | |
for (i1 = 0; i1 < 8; i1++) // Loop - Food | |
{ | |
food[i1][0] = 5 + rand() % 118; // X, Y, active in extra array | |
food[i1][1] = 5 + rand() % 54; | |
foodactive[i1] = 1; | |
} | |
} | |
// Load Level itself | |
if (level == 16) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 16 - GODSPEED 2 (CRUNSHER IN 60FPS) | |
{ | |
arduboy.setFrameRate(60); | |
foodcrowfactor = 50; | |
food[i1][0] = 5; // X, Y, active in extra array | |
food[i1][1] = 58; | |
// Types: 1 Line from 1=X,2=Y, to 3=X2, 4=Y2 | |
i1 = 0; // Obstacle number | |
for (i2 = 0; i2<6; i2++) // Loop | |
{ | |
obstacle[i1][0] = 3; obstacle[i1][1] = 55; obstacle[i1][2] = -40 + i2 * 20; obstacle[i1][3] = 5; obstacle[i1][4] = 5; i1++; | |
obstacle[i1][0] = 5; obstacle[i1][1] = 60; obstacle[i1][2] = 10 + i2 * 20; obstacle[i1][3] = 5; obstacle[i1][4] = 5; i1++; | |
} | |
for (i2 = 0; i2<6; i2++) // Loop | |
{ | |
obstacle[i1][0] = 4; obstacle[i1][1] = -40 + i2 * 30; obstacle[i1][2] = 43; obstacle[i1][3] = 5; obstacle[i1][4] = 5; i1++; | |
} | |
} | |
// Load Level itself | |
if (level == 17) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 17 - GODSPEED 3 (SUPERSIZE ME 60FPS) | |
{ | |
arduboy.setFrameRate(60); | |
foodcrowfactor = 120; | |
for (i1 = 0; i1 < 8; i1++) // Loop - Food | |
{ | |
food[i1][0] = 5 + rand() % 118; // X, Y, active in extra array | |
food[i1][1] = 5 + rand() % 54; | |
foodactive[i1] = 1; | |
} | |
} | |
// Load Level itself | |
if (level == 18) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 18 - SLOWMO 1 - FLASHED | |
{ | |
arduboy.setFrameRate(15); | |
food[0][0] = 10; // X, Y, active in extra array | |
food[0][1] = 10; | |
for (i1 = 0; i1 < 5; i1++) // Loop - flashing blocks | |
{ | |
obstacle[i1][0] = 9; obstacle[i1][1] = 20 + i1 * 20; obstacle[i1][2] = 0; obstacle[i1][3] = 10; obstacle[i1][4] = 63; | |
} | |
} | |
// Load Level itself | |
if (level == 19) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 19 - SLOWMO 2 - ZIGZAG | |
{ | |
arduboy.setFrameRate(15); | |
food[0][0] = 10; // X, Y, active in extra array | |
food[0][1] = 10; | |
i1 = 0; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 15; obstacle[i1][2] = 3; obstacle[i1][3] = 17; obstacle[i1][4] = 63; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 35; obstacle[i1][3] = 17; obstacle[i1][4] = 60; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 55; obstacle[i1][2] = 3; obstacle[i1][3] = 17; obstacle[i1][4] = 63; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 75; obstacle[i1][3] = 17; obstacle[i1][4] = 60; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 95; obstacle[i1][2] = 3; obstacle[i1][3] = 17; obstacle[i1][4] = 63; | |
} | |
// Load Level itself | |
if (level == 20) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 20 - SLOWMO 3 - CROSS | |
{ | |
arduboy.setFrameRate(15); | |
food[i1][0] = 3; // X, Y, active in extra array | |
food[i1][1] = 3; | |
i1++; | |
food[i1][0] = 3; // X, Y, active in extra array | |
food[i1][1] = 60; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 124; // X, Y, active in extra array | |
food[i1][1] = 60; | |
foodactive[i1] = 1; | |
i1 = 0; | |
obstacle[i1][0] = 2; obstacle[i1][2] = 28; obstacle[i1][3] = 20; obstacle[i1][4] = 6; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 107; obstacle[i1][2] = 28; obstacle[i1][3] = 20; obstacle[i1][4] = 6; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 60; obstacle[i1][3] = 6; obstacle[i1][4] = 15; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 60; obstacle[i1][2] = 48; obstacle[i1][3] = 6; obstacle[i1][4] = 15; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 12; obstacle[i1][2] = 10; obstacle[i1][3] = 117; obstacle[i1][4] = 51; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 10; obstacle[i1][2] = 12; obstacle[i1][3] = 115; obstacle[i1][4] = 53; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 10; obstacle[i1][2] = 51; obstacle[i1][3] = 115; obstacle[i1][4] = 10; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 12; obstacle[i1][2] = 53; obstacle[i1][3] = 117; obstacle[i1][4] = 12; i1++; | |
obstacle[i1][0] = 7; obstacle[i1][1] = 45; obstacle[i1][2] = 5; i1++; | |
obstacle[i1][0] = 7; obstacle[i1][1] = 45; obstacle[i1][2] = 58; | |
} | |
// Load Level itself | |
if (level == 21) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 21 - FLASHED | |
{ | |
food[0][0] = 10; // X, Y, active in extra array | |
food[0][1] = 10; | |
for (i1 = 0; i1 < 5; i1++) // Loop - flashing blocks | |
{ | |
obstacle[i1][0] = 9; obstacle[i1][1] = 20 + i1 * 20; obstacle[i1][3] = 10; obstacle[i1][4] = 63; | |
} | |
} | |
// Load Level itself | |
if (level == 22) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 22 - ZIGZAG | |
{ | |
food[0][0] = 10; // X, Y, active in extra array | |
food[0][1] = 10; | |
i1 = 0; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 15; obstacle[i1][2] = 3; obstacle[i1][3] = 17; obstacle[i1][4] = 63; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 35; obstacle[i1][3] = 17; obstacle[i1][4] = 60; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 55; obstacle[i1][2] = 3; obstacle[i1][3] = 17; obstacle[i1][4] = 63; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 75; obstacle[i1][3] = 17; obstacle[i1][4] = 60; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 95; obstacle[i1][2] = 3; obstacle[i1][3] = 17; obstacle[i1][4] = 63; | |
} | |
// Load Level itself | |
if (level == 23) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 23 - CROSS | |
{ | |
food[i1][0] = 3; // X, Y, active in extra array | |
food[i1][1] = 3; | |
i1++; | |
food[i1][0] = 3; // X, Y, active in extra array | |
food[i1][1] = 60; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 124; // X, Y, active in extra array | |
food[i1][1] = 60; | |
foodactive[i1] = 1; | |
i1 = 0; | |
obstacle[i1][0] = 2; obstacle[i1][2] = 28; obstacle[i1][3] = 20; obstacle[i1][4] = 6; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 107; obstacle[i1][2] = 28; obstacle[i1][3] = 20; obstacle[i1][4] = 6; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 60; obstacle[i1][3] = 6; obstacle[i1][4] = 15; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 60; obstacle[i1][2] = 48; obstacle[i1][3] = 6; obstacle[i1][4] = 15; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 12; obstacle[i1][2] = 10; obstacle[i1][3] = 117; obstacle[i1][4] = 51; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 10; obstacle[i1][2] = 12; obstacle[i1][3] = 115; obstacle[i1][4] = 53; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 10; obstacle[i1][2] = 51; obstacle[i1][3] = 115; obstacle[i1][4] = 10; i1++; | |
obstacle[i1][0] = 1; obstacle[i1][1] = 12; obstacle[i1][2] = 53; obstacle[i1][3] = 117; obstacle[i1][4] = 12; i1++; | |
obstacle[i1][0] = 7; obstacle[i1][1] = 45; obstacle[i1][2] = 5; i1++; | |
obstacle[i1][0] = 7; obstacle[i1][1] = 45; obstacle[i1][2] = 58; | |
} | |
// Load Level itself | |
if (level == 24) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 24 - REQUIEM | |
{ | |
tail[4] = 2; | |
food[i1][0] = 10; // X, Y, active in extra array | |
food[i1][1] = 2; | |
i1++; | |
food[i1][0] = 2; // X, Y, active in extra array | |
food[i1][1] = 50; | |
foodactive[i1] = 1; i1++; | |
food[i1][0] = 126; // X, Y, active in extra array | |
food[i1][1] = 62; | |
foodactive[i1] = 1; | |
i1 = 0; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 3; obstacle[i1][2] = 26; obstacle[i1][3] = 122; obstacle[i1][4] = 10; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][1] = 58; obstacle[i1][2] = 3; obstacle[i1][3] = 10; obstacle[i1][4] = 57; | |
} | |
// Load Level itself | |
if (level == 25) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 25 - RIBS | |
{ | |
food[i1][0] = 3; // X, Y, active in extra array | |
food[i1][1] = 31; | |
i1 = 0; | |
obstacle[i1][0] = 2; obstacle[i1][3] = 128; obstacle[i1][4] = 15; i1++; | |
obstacle[i1][0] = 2; obstacle[i1][2] = 48; obstacle[i1][3] = 128; obstacle[i1][4] = 15; | |
for (i1 = 2; i1 < 10; i1++) // Loop - flashing blocks | |
{ | |
obstacle[i1][0] = 1; obstacle[i1][1] = i1*16; obstacle[i1][2] = 15; obstacle[i1][3] = i1*16; obstacle[i1][4] = 48; | |
} | |
} | |
// Load Level itself | |
if (level == 26) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 26 - 3 LIVES FOR A FRIEND | |
{ | |
food[i1][0] = 63; // X, Y, active in extra array | |
food[i1][1] = 31; | |
// Nothing, just get one food drop and a free live | |
} | |
// Load Level itself | |
if (level == 27) ////////////////////////////////////////////////////////////////////////////////////////////////// LEVEL 27 - NIRVANA | |
{ | |
food[i1][0] = 10; // X, Y, active in extra array | |
food[i1][1] = 20; | |
i1 = 0; | |
obstacle[i1][0] = 2; obstacle[i1][3] = 80; obstacle[i1][4] = 63; i1++; | |
obstacle[i1][0] = 10; obstacle[i1][1] = 10; obstacle[i1][2] = 20; obstacle[i1][3] = 40; obstacle[i1][4] = 20; i1++; | |
obstacle[i1][0] = 10; obstacle[i1][1] = 40; obstacle[i1][2] = 20; obstacle[i1][3] = 40; obstacle[i1][4] = 50; i1++; | |
obstacle[i1][0] = 10; obstacle[i1][1] = 40; obstacle[i1][2] = 50; obstacle[i1][3] = 80; obstacle[i1][4] = 50; | |
} | |
} // Ende Start next level because button pressed | |
timer++; | |
break; | |
case 4: | |
// LETS PLAY! | |
arduboy.digitalWriteRGB(RED_LED, RGB_OFF); | |
arduboy.digitalWriteRGB(GREEN_LED, RGB_OFF); | |
if (jumppause > 0) | |
{ | |
arduboy.digitalWriteRGB(RED_LED, RGB_ON); // turn on red LED | |
jumppause--; | |
if (jumppause==0) | |
arduboy.digitalWriteRGB(GREEN_LED, RGB_ON); | |
} | |
// Draw Border: | |
arduboy.drawFastVLine(0, 0, 64, WHITE); | |
arduboy.drawFastVLine(127, 0, 64, WHITE); | |
//Draws a white or black vertical line of a certain height starting from the top. | |
arduboy.drawFastHLine(0, 0, 128, WHITE); | |
arduboy.drawFastHLine(0, 63, 128, WHITE); | |
//Draws a white or black horizontal line of a certain width starting from the left. | |
// Draw and handle Obstacles | |
if (floatingrocks == 0) floatingrocksdirection = 1; | |
if (floatingrocks == 50) floatingrocksdirection = 0; | |
if (floatingrocksdirection) floatingrocks++; | |
else | |
floatingrocks--; | |
for (i1 = 0; obstacle[i1][0] > 0 ; i1++) // Loop as long as obstacles inside | |
{ | |
if (obstacle[i1][0] == 1) // Typ Line | |
{ | |
arduboy.drawLine(obstacle[i1][1], obstacle[i1][2], obstacle[i1][3], obstacle[i1][4], WHITE); | |
} | |
if (obstacle[i1][0] == 2) // Typ Filled rectangle | |
{ | |
arduboy.fillRect(obstacle[i1][1], obstacle[i1][2], obstacle[i1][3], obstacle[i1][4], WHITE); | |
} | |
if (obstacle[i1][0] == 3) // Typ Filled rectangle moving 50 in Y forward and backwards | |
{ | |
arduboy.fillRect(obstacle[i1][1], obstacle[i1][2]+ floatingrocks, obstacle[i1][3], obstacle[i1][4], WHITE); | |
} | |
if (obstacle[i1][0] == 4) // Typ Filled rectangle moving 50 in X forward and backwards | |
{ | |
arduboy.fillRect(obstacle[i1][1] + floatingrocks, obstacle[i1][2], obstacle[i1][3], obstacle[i1][4], WHITE); | |
} | |
if (obstacle[i1][0] == 5) // Typ Filled rectangle moving 50 in Y forward and backwards - NEGATIVE DIRECTION! | |
{ | |
arduboy.fillRect(obstacle[i1][1], obstacle[i1][2] - floatingrocks, obstacle[i1][3], obstacle[i1][4], WHITE); | |
} | |
if (obstacle[i1][0] == 6) // Typ Filled rectangle moving 50 in X forward and backwards - NEGATIVE DIRECTION! | |
{ | |
arduboy.fillRect(obstacle[i1][1] - floatingrocks, obstacle[i1][2], obstacle[i1][3], obstacle[i1][4], WHITE); | |
} | |
// 7 = Hunters - Handled AFTER Obstacle Loop! | |
if (obstacle[i1][0] == 8) // Typ dissapearing filled Cycle | |
if (floatingrocks<25) | |
{ | |
arduboy.fillCircle(obstacle[i1][1], obstacle[i1][2], obstacle[i1][3], WHITE); | |
} | |
if (obstacle[i1][0] == 9) // Typ dissapearing filled Rectangles | |
if (floatingrocks<25) | |
{ | |
arduboy.fillRect(obstacle[i1][1], obstacle[i1][2], obstacle[i1][3], obstacle[i1][4], WHITE); | |
} | |
if (obstacle[i1][0] == 10) // Typ BLACK Line | |
{ | |
arduboy.drawLine(obstacle[i1][1], obstacle[i1][2], obstacle[i1][3], obstacle[i1][4], BLACK); | |
} | |
//... AD NEW OBSTACLES HERE | |
} | |
// Show Hunters Last | |
for (i1 = 0; obstacle[i1][0] > 0; i1++) // Loop as long as obstacles inside | |
if(obstacle[i1][0] == 7) | |
arduboy.drawPixel(obstacle[i1][1], obstacle[i1][2], WHITE); | |
// Handle Hunters AFTER Player so they get blocked by players tail | |
// Go through snake path and paint each step | |
x1 = startx; y1 = starty; angle1 = startangle; | |
if (angle1 == -1) | |
{ | |
deltax = 0; | |
deltay = -1; | |
} | |
if (angle1 == -2) | |
{ | |
deltax = 1; | |
deltay = 0; | |
} | |
if (angle1 == -3) | |
{ | |
deltax = 0; | |
deltay = 1; | |
} | |
if (angle1 == -4) | |
{ | |
deltax = -1; | |
deltay = 0; | |
} | |
snakelength = 0;// Start counting length | |
arduboy.drawPixel(x1, y1, WHITE); snakelength++; | |
for (i1 = 0; (tail[i1]!=-6); i1++) // until units head reached | |
{ | |
//Serial.print(i1); | |
if (tail[i1] > 0) // if positive distance value move along path | |
{ | |
for (i2 = tail[i1]; i2 > 0; i2--) | |
{ | |
x1 += deltax; | |
y1 += deltay; | |
arduboy.drawPixel(x1, y1, WHITE); snakelength++; | |
} | |
} | |
else | |
{ | |
if (tail[i1] == -1) // Turn Up | |
{ | |
angle1 = -1; | |
deltax = 0; | |
deltay = -1; | |
} | |
if (tail[i1] == -2) // Turn Right | |
{ | |
angle1 = -2; | |
deltax = 1; | |
deltay = 0; | |
} | |
if (tail[i1] == -3) // Turn Down | |
{ | |
angle1 = -3; | |
deltax = 0; | |
deltay = 1; | |
} | |
if (tail[i1] == -4) // Turn Left | |
{ | |
angle1 = -4; | |
deltax = -1; | |
deltay = 0; | |
} | |
if (tail[i1] == -5) // JUMP10 | |
{ | |
x1 += deltax*10; | |
y1 += deltay*10; | |
arduboy.drawPixel(x1, y1, WHITE); snakelength++; | |
} | |
} | |
snakeheadend = i1 + 1; | |
} | |
// Kopf erreicht | |
// Add new movement is array end is not yet reached! | |
if (snakeheadend > 94) maxlength--; | |
if (snakeheadend < 95) // Only if end of array not reached)) | |
{ | |
if ((angle1 == -1) || (angle1 == -3)) // moving up or down | |
{ | |
if (arduboy.pressed(LEFT_BUTTON)) | |
{ | |
tail[snakeheadend] = -4; // turn this direction | |
tail[snakeheadend + 1] = -6; // Head is now here | |
snakeheadend++; | |
angle1 = -4; | |
deltax = -1; | |
deltay = 0; | |
} | |
if (arduboy.pressed(RIGHT_BUTTON)) | |
{ | |
tail[snakeheadend] = -2; // turn this direction | |
tail[snakeheadend + 1] = -6; // Head is now here | |
snakeheadend++; | |
angle1 = -2; | |
deltax = 1; | |
deltay = 0; | |
} | |
} | |
if ((angle1 == -2) || (angle1 == -4)) // moving left or right | |
{ | |
if (arduboy.pressed(UP_BUTTON)) | |
{ | |
tail[snakeheadend] = -1; // turn this direction | |
tail[snakeheadend + 1] = -6; // Head is now here | |
snakeheadend++; | |
angle1 = -1; | |
deltax = 0; | |
deltay = -1; | |
} | |
if (arduboy.pressed(DOWN_BUTTON)) | |
{ | |
tail[snakeheadend] = -3; // turn this direction | |
tail[snakeheadend + 1] = -6; // Head is now here | |
snakeheadend++; | |
angle1 = -3; | |
deltax = 0; | |
deltay = 1; | |
} | |
} | |
if ((arduboy.pressed(B_BUTTON)) && (jumppause == 0)) // If Jump Key pressed | |
{ | |
jumppause = 15; | |
arduboy.digitalWriteRGB(RED_LED, RGB_ON); // turn on red LED | |
arduboy.drawCircle(x1, y1, 4, WHITE); | |
tail[snakeheadend] = -5; // Jump10 fields | |
tail[snakeheadend + 1] = -6; // Head is now here | |
snakeheadend++; | |
x1 += deltax * 10; | |
y1 += deltay * 10; | |
// Test if target field contain obstacle! Or if target is outside | |
if ( (arduboy.getPixel(x1, y1) == 1) || (x1<0) || (y1<0) || (x1>127) || (y1>63) ) | |
{ | |
timer = 0; | |
gamestate = 3; // Reset | |
lives--; | |
arduboy.setFrameRate(30); | |
if (lives == 0) gamestate = 5; | |
} | |
arduboy.drawPixel(x1, y1, WHITE); snakelength++; | |
} | |
else | |
{ | |
// if no jump, just move forward | |
if (tail[snakeheadend - 1] > 0) // If last segment was forward move add distance here without create new segment | |
{ | |
tail[snakeheadend - 1]++; | |
//Serial.print(F("- MOVE forward as ADD! -")); | |
} | |
else | |
{ | |
tail[snakeheadend] = 1; // One field movement | |
tail[snakeheadend + 1] = -6; // Head is now here | |
snakeheadend++; | |
//Serial.print(F("- MOVE forward as NEW ELEMENT -")); | |
} | |
x1 += deltax; | |
y1 += deltay; | |
if (arduboy.getPixel(x1, y1) == 1) | |
{ | |
timer = 0; | |
gamestate = 3; // Reset | |
lives--; | |
arduboy.setFrameRate(30); | |
if (lives == 0) gamestate = 5; | |
} | |
arduboy.drawPixel(x1, y1, WHITE); snakelength++; | |
} | |
//Serial.print(F("\n Headend:")); | |
//Serial.print(snakeheadend); | |
} | |
// Go through snake and move all elements one array field backwards | |
if (snakelength >= maxlength) // Cut 1 tail piece away if max length reached | |
{ | |
// Modify start value with first element before it gets deletet by [1] | |
// If angel change, change angel | |
if (tail[0] == -1) startangle = -1; | |
if (tail[0] == -2) startangle = -2; | |
if (tail[0] == -3) startangle = -3; | |
if (tail[0] == -4) startangle = -4; | |
angle1 = startangle; | |
if (angle1 == -1) | |
{ | |
deltax = 0; | |
deltay = -1; | |
} | |
if (angle1 == -2) | |
{ | |
deltax = 1; | |
deltay = 0; | |
} | |
if (angle1 == -3) | |
{ | |
deltax = 0; | |
deltay = 1; | |
} | |
if (angle1 == -4) | |
{ | |
deltax = -1; | |
deltay = 0; | |
} | |
// If positive movement | |
i3 = 1; // Memo if no section have to be deleted because existing length shortened | |
if (tail[0] >= 1) | |
{ | |
i3 = 0; | |
startx += deltax; | |
starty += deltay; | |
tail[0]--; | |
if (tail[0] == 0) // Now section can be deletet because length is exhausted | |
i3 = 1; | |
} | |
// If Jump | |
if (tail[0] == -5) | |
{ | |
startx += deltax * 10; | |
starty += deltay * 10; | |
} | |
if (i3 == 1) | |
{ | |
for (i1 = 0; i1 < 99; i1++)// Move all segments one space | |
{ | |
tail[i1] = tail[i1 + 1]; | |
i2 = i1 + 1; | |
} | |
tail[i2] = 0; // This element is unused now | |
} | |
} // End of cut 1 tail piece away | |
// Handle Hunters | |
for (i1 = 0; obstacle[i1][0] > 0; i1++) // Loop as long as obstacles inside | |
if (obstacle[i1][0] == 7) // HUNTER | |
if (rand() % 20>5) // Moving change | |
{ | |
if (x1 > obstacle[i1][1]) | |
{ | |
if (arduboy.getPixel(obstacle[i1][1] + 1, obstacle[i1][2]) == 0) // Only if target field is free space | |
obstacle[i1][1]++; | |
} | |
else | |
{ | |
if (arduboy.getPixel(obstacle[i1][1] - 1, obstacle[i1][2]) == 0) // Only if target field is free space | |
obstacle[i1][1]--; | |
} | |
if (y1 > obstacle[i1][2]) | |
{ | |
if (arduboy.getPixel(obstacle[i1][1], obstacle[i1][2] + 1) == 0) // Only if target field is free space | |
obstacle[i1][2]++; | |
} | |
else | |
{ | |
if (arduboy.getPixel(obstacle[i1][1], obstacle[i1][2] - 1) == 0) // Only if target field is free space | |
obstacle[i1][2]--; | |
} | |
} | |
// After snake shown hande food drops so we dont get some collisions with food | |
if (foodflashdirection == 1) | |
foodflash++; | |
if (foodflashdirection == 0) | |
foodflash--; | |
if (foodflash == 10) | |
foodflashdirection = 0; | |
if (foodflash == 0) | |
foodflashdirection = 1; | |
i4 = 0; | |
for (i1 = 0; i1 < 8; i1++) | |
if (foodactive[i1]==1) // If food drop is active | |
{ | |
i4++; | |
arduboy.drawCircle( food[i1][0] , food[i1][1], foodflash/4, WHITE); | |
// Calculate distance too snake head | |
i2 = (x1 - food[i1][0]); | |
i3 = (y1 - food[i1][1]); | |
if (i2 < 0) i2 = -i2; // Set to positive value if negative | |
if (i3 < 0) i3 = -i3; | |
if ((i2 < 2) && (i3 < 2)) | |
{ | |
maxlength += foodcrowfactor; // Snake gets longer | |
foodactive[i1] = 0; // Food drop dissapears | |
} | |
} | |
// If all Food gone Level one! | |
if (i4 == 0) | |
{ | |
level++; // Goto next level | |
lives += 3; // Every round add 3 new lives | |
if (lives > 7) lives = 7; | |
gamestate = 3; | |
timer = 0; | |
arduboy.setFrameRate(60); | |
if (level == 28) ////////////////////////////////////////////////////////////////////////////////////////////////// GAME SOLVED | |
{ | |
timer = 0; | |
gamestate = 6; | |
} | |
} | |
break; | |
case 5: | |
// SHOW GAME OVER | |
if (timer == 0) | |
{ | |
i1 = 1 + rand() % 125; | |
continuetext = 1; | |
if (i1 > 25) | |
continuetext = 2; | |
if (i1 > 50) | |
continuetext = 3; | |
if (i1 > 75) | |
continuetext = 4; | |
if (i1 > 100) | |
continuetext = 5; | |
i3 = 37; | |
} | |
timer++; | |
arduboy.digitalWriteRGB(RED_LED, RGB_ON); | |
arduboy.digitalWriteRGB(GREEN_LED, RGB_OFF); | |
if (arduboy.pressed(LEFT_BUTTON)) i3 = 37; | |
if (arduboy.pressed(RIGHT_BUTTON)) i3 = 70; | |
arduboy.setCursor(38, 9); | |
arduboy.print(F("GAME OVER")); // Show Level Name | |
if (continuegame==0) // Allow Continue | |
{ | |
if (continuetext == 1) | |
{ | |
arduboy.setCursor(6, 26); | |
arduboy.print(F("DO YOU LIKE MY GAME?")); // Show Level Name | |
} | |
if (continuetext == 2) | |
{ | |
arduboy.setCursor(3, 26); | |
arduboy.print(F("CHECKED CHIBICOM.COM?")); // Show Level Name | |
} | |
if (continuetext == 3) | |
{ | |
arduboy.setCursor(30, 26); | |
arduboy.print(F("EXTRA LIVES?")); // Show Level Name | |
} | |
if (continuetext == 4) | |
{ | |
arduboy.setCursor(20, 26); | |
arduboy.print(F("NEED SOME HELP?")); // Show Level Name | |
} | |
if (continuetext == 5) | |
{ | |
arduboy.setCursor(6, 26); | |
arduboy.print(F("DO YOU LOVE ARDUBOY?")); // Show Level Name | |
} | |
arduboy.setCursor(43, 45); | |
arduboy.print(F("YES NO")); // options | |
// Rectangle arround choosen option | |
arduboy.drawRect(i3, 43, 28, 11, WHITE); | |
if (timer > 50) | |
if ( (arduboy.pressed(A_BUTTON)) || (arduboy.pressed(B_BUTTON)) ) | |
if (i3 == 37) | |
{ | |
// YES | |
continuegame = 1; | |
lives = 5; | |
timer = 0; | |
gamestate = 3; | |
} | |
else | |
{ | |
// NO | |
timer = 0; | |
lives = 7; | |
gamestate = 0; | |
} | |
} | |
else | |
{ | |
// Only allow to accept GAME OVER SCREEN after pressing a button | |
arduboy.setCursor(38, 26); | |
arduboy.print(F("SORRY BRO")); // Show Level Name | |
arduboy.setCursor(26, 45); | |
arduboy.print(F("PRESS ANY KEY")); | |
if (timer > 50) | |
if ((arduboy.pressed(A_BUTTON)) || (arduboy.pressed(B_BUTTON)) ) | |
{ | |
gamestate = 0; | |
timer = 0; | |
} | |
} | |
d1 = 64 - timer * 3; | |
if (d1 < 0) d1 = 0; // Infade Circle | |
arduboy.fillCircle(64, 32, d1, BLACK); | |
break; | |
case 6: | |
// SHOW VICTORY SCREEN | |
timer++; | |
arduboy.digitalWriteRGB(RGB_OFF, RGB_OFF, RGB_OFF); | |
if (rand() % 100>80) arduboy.digitalWriteRGB(RED_LED, RGB_ON); | |
if (rand() % 100>80) arduboy.digitalWriteRGB(GREEN_LED, RGB_ON); | |
if (rand() % 100>80) arduboy.digitalWriteRGB(BLUE_LED, RGB_ON); | |
arduboy.setCursor(13, 20); | |
arduboy.print(F("VICTORY IS YOURS!")); // Show Level Name | |
if (timer > 80) | |
if ((arduboy.pressed(A_BUTTON)) || (arduboy.pressed(B_BUTTON))) | |
{ | |
gamestate = 0; | |
timer = 0; | |
} | |
d1 = 64 - timer * 3; | |
if (d1 < 0) d1 = 0; // Infade Circle | |
arduboy.fillCircle(64, 32, d1, BLACK); | |
break; | |
} | |
arduboy.display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment