#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define cloud_6_width 11
#define cloud_6_height 8
const unsigned char cloud_6_bits[] PROGMEM = {
0xc0, 0x03, 0xfe, 0x07, 0x3f, 0x07, 0xfb, 0x05, 0xcd, 0x05, 0xbf, 0x03,
0x3e, 0x03, 0xc0, 0x01 };
#define cloud_5_width 22
#define cloud_5_height 11
const unsigned char cloud_5_bits[] PROGMEM = {
0x07, 0x1c, 0x3c, 0x83, 0x80, 0x30, 0x01, 0x02, 0x30, 0x03, 0x40, 0x22,
0x85, 0x40, 0x00, 0x00, 0x28, 0x20, 0x10, 0x89, 0x34, 0x01, 0x0a, 0x38,
0x01, 0x02, 0x3c, 0x0b, 0xe3, 0x3f, 0x1f, 0xff, 0x3f };
#define cloud_3_width 14
#define cloud_3_height 8
const unsigned char cloud_3_bits[] PROGMEM = {
0x0e, 0x0f, 0x7a, 0x0f, 0xdf, 0x0f, 0xbb, 0x2f, 0xf9, 0x1d, 0xe4, 0x3d,
0xfc, 0x01, 0x1c, 0x00 };
#define cloud_4_width 22
#define cloud_4_height 11
const unsigned char cloud_4_bits[] PROGMEM = {
0xf8, 0xe3, 0x03, 0x7c, 0x7f, 0x0f, 0xfe, 0xfd, 0x0f, 0xfc, 0xbf, 0x1d,
0x7a, 0xbf, 0x3f, 0xff, 0xd7, 0x1f, 0xef, 0x76, 0x0b, 0xfe, 0xf5, 0x07,
0xfe, 0xfd, 0x03, 0xf4, 0x1c, 0x00, 0xe0, 0x00, 0x00 };
#define pad_width 47
#define pad_height 8
const unsigned char pad_bits[] PROGMEM = {
0x04, 0x00, 0x00, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10,
0x04, 0x00, 0x00, 0x00, 0x00, 0x10, 0xbb, 0xaa, 0xaa, 0xaa, 0xaa, 0x6e,
0x5f, 0x55, 0x55, 0x55, 0x55, 0x7d, 0xbf, 0xaa, 0xaa, 0xaa, 0xaa, 0x7e,
0x5f, 0x55, 0x55, 0x55, 0x55, 0x7d, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f };
#define flame_ver_2_width 5
#define flame_ver_2_height 7
const unsigned char flame_ver_2_bits[] PROGMEM = {
0x0a, 0x1f, 0x15, 0x0e, 0x0a, 0x00, 0x04 };
#define flame_ver_1_width 5
#define flame_ver_1_height 8
const unsigned char flame_ver_1_bits[] PROGMEM = {
0x0e, 0x15, 0x1b, 0x1f, 0x0a, 0x0e, 0x04, 0x04 };
#define flame_hor_2_width 7
#define flame_hor_2_height 5
const unsigned char flame_hor_2_bits[] PROGMEM = {
0x06, 0x1b, 0x4e, 0x1b, 0x06 };
#define rocket_ver_width 7
#define rocket_ver_height 25
const unsigned char rocket_ver_bits[] PROGMEM = {
0x08, 0x08, 0x1c, 0x1c, 0x3e, 0x3e, 0x36, 0x3e, 0x3e, 0x77, 0x7f, 0x7f,
0x77, 0x7f, 0x7f, 0x7f, 0x63, 0x1c, 0x63, 0x1c, 0x7f, 0x7f, 0x7f, 0x3e,
0x1c };
#define flame_hor_1_width 8
#define flame_hor_1_height 5
const unsigned char flame_hor_1_bits[] PROGMEM = {
0x0e, 0x3d, 0xeb, 0x3d, 0x0e };
#define cloud_1_width 13
#define cloud_1_height 8
const unsigned char cloud_1_bits[] PROGMEM = {
0xe0, 0x00, 0x7e, 0x0f, 0x72, 0x1e, 0xff, 0x1d, 0xbf, 0x1f, 0xf6, 0x0f,
0xb8, 0x03, 0x30, 0x00 };
#define cloud_2_width 21
#define cloud_2_height 11
const unsigned char cloud_2_bits[] PROGMEM = {
0x80, 0xde, 0x00, 0x70, 0xfe, 0x01, 0x7c, 0x7f, 0x03, 0xff, 0xff, 0x0f,
0xbc, 0x7b, 0x1f, 0xf0, 0xb3, 0x1b, 0xf0, 0xff, 0x1f, 0xb0, 0xef, 0x07,
0xc0, 0xff, 0x03, 0x80, 0x0f, 0x00, 0x00, 0x02, 0x00 };
#define rocket_diag_top_left_width 19
#define rocket_diag_top_left_height 19
const unsigned char rocket_diag_top_left_bits[] PROGMEM = {
0x01, 0x00, 0x00, 0x06, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x7c, 0x00, 0x00,
0xfc, 0x00, 0x00, 0xd8, 0x03, 0x00, 0xf8, 0x07, 0x00, 0x70, 0x0f, 0x00,
0xe0, 0x1f, 0x00, 0xe0, 0x3d, 0x00, 0xc0, 0x7f, 0x00, 0x80, 0xdf, 0x00,
0x00, 0xaf, 0x01, 0x00, 0x76, 0x03, 0x00, 0xac, 0x06, 0x00, 0xd8, 0x07,
0x00, 0xb0, 0x07, 0x00, 0xe0, 0x07, 0x00, 0xc0, 0x03 };
#define rocket_legs_3_width 21
#define rocket_legs_3_height 25
const unsigned char rocket_legs_3_bits[] PROGMEM = {
0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x0e, 0x00,
0x00, 0x1f, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x1f, 0x00,
0x00, 0x1f, 0x00, 0x80, 0x3b, 0x00, 0x80, 0x3f, 0x00, 0x80, 0x3f, 0x00,
0x80, 0x3b, 0x00, 0x80, 0x3f, 0x00, 0xc0, 0x7f, 0x00, 0xe0, 0xff, 0x00,
0xa0, 0xb1, 0x00, 0x10, 0x0e, 0x01, 0x90, 0x31, 0x01, 0x08, 0x0e, 0x02,
0x88, 0x3f, 0x02, 0x84, 0x3f, 0x04, 0x82, 0x3f, 0x08, 0x02, 0x1f, 0x08,
0x07, 0x0e, 0x1c };
#define rocket_legs_2_width 17
#define rocket_legs_2_height 25
const unsigned char rocket_legs_2_bits[] PROGMEM = {
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00,
0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x07, 0x00,
0xc0, 0x07, 0x00, 0xe0, 0x0e, 0x00, 0xe0, 0x0f, 0x00, 0xe0, 0x0f, 0x00,
0xe0, 0x0e, 0x00, 0xe0, 0x0f, 0x00, 0xf0, 0x1f, 0x00, 0xf8, 0x3f, 0x00,
0x68, 0x2c, 0x00, 0x84, 0x43, 0x00, 0x64, 0x4c, 0x00, 0x82, 0x83, 0x00,
0xe2, 0x8f, 0x00, 0xe1, 0x0f, 0x01, 0xe0, 0x0f, 0x00, 0xc0, 0x07, 0x00,
0x80, 0x03, 0x00 };
#define rocket_legs_1_width 13
#define rocket_legs_1_height 25
const unsigned char rocket_legs_1_bits[] PROGMEM = {
0x40, 0x00, 0x40, 0x00, 0xe0, 0x00, 0xe0, 0x00, 0xf0, 0x01, 0xf0, 0x01,
0xb0, 0x01, 0xf0, 0x01, 0xf0, 0x01, 0xb8, 0x03, 0xf8, 0x03, 0xf8, 0x03,
0xb8, 0x03, 0xf8, 0x03, 0xfc, 0x07, 0xfe, 0x0f, 0x1a, 0x0b, 0xe1, 0x10,
0x19, 0x13, 0xe0, 0x00, 0xf8, 0x03, 0xf8, 0x03, 0xf8, 0x03, 0xf0, 0x01,
0xe0, 0x00 };
#define rocket_hor_left_width 25
#define rocket_hor_left_height 7
const unsigned char rocket_hor_left_bits[] PROGMEM = {
0x00, 0xfe, 0x75, 0x00, 0xf0, 0xff, 0xf5, 0x00, 0xfc, 0xff, 0xfa, 0x01,
0xbf, 0xed, 0xfa, 0x01, 0xfc, 0xff, 0xfa, 0x01, 0xf0, 0xff, 0xf5, 0x00,
0x00, 0xfe, 0x75, 0x00 };
#define rocket_hor_right_width 25
#define rocket_hor_right_height 7
const unsigned char rocket_hor_right_bits[] PROGMEM = {
0x5c, 0xff, 0x00, 0x00, 0x5e, 0xff, 0x1f, 0x00, 0xbf, 0xfe, 0x7f, 0x00,
0xbf, 0x6e, 0xfb, 0x01, 0xbf, 0xfe, 0x7f, 0x00, 0x5e, 0xff, 0x1f, 0x00,
0x5c, 0xff, 0x00, 0x00 };
#define rocket_diag_top_right_width 19
#define rocket_diag_top_right_height 19
const unsigned char rocket_diag_top_right_bits[] PROGMEM = {
0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0xc0, 0x03, 0x00, 0xf0, 0x01,
0x00, 0xf8, 0x01, 0x00, 0xde, 0x00, 0x00, 0xff, 0x00, 0x80, 0x77, 0x00,
0xc0, 0x3f, 0x00, 0xe0, 0x3d, 0x00, 0xf0, 0x1f, 0x00, 0xd8, 0x0f, 0x00,
0xac, 0x07, 0x00, 0x76, 0x03, 0x00, 0xab, 0x01, 0x00, 0xdf, 0x00, 0x00,
0x6f, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x1e, 0x00, 0x00 };
#define sea_bed_width 128
#define sea_bed_height 12
const unsigned char sea_bed_bits[] PROGMEM = {
0x00, 0x00, 0xf8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, 0xec, 0x01, 0x00, 0x00, 0x8e,
0x43, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xa7, 0xff,
0x03, 0x00, 0xe0, 0xff, 0xff, 0x9c, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0xff, 0xf1, 0xff, 0x1f, 0x00, 0x3e, 0xfa, 0xfc, 0xf1, 0xff, 0x03,
0x00, 0x00, 0x00, 0x60, 0xc0, 0x7f, 0xa4, 0x2f, 0xfc, 0xff, 0xf3, 0x3b,
0x1c, 0xff, 0x43, 0x5e, 0x00, 0xd0, 0xfe, 0xfe, 0xa0, 0xfd, 0x06, 0xfc,
0xff, 0x7c, 0xfe, 0x0f, 0x0e, 0xfe, 0xf3, 0xff, 0xf7, 0xff, 0x7f, 0xff,
0xf0, 0xfd, 0x1f, 0xe0, 0xc7, 0x3f, 0xfc, 0x17, 0xff, 0xff, 0xff, 0xff,
0xff, 0xef, 0xf9, 0xff, 0xfc, 0xf8, 0xcf, 0xf8, 0x03, 0xf8, 0xff, 0x87,
0xff, 0x3f, 0xfc, 0xe7, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xfd, 0x90, 0x7f,
0xee, 0xff, 0xff, 0xff, 0xff, 0xbb, 0xc9, 0xc3, 0xff, 0xff, 0xff, 0xff,
0xff, 0x8f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff,
0xff, 0x91, 0xff, 0x7f, 0xfe, 0x8f, 0xfc, 0xe7, 0xe7, 0xc7, 0xfe, 0xfc,
0xff, 0x2c, 0xff, 0xbf, 0x4b, 0x01, 0xc6, 0xdf, 0x1e, 0xfa, 0x3f, 0xfe,
0x11, 0xc2, 0xe4, 0x04, 0xee, 0x35, 0xf3, 0x01, 0x44, 0x00, 0x00, 0xcc };
#define flame_diag_bottom_left_1_width 8
#define flame_diag_bottom_left_1_height 8
const unsigned char flame_diag_bottom_left_1_bits[] PROGMEM = {
0x20, 0x58, 0x9c, 0x74, 0x6c, 0x3a, 0x06, 0x01 };
#define flame_diag_bottom_left_2_width 6
#define flame_diag_bottom_left_2_height 6
const unsigned char flame_diag_bottom_left_2_bits[] PROGMEM = {
0x0c, 0x0a, 0x3e, 0x2e, 0x1c, 0x01 };
#define cloud_7_width 19
#define cloud_7_height 14
const unsigned char cloud_7_bits[] PROGMEM = {
0x00, 0x0d, 0x00, 0x00, 0x1f, 0x00, 0x08, 0xbf, 0x01, 0xff, 0xde, 0x03,
0x7c, 0xff, 0x07, 0x58, 0xbe, 0x06, 0x74, 0xff, 0x04, 0xfc, 0xcf, 0x04,
0xff, 0xff, 0x07, 0xb7, 0x1b, 0x00, 0xf0, 0x0f, 0x00, 0xc0, 0x0f, 0x00,
0xe0, 0x00, 0x00, 0x60, 0x00, 0x00 };
#define waves_width 30
#define waves_height 3
const unsigned char waves_bits[] PROGMEM = {
0x21, 0x84, 0x10, 0x02, 0x52, 0x4a, 0x29, 0x25, 0x8c, 0x31, 0xc6, 0x18 };
enum State {launching, pitching, orbiting};
State state = launching;
unsigned char * rocket_bits = rocket_legs_3_bits;
uint8_t rocket_width = rocket_legs_3_width;
uint8_t rocket_height = rocket_legs_3_height;
uint8_t rocket_x = (SCREEN_WIDTH-rocket_width)/2;
uint8_t rocket_y = SCREEN_HEIGHT-rocket_height;
unsigned char *flame_bits = flame_ver_1_bits;
uint8_t flame_width = flame_ver_1_width;
uint8_t flame_height = flame_ver_1_height;
uint8_t flame_x = (SCREEN_WIDTH-flame_width)/2;
uint8_t flame_y = SCREEN_HEIGHT;
const unsigned char waves_y = SCREEN_HEIGHT / 2;
int8_t waves_offset = 0;
uint8_t waves_repeat = 5;
void setup() {
u8g.setColorIndex(1);
}
uint8_t state_step = 0;
uint8_t step = 0;
void rocket_update() {
state_step++;
switch (state) {
case launching:
if (rocket_y < 1) {
state = pitching;
rocket_width = rocket_diag_top_right_width;
rocket_height = rocket_diag_top_right_height;
rocket_bits = rocket_diag_top_right_bits;
state_step = 0;
} else {
rocket_y--;
int8_t altitude = SCREEN_HEIGHT - sea_bed_height - (rocket_y + rocket_height);
if (altitude == 3) { // start folding the legs
rocket_bits = rocket_legs_2_bits;
rocket_width = rocket_legs_2_width;
rocket_height = rocket_legs_2_height;
rocket_x = (SCREEN_WIDTH-rocket_width)/2;
}
if (altitude == 6) { // fold the legs a bit more
rocket_bits = rocket_legs_1_bits;
rocket_width = rocket_legs_1_width;
rocket_height = rocket_legs_1_height;
rocket_x = (SCREEN_WIDTH-rocket_width)/2;
}
if (altitude == 9) { // fully fold the legs
rocket_bits = rocket_ver_bits;
rocket_width = rocket_ver_width;
rocket_height = rocket_ver_height;
rocket_x = (SCREEN_WIDTH-rocket_width)/2;
}
flame_y--;
if (step % 2) {
flame_bits = flame_ver_1_bits;
flame_width = flame_ver_1_width;
flame_height = flame_ver_1_height;
flame_x = (SCREEN_WIDTH-flame_width)/2;
} else {
flame_bits = flame_ver_2_bits;
flame_width = flame_ver_2_width;
flame_height = flame_ver_2_height;
flame_x = (SCREEN_WIDTH-flame_width)/2;
} // else
} // else
break;
case pitching:
if (state_step > 2) {
state = orbiting;
rocket_width = rocket_hor_right_width;
rocket_height = rocket_hor_right_height;
rocket_bits = rocket_hor_right_bits;
state_step = 0;
}
break;
case orbiting:
if (rocket_x + rocket_width > SCREEN_WIDTH) {
rocket_x = 0;
} else {
rocket_x++;
}
break;
} // switch
}
void rocket_draw() {
u8g.drawXBMP(rocket_x, rocket_y, rocket_width, rocket_height, rocket_bits);
if (state == launching) {
u8g.drawXBMP(flame_x, flame_y, flame_width, flame_height, flame_bits);
}
}
void sea_update() {
waves_offset = -(step % waves_repeat);
}
void sea_draw() {
for (int16_t waves_x = waves_offset; waves_x < SCREEN_WIDTH; waves_x += waves_width) {
u8g.drawXBMP(waves_x, waves_y, waves_width, waves_height, waves_bits);
}
u8g.drawXBMP(0, SCREEN_HEIGHT - sea_bed_height, sea_bed_width, sea_bed_height, sea_bed_bits);
}
void loop() {
step++;
sea_update();
rocket_update();
u8g.firstPage();
do {
//sea_draw();
rocket_draw();
} while ( u8g.nextPage() ); // u8g library specific, has to be there
//delay(250);
}