Skip to content

Instantly share code, notes, and snippets.

@Gitonym
Created April 28, 2018 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gitonym/30718996c12ea4b918b0daf47d0409b3 to your computer and use it in GitHub Desktop.
Save Gitonym/30718996c12ea4b918b0daf47d0409b3 to your computer and use it in GitHub Desktop.
My 2nd Arduboy game in which you have to shoot asteroids befor they crush you!
#include <Tinyfont.h>
#include <ArduboyTones.h>
#include <Arduboy2.h>
Arduboy2 arduboy;
ArduboyTones sound(arduboy.audio.enabled);
Tinyfont tinyfont = Tinyfont(arduboy.sBuffer, Arduboy2::width(), Arduboy2::height());
const unsigned char gameOver[] PROGMEM = {
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, 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,
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, 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,
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, 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,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x01, 0xf9, 0xf9, 0xf9, 0xf9, 0x09,
0xc9, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0xcf, 0xcf, 0xcf, 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x01, 0x01, 0xf9, 0xf9, 0xf9, 0xf9, 0x09, 0x09, 0x09, 0x09, 0x09, 0xf9, 0x01, 0x01, 0xff,
0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x01, 0xf9, 0xf1, 0xe3, 0xc7, 0x8f,
0x8e, 0x44, 0x22, 0x11, 0xf9, 0x01, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x01, 0x01, 0x79, 0x79, 0x79, 0x79, 0x49, 0x49, 0x49, 0xc9, 0xc9, 0xc9, 0xc9, 0x09, 0x0f,
0x0f, 0x0f, 0x0f, 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, 0xff, 0x80, 0x80, 0x9f, 0x9f, 0x9f, 0x9f, 0x90,
0x93, 0x92, 0x92, 0x92, 0x9e, 0x80, 0x80, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x80, 0x80, 0xf3, 0xf3, 0xf3, 0xf3, 0x12, 0x12, 0x12, 0x12, 0x12, 0xf3, 0x80, 0x80, 0xff,
0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x80, 0x80, 0xff, 0xff, 0xff, 0xff, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0x80, 0x80, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x80, 0x80, 0x9e, 0x9e, 0x9e, 0x9e, 0x92, 0x92, 0x92, 0x93, 0x93, 0x93, 0x93, 0x90, 0xf0,
0xf0, 0xf0, 0xf0, 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, 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, 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, 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, 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,
0xff, 0x01, 0x01, 0xf9, 0xf9, 0xf9, 0xf9, 0x09, 0x09, 0x09, 0x09, 0x09, 0xf9, 0x01, 0x01, 0xff,
0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0d, 0x31, 0xc1, 0x07, 0x1f, 0x7f, 0xff,
0xf8, 0x60, 0x18, 0x07, 0xc1, 0xf1, 0xfd, 0xff, 0x3f, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x01, 0x01, 0x79, 0x79, 0x79, 0x79, 0x49, 0x49, 0x49, 0xc9, 0xc9, 0xc9, 0xc9, 0x09, 0x0f,
0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x01, 0x19, 0x19, 0x19, 0x19, 0x19,
0x99, 0x99, 0x99, 0x99, 0x99, 0x81, 0x81, 0xff, 0xff, 0xff, 0xff, 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,
0xff, 0x80, 0x80, 0x9f, 0x9f, 0x9f, 0x9f, 0x90, 0x90, 0x90, 0x90, 0x90, 0x9f, 0x80, 0x80, 0xff,
0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0c, 0x30, 0xc1,
0xc1, 0xf0, 0xfc, 0xff, 0x3f, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x80, 0x80, 0x9e, 0x9e, 0x9e, 0x9e, 0x92, 0x92, 0x92, 0x93, 0x93, 0x93, 0x93, 0x90, 0xf0,
0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x80, 0x80, 0xff, 0xff, 0xfe, 0xfc, 0x08,
0x11, 0x23, 0x47, 0x8f, 0x9e, 0xbc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 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, 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const unsigned char xhaku[] PROGMEM = {
0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81, 0xff, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xff,
0xc0, 0x30, 0x1c, 0x13, 0x13, 0x1c, 0x30, 0xc0, 0xff, 0x18, 0x24, 0x24, 0x42, 0x42, 0x81, 0x81,
0xff, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff,
};
const unsigned char asteroidBelt[] PROGMEM = {
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, 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,
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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x01, 0x01, 0x01, 0xf1, 0x91, 0x91,
0x91, 0x91, 0xf1, 0x01, 0x01, 0x01, 0x01, 0xff, 0x00, 0xff, 0x01, 0x01, 0x01, 0x71, 0x51, 0x51,
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0xdf, 0x00, 0x1f, 0x11, 0x11, 0x11, 0x11, 0xf1, 0x01,
0x01, 0x01, 0xf1, 0x11, 0x11, 0x11, 0x11, 0x1f, 0x00, 0xff, 0x01, 0x01, 0x01, 0x71, 0x51, 0x51,
0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0xdf, 0x00, 0xff, 0x01, 0x01, 0x01, 0x79, 0x49, 0x49,
0x49, 0x49, 0x49, 0x79, 0x01, 0x01, 0x01, 0xff, 0x00, 0xff, 0x01, 0x01, 0x01, 0xf1, 0x11, 0x11,
0x11, 0x11, 0x11, 0xf1, 0x01, 0x01, 0x01, 0xff, 0x00, 0xff, 0x01, 0x01, 0x01, 0xff, 0x00, 0xff,
0x01, 0x01, 0x01, 0xf1, 0x11, 0x11, 0x11, 0x11, 0x11, 0x21, 0xc1, 0x01, 0x02, 0x0c, 0xf0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x80, 0x80, 0x80, 0xf8, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0xf8, 0x80, 0x80, 0x80, 0xff, 0x00, 0xfb, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
0x8a, 0x8a, 0x8a, 0x8e, 0x80, 0x80, 0x80, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x80,
0x80, 0x80, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x80, 0x80, 0x80, 0x8e, 0x8a, 0x8a,
0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0xfb, 0x00, 0xff, 0x80, 0x80, 0x80, 0xfc, 0x04, 0x04,
0xfc, 0x80, 0x80, 0x80, 0xfc, 0x04, 0x04, 0x07, 0x00, 0xff, 0x80, 0x80, 0x80, 0x8f, 0x88, 0x88,
0x88, 0x88, 0x88, 0x8f, 0x80, 0x80, 0x80, 0xff, 0x00, 0xff, 0x80, 0x80, 0x80, 0xff, 0x00, 0xff,
0x80, 0x80, 0x80, 0x8f, 0x88, 0x88, 0x88, 0x88, 0x88, 0x84, 0x83, 0x80, 0x40, 0x30, 0x0f, 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, 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, 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, 0xc0, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0xff, 0x01, 0x01, 0x01, 0x79, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x31, 0x01, 0x82, 0x7c, 0x04,
0xff, 0x01, 0x01, 0x01, 0x71, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0x51, 0xdf,
0x08, 0xff, 0x01, 0x01, 0x01, 0xff, 0x88, 0x48, 0x88, 0x08, 0x08, 0x08, 0x1f, 0x11, 0x91, 0x51,
0x91, 0xf1, 0x01, 0x01, 0x01, 0xf1, 0x91, 0x51, 0x91, 0x11, 0x1f, 0x08, 0x08, 0x08, 0x88, 0x48,
0x88, 0x08, 0x08, 0x08, 0x08, 0x08, 0x88, 0x48, 0x88, 0x08, 0x08, 0x08, 0x08, 0xff, 0x80, 0xff,
0x89, 0x89, 0x89, 0x89, 0x89, 0x89, 0x49, 0x89, 0x0f, 0x08, 0x0f, 0x08, 0x08, 0x88, 0x48, 0x88,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0xff, 0x80, 0x80, 0x80, 0x9e, 0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0x8c, 0x80, 0x41, 0x3e, 0x20,
0xff, 0x80, 0x80, 0x80, 0x8e, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0xfb,
0x10, 0xff, 0x80, 0x80, 0x80, 0x8f, 0x89, 0x8a, 0x89, 0x88, 0x88, 0x88, 0x88, 0x88, 0x89, 0xfa,
0x11, 0xff, 0x80, 0x80, 0x80, 0xff, 0x11, 0x12, 0x11, 0x10, 0x10, 0x10, 0x10, 0x10, 0x11, 0x12,
0x11, 0x10, 0x10, 0x10, 0x10, 0x10, 0x11, 0x12, 0x11, 0x10, 0x10, 0x10, 0x10, 0xff, 0x01, 0xff,
0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x92, 0x91, 0xf0, 0x10, 0xf0, 0x10, 0x10, 0x11, 0x12, 0x11,
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, 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,
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, 0x03, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 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, 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const unsigned char bomb [] PROGMEM = {
0x7e, 0x81, 0xbd, 0xa9, 0xa9, 0xb9, 0x81, 0x7e,
};
int screen = 0;
int playerDir = 0;
int lives = 5;
int score = 0;
int bombs = 1;
bool bulletState[10] = {false, false, false, false, false, false, false, false, false, false};
int bulletDir[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int bulletLen[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
bool enemyState[10] = {false, false, false, false, false, false, false, false, false, false};
int enemyDir[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int enemyLen[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int enemyBound[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int enemySpeed[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
bool powerupState = false;
int powerupX = 0;
int powerupY = 0;
int powerupLen = 0;
int powerupDir = 0;
int bombRad = 100;
void setup() {
arduboy.begin();
arduboy.setFrameRate(30);
arduboy.initRandomSeed();
arduboy.clear();
}
void loop() {
if (!(arduboy.nextFrame())) {
return;
}
arduboy.pollButtons();
if (screen == 0) {
arduboy.drawBitmap(0, -5, asteroidBelt, 128, 64, WHITE);
if (arduboy.everyXFrames(30)) {
arduboy.setCursor(15, 46);
arduboy.print("-Push any Button-");
tinyfont.setCursor(16, 56);
tinyfont.print("UP+DOWN TOGGLE SOUND");
}
if (arduboy.everyXFrames(60)) {
arduboy.fillRect(0, 46, 128, 16, BLACK);
}
toggleSound();
if (arduboy.justPressed(A_BUTTON) or arduboy.justPressed(B_BUTTON) or arduboy.justPressed(LEFT_BUTTON) or arduboy.justPressed(RIGHT_BUTTON)) {
screen += 1;
arduboy.clear();
}
}
if (screen == 1) {
if (arduboy.justPressed(A_BUTTON)) {
shootBullet();
}
if (arduboy.justPressed(B_BUTTON)) {
useBomb();
}
if (arduboy.everyXFrames(60 - (score / 20))) {
spawnEnemy();
}
if (arduboy.everyXFrames(1000)) {
spawnPowerup();
}
toggleSound();
movePlayer();
moveBullet();
moveEnemy();
movePowerup();
drawBombs();
drawScore();
drawLives();
drawPlayer(playerDir);
drawBullet();
drawEnemy();
drawPowerup();
drawBomb();
destroyBullet();
destroyEnemy();
destroyPowerup();
killEnemy();
killPlayer();
killPowerup();
}
if (screen == 2) {
drawScore();
arduboy.drawBitmap(0, 0, gameOver, 128, 64, WHITE);
arduboy.drawPixel(random(0, 128), random(5, 64), WHITE);
arduboy.drawPixel(random(0, 128), random(5, 64), WHITE);
if (arduboy.everyXFrames(3)) {
arduboy.drawPixel(random(43, 85), random(51, 61), WHITE);
}
arduboy.drawBitmap(44, 52, xhaku, 40, 8, BLACK);
if (arduboy.justPressed(A_BUTTON) or arduboy.justPressed(B_BUTTON) or arduboy.justPressed(UP_BUTTON) or arduboy.justPressed(DOWN_BUTTON) or arduboy.justPressed(LEFT_BUTTON) or arduboy.justPressed(RIGHT_BUTTON)) {
lives = 5;
score = 0;
bombs = 1;
for (int i = 0; i < 10; i++) {
enemyState[i] = 0;
bulletState[i] = 0;
}
arduboy.clear();
screen = 0;
}
}
arduboy.display();
}
int lengthdirX(int len, int dir) {
dir = dir % 360;
if (dir < 90) {
return (cos(dir * (3.14159265359f / 180.0f)) * len);
}
if (dir > 90 and dir < 180) {
return -(cos(dir * (3.14159265359f / 180.0f)) * len);
}
if (dir > 180 and dir < 270) {
return -(cos(dir * (3.14159265359f / 180.0f)) * len);
}
if (dir > 270) {
return (cos(dir * (3.14159265359f / 180.0f)) * len);
}
if (dir == 0 or dir == 360) {
return len;
}
if (dir == 90 or dir == 270) {
return 0;
}
if (dir == 180) {
return - len;
}
}
int lengthdirY(int len, int dir) {
dir = dir % 360;
if (dir < 90) {
return -(sin(dir * (3.14159265359f / 180.0f)) * len);
}
if (dir > 90 and dir < 180) {
return -(sin(dir * (3.14159265359f / 180.0f)) * len);
}
if (dir > 180 and dir < 270) {
return (sin(dir * (3.14159265359f / 180.0f)) * len);
}
if (dir > 270) {
return (sin(dir * (3.14159265359f / 180.0f)) * len);
}
if (dir == 0 or dir == 360 or dir == 180) {
return 0;
}
if (dir == 90) {
return - len;
}
if (dir == 270) {
return len;
}
}
void drawPlayer(int dir) {
arduboy.drawCircle(64, 32, 5, WHITE);
arduboy.drawLine(64, 32, 64 + lengthdirX(10, dir), 32 + lengthdirY(10, dir), WHITE);
}
void movePlayer() {
arduboy.drawLine(64, 32, 64 + lengthdirX(10, playerDir), 32 + lengthdirY(10, playerDir), BLACK);
if (arduboy.pressed(RIGHT_BUTTON)) {
playerDir -= 8;
}
if (arduboy.pressed(LEFT_BUTTON)) {
playerDir += 8;
if (playerDir > 0) {
playerDir = playerDir - 360;;
}
}
}
void shootBullet() {
for (int i = 0; i < 10; i++) {
if (!(bulletState[i])) {
bulletState[i] = true;
bulletDir[i] = playerDir;
bulletLen[i] = 10;
sound.tone(750, 75);
return;
}
}
}
void moveBullet() {
for (int i = 0; i < 10; i++) {
if (bulletState[i]) {
arduboy.drawLine(64 + lengthdirX(bulletLen[i], bulletDir[i]), 32 + lengthdirY(bulletLen[i], bulletDir[i]), 64 + lengthdirX(bulletLen[i] + 5, bulletDir[i]), 32 + lengthdirY(bulletLen[i] + 5, bulletDir[i]), BLACK);
bulletLen[i] += 1;
}
}
}
void destroyBullet() {
for (int i = 0; i < 10; i++) {
if (bulletState[i]) {
if (bulletLen[i] > 64) {
arduboy.drawLine(64 + lengthdirX(bulletLen[i], bulletDir[i]), 32 + lengthdirY(bulletLen[i], bulletDir[i]), 64 + lengthdirX(bulletLen[i] + 5, bulletDir[i]), 32 + lengthdirY(bulletLen[i] + 5, bulletDir[i]), BLACK);
bulletState[i] = false;
}
}
}
}
void drawBullet() {
for (int i = 0; i < 10; i++) {
if (bulletState[i]) {
arduboy.drawLine(64 + lengthdirX(bulletLen[i], bulletDir[i]), 32 + lengthdirY(bulletLen[i], bulletDir[i]), 64 + lengthdirX(bulletLen[i] + 5, bulletDir[i]), 32 + lengthdirY(bulletLen[i] + 5, bulletDir[i]), WHITE);
}
}
}
void spawnEnemy() {
for (int i = 0; i < 10; i++) {
if (!(enemyState[i])) {
enemyState[i] = true;
enemyDir[i] = random(-360 , 0);
enemyLen[i] = 70;
if ((enemyDir[i] < -225 and enemyDir[i] > -315) or (enemyDir[i] < -45 and enemyDir[i] > -135)) {
enemySpeed[i] = 1;
} else {
enemySpeed[i] = random(1, 3);
}
enemyBound[i] = random(0, 3);
return;
}
}
}
void moveEnemy() {
for (int i = 0; i < 10; i++) {
if (enemyState[i]) {
arduboy.drawCircle(64 + lengthdirX(enemyLen[i], enemyDir[i]), 32 + lengthdirY(enemyLen[i], enemyDir[i]), 4, BLACK);
if (enemySpeed[i] == 1) {
if (arduboy.everyXFrames(2)) {
enemyLen[i] -= 1;
}
}
if (enemySpeed[i] == 2) {
enemyLen[i] -= 1;
}
if (enemyBound[i] == 0) {
enemyDir[i] -= 1;
}
if (enemyBound[i] == 2) {
enemyDir[i] += 1;
}
}
}
}
void drawEnemy() {
for (int i = 0; i < 10; i++) {
if (enemyState[i]) {
arduboy.drawCircle(64 + lengthdirX(enemyLen[i], enemyDir[i]), 32 + lengthdirY(enemyLen[i], enemyDir[i]), 4, WHITE);
}
}
}
void destroyEnemy() {
for (int i = 0; i < 10; i++) {
if (enemyState[i]) {
if (enemyLen[i] < 1) {
arduboy.drawCircle(64 + lengthdirX(enemyLen[i], enemyDir[i]), 32 + lengthdirY(enemyLen[i], enemyDir[i]), 4, BLACK);
enemyState[i] = false;
lives -= 1;
sound.tone(250, 150, 100, 75);
}
}
}
}
void killEnemy() {
for (int i = 0; i < 10; i++) {
if (enemyState[i]) {
Rect rectEnemy{60 + lengthdirX(enemyLen[i], enemyDir[i]), 28 + lengthdirY(enemyLen[i], enemyDir[i]), 8, 8};
for (int j = 0; j < 10; j++) {
if (bulletState[j]) {
Point pointEnemy{64 + lengthdirX(bulletLen[j] + 5, bulletDir[j]), 32 + lengthdirY(bulletLen[j] + 5, bulletDir[j])};
if (arduboy.collide(pointEnemy, rectEnemy)) {
arduboy.drawCircle(64 + lengthdirX(enemyLen[i], enemyDir[i]), 32 + lengthdirY(enemyLen[i], enemyDir[i]), 4, BLACK);
enemyState[i] = false;
arduboy.drawLine(64 + lengthdirX(bulletLen[j], bulletDir[j]), 32 + lengthdirY(bulletLen[j], bulletDir[j]), 64 + lengthdirX(bulletLen[j] + 5, bulletDir[j]), 32 + lengthdirY(bulletLen[j] + 5, bulletDir[j]), BLACK);
bulletState[j] = false;
score += 10;
sound.tone(100, 75);
}
}
}
}
}
}
void drawScore() {
arduboy.fillRect(0, 0, 128, 4, BLACK);
tinyfont.setCursor(0, 0);
tinyfont.print("SCORE:");
tinyfont.setCursor(29, 0);
tinyfont.print(score);
}
void drawLives() {
tinyfont.setCursor(94, 0);
tinyfont.print("LIVES:");
tinyfont.setCursor(123, 0);
tinyfont.print(lives);
}
void drawBombs() {
arduboy.fillRect(94, 5, 40, 9, BLACK);
tinyfont.setCursor(94, 5);
tinyfont.print("BOMBS:");
tinyfont.setCursor(123, 5);
tinyfont.print(bombs);
}
void killPlayer() {
if (lives < 1) {
screen += 1;
sound.tone(300, 150, 150, 150, 50, 150);
delay(1000);
arduboy.clear();
}
}
void spawnPowerup() {
if (!(powerupState)) {
if (bombs < 9) {
powerupX = random(0, 128);
powerupY = random(0, 64);
powerupLen = 150;
powerupDir = random(-360, 0);
powerupState = true;
}
}
}
void drawPowerup() {
if (powerupState) {
arduboy.drawBitmap(powerupX + lengthdirX(powerupLen, powerupDir), powerupY + lengthdirY(powerupLen, powerupDir), bomb, 8, 8, WHITE);
}
}
void movePowerup() {
if (powerupState) {
if (arduboy.everyXFrames(2)) {
arduboy.drawBitmap(powerupX + lengthdirX(powerupLen, powerupDir), powerupY + lengthdirY(powerupLen, powerupDir), bomb, 8, 8, BLACK);
powerupLen -= 1;
}
}
}
void destroyPowerup() {
if (powerupState) {
if (powerupLen < -150) {
powerupState = false;
}
}
}
void killPowerup() {
if (powerupState) {
for (int j = 0; j < 10; j++) {
if (bulletState[j]) {
Point pointPowerup{64 + lengthdirX(bulletLen[j] + 5, bulletDir[j]), 32 + lengthdirY(bulletLen[j] + 5, bulletDir[j])};
Rect rectPowerup{powerupX + lengthdirX(powerupLen, powerupDir), powerupY + lengthdirY(powerupLen, powerupDir), 8, 8};
if (arduboy.collide(pointPowerup, rectPowerup)) {
arduboy.drawBitmap(powerupX + lengthdirX(powerupLen, powerupDir), powerupY + lengthdirY(powerupLen, powerupDir), bomb, 8, 8, BLACK);
powerupState = false;
arduboy.drawLine(64 + lengthdirX(bulletLen[j], bulletDir[j]), 32 + lengthdirY(bulletLen[j], bulletDir[j]), 64 + lengthdirX(bulletLen[j] + 5, bulletDir[j]), 32 + lengthdirY(bulletLen[j] + 5, bulletDir[j]), BLACK);
bulletState[j] = false;
bombs += 1;
sound.tone(300, 150, 500, 150, 1000, 150);
}
}
}
}
}
void useBomb() {
if (bombs > 0) {
for (int i = 0; i < 10; i++) {
arduboy.drawCircle(64 + lengthdirX(enemyLen[i], enemyDir[i]), 32 + lengthdirY(enemyLen[i], enemyDir[i]), 4, BLACK);
enemyState[i] = false;
}
bombs -= 1;
bombRad = 0;
sound.tone(300, 150, 700, 150, 50, 150);
}
}
void drawBomb() {
if (bombRad < 100) {
arduboy.drawCircle(64, 32, bombRad, BLACK);
bombRad += 3;
arduboy.drawCircle(64, 32, bombRad, WHITE);
}
}
void toggleSound() {
if ((arduboy.justPressed(UP_BUTTON) and arduboy.pressed(DOWN_BUTTON)) or (arduboy.justPressed(DOWN_BUTTON) and arduboy.pressed(UP_BUTTON))) {
arduboy.audio.toggle();
sound.tone(1000, 50);
arduboy.audio.saveOnOff();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment