Another Arduboy Breakout Game

This was my first arduboy game that I created after learning and going through craits pong lessons. Thank you crait for getting me started!!!

3 Likes

Good Job!
Here are some tips I came up with that could help you save memory.

In this case you can probaly save a bunch of memory by switching to a uint8_t type, as most of your vars are in the range that uint8_t allows.

#include <stdint.h>
uint8_t gamestate = 0;
uint8_t justpressed = 0;
uint8_t ballx = 55;
uint8_t bally = 60;
uint8_t ballsize = 2;
uint8_t ballright = 1;
int8_t balldown = -1; // Negative ints need to be signed! (Fixed type decrelation)
uint8_t paddlewidth = 20;
uint8_t paddleheight = 2;
uint8_t  blockwidth = 7;
uint8_t  blockheight = 2;
uint8_t playerx = 54;
uint8_t  playery = 62;
uint8_t playerscore = 0;
uint8_t ballcount = 9;
uint8_t level = 1;
uint8_t block10[16] = {};
uint8_t block13[16] = {};
uint8_t block16[16] = {};
uint8_t blockout10[16] = {};
uint8_t blockout13[16] = {};
uint8_t blockout16[16] = {};
uint8_t blocksHit = 0;
uint8_t ballspeed = 27;       //Delay to slow down ball.  Higher=slower
uint8_t highscore = 0;
uint8_t nextnote = 0;
#define BLOCK16SPEED 27   // Delay value if none or 1st row hit
#define BLOCK13SPEED 20   // Delay value if 2nd row hit
#define BLOCK10SPEED 13   // Delay value if 3rd(Top) row hit
uint8_t  released = 0; // Ints of 0/1 are cheaper than bools!

Also, with arduboy2 you dont need justPressed anymore since arduboy2 can do that for you
just poll buttons after the frame check:

if (!arduboy.nextFrame) {return;}
arduboy.pollButtons()

Then call arduboy.justPressed just like you would with pressed!

If your code raises an error when setting a uint8_t var, change it to uint16_t and it should be fine.

Wow! Thank you for the great tips. I had no idea what uint8_t does but have seen that used in other arduboy games. I will research and use next time. Also, had no idea with justpressed when using arduboy2 library. Great tips!

They do, but there is no sint8_t, it’s just int8_t.

Otherwise it’s correct as far as I can tell without much digging.

I think this is the tutorial’s fault.

We really need to either get a mod to go in and update it or organise a new one.


It’s to do with the size of the type.

There’s a good reference here:
http://en.cppreference.com/w/cpp/types/integer

Basically on the Arduboy int is equivalent to int16_t, which is 16 bits/2 bytes wide, and uint8_t & int8_t are 8 bits/1 byte wide.
Using only 1 byte means using both less memory and fewer processor instructions.


If you haven’t learnt binary yet, this is my favourite tutorial for hex and binary:
http://www.mathsisfun.com/binary-decimal-hexadecimal.html