//Chicken Launcher
//	Version 1.1, Sep 9, 2016
//	By Jonathan Holmes (crait)
//
//	Website: http://www.crait.net/
//	Twitter: @crait
//
//Chicken Launcher is a fun lil' game I made for the Playstation Vita and ported to
//the Arduboy based off of Kitten Cannon. Shoot a chicken as far as you can, trying
//to hit springboards to give you a boost, but watch out for spikes! Your high score
//is recorded and saved. If you think you get a big high score, Tweet me a pic!
//
//
//
//1.1 - Sep 9, 2016
//	Switched to standard get()/put() for storing data into EEPROM
//	Fixed potential text issue
//	Removed title and instruction screen from repeating
//	Added the option to erase game data
//1.0 - Sep 8, 2016
//	Initial release

#include "Arduboy.h"
#include <EEPROM.h>

Arduboy arduboy;
#define BLACK 0
#define WHITE 1
#define OFF HIGH
#define ON LOW
#define SAVELOCATION (EEPROM_STORAGE_SPACE_START + 404)
#define CHAROFFSET 3
#define GAMESPEED 3


boolean buttonfree = true;
int gamestate = 0;

long highscore = 0;
int maxchickeny = 0;

boolean isdone = false;
boolean isflying = false;
int chickeny = 0;
long distance = 0;
int xvelocity = 0;
double yvelocity = 0;
int xvelocitychecker = 0;
int yvelocitychecker = 0;
int groundx = 0;
int cloudx = 200;
int cloudy = 20;

int objects[2][2] = {
	{0, 0},
	{0, 0}
};

int currentx;
int currenty;

const unsigned char title[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0xe0, 0xf0, 0xf8, 0x38, 0x1c, 0x0c, 
	0x0c, 0x1c, 0x18, 0x10, 0x00, 0x00, 0x00, 0xfe, 
	0xfe, 0x60, 0x20, 0x20, 0xfe, 0xfe, 0xfe, 0x00, 
	0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00, 0x70, 0xfc, 
	0xfe, 0x8e, 0x07, 0x03, 0x03, 0x06, 0x8e, 0x8c, 
	0x00, 0x00, 0x00, 0xff, 0xff, 0x78, 0xfc, 0xec, 
	0xc6, 0x86, 0x02, 0x00, 0x00, 0xfe, 0xfe, 0xfe, 
	0x26, 0x66, 0x66, 0x06, 0x00, 0x00, 0xfc, 0xfc, 
	0x78, 0xf0, 0xe0, 0xc0, 0xf8, 0xf8, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x80, 0x80, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 
	0x0e, 0x0c, 0x0c, 0x86, 0x87, 0x03, 0x00, 0x00, 
	0x00, 0x07, 0xc7, 0xc0, 0xc0, 0x00, 0x07, 0x07, 
	0xc3, 0xc0, 0x00, 0x00, 0xc3, 0xc3, 0xc0, 0x00, 
	0x00, 0x00, 0x01, 0xc3, 0x03, 0x03, 0x03, 0x83, 
	0x81, 0xc0, 0xc0, 0xc0, 0xc0, 0xc3, 0x83, 0x00, 
	0x00, 0x01, 0x03, 0xc3, 0xc3, 0x02, 0x00, 0x07, 
	0xc7, 0xc7, 0xc6, 0x06, 0x06, 0x06, 0x80, 0x80, 
	0x87, 0x87, 0x80, 0x80, 0x81, 0x03, 0x07, 0x8f, 
	0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0xff, 0xff, 0x80, 0x80, 0x80, 0x80, 
	0x00, 0xc0, 0xf0, 0x3c, 0x1f, 0x17, 0x1f, 0x7e, 
	0xf8, 0xe0, 0x00, 0x00, 0x7f, 0x7f, 0xff, 0xc0, 
	0xc0, 0xc0, 0x7f, 0x3f, 0x00, 0x00, 0xff, 0xff, 
	0x07, 0x0f, 0x1e, 0x3c, 0x78, 0xff, 0x00, 0x00, 
	0x0e, 0x3f, 0x7f, 0xe1, 0xc0, 0xc0, 0xc0, 0x61, 
	0x73, 0x31, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0c, 
	0x0c, 0x0c, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 
	0xff, 0xff, 0xcc, 0xcc, 0xcc, 0xc0, 0xc0, 0x00, 
	0x00, 0xff, 0xff, 0x19, 0x39, 0xff, 0xef, 0xc0, 
	0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 
};

