Skip to content

Instantly share code, notes, and snippets.

@Cric75
Last active Jul 19, 2021
Embed
What would you like to do?
Moving_Ball
#include <Gamebuino-Meta.h>
int positionX = 32;
int speedX = 1;
void setup() {
gb.begin();
}
void loop() {
while (!gb.update());
gb.display.clear();
positionX = positionX + speedX;
if (positionX == gb.display.width()) {
positionX = 32;
}
if (gb.buttons.pressed(BUTTON_UP) && speedX <10) {
speedX += 1;
positionX = positionX + speedX;
gb.sound.playTick();
}
if (gb.buttons.pressed(BUTTON_DOWN) && speedX >1) {
speedX -= 1;
positionX = positionX + speedX;
gb.sound.playTick();
}
gb.display.print("PositionX : ");
gb.display.print(positionX);
gb.display.print("\nSpeedX : ");
gb.display.print(speedX);
gb.display.fillRect(positionX, 32, 4, 4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment