- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
int ball_x = LCDWIDTH/2;
int ball_y = LCDHEIGHT/2;
int ball_vx = 1;
int ball_vy = 1;
int ball_size = 6;
void setup() {
// put your setup code here, to run once:
gb.begin();
gb.titleScreen(F("Ball Control"));
}
void loop() {
// put your main code here, to run repeatedly:
if(gb.update());{
if(gb.buttons.pressed(BTN_RIGHT)){
ball_x = ball_x = ball_vx;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_LEFT)){
ball_x = ball_x - ball_vx;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_DOWN)){
ball_y = ball_y + ball_vy;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_UP)){
ball_y = ball_y + ball_vy;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_A)){
gb.sound.playOK();
}
if(gb.buttons.pressed(BTN_B)){
gb.sound.playCancel();
}
if(gb.buttons.pressed(BTN_C)){
gb.titleScreen(F("Ball Control"));
}
if(ball_x < 0){
ball_x = 0;
}
if((ball_x + ball_size) > LCDWIDTH){
ball_x = LCDWIDTH - ball_size;
}
if(ball_y < 0){
ball_y = 0;
}
if((ball_y + ball_size) > LCDHEIGHT){
ball_y = LCDHEIGHT - ball_size;
}
gb.display.fillRect(ball_x, ball_y, ball_size, ball_size);
}
}
also, I was fiddling around with the code and changed the
- Code: Select all
if(gb.buttons.repeat(BTN_RIGHT,2)){
ball_x = ball_x + ball_vx;
gb.sound.playTick();
}
if(gb.buttons.repeat(BTN_LEFT,2)){
ball_x = ball_x - ball_vx;
gb.sound.playTick();
}
if(gb.buttons.repeat(BTN_DOWN,2)){
ball_y = ball_y + ball_vy;
gb.sound.playTick();
}
if(gb.buttons.repeat(BTN_UP,2)){
ball_y = ball_y - ball_vy;
gb.sound.playTick();
}
to
- Code: Select all
if(gb.buttons.pressed(BTN_RIGHT)){
ball_x = ball_x = ball_vx;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_LEFT)){
ball_x = ball_x - ball_vx;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_DOWN)){
ball_y = ball_y + ball_vy;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_UP)){
ball_y = ball_y + ball_vy;
gb.sound.playTick();
}
but that didnt change anything
I know it's just an example, but if i did something wrong I would like to know so that I do not do it again when I am trying to make a real game