const static unsigned char abutton[] PROGMEM = {
	0xfc, 0x42, 0xb9, 0x95, 0xb9, 0x42, 0xfc, 0x00, 
	0x00, 0x82, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00, 
	0x00, 0x01, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const unsigned char chicken1b[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x80, 0xe0, 0x20, 0x40, 0x40, 0x80, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x60, 0x90, 0x88, 0x44, 0x22, 0x02, 0x92, 
	0x92, 0x03, 0x03, 0x03, 0x07, 0x86, 0x0e, 0x1c, 
	0xfc, 0x47, 0x34, 0x14, 0x09, 0x89, 0x4c, 0x3c, 
	0x45, 0x56, 0x44, 0x38, 0x10, 0x10, 0x20, 0xc0, 
	0x86, 0x0a, 0x93, 0xa4, 0xac, 0xf2, 0x31, 0x30, 
	0x48, 0xc6, 0xa5, 0xa5, 0x29, 0x00, 0x00, 0x80, 
	0x80, 0x9d, 0x93, 0x48, 0x38, 0x28, 0x47, 0x42, 
	0x36, 0x0d, 0x05, 0x03, 0x03, 0x01, 0x01, 0x01, 
	0x03, 0x05, 0x09, 0x0a, 0x05, 0x02, 0x02, 0x01, 
	0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};

const unsigned char chicken1w[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x80, 0x80, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x60, 0x70, 0xb8, 0xdc, 0xfc, 0x6c, 
	0x6c, 0xfc, 0xfc, 0xfc, 0xf8, 0x78, 0xf0, 0xe0, 
	0x00, 0xb8, 0xcb, 0xeb, 0xf6, 0x76, 0xb3, 0xc3, 
	0xba, 0xa8, 0xb8, 0xc0, 0xe0, 0xe0, 0xc0, 0x00, 
	0x00, 0x04, 0x0c, 0x1b, 0x13, 0x0d, 0xce, 0xcf, 
	0xb7, 0x39, 0x5a, 0x5a, 0xd6, 0xff, 0xff, 0x7f, 
	0x7f, 0x62, 0x6c, 0x37, 0x07, 0x17, 0x38, 0x3d, 
	0x09, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x02, 0x06, 0x05, 0x02, 0x01, 0x01, 0x00, 
	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 chicken2b[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x80, 0x40, 0xe0, 0x10, 0x5c, 0x12, 0xe1, 0x01, 
	0x7f, 0x98, 0xe0, 0x40, 0x80, 0x80, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x16, 0x31, 
	0x4c, 0x40, 0xf3, 0x8f, 0xb1, 0xa1, 0xc2, 0x84, 
	0x62, 0x23, 0x42, 0x5c, 0x68, 0x0c, 0x13, 0xe0, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x78, 0xfe, 0x0f, 0x03, 0x81, 0x00, 0x00, 0x84, 
	0x38, 0x40, 0x70, 0x88, 0x00, 0x38, 0xc0, 0x71, 
	0xce, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x07, 0x08, 0x10, 0x21, 0x44, 0x48, 0x31, 
	0x22, 0xe4, 0x98, 0x48, 0x27, 0x1f, 0x04, 0xbc, 
	0xe9, 0x96, 0x48, 0x30, 0x00, 0x00, 0x00, 0x00, 
};

const unsigned char chicken2w[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x80, 0x00, 0xe0, 0xa0, 0xec, 0x1e, 0xfe, 
	0x80, 0x60, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0e, 
	0x33, 0x3f, 0x0c, 0x70, 0x4e, 0x5e, 0x3d, 0x7b, 
	0x9d, 0xdc, 0xbd, 0xa3, 0x97, 0xf3, 0xe0, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0xf0, 0xfc, 0x7e, 0xff, 0xff, 0x7b, 
	0xc7, 0xbf, 0x8f, 0x77, 0xff, 0xc7, 0x3f, 0x8e, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x07, 0x0f, 0x1e, 0x3b, 0x37, 0x0e, 
	0x1d, 0x1b, 0x67, 0x37, 0x18, 0x00, 0x03, 0x03, 
	0x16, 0x68, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 
};

const unsigned char chicken3b[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x20, 0x20, 0x30, 
	0xa8, 0x88, 0xc8, 0x68, 0x78, 0x88, 0xa8, 0x88, 
	0x70, 0x08, 0x84, 0x44, 0xf4, 0x18, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0x20, 0x10, 0x08, 
	0x8c, 0x44, 0x46, 0x27, 0x07, 0x83, 0x83, 0x05, 
	0x3a, 0xe5, 0x20, 0xd0, 0x80, 0x43, 0x26, 0xfc, 
	0x24, 0x22, 0x1f, 0x01, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x87, 0xc8, 0x7c, 0x22, 0x21, 
	0xf0, 0x88, 0x84, 0x42, 0xf0, 0xcc, 0xc4, 0xb2, 
	0x90, 0xc0, 0x60, 0x20, 0x30, 0x38, 0x0c, 0x03, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x03, 
	0x01, 0x06, 0x32, 0x2e, 0x23, 0x19, 0x06, 0x03, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};

const unsigned char chicken3w[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 
	0x50, 0x70, 0x30, 0x90, 0x80, 0x70, 0x50, 0x70, 
	0x80, 0xf0, 0x78, 0xb8, 0x08, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe0, 0xf0, 
	0x70, 0xb8, 0xb8, 0xd8, 0xf8, 0x7c, 0x7c, 0xfa, 
	0xc5, 0x1a, 0xdf, 0x2f, 0x7f, 0xbc, 0xd9, 0x03, 
	0x1b, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x07, 0x83, 0xdd, 0xde, 
	0x0f, 0x77, 0x7b, 0xbd, 0x0f, 0x33, 0x3b, 0x4d, 
	0x6f, 0x3f, 0x1f, 0x1f, 0x0f, 0x07, 0x03, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 
	0x00, 0x01, 0x01, 0x11, 0x1c, 0x06, 0x01, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 	
};

const unsigned char chicken4b[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x84, 
	0x18, 0x30, 0xe0, 0x20, 0x30, 0x28, 0x48, 0x88, 
	0x10, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x1c, 0x24, 0x28, 0x4a, 0xde, 0xb1, 
	0xf7, 0x79, 0x91, 0x91, 0x22, 0x64, 0x88, 0x00, 
	0x61, 0x06, 0x08, 0x00, 0x01, 0x9f, 0x7c, 0xf8, 
	0x10, 0x10, 0xe0, 0x80, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x03, 0x06, 0x3c, 0x31, 0x60, 0x40, 0x80, 0x80, 
	0x9a, 0xaa, 0xc7, 0x89, 0x81, 0xc2, 0x61, 0x22, 
	0xe7, 0x1c, 0x59, 0x10, 0xff, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x03, 0x04, 0x04, 0x05, 0x06, 0x0c, 
	0x14, 0x19, 0x11, 0x31, 0x22, 0x1c, 0x00, 0x00, 	
};

const unsigned char chicken4w[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 
	0xe0, 0xc0, 0x00, 0xc0, 0xc0, 0xd0, 0xb0, 0x70, 
	0xe0, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x18, 0x10, 0x30, 0x20, 0x4e, 
	0x08, 0x86, 0x6e, 0x6e, 0xdd, 0x9b, 0x77, 0xff, 
	0x9e, 0xf9, 0xf7, 0xff, 0xfe, 0x60, 0x80, 0x00, 
	0xe0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x01, 0x03, 0x0e, 0x1f, 0x3f, 0x7f, 0x7f, 
	0x65, 0x55, 0x38, 0x76, 0x7e, 0x3d, 0x9e, 0xdd, 
	0x18, 0xe3, 0xa6, 0xef, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x03, 0x03, 0x02, 0x01, 0x03, 
	0x0b, 0x06, 0x0e, 0x0e, 0x1c, 0x00, 0x00, 0x00, 
};

const unsigned char chicken5b[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x0c, 0x12, 0x69, 0x97, 
	0x3d, 0x20, 0xf8, 0xe4, 0x12, 0x19, 0x27, 0x44, 
	0x8c, 0x12, 0x22, 0x84, 0x08, 0x10, 0xe0, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 
	0x8e, 0x03, 0x1c, 0x00, 0x11, 0x0e, 0x02, 0x1c, 
	0x21, 0x00, 0x00, 0x81, 0xc0, 0xf0, 0x7f, 0x1e, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x07, 0xc8, 0x30, 0x16, 0x3a, 0x42, 0xc4, 0x46, 
	0x21, 0x43, 0x85, 0x8d, 0xf1, 0xcf, 0x02, 0x32, 
	0x8c, 0x68, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x01, 0x01, 0x02, 0x07, 0x19, 0xfe, 
	0x80, 0x87, 0x48, 0x3a, 0x08, 0x07, 0x02, 0x01, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};

const unsigned char chicken5w[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x16, 0x68, 
	0xc0, 0xc0, 0x00, 0x18, 0xec, 0xe6, 0xd8, 0xb8, 
	0x70, 0xec, 0xdc, 0x78, 0xf0, 0xe0, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x71, 0xfc, 0xe3, 0xff, 0xee, 0xf1, 0xfd, 0xe3, 
	0xde, 0xff, 0xff, 0x7e, 0x3f, 0x0f, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x07, 0xcf, 0xe9, 0xc5, 0xbd, 0x3b, 0xb9, 
	0xde, 0xbc, 0x7a, 0x72, 0x0e, 0x30, 0xfc, 0xcc, 
	0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x01, 
	0x7f, 0x78, 0x37, 0x05, 0x07, 0x00, 0x01, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};


const unsigned char cloud[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 
	0x80, 0x40, 0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x80, 0x70, 0x48, 0x24, 0x02, 0x01, 0x01, 
	0xc1, 0x21, 0x01, 0x02, 0x01, 0x01, 0x01, 0x40, 
	0x80, 0x00, 0x10, 0x20, 0x20, 0x10, 0x10, 0x00, 
	0x01, 0x01, 0x22, 0x4c, 0x70, 0x80, 0x00, 0x00, 
	0x07, 0x18, 0x20, 0x40, 0x40, 0x80, 0x90, 0x80, 
	0x21, 0x20, 0x40, 0x40, 0x40, 0x00, 0x00, 0x80, 
	0x80, 0x80, 0x80, 0x20, 0x00, 0x04, 0x00, 0x00, 
	0x00, 0x80, 0x80, 0x40, 0x00, 0xc0, 0x31, 0x0e, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 
	0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 
	0x02, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 
};

const unsigned char coopb[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 
	0x08, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x84, 
	0x44, 0xa4, 0x54, 0x2c, 0x14, 0x28, 0x50, 0xa0, 
	0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0xf8, 0x14, 0x12, 0x11, 0x10, 0x10, 0x10, 0x10, 
	0x10, 0x10, 0xf0, 0x08, 0xf4, 0x1a, 0x15, 0x12, 
	0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x11, 0x12, 0x15, 0x1a, 0xf4, 0x08, 0xf0, 0x00, 
	0xff, 0x00, 0x60, 0xbe, 0xa2, 0xbe, 0xbe, 0xbe, 
	0x60, 0x00, 0xff, 0x00, 0xff, 0xa1, 0xa1, 0xa1, 
	0x80, 0xf8, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 
	0xf8, 0x81, 0xa1, 0xa1, 0xff, 0x00, 0xff, 0x00, 
	0xff, 0xba, 0xee, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 
	0x2a, 0x2a, 0xff, 0x82, 0xfe, 0x2a, 0x2a, 0x2a, 
	0x2a, 0xef, 0xae, 0xee, 0x3a, 0x3a, 0xea, 0xea, 
	0xab, 0xaa, 0xae, 0xaa, 0xbe, 0xba, 0xff, 0x00, 
};

const unsigned char coopw[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 
	0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0x78, 
	0xb8, 0x58, 0xa8, 0xd0, 0xe8, 0xd0, 0xa0, 0x40, 
	0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0xe8, 0xec, 0xee, 0xef, 0xef, 0xef, 0xef, 
	0xef, 0xef, 0x0f, 0xf7, 0x0b, 0xe5, 0xea, 0xed, 
	0xee, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
	0xee, 0xed, 0xea, 0xe4, 0x08, 0xf0, 0x00, 0x00, 
	0x00, 0xff, 0x9f, 0x41, 0x5d, 0x41, 0x41, 0x41, 
	0x9f, 0xff, 0x00, 0xff, 0x00, 0x5e, 0x5e, 0x5e, 
	0x7f, 0x07, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 
	0x07, 0x7e, 0x5e, 0x5e, 0x00, 0xff, 0x00, 0x00, 
	0x00, 0x45, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 
	0x11, 0x11, 0x00, 0x7d, 0x01, 0x11, 0x11, 0x11, 
	0x11, 0x10, 0x51, 0x11, 0x05, 0x05, 0x15, 0x15, 
	0x54, 0x55, 0x51, 0x51, 0x41, 0x45, 0x00, 0x00, 
};

const unsigned char grass[] 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, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x80, 0x40, 0x00, 0x00, 0x00, 0x80, 0xe0, 
	0xc0, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 
	0x02, 0x04, 0x04, 0x05, 0x02, 0x02, 0x04, 0x00, 
	0x06, 0x03, 0x02, 0x04, 0x02, 0x04, 0x03, 0x02, 
	0x04, 0x02, 0x01, 0x01, 0x01, 0x02, 0x02, 0x05, 
	0x00, 0x01, 0x01, 0x02, 0x01, 0x01, 0x02, 0x01, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	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 scale[] PROGMEM = {
	0x08, 0x0c, 0xfe, 0x0f, 0xfe, 0x0c, 0x08, 0x00, 
	0x00, 0x00, 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, 0x00, 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, 0xff, 0x00, 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, 0x0f, 0x08, 0x3f, 0x28, 0x28, 0x28, 
	0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 
	0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 
	0x28, 0x28, 0x28, 0x28, 0xfe, 0x7c, 0x38, 0x10, 
};

const unsigned char spikesb[] PROGMEM = {
	0x00, 0xf0, 0x0f, 0x1c, 0xe0, 0x00, 0x00, 0x00, 
	0x00, 0xf0, 0x0f, 0x1c, 0xe0, 0x00, 0x00, 0x00, 
	0x00, 0xf0, 0x0f, 0x1c, 0xe0, 0x00, 0x00, 0x00, 
	0x00, 0xf0, 0x0f, 0x1c, 0xe0, 0x00, 0x00, 0x00, 
	0x3c, 0x43, 0x40, 0x40, 0x40, 0x47, 0x78, 0x00, 
	0x3c, 0x43, 0x40, 0x40, 0x40, 0x47, 0x78, 0x00, 
	0x3c, 0x43, 0x40, 0x40, 0x40, 0x47, 0x78, 0x00, 
	0x3c, 0x43, 0x40, 0x40, 0x40, 0x47, 0x78, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	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 spikesw[] PROGMEM = {
	0x00, 0x00, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x3c, 0x3f, 0x3f, 0x3f, 0x38, 0x00, 0x00, 
	0x00, 0x3c, 0x3f, 0x3f, 0x3f, 0x38, 0x00, 0x00, 
	0x00, 0x3c, 0x3f, 0x3f, 0x3f, 0x38, 0x00, 0x00, 
	0x00, 0x3c, 0x3f, 0x3f, 0x3f, 0x38, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	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 springb[] PROGMEM = {
	0x7e, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 
	0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 
	0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 
	0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x7e, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x38, 0x45, 0x45, 0x45, 0xe3, 0xe3, 0xe3, 
	0x71, 0x71, 0x71, 0x28, 0x28, 0x28, 0xc7, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x1e, 0x31, 0x31, 0x31, 0x38, 0x38, 0x38, 
	0x3c, 0x3c, 0x3c, 0x32, 0x32, 0x32, 0x21, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	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 springw[] PROGMEM = {
	0x00, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 
	0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 
	0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 
	0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x38, 0x38, 0x38, 0x1c, 0x1c, 0x1c, 
	0x8e, 0x8e, 0x8e, 0xc7, 0xc7, 0xc7, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x0e, 0x0e, 0x0e, 0x07, 0x07, 0x07, 
	0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};

void resetgame() {
	distance = 0;
	xvelocity = 0;
	yvelocity = 0;
	isdone = false;
	isflying = false;
	xvelocitychecker = 0;
	yvelocitychecker = 0;
	chickeny = 0;
	groundx = 0;
	objects[0][0] = rand() % 2;
	objects[0][1] = rand() % 100 + 145;
	objects[1][0] = rand() % 2;
	objects[1][1] = rand() % 200 + 400;
	maxchickeny = 0;
}

void setup() {
	arduboy.begin();
	arduboy.setFrameRate(60);
	arduboy.display();
	srand(7/8);
	EEPROM.get(SAVELOCATION, highscore);
	arduboy.clear();
	
}

void loop() {
	arduboy.clear();

	switch (gamestate) {
		case 0:	//Title
			if(arduboy.pressed(A_BUTTON) && buttonfree) {
				gamestate = 1;
				buttonfree = false;
			}
			
			for (currentx = 0; currentx < 128; currentx++) {
				for (currenty = 0; currenty < 45; currenty++) {
					arduboy.drawPixel(currentx, currenty, WHITE);
				}
			}
			
			arduboy.drawBitmap(0, 17, grass, 32, 32, BLACK);
			arduboy.drawBitmap(32, 17, grass, 32, 32, BLACK);
			arduboy.drawBitmap(64, 17, grass, 32, 32, BLACK);
			arduboy.drawBitmap(96, 17, grass, 32, 32, BLACK);
			arduboy.drawBitmap(128, 17, grass, 32, 32, BLACK);
			arduboy.drawBitmap(4, 10, coopw, 32, 32, WHITE);
			arduboy.drawBitmap(4, 10, coopb, 32, 32, BLACK);
			
			arduboy.drawBitmap(34, 5, title, 90, 24, BLACK);
			
			arduboy.setCursor(30, 47);
			arduboy.print("1.1 - @crait");
			arduboy.setCursor(20, 55);
			arduboy.print("Jonathan Holmes");
			break;
		case 1:	//Instructions
			arduboy.drawBitmap(110, 51, abutton, 16, 16, WHITE);
			arduboy.setCursor(0, 0);
			arduboy.print(F("     Instructions\n\nLaunch your chicken\nas far as you can!\nHitting springs will\ngive you a boost, but\navoid the spikes!"));
			if(arduboy.pressed(A_BUTTON) && buttonfree) {
				gamestate = 15;
				buttonfree = false;
			}
			break;
		case 15:	//Controls
			arduboy.drawBitmap(110, 51, abutton, 16, 16, WHITE);
			arduboy.setCursor(0, 0);
			arduboy.print(F("       Controls\n\n     A: Set power\nUp + B: Delete data"));
			if(arduboy.pressed(B_BUTTON) && arduboy.pressed(UP_BUTTON) && buttonfree) {
				gamestate = 16;
				buttonfree = false;
				highscore = 0;
				EEPROM.put(SAVELOCATION, highscore);
			}
			if(arduboy.pressed(A_BUTTON) && buttonfree) {
				gamestate = 2;
				buttonfree = false;
				resetgame();
			}
			break;
		case 16:	//Erased
			arduboy.drawBitmap(110, 51, abutton, 16, 16, WHITE);
			arduboy.setCursor(0, 0);
			arduboy.print(F("       Complete\n\nAll high score data\nwas erased..."));
			if(arduboy.pressed(A_BUTTON) && buttonfree) {
				gamestate = 0;
				buttonfree = false;
				resetgame();
			}
			break;
		case 2:	//Game
			if(isdone && arduboy.pressed(A_BUTTON) && buttonfree) {
				gamestate = 3;
				buttonfree = false;
				if(highscore < distance) {
					highscore = distance;
					EEPROM.put(SAVELOCATION, highscore);
				}
			}

			for (currentx = 0; currentx < 128; currentx++) {
				for (currenty = 0; currenty < 64; currenty++) {
					arduboy.drawPixel(currentx, currenty, WHITE);
				}
			}

			if(chickeny > maxchickeny) {
				maxchickeny = chickeny;
			}

			arduboy.drawBitmap(0 + groundx, 21 + chickeny, grass, 32, 32, BLACK);
			arduboy.drawBitmap(32 + groundx, 21 + chickeny, grass, 32, 32, BLACK);
			arduboy.drawBitmap(64 + groundx, 21 + chickeny, grass, 32, 32, BLACK);
			arduboy.drawBitmap(96 + groundx, 21 + chickeny, grass, 32, 32, BLACK);
			arduboy.drawBitmap(128 + groundx, 21 + chickeny, grass, 32, 32, BLACK);

			if(distance < 60) {
				arduboy.drawBitmap(4 - distance, 10 + chickeny, coopw, 32, 32, WHITE);
				arduboy.drawBitmap(4 - distance, 10 + chickeny, coopb, 32, 32, BLACK);
			}

			if(objects[0][1] < 128) {
				if(objects[0][0]) {
					//SPRING
					arduboy.drawBitmap(objects[0][1], 34 + chickeny, springw, 32, 32, WHITE);
					arduboy.drawBitmap(objects[0][1], 34 + chickeny, springb, 32, 32, BLACK);
				} else {
					//SPIKES
					arduboy.drawBitmap(objects[0][1], 34 + chickeny, spikesw, 32, 32, WHITE);
					arduboy.drawBitmap(objects[0][1], 34 + chickeny, spikesb, 32, 32, BLACK);
				}
			}
			
			if(isflying || isdone) {
				if(cloudy < 95) {
					cloudy = 95 + (0 - cloudy);
				}
				if(cloudx < 128 && chickeny - cloudy < 64 && chickeny - cloudy > 0) {
					arduboy.drawBitmap(cloudx, chickeny - cloudy, cloud, 32, 32, BLACK);
				}
				
				arduboy.setCursor(0, 0);
				arduboy.print(distance);

				if(yvelocity == xvelocity) {
					arduboy.drawBitmap(5, 18, chicken1w, 32, 32, WHITE);
					arduboy.drawBitmap(5, 18, chicken1b, 32, 32, BLACK);
					if(cloudx < -31) {
						cloudx = rand() % 31 + 129;
						cloudy = 30 - rand() % 60 + chickeny;
					}
				} else {
					if(xvelocity > yvelocity) {
						if(yvelocity < 0) {
							if(cloudx < -31) {
								cloudx = rand() % 200;
								cloudy = chickeny - rand() % 30 - 32;
							}
							if(yvelocity < 0 - (xvelocity + 10)) {
								arduboy.drawBitmap(5, 18, chicken5w, 32, 32, WHITE);
								arduboy.drawBitmap(5, 18, chicken5b, 32, 32, BLACK);
							} else {
								arduboy.drawBitmap(5, 18, chicken4w, 32, 32, WHITE);
								arduboy.drawBitmap(5, 18, chicken4b, 32, 32, BLACK);
							}
						} else {
							arduboy.drawBitmap(5, 18, chicken1w, 32, 32, WHITE);
							arduboy.drawBitmap(5, 18, chicken1b, 32, 32, BLACK);
							if(cloudx < -31) {
								cloudx = rand() % 31 + 129;
								cloudy = 30 - rand() % 60 + chickeny;
							}
						}
					}
					if(yvelocity > xvelocity) {
						if(cloudx < -31) {
							cloudx = rand() % 200;
							cloudy = chickeny + rand() % 30 + 32;
						}
						if(yvelocity > xvelocity + 10) {
							arduboy.drawBitmap(5, 18, chicken2w, 32, 32, WHITE);
							arduboy.drawBitmap(5, 18, chicken2b, 32, 32, BLACK);
						} else {
							arduboy.drawBitmap(5, 18, chicken3w, 32, 32, WHITE);
							arduboy.drawBitmap(5, 18, chicken3b, 32, 32, BLACK);
						}
					}
				}
			}

			if(!isdone) {
				if(isflying) {
					
					buttonfree = false;
					groundx -= xvelocity;
					groundx = groundx % 32;
					buttonfree = false;
					yvelocity -= 1;
					if(0 <= yvelocity) {
						yvelocity = yvelocity - ((1 / 16) * yvelocity);
					}
					if(0 > yvelocity) {
						yvelocity = yvelocity + (1 / 16) * yvelocity;
					}
					chickeny = yvelocity + chickeny;
					if (chickeny < 0) {
						chickeny = 0;
						yvelocity = 0 - .5 * yvelocity;
					}
					if (chickeny == 0 && xvelocity != 0) {
						xvelocity -= rand() % 1;
					}
					if (chickeny == 0 && yvelocity == 0 && xvelocity == 0) {
						isdone = true;
					}
					distance += xvelocity;
					if (chickeny < 5 && (objects[0][1] < 40 && objects[0][1] > 5)) {
						if (objects[0][0]) {
							//SPRING
							xvelocity += rand() % 5;
							yvelocity += rand() % 50 + 50;
						} else {
							//SPIKES
							isdone = true;
							isflying = false;
						}
					}
					objects[0][1] = objects[0][1] - xvelocity;
					objects[1][1] = objects[1][1] - xvelocity;
					cloudx -= xvelocity;
					if (objects[0][1] < -31) {
						objects[0][0] = objects[1][0];
						objects[0][1] = objects[1][1];

						int newobject = 0;
						int newobjectfinder = rand() % 5;
						switch(newobjectfinder) {
							case 1:
							case 2:
								//SPRING
								newobject = 0;
								break;
							case 3:
							case 4:
							case 5:
								//SPIKES
								newobject = 1;
								break;
						}
						objects[1][0] = newobject;
						objects[1][1] = rand() % 800 + 130;
					}
				} else {
					arduboy.drawBitmap(40, 20, scale, 32, 32, BLACK);
					if(xvelocity == 0) {
						if(xvelocitychecker < 25) {
							xvelocitychecker += 3;
						} else {
							xvelocitychecker = 0;
						}
						if(arduboy.pressed(A_BUTTON) && buttonfree) {
							buttonfree = false;
							xvelocity = xvelocitychecker;
						}
					}
					if(xvelocity != 0 && yvelocity == 0) {
						if(yvelocitychecker < 25) {
							yvelocitychecker += 3;
						} else {
							yvelocitychecker = 0;
						}
						if(arduboy.pressed(A_BUTTON) && buttonfree) {
							buttonfree = false;
							yvelocity = yvelocitychecker;
							
							xvelocity += 5 + rand() % 3;
							yvelocity += 5 + rand() % 3;
							isflying = true;
							chickeny = 0;
						}
					}
	
					arduboy.drawLine(43, 47, 43, 47 - yvelocitychecker, BLACK);
					arduboy.drawLine(44, 48, 44 + xvelocitychecker, 48, BLACK);
				}
			}
			
			break;
		case 3:	//Game Over
			arduboy.drawBitmap(110, 51, abutton, 16, 16, WHITE);
			
			arduboy.setCursor(41, 9);
			arduboy.print("GAME OVER");
			if(highscore == distance) {
				arduboy.setCursor(22, 30);
				arduboy.print(F("NEW HIGH SCORE!"));
				arduboy.setCursor(48, 38);
				arduboy.print(highscore);
			} else {
				arduboy.setCursor(30, 19);
				arduboy.print(F("SCORE: "));
				arduboy.print(distance);
				arduboy.setCursor(10, 34);
				arduboy.print(F("HIGH SCORE: "));
				arduboy.print(highscore);
			}

			if(arduboy.pressed(A_BUTTON) && buttonfree) {
				gamestate = 2;
				resetgame();
				buttonfree = false;
			}
			break;
	}
	
	if(!arduboy.pressed(A_BUTTON)) {
		buttonfree = true;
	}
	
	arduboy.display();
}
