Okay, so I have (mostly) scrapped this initial game design in favor of reducing as much as I can, and because i would have had to have rewritten most of it anyway using functions, but I now have something thats still very similar, which I was hoping i might be able to merge with my other game (but, worst case scenario, could still use for something else).
All that being said, the most recent thing I did with my other game Ive also implemented here, which is the infinite background looping, and this is something that takes up the most resources and im hoping to slim down but am not sure how. I was thinking image compression might help, although between the two games i would already be at my RAM limitations, unless there was a way to do this that would also help cut down on RAM (and i dont know enough about compression to know).
If just looking into compression and seeing how i might implement it would be the way to go then I can do the legwork myself, im just not sure if thats the direction i should take. Here is my currrent code (sorry for the length, been having difficulty figuring out how to get header files working, but thats something i have been reading about in between posts):
#include <Arduboy2.h>
Arduboy2 arduboy;
uint8_t playerFrame = 0;
constexpr uint8_t worldWidth = 128;
constexpr uint8_t worldHeight = 64;
constexpr uint8_t tileWidth = 128;
constexpr uint8_t tileHeight = 64;
uint8_t const *playerSprite = nullptr;
uint8_t const *playerMask = nullptr;
struct PointXY {
int x = 0;
int y = 0;
};
PROGMEM const unsigned char planetBackgroundTile1[] = {
// Bitmap Image. No transparency
// Width: 64 Height: 64
128, 64,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 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, 0x04, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x08, 0x10, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
PROGMEM const unsigned char ardunautDown[] = {
// Bitmap Image. No transparency
// Width: 7 Height: 8
7, 8,
0x00, 0x18, 0xFE, 0x3B, 0xFE, 0x18, 0x00,
0x00, 0x18, 0xFE, 0x3B, 0x7E, 0x38, 0x00,
0x00, 0x18, 0xFE, 0x3B, 0xFE, 0x18, 0x00,
0x00, 0x38, 0x7E, 0x3B, 0xFE, 0x18, 0x00,
};
PROGMEM const unsigned char ardunautUp[] = {
// Bitmap Image. No transparency
// Width: 7 Height: 8
7, 8,
0x00, 0x18, 0xFE, 0x3F, 0xFE, 0x18, 0x00,
0x00, 0x18, 0xFE, 0x3F, 0x7E, 0x38, 0x00,
0x00, 0x18, 0xFE, 0x3F, 0xFE, 0x18, 0x00,
0x00, 0x38, 0x7E, 0x3F, 0xFE, 0x18, 0x00,
};
PROGMEM const unsigned char ardunautLeft[] = {
// Bitmap Image. No transparency
// Width: 7 Height: 8
7, 8,
0x00, 0x00, 0x3E, 0xE3, 0x3E, 0x1C, 0x00,
0x00, 0x48, 0xB6, 0x73, 0xBE, 0x1C, 0x00,
0x00, 0xC0, 0x3E, 0x2B, 0x76, 0x9C, 0x00,
0x00, 0x48, 0xB6, 0x73, 0xBE, 0x1C, 0x00,
};
PROGMEM const unsigned char ardunautRight[] = {
// Bitmap Image. No transparency
// Width: 7 Height: 8
7, 8,
0x00, 0x1C, 0x3E, 0xE3, 0x3E, 0x00, 0x00,
0x00, 0x9C, 0x7E, 0x33, 0xB6, 0x48, 0x00,
0x00, 0x1C, 0xB6, 0x6B, 0x3E, 0xC8, 0x00,
0x00, 0x9C, 0x7E, 0x33, 0xB6, 0x48, 0x00,
};
PROGMEM const unsigned char ardunautDownMask[] = {
// Bitmap Image. No transparency
// Width: 7 Height: 8
7, 8,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
};
PROGMEM const unsigned char ardunautRightMask[] = {
// Bitmap Image. No transparency
// Width: 7 Height: 8
7, 8,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
};
PointXY planetBackground1;
PointXY planetBackground2;
PointXY planetBackground3;
PointXY planetBackground4;
void setup() {
arduboy.boot();
arduboy.setFrameRate(10);
arduboy.clear();
playerSprite = ardunautDown;
}
void loop() {
if (!arduboy.nextFrame()) {
return;
}
arduboy.clear();
Sprites::drawExternalMask(64,32,playerSprite,playerMask,playerFrame,0);
drawPlanetBackground();
handleInput();
arduboy.print(planetBackground2.y);
arduboy.display();
}
void playerAnimate() {
if (playerFrame < 3) {
++playerFrame;
}
else
playerFrame = 0;
}
void drawPlanetBackground(){
//Bottom right(player start)
for (int x = 0; x < worldWidth; x += tileWidth ) {
for (int y = 0; y < worldHeight; y += tileHeight) {
Sprites::drawSelfMasked(x + planetBackground1.x, y - planetBackground1.y, planetBackgroundTile1, 0 );
}
}
//Top right)
for (int x = 0; x < worldWidth; x += tileWidth ) {
for (int y = 0; y < worldHeight; y += tileHeight) {
Sprites::drawSelfMasked(x + planetBackground2.x, y - planetBackground2.y - 64, planetBackgroundTile1, 0 );
}
}
//Bottom left
for (int x = 0; x < worldWidth; x += tileWidth ) {
for (int y = 0; y < worldHeight; y += tileHeight) {
Sprites::drawSelfMasked(x + planetBackground3.x - 128, y - planetBackground3.y, planetBackgroundTile1, 0 );
}
}
//Top left
for (int x = 0; x < worldWidth; x += tileWidth ) {
for (int y = 0; y < worldHeight; y += tileHeight) {
Sprites::drawSelfMasked(x + planetBackground4.x - 128, y - planetBackground4.y - 64, planetBackgroundTile1, 0 );
}
}
//Bottom right limits and reset
if (planetBackground1.y < -64){
planetBackground1.y = 64;
}
if (planetBackground1.y > 64){
planetBackground1.y = -64;
}
if (planetBackground1.x < -128){
planetBackground1.x = 128;
}
if (planetBackground1.x > 128){
planetBackground1.x = -128;
}
//Top right limits and reset
if (planetBackground2.y < -128){
planetBackground2.y = 0;
}
if (planetBackground2.y > 0){
planetBackground2.y = -128;
}
if (planetBackground2.x < -128){
planetBackground2.x = 128;
}
if (planetBackground2.x > 128){
planetBackground2.x = -128;
}
//Bottom left limits and reset
if (planetBackground3.x < 0){
planetBackground3.x = 256;
}
if (planetBackground3.x > 256){
planetBackground3.x = 0;
}
if (planetBackground3.y < -64){
planetBackground3.y = 64;
}
if (planetBackground3.y > 64){
planetBackground3.y = -64;
}
//Top left limits and reset
if (planetBackground4.x < 0){
planetBackground4.x = 256;
}
if (planetBackground4.x > 256){
planetBackground4.x = 0;
}
if (planetBackground4.y < -128){
planetBackground4.y = 0;
}
if (planetBackground4.y > 0){
planetBackground4.y = -128;
}
}
void handleInput(){
if (arduboy.pressed(DOWN_BUTTON)){
playerSprite = ardunautDown;
playerMask = ardunautDownMask;
playerAnimate();
++planetBackground1.y;
++planetBackground2.y;
++planetBackground3.y;
++planetBackground4.y;
}
if (arduboy.pressed(UP_BUTTON)){
playerSprite = ardunautUp;
playerMask = ardunautDownMask;
playerAnimate();
--planetBackground1.y;
--planetBackground2.y;
--planetBackground3.y;
--planetBackground4.y;
}
if (arduboy.pressed(LEFT_BUTTON)){
playerSprite = ardunautLeft;
playerMask = ardunautRightMask;
playerAnimate();
++planetBackground1.x;
++planetBackground2.x;
++planetBackground3.x;
++planetBackground4.x;
}
if (arduboy.pressed(RIGHT_BUTTON)){
playerSprite = ardunautRight;
playerMask = ardunautRightMask;
playerAnimate();
--planetBackground1.x;
--planetBackground2.x;
--planetBackground3.x;
--planetBackground4.x;
}
if (!arduboy.pressed(UP_BUTTON) && !arduboy.pressed(DOWN_BUTTON) && !arduboy.pressed(LEFT_BUTTON) && !arduboy.pressed(RIGHT_BUTTON)) {
playerFrame = 0;
}
}