Skip to content

Instantly share code, notes, and snippets.

@pompopo
Created November 20, 2016 13:17
Show Gist options
  • Save pompopo/fbbf3a4c2eb8ca5ef86b7977a8743136 to your computer and use it in GitHub Desktop.
Save pompopo/fbbf3a4c2eb8ca5ef86b7977a8743136 to your computer and use it in GitHub Desktop.
#include "Arduboy.h"
Arduboy arduboy;
int x = 0;
int y = WIDTH / 2;
float dx = 0;
float dy = 0;
float g = 3;
void setup() {
arduboy.begin();
arduboy.setFrameRate(30);
x = 0;
y = 0;
}
void loop() {
if (!(arduboy.nextFrame())) {
return;
}
if (arduboy.pressed(RIGHT_BUTTON)) {
dx++;
}
if (arduboy.pressed(LEFT_BUTTON)) {
dx--;
}
if (arduboy.pressed(UP_BUTTON)) {
g -= 0.1;
}
if (arduboy.pressed(DOWN_BUTTON)) {
g += 0.1;
}
x += dx;
if (x < 0) {
x = 0;
dx = -dx;
} else if (x > WIDTH - 2) {
x = WIDTH -2;
dx = -dx;
}
y += dy;
if (y < 0) {
y = 0;
dy = -dy;
} else if (y > HEIGHT - 10) {
y = HEIGHT - 10;
dy = -dy;
}
dy += g;
arduboy.clear();
arduboy.drawRect(x, y, 2, 2, 1);
arduboy.display();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment