Skip to content

Instantly share code, notes, and snippets.

@Cric75
Last active July 19, 2021 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cric75/7cadd44e74d9247c80d9fd32322e9b9e to your computer and use it in GitHub Desktop.
Save Cric75/7cadd44e74d9247c80d9fd32322e9b9e to your computer and use it in GitHub Desktop.
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